Final Project로 실제 점검에 사용된 코드

Dependencies:   mbed Adafruit_GFX

Committer:
21400688
Date:
Sat Jun 15 20:52:15 2019 +0000
Revision:
0:22391cd705e2
vb

Who changed what in which revision?

UserRevisionLine numberNew contents of line
21400688 0:22391cd705e2 1 /* File: TB6612FNG.h
21400688 0:22391cd705e2 2 * Author: Robert Abad Copyright (c) 2013
21400688 0:22391cd705e2 3 *
21400688 0:22391cd705e2 4 * Desc: driver for Toshiiba TB6612FNG Motor Driver. Though this motor driver
21400688 0:22391cd705e2 5 * can be used to drive two motors (A and B), it can be used to drive
21400688 0:22391cd705e2 6 * just one. Member functions can be used to set period and pulsewidth
21400688 0:22391cd705e2 7 * but are not necessary as the constructor does set default values).
21400688 0:22391cd705e2 8 * The datasheet for this device can be found here:
21400688 0:22391cd705e2 9 * http://www.toshiba.com/taec/components2/Datasheet_Sync/261/27197.pdf
21400688 0:22391cd705e2 10 *
21400688 0:22391cd705e2 11 * Below is some sample code:
21400688 0:22391cd705e2 12 *
21400688 0:22391cd705e2 13 * #include "mbed.h"
21400688 0:22391cd705e2 14 * #include "TB6612FNG.h"
21400688 0:22391cd705e2 15 *
21400688 0:22391cd705e2 16 * #define TB6612FNG_PIN_PWMA (p22)
21400688 0:22391cd705e2 17 * #define TB6612FNG_PIN_AIN1 (p17)
21400688 0:22391cd705e2 18 * #define TB6612FNG_PIN_AIN2 (p16)
21400688 0:22391cd705e2 19 * #define TB6612FNG_PIN_PWMB (p21)
21400688 0:22391cd705e2 20 * #define TB6612FNG_PIN_BIN1 (p19)
21400688 0:22391cd705e2 21 * #define TB6612FNG_PIN_BIN2 (p20)
21400688 0:22391cd705e2 22 * #define TB6612FNG_PIN_NSTBY (p18)
21400688 0:22391cd705e2 23 * TB6612FNG motorDriver( TB6612FNG_PIN_PWMA, TB6612FNG_PIN_AIN1, TB6612FNG_PIN_AIN2,
21400688 0:22391cd705e2 24 * TB6612FNG_PIN_PWMB, TB6612FNG_PIN_BIN1, TB6612FNG_PIN_BIN2,
21400688 0:22391cd705e2 25 * TB6612FNG_PIN_NSTBY );
21400688 0:22391cd705e2 26 * float fPwmPeriod;
21400688 0:22391cd705e2 27 * float fPwmPulsewidth;
21400688 0:22391cd705e2 28 *
21400688 0:22391cd705e2 29 * int main()
21400688 0:22391cd705e2 30 * {
21400688 0:22391cd705e2 31 * fPwmPeriod = 0.00002f; // 50KHz
21400688 0:22391cd705e2 32 * fPwmPulsewidth = 0.50; // 50% duty cycle
21400688 0:22391cd705e2 33 * motorDriver.setPwmAperiod(fPwmPeriod);
21400688 0:22391cd705e2 34 * motorDriver.setPwmBperiod(fPwmPeriod);
21400688 0:22391cd705e2 35 * motorDriver.setPwmApulsewidth(fPwmPulsewidth);
21400688 0:22391cd705e2 36 * motorDriver.setPwmBpulsewidth(fPwmPulsewidth);
21400688 0:22391cd705e2 37 *
21400688 0:22391cd705e2 38 * while(1)
21400688 0:22391cd705e2 39 * {
21400688 0:22391cd705e2 40 * motorDriver.motorA_ccw();
21400688 0:22391cd705e2 41 * wait(2);
21400688 0:22391cd705e2 42 * motorDriver.motorA_cw();
21400688 0:22391cd705e2 43 * wait(2);
21400688 0:22391cd705e2 44 * motorDriver.motorA_stop();
21400688 0:22391cd705e2 45 * wait(2);
21400688 0:22391cd705e2 46 * motorDriver.motorB_ccw();
21400688 0:22391cd705e2 47 * wait(2);
21400688 0:22391cd705e2 48 * motorDriver.motorB_cw();
21400688 0:22391cd705e2 49 * wait(2);
21400688 0:22391cd705e2 50 * motorDriver.motorB_stop();
21400688 0:22391cd705e2 51 * wait(2);
21400688 0:22391cd705e2 52 * }
21400688 0:22391cd705e2 53 * }
21400688 0:22391cd705e2 54 */
21400688 0:22391cd705e2 55
21400688 0:22391cd705e2 56 #ifndef __TB6612FNG_H__
21400688 0:22391cd705e2 57 #define __TB6612FNG_H__
21400688 0:22391cd705e2 58
21400688 0:22391cd705e2 59 #include "mbed.h"
21400688 0:22391cd705e2 60
21400688 0:22391cd705e2 61 #define TB6612FNG_PWM_PERIOD_DEFAULT (0.00002) // 50KHz
21400688 0:22391cd705e2 62 #define TB6612FNG_PWM_PULSEWIDTH_DEFAULT (0.50) // 속도 이거다!
21400688 0:22391cd705e2 63
21400688 0:22391cd705e2 64 class TB6612FNG
21400688 0:22391cd705e2 65 {
21400688 0:22391cd705e2 66 public:
21400688 0:22391cd705e2 67 TB6612FNG( PinName pinPwmA, PinName pinAin1, PinName pinAin2,
21400688 0:22391cd705e2 68 PinName pinPwmB, PinName pinBin1, PinName pinBin2,
21400688 0:22391cd705e2 69 PinName pinNStby );
21400688 0:22391cd705e2 70 void setPwmA(float fPeriod, float fPulsewidth);
21400688 0:22391cd705e2 71 void setPwmAperiod(float fPeriod);
21400688 0:22391cd705e2 72 void setPwmApulsewidth(float fPulsewidth);
21400688 0:22391cd705e2 73 void setPwmB(float fPeriod, float fPulsewidth);
21400688 0:22391cd705e2 74 void setPwmBperiod(float fPeriod);
21400688 0:22391cd705e2 75 void setPwmBpulsewidth(float fPulsewidth);
21400688 0:22391cd705e2 76 void standby(void);
21400688 0:22391cd705e2 77 void motorA_stop(void);
21400688 0:22391cd705e2 78 void motorA_ccw(void);
21400688 0:22391cd705e2 79 void motorA_cw(void);
21400688 0:22391cd705e2 80 void motorB_stop(void);
21400688 0:22391cd705e2 81 void motorB_ccw(void);
21400688 0:22391cd705e2 82 void motorB_cw(void);
21400688 0:22391cd705e2 83 void upPulsewidth(void);
21400688 0:22391cd705e2 84 void downPulsewidth(void);
21400688 0:22391cd705e2 85 float getPwmA(void);
21400688 0:22391cd705e2 86 float getPwmB(void);
21400688 0:22391cd705e2 87
21400688 0:22391cd705e2 88 private:
21400688 0:22391cd705e2 89 PwmOut pwmA;
21400688 0:22391cd705e2 90 DigitalOut Ain1;
21400688 0:22391cd705e2 91 DigitalOut Ain2;
21400688 0:22391cd705e2 92 PwmOut pwmB;
21400688 0:22391cd705e2 93 DigitalOut Bin1;
21400688 0:22391cd705e2 94 DigitalOut Bin2;
21400688 0:22391cd705e2 95 DigitalOut nStby;
21400688 0:22391cd705e2 96 };
21400688 0:22391cd705e2 97
21400688 0:22391cd705e2 98 #endif /* __TB6612FNG_H__ */