Arduino uno - How to overcome only 8bit counter for PWM?

Hello,

I need to use 4 pwm outputs for 4 ESC regulators on my quadcopter. There are 2 8-bits timers and only 1 16-bits timer. It is really impossible to control quadcopter with only 255 resolution points! So my question is: is it possible to get bigger resolution?

For example: ESC need 1ms (throtle down) to 2ms (full gas) pulses. With 8bit counter I can only increase time by aprox 4us and thats too much.

And in addition: 255 values is too small also for servo - why it is so small on Arduino Uno? I'm really confused from this...

Why not use the servo library to control the ESCs ?
Using the writeMicroseconds() method you can have 1000 discrete output values.

UKHeliBob: are you sure with it? You can write 1000 values to that function but how do you know it is working properly? (not only for 255 values on timer1 and tumer2)

RC servos work by responding to pulses between 1000 and 2000 microseconds to move between 0 and 180 degrees. So by using the writeMicroseconds() method you can have 1000 different servo positions, assuming that is that the servo is mechanically able to provide such a resolution.

ESCs work in the same way but of course they do not move but produce the requisite outputs to drive brushless motors which is what I assume you are using.

The servo library users a timer to time the pulses not to produce 255 different PWM values.

Well, I connect osciloscop to the PWM outpusts and with WriteMicroseconds() I really see that difference between 1000, 1001, 1002. So it really works. But how is it possible? In addition when I attach D2 which is not PWM output it also works. How? :astonished: That Servo library must make some bypass above that PWM registers...

So in fact I have 1000 points resolution for control motors speed at my quadcopter. It's not so bad but more will be better. On the other hand quadcopter also fly with just 2us resolution - I tested it but it was not such smooth.

Here's the problem: the frequency of pulses generated by Servo is only 50Hz. It's not enaugh I need 100Hz Minimally.

So I go inside servo.h code and modify this line:

#define REFRESH_INTERVAL 5000 // minumim time to refresh servos in microseconds

from 20000us to 5000us. Then I measured result by osciloscope and it's really sending pulses with 200Hz frequency! Then I put this lines:

myservo3.writeMicroseconds(100);
delay(5);
myservo3.writeMicroseconds(1500);
delay(5);

And on the osciloscope it really works - one pulse 100us and the another 1500us!

So it's working :wink:

But how is it possible?

That Servo library must make some bypass above that PWM registers...

You have the source code of the library so you could look and see how it is done and maybe change it to suit your needs.

jurass17:
That Servo library must make some bypass above that PWM registers...

The servo library does not use PWM (in the way that analogWrite() uses it) at all.

jurass17:
Here's the problem: the frequency of pulses generated by Servo is only 50Hz. It's not enaugh I need 100Hz Minimally. WHat can I do?

You can modify the code in the Servo library.
I'm pretty sure this has been covered in other Threads in the Forum. Google should be able to find them.

...R

Well and isn't it problem to control quadcopter by Servo when it isn't using PWM? My osciloscope sometimes show about 4us lags in signal generated by Servo.

There are very well respected flight controllers based on the Arduino, such as the ArduCopter, for which the source code is freely available. Perhaps you could look at how they achieve what they do.

jurass17:
Well and isn't it problem to control quadcopter by Servo when it isn't using PWM?

This does not make sense.
The phrase PWM is used in 2 different contexts. It is the output produced by analogWrite() which is used to control the speed of DC motors or the brightness of LEDS.

The pulses used to tell a servo what position to adopt are also, strictly speaking, PWM signals but the way they are used is quite different from the way the other signals are used to control the speed of a motor. The servo is only concerned with the absolute width of the pulses whereas a DC motor controller also uses the width of the gap between the pulses as part of the speed control system - it is the relative width of the pulse to the width of the gap that matters.

The Atmega chips have special features to enable them to produce in the background the type of PWM needed for a DC motor while the rest of the CPU gets on with other stuff.

...R