2
Answers 2
-
- RAM is located from $0000 to $00FF, this allows 256 bytes of RAM. This
area is also where the stack must be (usually starting at $00FF and growing
downwards. It is possible to write to EEPROM, but this
is a fairly stupid thing to do for variable storage because is takes very
long to write and takes much more energy from the battery than writing to
RAM.
- A double byte variable should store the low order byte in the high
memory address and the high order byte in the low memory address. This
ordering is to facilitate instructions that deal with transferring
variables between memory and double byte registers like LDD, STD, LDX, and
LDY.
- Special Functions Registers are located from $1000 to $103F.
$1000 -> PORTA
$1003 -> PORTC
$1004 -> PORTB
$1008 -> PORTD
$100A -> PORTE
These are the input and output capabilities of a Miniboard. When you write
a value to a port, that byte is asserted on the pins of the port. When you
read a value from these memory locations, you are acquiring what ever
values are asserted on the port pins from external sources.
- The two cases show the use of immediate and indexed addressing modes.
The LDX #$1000 instruction (in the indexed addressing mode program) cost 3
bytes of extra code space not present in immediate addressing mode program.
However, each 'LDX immediate' instruction is 3 bytes long where as each
'LDX indexed' is two bytes long. Since the program uses 5 LDX instructions
the indexed program saves 5 bytes here over the immediate program. The cost
of 3 bytes is more than made up by the savings of 5 bytes. Considering time
efficiency, The indexed program has the extra 'LDX #$1000' instruction
which takes 3 cycles. Then the five 'LDX indexed' instructions compare to
the 5 'LDX immediate' instructions by being 5 cycles to 3 cycles. So the
indexed program will take 3 cycles + 5 * 2 cycles = 13 cycles longer to
complete than the immediate program. The indexed program is more space
efficient and less time efficient.
3
Answers 3
- After power up and after the reset button is pressed, the Miniboard
looks to memory locations $FFFE and $FFFF to find a reset vector. The
contents of these memory locations will be used as the next PC location. A
wise Miniboard programmer will store the value $F800 at memory locations
$FFFE and $FFFF because this is the beginning of EEPROM memory. So then
after power up or reset the Miniboard would begin executing instructions at
the beginning of EEPROM memory.
- The special Function Register DDRC at memory location $1007. The 8
bits of DDRC define the 8 pins of Port C as being either an input or an
output pin.
- 0 = input
- 1 = output
- The programmer. Because the DDRC register can be altered at any time.
- There is no exit or halt or shutdown instruction in the 6811
instruction set. No program should ever exit. Always keep an infinite loop
going somewhere in your program.
- The program starts over with all of RAM preserved. In this program
there should be no noticeable effect.
- The program starts over with all of RAM wiped out. This program should
probably recover from a power interrupt and continue to operate.
- Yes this program is still written as an infinite loop like all
Miniboard programs should be. But now the infinite loop is a foreground
task with all the functionality of this program occurring as a background
task. As a programmer, you would now be free to add tasks in the foreground
(and more in the background).
4
Answers 4
- An Output Compare Timer would be best suited to keeping track of the
passage of seconds. The Real Time interrupt does not count in increments
that can add up to an even second. An Input Capture Timer could also be
used but the task fits better with the philosophy of an Output compare
timer... the Input Capture is usually thought of as monitoring external
events. A Pulse Accumulator is not triggered until some external event
occurs and so are inappropriate to counting time.
- Yes, surprisingly. If you use a delay loop and calculate how long it
must waste time so that you will have just exactly the time left over you
need to increment a counter and display it on PORTC, then you can display
the passage of seconds on PORTC. To perform the calculations you need to
know your clock frequency (8MHz on a Miniboard) and know the amount of
instruction cycles your increment count and display program takes up. Then
you can calculate the amount of time in a second left over and determine
the number of cycles to waste. This approach however, is dumb.
- A Miniboard can be configured to have up to 5 Output Compare timers.
- One interrupt is required: one of OC[1:5]. The OC interrupts is used
to mark when the next second occurs. The TOI interrupt is used to handle
anything that may need to happen on a main system timer overflow, but in
this program it is not needed.
5
Answers 5
- One argument needs to be passed on the stack. It is a double byte value
representing which port you wish to read a value from ( 0 -> 8). The low
order byte must be pushed onto the stack first, followed by the high order
byte. (NOTE: the high order byte will never contain any information since
the port number ( 0 -> 8) can always be represented in just the low order
byte alone. But the minilib analog() function call expects to have a double
byte value on the stack so you cannot leave off the useless high order
byte. The minilib was built for use with a C compiler which treats all
variables as double bytes.)
- The Minilib analog() call converts one channel four times.
- It is very near the top, just following the "start" label.
- An analog conversion takes 128 cycles. The code in the analog() call
also takes up some cycles and you can count as well as I.
- Two places really; the most obvious in Accumulator B. But the values in
ADR[1:4] will stay valid and may be read any time before another analog
conversion.
6
Answers 6
- This program would be completely different depending on if you
implemented stepper motors or DC motors. In the simplest case, DC motors
would be on forward when ever the green LED is on and on reverse whenever
the red LED is on. However, It is wise to Pulse Width Modulate the signal
to DC motors so there would be continuos interactions with the DC motors.
Stepper motors must be continuously stepped in order to stay in motion. So
a wise DC motor program and a Stepper motor program would both need very
extensive (and very different) code routines to implement them.
- If a motor stalls it begins to draw very high currents. If you are
using DC motors, this current will be pulled right out of your motor driver
chips. If you are using stepper motors you have a choice about how to wire
them that would allow you to use a separate power line from the minibord's
+5 volt rail. (perhaps even a separate power source). In that case the
extra current would come directly from the power supply and not through the
Miniboard. If a stalled motor tries to draw a high current through the
motor driver chips, they will probably give up the ghost in a puff of smoke
and leave you with a power to ground short in your Miniboard. That is very
bad! The motor driver chips are rated at .6 Amps max so if you place a 1/2
amp fuse in line with the motors you will be protected. If you get another
two L293D Motor driver chips, you could soldier them down directly on top
of the two on the Miniboard sort'of piggy back style. With the two chips in
place, the pin out is still the same, the voltage is still the same, but
now the two chips can carry twice as much current as a single chip.
- In the minilib, Pulse Width Modulation is already implemented and you
can make a call to the motor() function to set a particular motor at a
particular speed. Also in the minilib, there is a sleep function called
msleep() that will wait for the specific number of milliseconds.
ieeecs@hal.elee.calpoly.edu
Back to Table of Contents