ESC at 100/300Hz PWM frequency

Hey guys, i am developing a little flight control software just to learn something.. I started programming the connection between arduino and ESC. I know the existence of servo.h library, however i want to manage the ESCs with different PWM frequency. I would use a PWM frequency between 100Hz and 300Hz. At the time i know how i can change PWM frequency in arduino, but i don't know neither how to create the right pulse nor what is the right size of the pulse. Whit servo.h, the ESC input is generate by function writeMillisecond(). In my case, what should be the right function? Maybe analogWrite? I am looking forward your answer. Thanks guys!

You would typically program timer1 in 16 bit mode using ICR to set the period and OCR1A or OCR1B
(which are 16 bit if used directly) to set the pulse width directly. Run timer1 at full speed (prescale by 1)
gives you 244Hz cycle time with 0.0625us granularity in pulse width. For lower frequencies you'd prescale
by the next factor (4 or 8 I think) and lose some resolution in pulse width).

Thanks for the answer. Your words let me know a lot of things. Now, i finally can adjust arduino PWM frequency and use a specific mode that i want. I just have a doubt, assuming that my frequency is 400Hz, it means that i use a 2500 ms pulse width. In this case, should i always use the pulse width corresponding to interval 1000 - 2000 ms converted into the right duty cycle?

You won't be using a 2500ms pulse width at 400Hz!

You might be using a 2.5ms period.

Servos and ESCs are pulse-width modulated, so set the pulse width correctly.

I know the existence of servo.h library, however i want to manage the ESCs with different PWM frequency.

Is the ESC specially made to accept the changed control input?

The PWM that is created by analogRead() and by the hardware Timers is not what you want for an ESC. That Pulse Width is intended to Modulate the power going to a motor or a lamp.

The Pulse Width of the signal going to a servo (or ESC) is intended to signify the position of the servo or the power setting of the ESC. Internally the ESC will use regular PWM to modulate the power going to the motor. The signal you send to the ESC does not directly affect the motor - it is just used by the MCU within the ESC.

The normal servo signal repeats every 20 millisecs (50 per second) and (approximately) a 1000 microsec pulse represents 0 degrees and 2000 µsecs represents 180 degrees.

...R

Robin2:
The Pulse Width of the signal going to a servo (or ESC) is intended to signify the position of the servo or the power setting of the ESC.

Hence why it is termed "Pulse Position Modulation" or PPM...

MarkT:
You won't be using a 2500ms pulse width at 400Hz!

You might be using a 2.5ms period.

Yes! you're right. I made a mistake while i was writing. My question would be this: With general frequency of 50Hz, using PWM, we have a period of 20ms. So, conventionally, we send a ~1ms (5% duty cycle) pulse width to the servo to obtain the 0° position and ~2ms (10% duty cycle) for 180° position. Assuming that perfectly works for the ESC as well and 1ms input means 0% and 2ms means 100%. If i decide to use a different frequency, for example 400Hz, thus 2.5ms period, what pulse width should i use to manage the ESC in order to reach the same results? Which duty cycle for the minimum and for the maximum?

cr0sh:
Hence why it is termed "Pulse Position Modulation" or PPM...

PPM is different kind of modulation. With a 50hz frequency we have a period of 20ms. We divide this period in equal parts and we appoint each of these part to each single unit. In this way we can use a single channel to transfer more inputs, but we have a maximum number of signals that we can transmit. From here, for example, the channel number of the RC Transmitter are determinated. This image would illustrate better the idea: http://api.ning.com/files/WmjViE3faLYy73Ry7eTzn4XMryr8qlAMeb*edCbrzW1BVUPtR1iXBIGgsS93iG1x5roVRkAWHqg7V3FAhK*o8NYsajr5nW7G/RC_Receiver_Timing_Diagram1.jpg

cr0sh:
Hence why it is termed "Pulse Position Modulation" or PPM...

As @uservdev has said, the terminology is hopelessly confusing. What he describes is common usage but is no more accurate use of language than using PWM to describe both the action for a single servo as well as for motor control.

The position of the pulses is not used to modulate anything. It is just used to distinguish pulses for servo A from pulses for servo B etc.

...R

Lots of terminology seems to be getting mixed up. Below are my thoughts on what is going on from an RC tx to the servo motor. PPM in particular is subject to some confusion.

There are three types of pulse setups from an RC transmitter to a servo. The first is usually referred to as PPM (pulse position modulation). The rc tx sends a number of pulses to the rc rx. These pulses have a duration that corresponds to a desired servo position. These pulses are sent in a looping sequence setup where the pulse position in the sequence determines which servo gets that command. The rc rx is in sync with the sent pulses and sends a pulse of a specific duration to the assigned servo (usually in the 1000us-2000us range). The internals of the servo converts this pulse duration into a voltage value that will be compared to the voltage input from the servo pot. Depending on the magnitude of the voltage difference, the servo internals generate a pulse for controlling the internal motor H-bridge. The width of this pulse will be somewhere between 0% (full off) to ~100% (full on). The PWM used to control the internal H-bridge is of the same type that is used in the arduino analog out to control an external H-bridge or transistor. At least that is my take on it.

Getting back to the main point of sending pulses to the ESC to control the speed of a brushless dc motor.

Zoomkat asks

Is the ESC specially made to accept the changed control input?

What are the specs on the ESC and its firmware?

Assuming that perfectly works for the ESC as well and 1ms input means 0% and 2ms means 100%. If i decide to use a different frequency, for example 400Hz, thus 2.5ms period, what pulse width should i use to manage the ESC in order to reach the same results?

Some quadcopter ESCs can be calibrated from stop to full speed over 700-2000 us pulse lengths but I think you will be in the range of 1-2 ms regardless of update frequency.

What are the specs on the ESC and its firmware?

I assume the control input to the esc is the same as for a standard servo, ~1000us-2000us high pulse separated by at least a ~5us low reset.

Hey guys, thanks for your help. Now I have an idea how i can proceed. I am going to build my sketch and try it with my Escs. I have afro Esc 20A, with simonk firmware, does it use either a fast pwm or phase correct or both? Can it use inverter mode? Unfortunately, I didn't find anything about this.

userxdev:
I have afro Esc 20A, with simonk firmware, does it use either a fast pwm or phase correct or both?

Are you planning to rewrite the firmware?

If not all you need is the standard output of the Servo library.
All the complex code is inside the ESC - not in your Arduino.

If you are planning to rewrite the firmware I will be interested to learn from your experience. I have an application in mind in which a re-programmed ESC may be useful.

...R

Robin2:
Are you planning to rewrite the firmware?

If not all you need is the standard output of the Servo library.
All the complex code is inside the ESC - not in your Arduino.

Just for the moment i would write a code in order to communicate from my arduino to my Esc. I don't want to use any library because i would learn about this and i would improve my skill to reach this goal. I am developing a skecth and for this reason i asked about frequency, pulse width, and kind of PWM. My aim is just communicate with Esc at custom frequency, obviously under 500Hz. So, do you have any idea about my last question? When i configure PWM setting in arduino, do i have to choose between fast pwm or phase correct?

Robin2:
If you are planning to rewrite the firmware I will be interested to learn from your experience. I have an application in mind in which a re-programmed ESC may be useful.

It is going to be the next step of my project, so i will keep in mind you for that time.

userxdev:
My aim is just communicate with Esc at custom frequency, obviously under 500Hz.

Wanting to learn and to experiment is great.

But if you are using an off-the-shelf ESC it will expect normal "servo" signals. If you write code that produces a different signal pattern how can you expect the ESC to understand it. It would be the same problem as you trying to talk to me in Russian which I don't understand.

If your ESC can accept some other signal format please provide a link to its datasheet.

Neither fast-pwm nor phase-correct-pwm has anything to do with servo signals.

I don't want to use any library because i would learn about this and i would improve my skill to reach this goal.

i understand your objectives, and writing the low level code will be a useful learning experience. I would recommend that you start working with a modified version of servo.h in order to sort out any issues with the hardware and its set up before you start getting into your own code.

Go into Servo.h and find

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

Change that line to an interval of 2500 and you will get the pulses at 400 Hz. Get everything working, and then write your own pulse generating code.

Regarding the pwm mode, here is a link explaining some of the differences
http://www.societyofrobots.com/member_tutorials/node/229

It's unclear how the ESC processes the pulse signals it receives and the relevance of pwm mode.

I would start with 16 bit timer 1, prescaler 8 for .5us steps, mode 14 fast pwm to ICR1 top value of 5000(400hz), non-inverting output mode. Pulses will begin at the start of the cycle, and end with a match to your pulse length setting with OCR1A or B.

As Robin2 says, its not clear if the ESC will respond to these pulses properly.