Giving out pulses using propeller chip
prabhat
Posts: 4
Hi,
I am trying to program a robot with servos on its joints which are controlled by a propeller. Its a HS 422 servo. It has a neutral at 1.5ms pulse. I am trying to give this pulse using the clkfreq and waitcnt but never getting it right. The servo who run to an extreme and hit a mechanical limit. I am not really sure if the pulses i am giving are of the right duration. 1.5ms every 20ms. the following is the code I used. Please help
CON
_clkmode = xtal1 + pll16x ' Feedback and PLL multiplier
_xinfreq = 5_000_000
Led = 1
PUB LedOnOff
dira[noparse][[/noparse]Led] := 1
repeat
outa[noparse][[/noparse]Led] := 1
waitcnt(clkfreq/667 + cnt)
outa[noparse][[/noparse]Led] := 0
waitcnt(clkfreq/50 + cnt)
Is there a problem with the code? I tried the servo with Basic stamp and that works fine.
Thank you in advance
Prabhat
I am trying to program a robot with servos on its joints which are controlled by a propeller. Its a HS 422 servo. It has a neutral at 1.5ms pulse. I am trying to give this pulse using the clkfreq and waitcnt but never getting it right. The servo who run to an extreme and hit a mechanical limit. I am not really sure if the pulses i am giving are of the right duration. 1.5ms every 20ms. the following is the code I used. Please help
CON
_clkmode = xtal1 + pll16x ' Feedback and PLL multiplier
_xinfreq = 5_000_000
Led = 1
PUB LedOnOff
dira[noparse][[/noparse]Led] := 1
repeat
outa[noparse][[/noparse]Led] := 1
waitcnt(clkfreq/667 + cnt)
outa[noparse][[/noparse]Led] := 0
waitcnt(clkfreq/50 + cnt)
Is there a problem with the code? I tried the servo with Basic stamp and that works fine.
Thank you in advance
Prabhat
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
Post Edited (JonnyMac) : 8/4/2010 8:14:29 PM GMT
It does look like your code is wrong.· Maybe :
Might be a simple way to do it.· Note the indentation!
edit - or this is a better way, as it provides a syncronised 1.5ms pulse - i.e. it begins every 20ms, rather than every 21.5ms as in previous loop.· (look at page 220 in the propeller manual)
James
Post Edited (Javalin) : 8/4/2010 8:25:03 PM GMT
james
waitcnt((clkfreq/1_000_000) * 1500 + cnt) is easier to understand (in my opinion) and will work at any _clkmode or _xinfreq without modification.
Rich H
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Simple Servo Tester, a kit from Gadget Gangster.
but requires the delay to be calculated each and every time you run the line.
>will work at any _clkmode or _xinfreq without modification.
so will mine.
I'll run up the code on my dev board tonight & put the o'scope to work on it.
Cheers,
James
Attachments to this post show the 1.5ms pulse (1ms per division) and the 20ms gap between the pulses (5ms per div).
Cheers,
James