writeMicroseconds() vs analogWrite() and Pulse Period

Hello everyone,

I am still not very familiar with Arduino. Currently I am trying to control four brushless motors with PWM. What is the difference between writeMicroseconds() and analogWrite() other than input value? I am using writeMicroseconds() to control my motors. However, when I tried

writeMicroseconds(1300)
delay(15)
writeMicroseconds(1800)
delay(15)

in the loop. My motors did not change the spinning rate every 15 ms. I read somewhere that PWM expects a pulse every 20 ms. Does this mean the motor can change its spinning rate at most 20 ms once?

A servo re-pulse is every 20ms (50Hz). Bur the PWM pins are 490Hz and 980Hz depending which pins you use.

I've never used writeMicroseconds() because I don't do much with motors.

It looks like that's only used for a servo. Do you have a servo or some other component like an ESC between the Arduino and the motor?

Yes I have an ESC between the brushless motor and Arduino.
What does servo re-pulse mean? I want the motor to change its angular speed as soon as possible and from what I measured the fastest it could go seem to be 50 Hz.

OK, some useful information. Do you have a datasheet or a manual with the ESC? If not, you may need to do some reading elsewhere on how servos get their information from a radio reciever. Then you will know more about how an RC servo works and why it needs regular pulses.

Ja by default, the servo library renews its acquaintance with a servo every 20ms (50Hz)- it re-sends the last write at that frequency, so the servo can hold its position properly.

You can change that default though, by changing the value of REFRESH_INTERVAL in servo.h.

See attached scope traces: one at default 20ms, one after I changed REFRESH_INTERVAL to 10.

EDIT: I read somewhere you don't wany to make that lower than about 6-7 though, since the servo needs time to digest.... Not sure of the exact minimum though.

servo attached.jpg

10ms servo refresh.jpg

When you issue the command servo.writeMicroseconds(1300) the Arduino produces a pulse that is 1300 micros wide every 20 millisecs indefinitely. If you don't need to change the speed there is no need to repeat the command.

If the ESC can only drive the motor in one direction this will be interpreted by the ESC as your wish for the motor to work at (approx) (1000 -1300) / (1000 - 2000) * 100 percent of full speed. That is 300 / 1000 * 100 = 30% (E&OE)

Your example changes the value from 1300 to 1800 (30% to 80%) every 15 millisecs. That is much too quickly for the motor to be able to react. If you want to see the effect run the motor at one speed for (say) 10 seconds and then at another speed for 10 seconds. Then you can experiment with shorter intervals.

...R

Also remember that there will be a mechanical lag between the speed asked for, and the actual speed. The motor won't go from slow to fast in 15ms/20ms. It will take longer,(but I'm not sure how much), maybe up to a second?