Go Down

Topic: Due controlling ESC with PWM. (Read 2003 times) previous topic - next topic

TwiggySticks

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?

so3ody

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

TjaartBester

Hi TwiggySticks

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

Code: [Select]
#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);

}

TjaartBester

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.

DuaneB

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 -

http://rcarduino.blogspot.ae/2013/04/reading-rc-channels-with-arduino-due.html

Duane B

rcarduino.blogspot.com
Read this
http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html
then watch this
http://rcarduino.blogspot.com/2012/04/servo-problems-part-2-demonstration.html

Rcarduino.blogspot.com

TjaartBester

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.

Go Up