400 Hz ESC PWM

Status
Not open for further replies.

chris.sallis

New member
I'm using a Teensy 3.6 to intercept individual channel PWM output signals from a flight controller that are used to control individual ESCs for a multi-rotor. Reading the incoming 400 Hz signals has not been an issue, but I don't have a way to pass them out at 400 Hz. Modifying the standard Servo library only allows up to ~130 Hz. I'm looking for completed code or library that allows me to generate 400 Hz PWM signals with similar structure to the existing Servo library. I am an entry level Arduino programmer without formal training. I know this is possible and has been completed by several other projects but I'm having difficulty finding documentation. For example, the Ardupilot APM 2.5 was based on an Arduino Mega was was used as a multi-rotor aircraft flight controller. Thanks!
 
My recommendation would be to use analogWrite as recommended by manitou. I've used this for sending servo signals at update rates up to 800 Hz (update rate recommended by the servo manufacturer for a tail rotor servo). Some example code for pin 2 used as the PWM signal with a 400 Hz update rate:

Code:
void setup() {
  analogWriteResolution(16);
  analogWriteFrequency(2,400);
}

// This function would be called every time the servo command is updated. 
// Cmd is the microsecond command sent to the servo or ESC to control
// its position or power output. Typically it's 1000 - 2000 with a center at 1500.
void sendServoCmd(float Cmd) {
  analogWrite(2,Cmd/2500.0f*65535.0f);
}
 
Status
Not open for further replies.
Back
Top