Society of Robots - Robot Forum

Electronics => Electronics => Topic started by: freddie00 on October 12, 2011, 12:15:26 AM

Title: Servo Motors and PWM
Post by: freddie00 on October 12, 2011, 12:15:26 AM
So this is probably a really easy question for someone.

I am just starting to work with servo motors, so I am trying to work up to doing PWM on a PIC microcontroller.  I attached my servos, to a signal generator, where 1.5ms was suppose to correspond to the center position, then when I increasing the duty cycle the motor rotated clockwise, if I trying to reduce the duty cycle it would not move counter clockwise.  It would just move along clockwise direction as duty cycle varied, but never move back from the furthest point it had moved.

Is this because my frequency is out of wack or something else?

Thanks.
Title: Re: Servo Motors and PWM
Post by: newInRobotics on October 12, 2011, 12:45:58 AM
Well, frequency should be 50Hz however, it would not affect servo too much if it gone up or down a bit.
Title: Re: Servo Motors and PWM
Post by: Soeren on October 12, 2011, 08:05:58 AM
Hi,

I am just starting to work with servo motors, so I am trying to work up to doing PWM on a PIC microcontroller.
Not that it matters for the function, but servo signals are not PWM but rather PDM (Pulse Duration Modulation).


I attached my servos, to a signal generator, where 1.5ms was suppose to correspond to the center position, then when I increasing the duty cycle the motor rotated clockwise, if I trying to reduce the duty cycle it would not move counter clockwise.  It would just move along clockwise direction as duty cycle varied, but never move back from the furthest point it had moved.

Is this because my frequency is out of wack or something else?
Hard to say from only a (loose) description.

Is it a modified servo?
The servo itself may be at fault - have you checked this with another servo?

The timing of the signals, which you probably know, are pulses of 1ms to 2ms with a repetition rate of 20ms.
As newInRobotics stated, the repetition rate can differ a bit without causing any problems, as long as it is stable.
The pulses on the other hand must follow the 1..2ms - do you have access to an oscilloscope to test the duration of the pulses?

If you have only one servo and no 'scope, consider building a simple servo tester with a 555.

If you have a crystal earphone, a crystal microphone capsule or a piezo disc, you can use that for listening to the signal out of the PIC and compare it with a signal generated on your PC (adjust until there's no beat note, like when tuning a guitar) this will tell you the pulse repetition rate.

Posting the bit of the code you use to generate the pulse timing may be an option as well.
Title: Re: Servo Motors and PWM
Post by: freddie00 on October 12, 2011, 10:06:02 AM
The servo is a futaba S3114 with torque: 21 oz-in (1.5 kg/cm)  and speed: 0.10 sec/60°. The servo is not modified.  I took the servo to a hobby shop and the guy tested it with his RC controller, so I know that it works fine.

The function generator has a very simple command to set the pulse length, which I set to 1.5 ms, at a frequency of 20Hz, then I just varied the duty cycle.  I did not observe on oscilloscope but I have access to one.  I'm sure I would see exactly a 1.5ms pulse if I observed with oscilloscope.

The pulse is generated from a function generator, no coding here, I just want to use this to understand what code I must write.  THe function generator allows you to enter, amplitute, length of pulse, frequency, duty cycle... I should be able to simulate everything with this?

THe part about the pulse repetition rate sounds interesting because I do know how to tune a guitar, but I still dont know how it applies to what I'm doing.  I'm not actually using the PIC to control the servo yet.  I am using a function generator to learn how PWM/PDM works.
Title: Re: Servo Motors and PWM
Post by: waltr on October 12, 2011, 06:56:00 PM
Just on the off chance:
Did you connect ground and +5 Volts to the servo?
Title: Re: Servo Motors and PWM
Post by: freddie00 on October 13, 2011, 10:34:48 AM
yes
Title: Re: Servo Motors and PWM
Post by: waltr on October 13, 2011, 07:46:33 PM
Does the function generator output a 0 to 5V signal?
Is there a amplitude and offset adjustments correct?
Is the pulse (1.5msec) positive going?
Do use an O'scope to check the signal.
Title: Re: Servo Motors and PWM
Post by: freddie00 on October 14, 2011, 03:09:55 AM
The signal was 0 - 5V.  There is an amplitude adjustment.  What do you mean by offset adjustment, and what will be the outcome of adjusting it?  The pulse was 1.5ms, positive going.  Then I varied the duty cycle, simply by selecting the duty cycle adjustment knob, and increasing, then the servo would move clockwise, but whenever varying the duty cycle the opposite direction, the servo did not move counter clockwise?

I didnt use an oscilloscope, I trusted the function generator.  I can use one next time.
Title: Re: Servo Motors and PWM
Post by: Soeren on October 14, 2011, 05:07:34 PM
Hi,

The function generator has a very simple command to set the pulse length, which I set to 1.5 ms, at a frequency of 20Hz,
It's supposed to be 20ms, not 20Hz
20ms equates to 50Hz


then I just varied the duty cycle.  I did not observe on oscilloscope but I have access to one.  I'm sure I would see exactly a 1.5ms pulse if I observed with oscilloscope.
I'm sure it would be at least somewhere near the 1.5ms when you set it (don't know the precision of what you used), but you "varied the duty cycle" '(a good reason why people should realize that PWM and PDM is different things).
If you wanna view the signal as if it was (a small part) a PWM signal, you need to realize that the allowable range of duty cycle is only 5% to 10% of the 20ms period (with 7.5% being the center setting), so you need to take that into account when setting it.
Better 'scope it though.

To set/check the repeat rate of the pulse, listen to it together with a 50Hz signal generated on your computer - listen for the beat note and adjust until zero (or at least very slow) beating - as said, like tuning a guitar (unless you use one of the guitar tuners that just show you which way to tune for any given string).

'If you haven't got the means to make a 50Hz signal for comparison, I can make you a wav-file.
A continuous tone compresses really well sound file - a 100MB file can be packed (zipped) to a little over 200kB).