REGENERATIVE BRAKING OF BLDC MOTOR USING ARDUINO

Photo of author

By Jackson Taylor

Home » DIY Tech Projects » REGENERATIVE BRAKING OF BLDC MOTOR USING ARDUINO

As an Amazon Associate we earn from qualifying purchases.

YouTube video

WAVE FORMS

COMPUTER HARD DISK BLDC MOTOR (LOAD IS HARD DISK DRUM)

(blue color is pwm given to boost circuit mosfet gate and yellow is output voltage with filtering across load of 1K ohm)

Waveform 1 Waveform 2 Waveform 3

Quadcopter BLDC motor (at no load – free running)

Quadcopter waveform 1 Quadcopter waveform 2

PROGRAM

BOOST SIDE

#define relay 13
void setup()
{
    pinMode(relay,OUTPUT);  
    delay(2000);
    digitalWrite(relay,HIGH);
    setPwmFrequency(11, 1);
    analogWrite(11,50);
}
void loop()
{
    //int a=analogRead(3)/4;delay(1);
    //if(a>220) a=220;
    //analogWrite(11,a);
}
void setPwmFrequency(int pin, int divisor) {
     byte mode;
     if(pin == 5 || pin == 6 || pin == 9 || pin == 10) {
       switch(divisor) {
         case 1: mode = 0x01; break;
         case 8: mode = 0x02; break;
         case 64: mode = 0x03; break;
         case 256: mode = 0x04; break;
         case 1024: mode = 0x05; break;
         default: return;
       }
       if(pin == 5 || pin == 6) {
         TCCR0B = TCCR0B & 0b11111000 | mode;
       } else {
         TCCR1B = TCCR1B & 0b11111000 | mode;
       }
     } else if(pin == 3 || pin == 11) {
       switch(divisor) {
         case 1: mode = 0x01; break;
         case 8: mode = 0x02; break;
         case 32: mode = 0x03; break;
         case 64: mode = 0x04; break;
         case 128: mode = 0x05; break;
         case 256: mode = 0x06; break;
         case 1024: mode = 0x7; break;
         default: return;
       }
       TCCR2B = TCCR2B & 0b11111000 | mode;
     }
}

/**
 * Divides a given PWM pin frequency by a divisor.
 * 
 * The resulting frequency is equal to the base frequency divided by
 * the given divisor:
 *   - Base frequencies:
 *       o The base frequency for pins 3, 9, 10, and 11 is 31250 Hz.
 *       o The base frequency for pins 5 and 6 is 62500 Hz.
 *   - Divisors:
 *       o The divisors available on pins 5, 6, 9 and 10 are: 1, 8, 64,
 *         256, and 1024.
 *       o The divisors available on pins 3 and 11 are: 1, 8, 32, 64,
 *         128, 256, and 1024.
 * 
 * PWM frequencies are tied together in pairs of pins. If one in a
 * pair is changed, the other is also changed to match:
 *   - Pins 5 and 6 are paired on timer0
 *   - Pins 9 and 10 are paired on timer1
 *   - Pins 3 and 11 are paired on timer2
 * 
 * Note that this function will have side effects on anything else
 * that uses timers:
 *   - Changes on pins 3, 5, 6, or 11 may cause the delay() and
 *     millis() functions to stop working. Other timing-related
 *     functions may also be affected.
 *   - Changes on pins 9 or 10 will cause the Servo library to function
 *     incorrectly.
 * 
 * Thanks to macegr of the Arduino forums for his documentation of the
 * PWM frequency divisors. His post can be viewed at:
 *   http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235060559/0#4
 *
 */

ESC SIDE (ESC SPEED CONTROL USING POT)

//WHITE OR ORANGE WIRE TO PIN 9
//BLACK WIRE TO GNDX

See also
REGENERATIVE BRAKING OF BLDC MOTOR USING ARDUINO
#include <Servo.h>
Servo esc;
int throttlePin = 0;
void setup()
{
    esc.attach(9);
}
void loop()
{
    int throttle = analogRead(throttlePin);
    throttle = map(throttle, 0, 1023, 0, 179);
    esc.write(throttle);
}

How Regenerative Braking Works in This Setup

A brushless DC motor can also work as a generator. When something else spins the rotor, such as a flywheel, a propeller or a wheel that is still turning, the windings produce a voltage called back-EMF. That voltage rises and falls with rotor speed. Regenerative braking uses this effect: the motor’s energy is pulled out electrically instead of being lost as heat in a mechanical brake, and the extracted energy also slows the rotor down.

Hardware Hack

Stop Buying New Batteries for Your Tech

Electronics are expensive, but their power sources don't have to be. Discover the simple engineering trick to recondition dead batteries and bring your gadgets back to 100% capacity.

Watch the Free Video

A BLDC motor produces three-phase AC, so the output normally has to be rectified before a DC circuit can use it. The voltage is also often too low to be useful when the motor is turning slowly. This is why the project uses a boost converter. The Arduino sends a high-frequency PWM signal to the MOSFET in the converter, and the converter steps the rectified voltage up to a level that can charge a battery or feed a load. In the boost-side code, setPwmFrequency(11, 1) sets pin 11 to its fastest PWM rate, and analogWrite(11, 50) fixes the duty cycle. The commented-out lines in loop() show how you could change the duty cycle with a potentiometer.

The ESC side of the project is only there to spin the motor up. The potentiometer sets the throttle, and the ESC drives the motor. When you reduce the throttle or cut it, the motor keeps turning for a while and the boost circuit collects energy from it.

Tips before you build it

  • Tie the grounds together. The Arduino, the ESC and the boost circuit need a common ground for the PWM signals to work properly.
  • Start with a small motor. A hard disk motor or a free-running quadcopter motor, as used in the waveforms above, produces low power and is safer for first tests.
  • Check the output voltage before connecting a load. A boost converter with no load or a fixed duty cycle can reach a higher voltage than your parts are rated for, so use a capacitor and a resistor load rated for the voltage you expect.
  • Add a fuse and keep the Arduino isolated. The Arduino pin should drive the MOSFET gate only, ideally through a gate driver, and never connect it to the power side.
  • Expect small returns. Small motors recover only a little energy, so treat this as a learning project, not a way to save power.
See also
LCD ARDUINO

Revive Your Dead Electronics

Got a drawer full of dead gadgets or a failing car battery? Instead of paying a premium for replacements, use this simple trick to easily recondition them right from home.

See How It Works