a Virtual Robotix Network Team

Today I made some tests with my BLMC's. With a 50 Hz PWM Signal they work fine, but connected with the MP32 they don't start, so I had a look with my Osziloscope and found out that my MP32 sends it's PWM with 550 Hz. That's maybe to much for my Turnigy 25A Basic. They should work with 400 Hz, I read, so I would like to reduce the frequency a little.

Has anybody an idea where I can change this.

Views: 1949

Reply to This

Replies to This Discussion

I did a little reseach. It seems that the ARR Register (Autoreload) shold be set to a value around 2500 for 400 Hz (found this in the AutoQuad code from Bill Nesbit).

The ARR can be set with the 'timer_set_reload' Function in the 'timers.c'.

This function is called only from one position: 'setOverflow' in HardwareTimer.cpp.

And setOverflow is called in the Servo::attach() with the parameter SERVO_OVF

SERVO_OVF is a result of:

#define CYC_20MSEC     (20000 * CYCLES_PER_MICROSECOND)

#define SERVO_PRE ((uint16)((CYC_20MSEC >> 16) + 1))

#define SERVO_OVF ((uint16)((CYC_20MSEC / SERVO_PRE) - 1))


so I should increase the SERVO_OVF value, to get a longer period, right?


Hi Thomas ,

yes doing a test ... strange that turnigy don't work at 550 hz ...I try also china supersimple buy from giantcod and it works.

Inform you about the results ..are  you connected signal and ground ? Some times if you don't connect gnd the esc don't work fine ...



Hi Roberto,


Yes, I connected ground and signal (cut only +5V)

I read in other forums (e.g. OpenPilot) about problems with frequencies higher than 400 Hz.

Some of them only support 350 Hz well.

I've here some HobbyKing brand BLMC, will make a test with them (to compare them with the turnigy BLMCs)  if I've some spare time.


nice day


Hi Roberto,

With some modifications in the Timers.c I reduced the PWM frequency to 410 Hz.

Now the Turnigy's working well. For optimum there should be an universial function which could adjust the PWM Frequency by parameter. I will try this, but at first I've to learn a little more about the maple functions and the STM32F103 processor. 

(now I'm able to debug with the Olimex JTag, seems to be a little bit 'jumpy' in single step mode, but should be enough make some code experiments  :)

Perfect Thomas,

if you can share you code with the other part of community so we can test your patch.

What kind of configuration are you using for your Olimex Jtag ?Ide ? Are you using eclipse and are you testing only the library ... or you are working on Ardupirates code and debug it using Olimex Jtag ?



Hi Roberto,

If I finish the Timer functions, I will puplish the codechange as attachment here (up to now I don't know your email address :)

I use Eclipse (Helios), OpenOCD 4.0, Olimex JTag

At the moment  I don't use the GCC for making the project, because I had no time for creating a makefile (or only to have a look if you have something ready like that).

So I make a normal ArduPirates sketch build and copy it in my Eclipse folder to debug it  :)

Will improve this as soon as possible




To reduce the Motor PWM frequency to 350 Hz only small changes are needed:


set precaler of timer 3+5 to 2

timer_init(TIMER1, 1);     

timer_init(TIMER2, 1);    

timer_init(TIMER3, 2); // PWM Out 4    

timer_init(TIMER4, 1);    

timer_init(TIMER5, 2);  // PWM OUT 1-3    

timer_init(TIMER8, 1); 

Change PWM mapping from 32000/64000 to 24000/49000

void APM_RC_Class::OutputCh(unsigned char ch, uint16_t pwm){
//  pwm=map(pwm, 1000, 2000, 32000, 64000); 

pwm=map(pwm, 1000, 2000, 24000, 49000); 

analogWrite(analogOutPin[ch], pwm);



Works well with my Turnigy Basic ESC's


If i've time for a more universal solution I will post it asap


Great Work Thomas,

are you yet try to activate the other pwm output for hexa or okto configuration ?

I'm working on i2c ESC ... now i finish the code and i start to test it.



i just rised the speed of the main loop to 250 hz.

it is windy and i had to move the stick up to the physical end to fight against the wind.

the copter come down two times belly up and the esc's didn't stop with beeping until i pulled the power plug.


i use standard esc's sold from the diydrones store.


a few turnigy plush are in my box ... looks like i have to test them.


Hi Robert but are you using Multipilot32 ? What firmware ? on MP32 i'm going until 800 hz of main loop.




it is still my old frame with the atmel.

for the testing that combo is nice.

the motors produce lot's of vibrations and with gusts in the wind i notice

a big amount of gyrodrift.

my intention is it to reduce the overreaction of dcm with 'saturated' accel values.

it can also be the fact that the esc tries to drive the motor and the battery is unable to deliver the power. as a result the voltage drops and the esc's automatically issue a shutdown.

 the next step is having mp32 with turnigy plush as esc's.

the accel unit on the oilpan has a hardcoded upper frequency which is 400 hz. anything above

you run against a 'wrong' filter. that hardcoded element is a capacitor.



The problem with my turnigy Basic 25 A: With 550 Hz Motor PWM (not main loop) they were beeping most of the time.

With 400 Hz they work, but while increasing the throttle, they stopped to work.

I think the problem is the very small gap between the pulses while hard gas,

so then ESC goes out of sync and stops to work.

With 350 Hz PWM the ESC worked good from minimum to full throttle.

(The Plush should work with 400 Hz)



© 2019   Created by Roberto Navoni.   Powered by

Badges  |  Report an Issue  |  Terms of Service