Go Down

Topic: Servo library alternative (Read 381 times) previous topic - next topic

mate115

Hi,

I am controlling 4 bldc motors using standard simonk esc drivers. I am currently using standard arduino servo library, but as i am controlling 4 motors, that means that the highest refresh frequency can be 125Hz with a period of 8ms. For me that is too slow as i need a refresh frequency of 400Hz. The servo library works so that it makes a pulse for the first motor and only then starts counting for the second motor and so on.
So what i need is a library that can create pulses for all four motors at the same time, so that the refresh period can be 2.5ms. I know that the varspeedservo.h library exists but it uses the same principle as standard servo library.
I dont have time for modifying servo library for my needs.
Does anyone know an alternative library that can achieve higher refresh rates?

Thank you for all your help, mate115

alka

#1
Mar 11, 2018, 12:47 am Last Edit: Mar 11, 2018, 02:05 am by alka
Simonk firmware only uses a range of 1000 to 1850 us I believe. This can allow for up to 500hz refresh. What if you were to just use analogwrite. If you use one of the analog outs with 500hz refresh analogWrite(127) should be a 1000ms pulse? Or am I crazy..

Otherwise this might help https://github.com/superjax/ESC

mate115

I was actually thinking the same thing. Just using PWM with a frequency of 400Hz. The problem is that 8 bits of resolution would be too low for my needs. Actually even 850 steps of resolution is a bit too low, but it gets the job done.
But thank you for the reply nonetheless!

alka

Have you looked at Multiwii?  It's an open source Arduino program for controlling multirotors. I'm sure the answer is in that source somewhere.

Robin2

What if you were to just use analogwrite.
The output of analogWrite() is not at all the same as the output of the Servo library. Unfortunately both outputs are referred to as PWM.

IMHO the output of the Servo library should not be called PWM.


...R
Two or three hours spent thinking and reading documentation solves most programming problems.

mate115

Alka, i have not looked at multiwii, as its a full multirotor controller and i want to create my own. Everything is actually working, the only thing that stopping me right now is the esc refresh rate. I have looked at multiwii and it seems they coded their own esc control.

Robin2 - you are right, its not at all the same. Btw, the servo control output actually has its own name, its called PPM - pulse position modulation ;)

I think i'll stick to my 125Hz standard servo library for now. Modifying the library seems like too much for me right now. Thank you all :)

Robin2

Btw, the servo control output actually has its own name, its called PPM - pulse position modulation ;)
Alas. PPM is often used to mean the stream or 4 or 6 pulses that are sent by a transmitter to a receiver (old style RC equipment).

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

MartinL

Hi mate115,

It's possible to create a 400Hz PWM signal with 11-bit resolution using a few lines of register manipulation. A library isn't really necessary.

On the Arduino Uno however it's only possible to get this resolution on two pins, not enough for a quadcopter. The Mirco fares a little better with four, the Mega twelve and the ARM based Zero and Due eight, with additional PWM outputs on auxiliary timers.

Which Arduino are you intending to use for your flight controller?

alka

#8
Mar 11, 2018, 08:49 pm Last Edit: Mar 11, 2018, 08:50 pm by alka
The output of analogWrite() is not at all the same as the output of the Servo library. Unfortunately both outputs are referred to as PWM.

IMHO the output of the Servo library should not be called PWM.


...R
You are right.. not the same but the are both pulse width modulation aren't they? The servo library just has a longer period between pulses. The ESC doesn't care what we call it.


Robin2

You are right.. not the same but the are both pulse width modulation aren't they? The servo library just has a longer period between pulses.
Whatever you choose to call them they are NOT interchangeable.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

alka

#10
Mar 12, 2018, 04:56 am Last Edit: Mar 12, 2018, 04:57 am by alka
Whatever you choose to call them they are NOT interchangeable.

...R
Yes, but this is for a specific speed controller firmware that can take up to a 500hz refresh rate.  A half duty cycle pwm with at 500hz frequency is a 1000us pulse. It works. The problem as the OP said was just the precision. You only have 120 steps or so of it this way.

Robin2

Yes, but this is for a specific speed controller firmware that can take up to a 500hz refresh rate.
I don't see how that changes things.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

MartinL

#12
Mar 12, 2018, 09:29 am Last Edit: Mar 12, 2018, 09:30 am by MartinL
Hi alka,

Quote
You are right.. not the same but the are both pulse width modulation aren't they? The servo library just has a longer period between pulses. The ESC doesn't care what we call it.
As Robin2 mentions, there's a difference between Pulse Width Modulation (PWM) and Pulse Position Modulation (PPM).

With PWM the receiving device, the flight controller, ESC, servo etc.., extracts information from the width of the incoming pulse.

With PPM the receiving device, say a flight controller, extracts information from the pulse edges relative to the next pulse, hence the pulses' position is important. This is used mainly in CPPM RC receivers where all the signal channels are multiplexed on to a single line.

Quote
Yes, but this is for a specific speed controller firmware that can take up to a 500hz refresh rate.  A half duty cycle pwm with at 500hz frequency is a 1000us pulse. It works. The problem as the OP said was just the precision. You only have 120 steps or so of it this way.
It's possible for an Arduino to output PWM at 400Hz with 11-bit resolution, that's accurate to the 1uS required by ESCs and servos, by directly setting the microcontroller's registers.

Here's an example of how to do it on the Arduino Mega: https://forum.arduino.cc/index.php?topic=444373.0.

It's set-up to drive 12 servos at 50Hz, however to change the PWM frequency from 50Hz to 400Hz, just amend the value of the ICRx registers from 20000 to 2500.

alka

#13
Mar 12, 2018, 12:15 pm Last Edit: Mar 12, 2018, 12:52 pm by alka
I don't see how that changes things.

...R
Because THIS firmware on THIS ESC is ONLY timing the length of the pulse. I know what the difference is. If he had said he had a different firmware i would have a different answer about using analogWrite(). Simonk firmware only cares about pulse width. Anyway, martinL's link is quite useful. 11 bit PWM.
Edit: I will maintain that the signal from the servo library IS a PWM signal. The only thing that changes is the width of the pulse.. servo library output = pwm.

Robin2

Simonk firmware only cares about pulse width.
And what range of pulse widths does it expect?

Is it the normal servo range of 1000 to 2000 microsecs?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up