Basic test program to control a gimbal brushless motor with TB6612FNG s

Dependencies:   brushlessController_TB6612FNG mbed

Committer:
BaserK
Date:
Fri Jul 17 11:30:34 2015 +0000
Revision:
0:0b4306ff8df4
Child:
2:1302cfb8f0e9
basic test program to control the brushless motor with TB6612FNG

Who changed what in which revision?

UserRevisionLine numberNew contents of line
BaserK 0:0b4306ff8df4 1 /* Controlling a brushless motor precisely with 2X TB6612FNG
BaserK 0:0b4306ff8df4 2 *
BaserK 0:0b4306ff8df4 3 * @author: Baser Kandehir
BaserK 0:0b4306ff8df4 4 * @date: July 17, 2015
BaserK 0:0b4306ff8df4 5 * @license: Use this code however you'd like
BaserK 0:0b4306ff8df4 6 *
BaserK 0:0b4306ff8df4 7 * @description of the program:
BaserK 0:0b4306ff8df4 8 *
BaserK 0:0b4306ff8df4 9 * This a brushless motor control program. As an example it uses a timer to change the direction of the
BaserK 0:0b4306ff8df4 10 * motor. When timer reaches 2 seconds, it changes the direction of movement and resets the timer. One can
BaserK 0:0b4306ff8df4 11 * change the speed of the motor by changing the delay between brushless motor steps.
BaserK 0:0b4306ff8df4 12 *
BaserK 0:0b4306ff8df4 13 * I learned the method from this website, check out the website for more information:
BaserK 0:0b4306ff8df4 14 *
BaserK 0:0b4306ff8df4 15 * http://www.berryjam.eu/2015/04/driving-bldc-gimbals-at-super-slow-speeds-with-arduino/
BaserK 0:0b4306ff8df4 16 *
BaserK 0:0b4306ff8df4 17 */
BaserK 0:0b4306ff8df4 18
BaserK 0:0b4306ff8df4 19 #include "mbed.h"
BaserK 0:0b4306ff8df4 20 #include "brushlessController_TB6612FNG.h"
BaserK 0:0b4306ff8df4 21
BaserK 0:0b4306ff8df4 22 Timer changeDir; // Timer for changing the direction
BaserK 0:0b4306ff8df4 23 bool dir = 0; // Direction of movement
BaserK 0:0b4306ff8df4 24 int delay = 10; // Delay between steps
BaserK 0:0b4306ff8df4 25
BaserK 0:0b4306ff8df4 26 int main()
BaserK 0:0b4306ff8df4 27 {
BaserK 0:0b4306ff8df4 28 changeDir.start(); // Start timer
BaserK 0:0b4306ff8df4 29 while(1)
BaserK 0:0b4306ff8df4 30 {
BaserK 0:0b4306ff8df4 31 if(changeDir.read() > 2)
BaserK 0:0b4306ff8df4 32 {
BaserK 0:0b4306ff8df4 33 dir = !dir;
BaserK 0:0b4306ff8df4 34 changeDir.reset();
BaserK 0:0b4306ff8df4 35 }
BaserK 0:0b4306ff8df4 36 brushlessControl(dir, delay);
BaserK 0:0b4306ff8df4 37 }
BaserK 0:0b4306ff8df4 38 }