#rem
VexSim.bas: for the 08M at 4 MHz
Simulates the 4 servo/2 switch PPM frame of the Vex transmitter
Servos start at neutral position. One by one, they move from
lock to lock, then back to neutral.
The switch outputs alternate between min and max at each servo change.
Normal polarity frame on out2 (leg 5)
Inverted polarity frame on out4 (leg 3)
tjl Oct 14 07
#endrem
symbol Sync = w6
symbol Phase = b0
symbol Active = b1
symbol ServLen = b2
symbol Sw1 = b3
symbol Sw2 = b4
symbol Length = b5
symbol ServNum = b6
symbol NormPin = 2
symbol InvPin = 4
Main:
setfreq m4
dirs = %00010100
ServLen = 100
Sw1 = 50
Sw2 = 150
Active = 0
Phase = 0
ServNum = 0
do
; Send sync pulse: length set to make total frame time 20 mSec
Sync = 1150 - ServLen
pulsout InvPin,Sync
for ServNum = 0 to 3
gosub PulseServos
next
; Switch 1
pulsout NormPin,50
pulsout InvPin,Sw1
; Switch 2
pulsout NormPin,50
pulsout InvPin,Sw2
; End pulse
pulsout NormPin,50
gosub AdjServo
loop
end
PulseServos:
pulsout NormPin,50
if Active = ServNum then
Length = ServLen
else
Length = 100
endif
pulsout InvPin,Length
return
AdjServo:
; Servo starts at neutral, moves to min,
; moves to max, then to back to neutral
if Phase = 0 then
if ServLen > 50 then
dec ServLen
else
Phase = 1
inc ServLen
endif
elseif Phase = 1 then
if ServLen < 150 then
inc ServLen
else
Phase = 2
dec ServLen
endif
else ; Phase = 2
if ServLen > 100 then
dec ServLen
else
Phase = 0
Sw1 = 200 - Sw1
Sw2 = 200 - Sw2
Active = Active + 1 % 4
endif
endif
return