Two things of note: 1) We use a value of 2048 for the
frame as our effective rate is 9.765 microseconds, and 2)
By devoting the eight contiguous bits for the servos, the
control and updating of outputs is made very simple. Here’s
how it works:
Check_Servo_Timer:
TEST svoPin
SNZ
JMP ISR_Exit
DEC svoTimer
SZ
JMP ISR_Exit
Reload_Servo_Timer:
INC svoIdx
CLRB svoidx.3
MOV W, #pos
ADD W, svoIdx
MOV FSR, W
MOV svoTimer, IND
Select_Next_Servo:
CLC
RL svoPin
Refesh_Servo_Outs:
MOV ServoCtrl, svoPin
ISR_Exit:
BANK 0
ENDASM
RETURNINT
The TEST instruction lets us check a variable for zero —
so we look at the active servo pin control value, svoPin. If
no servos are running, then it will be zero and the routine
will exit. Otherwise, we can decrement the timer for the
servo that is presently running.
When the timer expires, we increment the servo
index pointer (keeping it in the range 0.. 7) and reload the
timer for the newly-selected servo. By doing a left
shift (RL) on the servo control value, the next servo is
activated when we write that value to the physical control
■ FIGURE 4. Servo pulse outputs.
22
May 2007
port (RB, in this case). It is necessary to clear the carry bit
before the RL instruction so that previous servo ports get
turned off.
Whew ... we have just done a whole lot of work in
the ISR. The payoff? Look how simple the foreground
program is:
Start:
Outs = %00000000
FOR idx = 0 TO 7
pos(idx) = 154
NEXT
TX = 1
DELAY_MS 2
Main:
IF armed = No THEN Main
Outs = RX_BYTE
FOR idx = 0 TO 7
IF armed = Yes THEN EXIT
pos(idx) = RX_BYTE
NEXT
GOTO Main
At Start, we clear the outputs and center the servos,
set the TX pin and let it idle so that the receiver doesn’t get
any junk, and then wait for bytes to come in. Again, we
don’t want to receive anything unless there has been a
valid idle period. When this has happened, the armed bit
will be set. Note that the servo position values are
received in a loop with a recheck of the armed
flag between each; what this does is allow the program
to escape from that loop if the packet transmission gets
interrupted.
CONSTRUCTION NOTES
As with the past few projects, I used ExpressSCH for
the schematic and created the board with its companion,
ExpressPCB. Please, please, please ... don’t think you
can do boards manually anymore. ExpressSCH will let
■ FIGURE 5. Animatronics controller PCB.