나중에 급하게 PID 알고리즘을 적용해 짜본 코드... 시간이 충분치 않아서 그냥 원래 있던 코드를 수정해서 하기로 했기에 버려진 코드지만, 교수님께 참고용으로 Publish를 했다.

Dependencies:   mbed Adafruit_GFX

Committer:
21400688
Date:
Sat Jun 15 20:39:39 2019 +0000
Revision:
0:c4c874d702f9
first commit

Who changed what in which revision?

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