Runs an RC Brushless DC motor using with an ESC module. Mbed supplies the PWM control signal for the ESC. See https://developer.mbed.org/users/4180_1/notebook/using-a-dc-brushless-motor-with-an-rc-esc/ for more info

Dependencies:   Servo mbed

Committer:
4180_1
Date:
Sun May 14 12:38:56 2017 +0000
Revision:
0:378b1492eaf6
ver 1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
4180_1 0:378b1492eaf6 1 // Calibrate and arm ESC and then sweep through motor speed range
4180_1 0:378b1492eaf6 2 // To run: Hold down reset on mbed and power up ESC motor supply
4180_1 0:378b1492eaf6 3 // Wait for three power up beeps from ESC, then release reset (or apply power) on mbed
4180_1 0:378b1492eaf6 4 // See https://github.com/bitdump/BLHeli/blob/master/BLHeli_S%20SiLabs/BLHeli_S%20manual%20SiLabs%20Rev16.x.pdf
4180_1 0:378b1492eaf6 5 // for info on beep codes and calibration
4180_1 0:378b1492eaf6 6 #include "mbed.h"
4180_1 0:378b1492eaf6 7 #include "Servo.h"
4180_1 0:378b1492eaf6 8 PwmOut ledf(LED1); //throttle up test led with PWM dimming
4180_1 0:378b1492eaf6 9 PwmOut ledr(LED2); //throttle down test led with PWM dimming
4180_1 0:378b1492eaf6 10
4180_1 0:378b1492eaf6 11 Servo myservo(p21);
4180_1 0:378b1492eaf6 12
4180_1 0:378b1492eaf6 13 int main()
4180_1 0:378b1492eaf6 14 {
4180_1 0:378b1492eaf6 15 myservo = 0.0;
4180_1 0:378b1492eaf6 16 ledf = ledr = 1;
4180_1 0:378b1492eaf6 17 wait(0.5); //ESC detects signal
4180_1 0:378b1492eaf6 18 //Required ESC Calibration/Arming sequence
4180_1 0:378b1492eaf6 19 //sends longest and shortest PWM pulse to learn and arm at power on
4180_1 0:378b1492eaf6 20 myservo = 1.0; //send longest PWM
4180_1 0:378b1492eaf6 21 ledf = ledr = 0;
4180_1 0:378b1492eaf6 22 wait(8);
4180_1 0:378b1492eaf6 23 myservo = 0.0; //send shortest PWM
4180_1 0:378b1492eaf6 24 wait(8);
4180_1 0:378b1492eaf6 25 //ESC now operational using standard servo PWM signals
4180_1 0:378b1492eaf6 26 while (1) {
4180_1 0:378b1492eaf6 27 for (float p=0.0; p<=1.0; p += 0.025) { //Throttle up slowly to full throttle
4180_1 0:378b1492eaf6 28 myservo = p;
4180_1 0:378b1492eaf6 29 ledf = p;
4180_1 0:378b1492eaf6 30 wait(1.0);
4180_1 0:378b1492eaf6 31 }
4180_1 0:378b1492eaf6 32 myservo = 0.0; //Motor off
4180_1 0:378b1492eaf6 33 ledf = ledr = 0;
4180_1 0:378b1492eaf6 34 wait(4.0);
4180_1 0:378b1492eaf6 35 for (float p=1.0; p>=0.0; p -= 0.025) { //Throttle down slowly from full throttle
4180_1 0:378b1492eaf6 36 myservo = p;
4180_1 0:378b1492eaf6 37 ledr = p;
4180_1 0:378b1492eaf6 38 wait(1.0);
4180_1 0:378b1492eaf6 39 }
4180_1 0:378b1492eaf6 40 myservo = 0.0; //Motor off
4180_1 0:378b1492eaf6 41 ledf = ledr = 0;
4180_1 0:378b1492eaf6 42 wait(4.0);
4180_1 0:378b1492eaf6 43 }
4180_1 0:378b1492eaf6 44 }