Due controlling ESC with PWM.

Hi there,
I'm trying to control a brushless motor through an ESC with my Due however the Due's PWM doesn't work. However, if I use the servo library it works although that is not ideal as it is much slower than analogWrite. My arduino Mega's PWM works for controlling the ESC so maybe there is something different between the Mega and the Due, im not sure?

Can you please post a link with the Servo Library. I need excatly the same application like you and I have the same problem

Thanks do you have any progress with your code it would be nice if you can post it either

Best regardes from Germany

Hi TwiggySticks

I've implemented esc control on my DUE using the "DUETimer.h"

#include <DueTimer.h>
//VARIABLES////////////////////////////////////
int Motor1PWM,Motor2PWM,Motor3PWM,Motor14PWM=0;

int Motor1PIN  = 53;
int Motor2PIN  = 51;
int Motor3PIN  = 49;
int Motor4PIN  = 47;
///////////////////////////////////////////////

//Pin Modes////////////////////////////////////
 
///////////////////////////////////////////////

//ISR//////////////////////////////////////////
void PWMStart()
{
	digitalWrite(Motor1PIN,HIGH);
        digitalWrite(Motor2PIN,HIGH);
        digitalWrite(Motor3PIN,HIGH);
        digitalWrite(Motor4PIN,HIGH);
        Timer3.start(Motor1PWM);
}

void Motor1()
{
	digitalWrite(Motor1PIN,LOW);
        Timer1.stop();  
}    

void Motor2()
{
	//Not implemented yet;
}

void Motor3()
{
	//Not implemented yet
}

void Motor4()
{
	//Not implemented yet
}
////////////////////////////////////////////////

void setup(){

//Pin Modes setup////////////////////////////////////
        pinMode(Motor1PIN, OUTPUT); 
        pinMode(Motor2PIN, OUTPUT); 
        pinMode(Motor3PIN, OUTPUT); 
        pinMode(Motor4PIN, OUTPUT);
//Timers setup//////////////////////////////////// 
	Timer3.attachInterrupt(Motor1);
	Timer4.attachInterrupt(Motor2);
	Timer5.attachInterrupt(Motor3);
        Timer6.attachInterrupt(Motor3);
        Timer0.attachInterrupt(PWMStart).start(21740);
        
       // analogReadResolution(10);
}

void loop(){
Motor1PWM=map(analogRead(A0),0,1023,780,1800); //Maps a potentiometer to PWM output for the ESC
delay(500);

}

Hello, I'm very sorry for my late reply. I have tested this code with a Turnigy Plush 30A ESC and a 1300kv brushless motor, and I am able to vary the speed of the motor. I am unfamiliar with asycronous motors and ESCs, but the code is very simple, every 22ms a pulse is sent to the ESC, depending on the width of the pulse, you can control the speed of the motor. Please contact me if you have any further problems.

Why not just use the servo library, its standard, well supported, means you can port code from the 8-bit Arduino's etc ?

This example outputs 8 servo signals and reads them back in using interrupts -

Duane B

rcarduino.blogspot.com

I agree DuaneB, I haven't used the servo library because I'm restricted to developing code from first principles for a project. But the servo library aught to work, as servos and ESC operate on the same PWM signals.