Picaxe serial servo controller solved

profmason

Member
I fought with the blocking serin problem for a long time for servo controllers. Finally there is a simple solution for making a picaxe based serial servo controller.(08m in this case) Use an interrupt and trigger the interrupt from your serial source as part of the stream. This idea is really simple, but I hadn't seen it written up before.
<code>
'Serial servo program
main:
setint %00010000,%00010000 'Set an Interrupt on pin 4 to look for the pin to go high
servo 2,b0 'update the servos
servo 1,b1
pause 20
goto main

interrupt: 'If the interrupt goes high this means that there is serial data waiting
serin 4,N2400,b0,b1 'Get the bytes of serial data
return
</code>

There are several limitations. I can only seem to make it work for 2 servos and the maximum update rate is around 10Hz.

When transmitting from the pc, I start each stream with a %00000001 to trigger the interrupt and then send ascii values which are written to the servos.

For more info and video of servos under control from the serial port see:
http://profmason.com/?p=766

Now, how to improve this? Would it be better to pull each servo low when the interrupt is called? Ideas on how to get more servos. Any experience with servos at 8mhz on an 08m?Worth trying, but I am for bed.

have fun,
mmason
 

Technical

Technical Support
Staff member
As a starter you are issuing a new servo command every 20ms, which is bad practice. You only need to issue it once as below, and can also take setint out of the loop.

Code:
'Serial servo program
init:
setint %00010000,%00010000 'Set an Interrupt on pin 4 to look for the pin to go high

main:
goto main

interrupt: 'If the interrupt goes high this means that there is serial data waiting
serin 4,N2400,b0,b1 'Get the bytes of serial data
servo 2,b0 'update the servos
servo 1,b1
setint %00010000,%00010000 'Set an Interrupt on pin 4 to look for the pin to go high
return
or did you mean pulsout?

Code:
'Serial servo program
init:
setint %00010000,%00010000 'Set an Interrupt on pin 4 to look for the pin to go high

main:
pulsout 2,b0 'update the servos
pulsout 1,b1
pause 20
goto main

interrupt: 'If the interrupt goes high this means that there is serial data waiting
serin 4,N2400,b0,b1 'Get the bytes of serial data
setint %00010000,%00010000 'Set an Interrupt on pin 4 to look for the pin to go high
return
 

profmason

Member
Thanks!

That improves things quite a bit!

It makes sense to only set the interrupt when it has been triggered.. I guess the servo command doesn't need to be refreshed once it is initialized.

Thanks!
mmason
 
Top