I’m having difficulty with the program. I added some simple servo pulse commands to the main loop and it’s acting up. Here is the code.
[code]ONINTERRUPT WKPINT_3,handle_irpd
PMR5.bit3 = 1
TMA=4 ;increments on clock/256
ENABLE WKPINT_3
lasttime var long
currenttime var long
datacount var byte
irpd_data var word
command var byte
address var byte
ServoP var word
lasttime = -1 ;indicate next data should be a startpulse
low 15
main
pulsout 15,servop
pause 20
if(command<>0xFF)then
’ serout S_OUT,i115200,"Address = ",hex address,13,"Command = ",hex command,13]
if (command = 0) then
servop = 4000
endif
if (command = 1) then
servop = 3000
endif
if (command = 2) then
servop = 2000
endif
Command=0xFF
endif
goto main
handle_irpd
currenttime=TCA
if(lasttime<0)then
datacount=0
lasttime=currenttime
else
datacount=datacount+1
if(currenttime<lasttime)then
lasttime=lasttime-256
endif
lasttime=currenttime-lasttime
irpd_data=irpd_data>>1
if(lasttime>175 AND lasttime<195)then
irpd_data=0
elseif(lasttime>100 and lasttime<120)
irpd_data.bit10=1
elseif(lasttime>65 and lasttime<85)
irpd_data.bit10=0
endif
if(datacount=12)then
lasttime=-1
command = irpd_data&0x7F
address = irpd_data>>7
else
lasttime = currenttime
endif
endif
resume[/code]
It apears to work at first. When I press the [2] button it moves to the center, when I press the [1] button it moves to the +45° position, when I press the [3] button it moves to the -45° position. It does this fine for a while then only the [1] button will move it to the correct place, and the one or both of the other two will not work. I also notice some jitter in the servo when pressing and holding the buttons.
Maybe I’m doing something wrong.