Newbie servo control question
Daniel Lloyd-Wood
Posts: 14
Hello,
I've got a PE USB kit. I've been through all the labs in the PE Fundamentals Book and am now stepping out on my own and starting to play around. I am currently trying to control a servo with the Propeller. The code I'm using is pinched for the Fundamentals book and is as follows:
The servo I am using is the Hitec HS-65MG:
-90o - 600 usec
-45o - 1050 usec
0o - 1500 usec
45o - 1950 usec
90o - 2400 usec
The code runs fine. The problem is even though the pulse is sent continuously once the repeat loop is entered the sero only moves slightly towrards centre then stops. I have to repeat the program again to get the servo to move a bit further. I have to keep doing this until the servo reaches centre and then it stays in the centre as it should. Is it the servo causing this or something I've missed in the code?
Thanks,
Dan
I've got a PE USB kit. I've been through all the labs in the PE Fundamentals Book and am now stepping out on my own and starting to play around. I am currently trying to control a servo with the Propeller. The code I'm using is pinched for the Fundamentals book and is as follows:
CON _clkmode = xtal1 + pll16x ' System clock → 80 MHz _xinfreq = 5_000_000 PUB TestPwm | tc, tHa, t ctra[noparse][[/noparse]30..26] := %00100 ' Configure Counter A to NCO ctra[noparse][[/noparse]8..0] := 24 frqa := 1 dira[noparse][[/noparse]24]~~ tC := 1_600_000 ' Set up cycle time for 20ms tHa := 120_000 ' Set up high time for 1.5ms t := cnt ' Mark counter time repeat ' Repeat PWM signal phsa := -tHa ' Set up the pulse t += tC ' Calculate next cycle repeat waitcnt(t) ' Wait for next cycle
The servo I am using is the Hitec HS-65MG:
-90o - 600 usec
-45o - 1050 usec
0o - 1500 usec
45o - 1950 usec
90o - 2400 usec
The code runs fine. The problem is even though the pulse is sent continuously once the repeat loop is entered the sero only moves slightly towrards centre then stops. I have to repeat the program again to get the servo to move a bit further. I have to keep doing this until the servo reaches centre and then it stays in the centre as it should. Is it the servo causing this or something I've missed in the code?
Thanks,
Dan
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Airspace V - international hangar flying!
www.airspace-v.com/ggadgets for tools & toys
I found these details about the servo:
Required Pulse: 3-5 Volt Peak to Peak Square Wave - Do you think this means it requires a 3V low, 5V high signal or anywhere between 3V-5V is counted as high and the low is 0V?
'3-5 V Peak to Peak Square Wave' means that the difference between high level and low level should be 3 V to 5 V. As a MOS circuit the prop should be able to deliver 3 V peak to peak output when powered with 3.3 V if there is no load at the output. The transistor in the prop driving the pin, the connectino to the servo, as well as the input of the servo have certain resistances which form a voltage divider. If you can get an oscilloscope watch the signal. Or just give it a try and build a simple level converter from a few discrete parts.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Airspace V - international hangar flying!
www.airspace-v.com/ggadgets for tools & toys
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ D Rat
Dave Ratcliff· N6YEE
I don't think that is a answer you are looking for, but it may work.
I'm not too familiar with CTRs, I usually end up programming 20 lines of code that CTR could do in 3, but then at least I understand exactly what is happening. So I'm sure someone else can give a little more insightful input.
The fact that the servo is moving at all would make me think that the pulse's voltage is high enough. And an oscilloscope would help the process out a bit to make sure that the output frequencies are good.
I'm not familiar with the operation of the timers, so I can't comment on that part.
Jason
I tried your code, and it is supplying the correct pulse. (See attached image)
As far as the 3V to 5V, I believe it has been answered, but it simply means that the Servo will accept a signal as a logic level "1" or HIGH from 3V to 5V.
This does not mean that the servo itself should be powered from a 3V to 5V supply. According to your data, it will need at least 4.8V.
The Propeller provides a 3.3V output under the load conditions that would be demanded of it from a servo.
As others have asked, what does your power supply to the Servo(s) look like and are you sharing the Ground connection (VSS) between the Propeller and your Servo?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Thanks for all the suggestions. I've tried a few things out and it looks like the power drain caused by the·servo operating was the culprit. This·was reseting the Prop. I've set up a separate power supply for the servo and everything·is working fine now.
Thanks again,
Dan·