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

Dependencies:   brushlessController_TB6612FNG mbed

Committer:
BaserK
Date:
Tue Jul 21 08:01:33 2015 +0000
Revision:
3:afece675a1d5
Parent:
2:1302cfb8f0e9
MIT license is added

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 3:afece675a1d5 5 * @license: MIT license
BaserK 3:afece675a1d5 6 *
BaserK 3:afece675a1d5 7 * Copyright (c) 2015, Baser Kandehir, baser.kandehir@ieee.metu.edu.tr
BaserK 3:afece675a1d5 8 *
BaserK 3:afece675a1d5 9 * Permission is hereby granted, free of charge, to any person obtaining a copy
BaserK 3:afece675a1d5 10 * of this software and associated documentation files (the "Software"), to deal
BaserK 3:afece675a1d5 11 * in the Software without restriction, including without limitation the rights
BaserK 3:afece675a1d5 12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
BaserK 3:afece675a1d5 13 * copies of the Software, and to permit persons to whom the Software is
BaserK 3:afece675a1d5 14 * furnished to do so, subject to the following conditions:
BaserK 3:afece675a1d5 15 *
BaserK 3:afece675a1d5 16 * The above copyright notice and this permission notice shall be included in
BaserK 3:afece675a1d5 17 * all copies or substantial portions of the Software.
BaserK 3:afece675a1d5 18 *
BaserK 3:afece675a1d5 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
BaserK 3:afece675a1d5 20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
BaserK 3:afece675a1d5 21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
BaserK 3:afece675a1d5 22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
BaserK 3:afece675a1d5 23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
BaserK 3:afece675a1d5 24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
BaserK 3:afece675a1d5 25 * THE SOFTWARE.
BaserK 3:afece675a1d5 26 *
BaserK 0:0b4306ff8df4 27 * @description of the program:
BaserK 0:0b4306ff8df4 28 *
BaserK 0:0b4306ff8df4 29 * This a brushless motor control program. As an example it uses a timer to change the direction of the
BaserK 0:0b4306ff8df4 30 * motor. When timer reaches 2 seconds, it changes the direction of movement and resets the timer. One can
BaserK 0:0b4306ff8df4 31 * change the speed of the motor by changing the delay between brushless motor steps.
BaserK 0:0b4306ff8df4 32 *
BaserK 0:0b4306ff8df4 33 * I learned the method from this website, check out the website for more information:
BaserK 0:0b4306ff8df4 34 *
BaserK 0:0b4306ff8df4 35 * http://www.berryjam.eu/2015/04/driving-bldc-gimbals-at-super-slow-speeds-with-arduino/
BaserK 0:0b4306ff8df4 36 *
BaserK 0:0b4306ff8df4 37 */
BaserK 0:0b4306ff8df4 38
BaserK 0:0b4306ff8df4 39 #include "mbed.h"
BaserK 0:0b4306ff8df4 40 #include "brushlessController_TB6612FNG.h"
BaserK 0:0b4306ff8df4 41
BaserK 0:0b4306ff8df4 42 Timer changeDir; // Timer for changing the direction
BaserK 0:0b4306ff8df4 43 bool dir = 0; // Direction of movement
BaserK 2:1302cfb8f0e9 44 int delay = 1000; // Delay between steps (us)
BaserK 0:0b4306ff8df4 45
BaserK 0:0b4306ff8df4 46 int main()
BaserK 0:0b4306ff8df4 47 {
BaserK 0:0b4306ff8df4 48 changeDir.start(); // Start timer
BaserK 0:0b4306ff8df4 49 while(1)
BaserK 0:0b4306ff8df4 50 {
BaserK 2:1302cfb8f0e9 51 if(changeDir.read() > 1)
BaserK 0:0b4306ff8df4 52 {
BaserK 0:0b4306ff8df4 53 dir = !dir;
BaserK 0:0b4306ff8df4 54 changeDir.reset();
BaserK 0:0b4306ff8df4 55 }
BaserK 0:0b4306ff8df4 56 brushlessControl(dir, delay);
BaserK 0:0b4306ff8df4 57 }
BaserK 0:0b4306ff8df4 58 }