Arduino pwm

Hello, I am currently working on a quadrotor project, for this I require the response of my brushless motors to be very high. How can I increase the frequency of the pwm in the servo library as I am using servo.write() command to control my motors. I tried decreasing the refresh interval in the servo.h header file from 20000 to 1000 , but the response of the motors barely changed.Please help..

If you're using standard R/C ESCs, they expect to work with a 50Hz frame rate.

@OP don't repeat the same question - it won't make any difference to the answer.

If you don't want R/C 50Hz response, bypass the R/C interface in the ESC altogether, and interface directly to the output stage with your own PWM.

ars: Hello, I am currently working on a quadrotor project, for this I require the response of my brushless motors to be very high. How can I increase the frequency of the pwm in the servo library as I am using servo.write() command to control my motors. I tried decreasing the refresh interval in the servo.h header file from 20000 to 1000 , but the response of the motors barely changed.Please help..

Changing to 1000 update rate is seriously flawed for a servo PPM type signal update rate, your ESC would choke on such a value. I suspect you mean you changed it to 10,000 which would change the update rate from 50hz to 25hz. To be honest I suspect your looking at the wrong thing to 'correct' whatever problem you are having. Have you made certain that you have good PID tuning values setup for your specfic system?

Lefty

Using a faster update frequency is pretty standard for multicopter use. Right now I'm flashing new firmware into some ESCs from Hobbyking. I'm using a KK controller card to control them. I believe the KK controller updates the ESCs at around 290 Hz. http://www.hobbyking.com/hobbyking/store/%5F%5F19534%5F%5FHobbyKing%5FMulti%5FRotor%5FControl%5FBoard%5FV2%5F1%5FAtmega168PA%5F.html http://www.hobbyking.com/hobbyking/store/%5F%5F15202%5F%5FHobby%5FKing%5F20A%5FESC%5F3A%5FUBEC.html http://www.rcgroups.com/forums/showthread.php?t=1513678

I don't know how to change the servo lib, but I might need to know soon. So I'm interested in the info too.

Using a faster update frequency is pretty standard for multicopter use

assuming, that is, that the ESC supports >50Hz frame rates.

I think most ESCs these days can handle quite a bit higher update rate than 50 Hz. I would not take the risk with an expensive one though. The ones I'm using is dirt cheap, and runs with ATMega8. These can be flashed with different firmware optimized for multicopter use. Google gave me this; http://www.multirotorforums.com/showthread.php?2269-ESCs-and-refresh-rates&s=d9532eed13d7ae09791e4e469e1fbab2 ESCs can even be programmed with Arduino http://www.rcgroups.com/forums/showthread.php?t=1349333

FerryP: Using a faster update frequency is pretty standard for multicopter use.

Why? I assume the goal is to enable you to change thrust levels very rapidly, but I'm surprised that you get any benefit from switching the power supply faster than 50Hz. Isn't this already way faster than the rest of the system can respond, once you consider rotational inertia of the motor+prop and the inertia of the air frame that you're trying to control?

If your ESC uses an atmega8, then why don't you just replace it with your arduino chip that's programmed to simple output PWM to the motors? It wouldn't add much to your sketch size (it may even subtract: analogWrite (hardware PWM) vs Servo (which is an ISR)), and you'd have a much faster update rate.

And since nobody is actually answering your question: You're going to have to modify the servo library and change the function initISR. If they designed the library correctly, this should be easy, but they did a bad job. You could either modify the library slightly so that you can override the functions needing to be changed (add them to the class and declare them static and virtual) or you could just modify the library as you need it.

I'm no expert at these multicopters, as I'm building my first one now. I've been reading up on the web about different firmware for the ESCs and the controller card. From what I've read, but not yet tried myself, an update rate of at least 100 Hz is desirable. It gives a more stable platform. The stock ESCs are slow on purpose. Too fast a ramp up can wreck the gears on a helicopter or similar use. Custom firmware optimize them for multicopter use. I don't know if it's clear, but we're talking BLDC motors here. Six outputs from the ATMega8 controlling six FETs, driving two wires at a given time, and measuring voltage on the third wire. It's way more complex than just outputting a single PWM signal. ESCs are "dumb" devices, just driving the motors based on the input signal. The controller card is doing all the work here. Measuring signals from 3 gyros, calculating and driving the ESCs. For my quadrocopter there is a total of five Atmels on board, 1 ATMega8 in each of the 4 ESCs, and 1 ATMega328 on the controller card. (I even think there's one inside the RC receiver)

From a control point of view I agree on the skepticism for the fast update rates. Some even modify the ESCs to run I2C for multi KHz update rates. On the other hand, my goal with this quadcopter is to fly. I'll start out with proven firmware and components.

The ideal solution would be to have a specialized library for ESCs. The servo lib is for driving regular servos, not speed controllers. They just happen to use the same ppm signal.

FerryP: I'm no expert at these multicopters, as I'm building my first one now. I've been reading up on the web about different firmware for the ESCs and the controller card. From what I've read, but not yet tried myself, an update rate of at least 100 Hz is desirable. It gives a more stable platform. The stock ESCs are slow on purpose. Too fast a ramp up can wreck the gears on a helicopter or similar use. Custom firmware optimize them for multicopter use. I don't know if it's clear, but we're talking BLDC motors here. Six outputs from the ATMega8 controlling six FETs, driving two wires at a given time, and measuring voltage on the third wire. It's way more complex than just outputting a single PWM signal.

Even so, you said the firmware was written for the "arduino language," so you could just incorporate that into your code. Unless, of course, it uses more than 32KB of program memory or 2KB of ram, which I find highly unlikely.

I would agree with you that a method should be added to the Servo library to change the update rate -- it could probably just be a really giant, crude switch statement. I'd google around and perhaps you could submit a patch.