Sample for TB6612FNG without library

Dependencies:   mbed

Committer:
ppr2013G2
Date:
Fri Jul 01 05:00:12 2016 +0000
Revision:
0:0c3d3031e710
TB6612FNG sample without library;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ppr2013G2 0:0c3d3031e710 1 #include "mbed.h"
ppr2013G2 0:0c3d3031e710 2
ppr2013G2 0:0c3d3031e710 3 #define LOW 0
ppr2013G2 0:0c3d3031e710 4 #define HIGH 1
ppr2013G2 0:0c3d3031e710 5
ppr2013G2 0:0c3d3031e710 6 PwmOut pwmA(PTC9);
ppr2013G2 0:0c3d3031e710 7 DigitalOut Ain1(PTB1);
ppr2013G2 0:0c3d3031e710 8 DigitalOut Ain2(PTB0);
ppr2013G2 0:0c3d3031e710 9 PwmOut pwmB(PTA1);
ppr2013G2 0:0c3d3031e710 10 DigitalOut Bin1(PTB3);
ppr2013G2 0:0c3d3031e710 11 DigitalOut Bin2(PTC2);
ppr2013G2 0:0c3d3031e710 12 DigitalOut Stby(PTB2);
ppr2013G2 0:0c3d3031e710 13
ppr2013G2 0:0c3d3031e710 14 int main() {
ppr2013G2 0:0c3d3031e710 15 float p_a = 0.00002f;//50KHz
ppr2013G2 0:0c3d3031e710 16 float p_b = 0.00002f;
ppr2013G2 0:0c3d3031e710 17 float pw_a = 1.0;//duty cycle 0.0~1.0 -> 0%~100%
ppr2013G2 0:0c3d3031e710 18 float pw_b = 1.0;
ppr2013G2 0:0c3d3031e710 19
ppr2013G2 0:0c3d3031e710 20 pwmA.period(p_a);
ppr2013G2 0:0c3d3031e710 21 pwmB.period(p_b);
ppr2013G2 0:0c3d3031e710 22
ppr2013G2 0:0c3d3031e710 23 pwmA = pw_a;
ppr2013G2 0:0c3d3031e710 24 pwmB = pw_b;
ppr2013G2 0:0c3d3031e710 25
ppr2013G2 0:0c3d3031e710 26 while(1) {
ppr2013G2 0:0c3d3031e710 27 //CW
ppr2013G2 0:0c3d3031e710 28 Stby = HIGH;
ppr2013G2 0:0c3d3031e710 29
ppr2013G2 0:0c3d3031e710 30 Ain1 = HIGH;
ppr2013G2 0:0c3d3031e710 31 Ain2 = LOW;
ppr2013G2 0:0c3d3031e710 32
ppr2013G2 0:0c3d3031e710 33 Bin1 = HIGH;
ppr2013G2 0:0c3d3031e710 34 Bin2 = LOW;
ppr2013G2 0:0c3d3031e710 35
ppr2013G2 0:0c3d3031e710 36 wait(5);
ppr2013G2 0:0c3d3031e710 37
ppr2013G2 0:0c3d3031e710 38 //STBY
ppr2013G2 0:0c3d3031e710 39 Stby = LOW;
ppr2013G2 0:0c3d3031e710 40
ppr2013G2 0:0c3d3031e710 41 wait(5);
ppr2013G2 0:0c3d3031e710 42
ppr2013G2 0:0c3d3031e710 43 //CCW
ppr2013G2 0:0c3d3031e710 44 Stby = HIGH;
ppr2013G2 0:0c3d3031e710 45 Ain1 = LOW;
ppr2013G2 0:0c3d3031e710 46 Ain2 = HIGH;
ppr2013G2 0:0c3d3031e710 47
ppr2013G2 0:0c3d3031e710 48 Bin1 = LOW;
ppr2013G2 0:0c3d3031e710 49 Bin2 = HIGH;
ppr2013G2 0:0c3d3031e710 50
ppr2013G2 0:0c3d3031e710 51 wait(5);
ppr2013G2 0:0c3d3031e710 52
ppr2013G2 0:0c3d3031e710 53 //STOP
ppr2013G2 0:0c3d3031e710 54 Ain1 = LOW;
ppr2013G2 0:0c3d3031e710 55 Ain2 = LOW;
ppr2013G2 0:0c3d3031e710 56
ppr2013G2 0:0c3d3031e710 57 Bin1 = LOW;
ppr2013G2 0:0c3d3031e710 58 Bin2 = LOW;
ppr2013G2 0:0c3d3031e710 59
ppr2013G2 0:0c3d3031e710 60 wait(5);
ppr2013G2 0:0c3d3031e710 61
ppr2013G2 0:0c3d3031e710 62 }
ppr2013G2 0:0c3d3031e710 63 }