H-Bridge driver

Fork of TB6612FNG by Robert Abad

Committer:
rabad1
Date:
Mon Dec 02 03:58:48 2013 +0000
Revision:
1:8f562bdd5e93
Parent:
0:1a07771ff613
Child:
2:4231e0b6e68d
updated library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rabad1 0:1a07771ff613 1 /* File: TB6612FNG.h
rabad1 0:1a07771ff613 2 * Author: Robert Abad Copyright (c) 2013
rabad1 0:1a07771ff613 3 *
rabad1 0:1a07771ff613 4 * Desc: driver for TB6612FNG Motor Driver. For further details see
rabad1 0:1a07771ff613 5 * header file, TB6612FNG.h
rabad1 0:1a07771ff613 6 */
rabad1 0:1a07771ff613 7
rabad1 0:1a07771ff613 8 #include "mbed.h"
rabad1 0:1a07771ff613 9 #include "TB6612FNG.h"
rabad1 0:1a07771ff613 10
rabad1 0:1a07771ff613 11 #define SIGNAL_HIGH (1)
rabad1 0:1a07771ff613 12 #define SIGNAL_LOW (0)
rabad1 0:1a07771ff613 13
rabad1 0:1a07771ff613 14 TB6612FNG::TB6612FNG( PinName pinPwmA, PinName pinAin1, PinName pinAin2,
rabad1 0:1a07771ff613 15 PinName pinPwmB, PinName pinBin1, PinName pinBin2,
rabad1 0:1a07771ff613 16 PinName pinNStby ) :
rabad1 0:1a07771ff613 17 pwmA(pinPwmA),
rabad1 0:1a07771ff613 18 Ain1(pinAin1),
rabad1 0:1a07771ff613 19 Ain2(pinAin2),
rabad1 0:1a07771ff613 20 pwmB(pinPwmB),
rabad1 0:1a07771ff613 21 Bin1(pinBin1),
rabad1 0:1a07771ff613 22 Bin2(pinBin2),
rabad1 0:1a07771ff613 23 nStby(pinNStby)
rabad1 0:1a07771ff613 24 {
rabad1 0:1a07771ff613 25 Ain1 = SIGNAL_LOW;
rabad1 0:1a07771ff613 26 Ain2 = SIGNAL_LOW;
rabad1 0:1a07771ff613 27 Bin1 = SIGNAL_LOW;
rabad1 0:1a07771ff613 28 Bin2 = SIGNAL_LOW;
rabad1 0:1a07771ff613 29 pwmA.period(TB6612FNG_PWM_PERIOD_DEFAULT);
rabad1 0:1a07771ff613 30 pwmA = TB6612FNG_PWM_PULSEWIDTH_DEFAULT;
rabad1 0:1a07771ff613 31 pwmB.period(TB6612FNG_PWM_PERIOD_DEFAULT);
rabad1 0:1a07771ff613 32 pwmB = TB6612FNG_PWM_PULSEWIDTH_DEFAULT;
rabad1 0:1a07771ff613 33 nStby = SIGNAL_LOW;
rabad1 0:1a07771ff613 34 }
rabad1 0:1a07771ff613 35
rabad1 1:8f562bdd5e93 36 void TB6612FNG::setPwmA(float fPeriod, float fPulsewidth)
rabad1 1:8f562bdd5e93 37 {
rabad1 1:8f562bdd5e93 38 pwmA.period(fPeriod);
rabad1 1:8f562bdd5e93 39 pwmA = fPulsewidth;
rabad1 1:8f562bdd5e93 40 }
rabad1 1:8f562bdd5e93 41
rabad1 0:1a07771ff613 42 void TB6612FNG::setPwmAperiod(float fPeriod)
rabad1 0:1a07771ff613 43 {
rabad1 0:1a07771ff613 44 pwmA.period(fPeriod);
rabad1 0:1a07771ff613 45 }
rabad1 0:1a07771ff613 46
rabad1 0:1a07771ff613 47 void TB6612FNG::setPwmApulsewidth(float fPulsewidth)
rabad1 0:1a07771ff613 48 {
rabad1 0:1a07771ff613 49 pwmA = fPulsewidth;
rabad1 0:1a07771ff613 50 }
rabad1 0:1a07771ff613 51
rabad1 1:8f562bdd5e93 52 void TB6612FNG::setPwmB(float fPeriod, float fPulsewidth)
rabad1 1:8f562bdd5e93 53 {
rabad1 1:8f562bdd5e93 54 pwmB.period(fPeriod);
rabad1 1:8f562bdd5e93 55 pwmB = fPulsewidth;
rabad1 1:8f562bdd5e93 56 }
rabad1 1:8f562bdd5e93 57
rabad1 0:1a07771ff613 58 void TB6612FNG::setPwmBperiod(float fPeriod)
rabad1 0:1a07771ff613 59 {
rabad1 0:1a07771ff613 60 pwmB.period(fPeriod);
rabad1 0:1a07771ff613 61 }
rabad1 0:1a07771ff613 62
rabad1 0:1a07771ff613 63 void TB6612FNG::setPwmBpulsewidth(float fPulsewidth)
rabad1 0:1a07771ff613 64 {
rabad1 0:1a07771ff613 65 pwmB = fPulsewidth;
rabad1 0:1a07771ff613 66 }
rabad1 0:1a07771ff613 67
rabad1 0:1a07771ff613 68 void TB6612FNG::standby(void)
rabad1 0:1a07771ff613 69 {
rabad1 0:1a07771ff613 70 nStby = SIGNAL_LOW;
rabad1 0:1a07771ff613 71 }
rabad1 0:1a07771ff613 72
rabad1 0:1a07771ff613 73 void TB6612FNG::motorA_stop(void)
rabad1 0:1a07771ff613 74 {
rabad1 0:1a07771ff613 75 Ain1 = SIGNAL_LOW;
rabad1 0:1a07771ff613 76 Ain2 = SIGNAL_LOW;
rabad1 0:1a07771ff613 77 }
rabad1 0:1a07771ff613 78
rabad1 0:1a07771ff613 79 void TB6612FNG::motorA_ccw(void)
rabad1 0:1a07771ff613 80 {
rabad1 0:1a07771ff613 81 Ain1 = SIGNAL_LOW;
rabad1 0:1a07771ff613 82 Ain2 = SIGNAL_HIGH;
rabad1 0:1a07771ff613 83 nStby = SIGNAL_HIGH;
rabad1 0:1a07771ff613 84 }
rabad1 0:1a07771ff613 85
rabad1 0:1a07771ff613 86 void TB6612FNG::motorA_cw(void)
rabad1 0:1a07771ff613 87 {
rabad1 0:1a07771ff613 88 Ain1 = SIGNAL_HIGH;
rabad1 0:1a07771ff613 89 Ain2 = SIGNAL_LOW;
rabad1 0:1a07771ff613 90 nStby = SIGNAL_HIGH;
rabad1 0:1a07771ff613 91 }
rabad1 0:1a07771ff613 92
rabad1 0:1a07771ff613 93 void TB6612FNG::motorB_stop(void)
rabad1 0:1a07771ff613 94 {
rabad1 0:1a07771ff613 95 Bin1 = SIGNAL_LOW;
rabad1 0:1a07771ff613 96 Bin2 = SIGNAL_LOW;
rabad1 0:1a07771ff613 97 }
rabad1 0:1a07771ff613 98
rabad1 0:1a07771ff613 99 void TB6612FNG::motorB_ccw(void)
rabad1 0:1a07771ff613 100 {
rabad1 0:1a07771ff613 101 Bin1 = SIGNAL_LOW;
rabad1 0:1a07771ff613 102 Bin2 = SIGNAL_HIGH;
rabad1 0:1a07771ff613 103 nStby = SIGNAL_HIGH;
rabad1 0:1a07771ff613 104 }
rabad1 0:1a07771ff613 105
rabad1 0:1a07771ff613 106 void TB6612FNG::motorB_cw(void)
rabad1 0:1a07771ff613 107 {
rabad1 0:1a07771ff613 108 Bin1 = SIGNAL_HIGH;
rabad1 0:1a07771ff613 109 Bin2 = SIGNAL_LOW;
rabad1 0:1a07771ff613 110 nStby = SIGNAL_HIGH;
rabad1 0:1a07771ff613 111 }
rabad1 0:1a07771ff613 112
rabad1 1:8f562bdd5e93 113