This is old news for most of you, but not everyone received the memo.

There is a maximum safe pulse repetition rate of approximately 40 pulses per second for the most common PWM servos. The uppper limit arises because of the pulse stretcher circuitry in the servo. Pulse width is between 1 and 2 milliseconds, and the time between pulses is on the order of 20 milliseconds. The designers of the servos improve the performance of the servo by using a pulse stretcher circuit to energize the servo motor for a major portion of the available time. To try to squeeze all of the response of the servo into 1-2 milliseconds would put the motor, the power electronics, and the power supply at an electrical disadvantage, so a pulse stretcher circuit is used to spread the response out over the available time between pulses.

The servo motor is driven by 4 electronic switches in what is called an H-bridge configuration. Only two of the switches should be turned on at the same time. Depending on which pair of the 4 switches is turned on, the servo electronics can drive the motor forward or backward. The pulse stretcher stretches the 1-2 millisecond pulse into a power pulse applied to the motor of up to approximately 20 milliseconds.

To simplify the electronics, the designer assumed a maximum pulse rate of around 40 to 50 pulses per second. Very bad things happen if you exceed this rate. The source of the problem is the pulse stretcher. If the servo electronics receives a new pulse before the pulse stretcher completes its response to the previous pulse, it will try to apply both pulses at once. If the two pulses represent motion in opposite directions, there is big trouble: all 4 electronic switches will be turned on at the same time, creating a direct short circuit on the power supply. Besides drawing massive amounts of current through the power electronics in the servo, this will also collapse the voltage of the power supply and will reboot the CPU.

I learned about pulse stretchers the hard way. When I was starting out with my first board, I knew that the servo PWM pulse rate was around 50 pulses per second. I reasoned that if 50 pulses per second was good, 100 pulses was better. Not so. I almost fried my first board.

Since then I limit my servo PWM pulse rate to around 40 pulses per second. I never have any problems with interference from servo pulses with any of my firmware, on either of my two boards. Servo operation is smooth as silk, and analog to digital conversion is noise free.

best regards,
Bill Premerlani

Views: 1484

Reply to This

Replies to This Discussion

Bill - I have used 50 Hz with fine results from the beginning. It seems 100% A OK. My question for you is do you know of a lower limit? For example, Is 10 Hz update rate doable for servos? I don't plan to ever go that slow but would like to know if you have any insight. Thanks, Dean G
I tested various rates, ~5Hz makes my servo to move in visible steps, each signal moves servo a little bit to correct position, but servo motor stops after while (not working if signal's not coming). A force applied to servo lever makes it easier to move away from target servo rotation when delays among signals are big.
But this behavior may be servo-specific, not a rule. To be safe, 50Hz "standard" should be used.
Dean,

I have used both 40 Hz and 50 Hz pulse rate. I have tried going lower than 40 Hz. I do not recommend it. There are not any problems with the power supply, but the servos become sluggish. I never went has low as 10 Hz, but at that rate the servos would crawl.

There are actually two frequencies involved. I am not sure what the standard terms for them are, but I will call them the pulse rate and the update rate.

The pulse rate is how often pulses are sent to the servo. Both the servo speed and average torque increase with pulse rate. So its best to take full advantage of the maximum pulse rate that the servos will take, which is around 50 Hz. It is generally possible to achieve a 50 Hz pulse rate without making excessive computational demands on the CPU.

The update rate is how often the pulse width is adjusted. Update rate affects the stability and smoothness of feedback control. Update rate does not have to be the same as pulse rate. There is no point in having an update rate higher than the pulse rate, but you can go slower. For example, if you use a 10 Hz update rate and a 50 Hz pulse rate, you will send out 5 identical pulses in a row before changing to a new value. The lower limit on update rate depends on your control approach and the dynamics of your plane. The higher the update rate the better, so you should also have a 50 Hz update rate if you can. However, if your feedback control computations make excessive computational demands on the CPU, you have the option of lowering the update rate.

The experience that I have had with the various algorithms I have tried out and the two boards that I have used is that my boards have more than enough CPU power to execute my control algorithms at 50 Hz.

best regards,
Bill Premerlani
Have you ever test servo with more then 50 Hz rate ?
Loyd,
I tested at 100 Hz, that shorts the power supply. I have not tested in the range between 50 Hz and 100 Hz.
It is true both for analogue, and for digital servos?
Victor,
Good question. I have not tested digital servos, so I do not know.
Bill
Most digital servos can handle higher rates since they close the position loop independently of the input pulse rate. I came across one that claimed 300Hz as a max command rate, but I don't think that's typical. I have a Hitech digital servo that I have tested to 100 Hz with no issue. I still need to do some testing to see if the updated command rate does anything though. The servo may still be closing its position loop at a slower rate, say 50Hz and simply using the most recent command pulse in which case we wont see and improvment in bandwidth or latency.

Brian
I have a question : How do you generate un PWM with a 50hz freq when the PWM module of the PIC that I'm working on, can only do much higher frequency ?
I've sorted that problem out by creating my on code but because it requires interrupts routines I can't do A/D convertions on a regular time frame :-( . I've also found a solution for that but it wastes over 50% of my small CPU power.
Dave,
What PIC are you using?
My very first board used an 18F2520, I had to write my own pseudo operating system to generate the PWM pulses and to do the A/D conversion. I ran into the same problem that you are talking about. Basically, I ran the underlying PWM calculations at 1000 Hz (for a 1 msec basic "heartbeat".) I built the PWM pulses out of two pieces, a 1 msec fixed piece, and then a variable piece. There were around 20 "time slots" that I used for various regular tasks, including creating the pulses and for sampling the A/D. When I was all done with everything, I was using only about 4% of the CPU power of the 18F2520.
My new board, the UAV DevBoard, has much better support for PWM, you can get it to generate the required pulses entirely in the hardware of the dsPIC30F4011 CPU.
Best regards,
Bill
Thank you Bill for your answer.

I'm using a PIC16F690 (pickit2).
Well it looks like we had the same approach to the problem. In order to make it simpler I'm also working on a 1000Hz freq as I generate an Timer0 interrupt every 1000 instruction cycles (1ms). A counter variable numbers off the interrupt routines, "time slot" [1;20] :
1)Output = 1
2)Load the ServoCommand into TMR0 (3 is then triggered 1ms after if ServoC=0 // 0ms if ServoC=255)
3)Ouput=0
4)nop
5)nop
.........................
19)InteruptNumber=1

That's the method I'm using now. The problem is that I don't have a regular time frame because the time elapsed between 2 and 3 is variable (equals the servo command).

From then, my next code will try to include a second source of interruption using TMR2 so that between 2 and 3 there will also be 1ms. Now you see the problem is the I can't launch a A/D convertion during the second interrupt routine because it will interfere with the TMR2 interrupt (output has to go back to 0 sometimes within the second interruption). Therefore, in order to have a constant sampling period, now, I have to drop off 1/2 of the time slots.
As a conclusion I will end up having 1/2 of the time slots, where sampling is possible ( genuinely used) and the other half is left to "interruptable" routines.

I'm just expecting you to tell me if I'm going the right way. I'm thinking of one day getting your DevBoard but before I want to be able to get myself fully sorted with my small PICs. I have a flew projects in mind essentially very basic attitude and airspeed stabilization and getting aquainted with C programming (only know assembly).

I hope that you have accomplished a lot of successful flights !

Best regards,

Dave
Dave,

Jack Crossfire has a good suggestion, which I will elaborate.

You can dedicate a single timer to generating the PWM, and another one for the A/D, if you want.

You can maintain a constant frame rate and generate variable pulses by timing both the "on" portion of the pulse and the "off" portion of the pulse.

So, lets say you want to generate a 1.5 millisecond pulse...

Set the pin high, set a 1 millisecond delay for the next interrupt.
Set the pin high, set a .5 millisecond delay for the next interrupt.
Set the pin low, set a .5 millisecond dealy for the next interrupt.

Basically, you will need 3 time slots for each PWM channel, but you can have more than 20 time slots, since the total time for the variable on and variable off time will be 1 millisecond.

You should be able to generate the pulses without much CPU burden.

Best regards,
Bill

RSS

Groups

© 2012   Created by Chris Anderson.

Badges  |  Report an Issue  |  Terms of Service