Final Project로 실제 점검에 사용된 코드
Dependencies: mbed Adafruit_GFX
TB6612FNG/TB6612FNG.cpp@0:22391cd705e2, 2019-06-15 (annotated)
- Committer:
- 21400688
- Date:
- Sat Jun 15 20:52:15 2019 +0000
- Revision:
- 0:22391cd705e2
vb
Who changed what in which revision?
User | Revision | Line number | New 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 TB6612FNG Motor Driver. For further details see |
21400688 | 0:22391cd705e2 | 5 | * header file, TB6612FNG.h |
21400688 | 0:22391cd705e2 | 6 | */ |
21400688 | 0:22391cd705e2 | 7 | |
21400688 | 0:22391cd705e2 | 8 | #include "mbed.h" |
21400688 | 0:22391cd705e2 | 9 | #include "TB6612FNG.h" |
21400688 | 0:22391cd705e2 | 10 | |
21400688 | 0:22391cd705e2 | 11 | #define SIGNAL_HIGH (1) |
21400688 | 0:22391cd705e2 | 12 | #define SIGNAL_LOW (0) |
21400688 | 0:22391cd705e2 | 13 | |
21400688 | 0:22391cd705e2 | 14 | TB6612FNG::TB6612FNG( PinName pinPwmA, PinName pinAin1, PinName pinAin2, |
21400688 | 0:22391cd705e2 | 15 | PinName pinPwmB, PinName pinBin1, PinName pinBin2, |
21400688 | 0:22391cd705e2 | 16 | PinName pinNStby ) : |
21400688 | 0:22391cd705e2 | 17 | pwmA(pinPwmA), |
21400688 | 0:22391cd705e2 | 18 | Ain1(pinAin1), |
21400688 | 0:22391cd705e2 | 19 | Ain2(pinAin2), |
21400688 | 0:22391cd705e2 | 20 | pwmB(pinPwmB), |
21400688 | 0:22391cd705e2 | 21 | Bin1(pinBin1), |
21400688 | 0:22391cd705e2 | 22 | Bin2(pinBin2), |
21400688 | 0:22391cd705e2 | 23 | nStby(pinNStby) |
21400688 | 0:22391cd705e2 | 24 | { |
21400688 | 0:22391cd705e2 | 25 | Ain1 = SIGNAL_LOW; |
21400688 | 0:22391cd705e2 | 26 | Ain2 = SIGNAL_LOW; |
21400688 | 0:22391cd705e2 | 27 | Bin1 = SIGNAL_LOW; |
21400688 | 0:22391cd705e2 | 28 | Bin2 = SIGNAL_LOW; |
21400688 | 0:22391cd705e2 | 29 | pwmA.period(TB6612FNG_PWM_PERIOD_DEFAULT); |
21400688 | 0:22391cd705e2 | 30 | pwmA = TB6612FNG_PWM_PULSEWIDTH_DEFAULT; |
21400688 | 0:22391cd705e2 | 31 | pwmB.period(TB6612FNG_PWM_PERIOD_DEFAULT); |
21400688 | 0:22391cd705e2 | 32 | pwmB = TB6612FNG_PWM_PULSEWIDTH_DEFAULT; |
21400688 | 0:22391cd705e2 | 33 | nStby = SIGNAL_LOW; |
21400688 | 0:22391cd705e2 | 34 | } |
21400688 | 0:22391cd705e2 | 35 | |
21400688 | 0:22391cd705e2 | 36 | void TB6612FNG::setPwmA(float fPeriod, float fPulsewidth) |
21400688 | 0:22391cd705e2 | 37 | { |
21400688 | 0:22391cd705e2 | 38 | pwmA.period(fPeriod); |
21400688 | 0:22391cd705e2 | 39 | pwmA = fPulsewidth; |
21400688 | 0:22391cd705e2 | 40 | } |
21400688 | 0:22391cd705e2 | 41 | |
21400688 | 0:22391cd705e2 | 42 | void TB6612FNG::setPwmAperiod(float fPeriod) |
21400688 | 0:22391cd705e2 | 43 | { |
21400688 | 0:22391cd705e2 | 44 | pwmA.period(fPeriod); |
21400688 | 0:22391cd705e2 | 45 | } |
21400688 | 0:22391cd705e2 | 46 | |
21400688 | 0:22391cd705e2 | 47 | void TB6612FNG::setPwmApulsewidth(float fPulsewidth) |
21400688 | 0:22391cd705e2 | 48 | { |
21400688 | 0:22391cd705e2 | 49 | pwmA = fPulsewidth; |
21400688 | 0:22391cd705e2 | 50 | } |
21400688 | 0:22391cd705e2 | 51 | float TB6612FNG::getPwmA() |
21400688 | 0:22391cd705e2 | 52 | { |
21400688 | 0:22391cd705e2 | 53 | return pwmA; |
21400688 | 0:22391cd705e2 | 54 | } |
21400688 | 0:22391cd705e2 | 55 | float TB6612FNG::getPwmB() |
21400688 | 0:22391cd705e2 | 56 | { |
21400688 | 0:22391cd705e2 | 57 | return pwmB; |
21400688 | 0:22391cd705e2 | 58 | } |
21400688 | 0:22391cd705e2 | 59 | void TB6612FNG::setPwmB(float fPeriod, float fPulsewidth) |
21400688 | 0:22391cd705e2 | 60 | { |
21400688 | 0:22391cd705e2 | 61 | pwmB.period(fPeriod); |
21400688 | 0:22391cd705e2 | 62 | pwmB = fPulsewidth; |
21400688 | 0:22391cd705e2 | 63 | } |
21400688 | 0:22391cd705e2 | 64 | |
21400688 | 0:22391cd705e2 | 65 | void TB6612FNG::setPwmBperiod(float fPeriod) |
21400688 | 0:22391cd705e2 | 66 | { |
21400688 | 0:22391cd705e2 | 67 | pwmB.period(fPeriod); |
21400688 | 0:22391cd705e2 | 68 | } |
21400688 | 0:22391cd705e2 | 69 | |
21400688 | 0:22391cd705e2 | 70 | void TB6612FNG::setPwmBpulsewidth(float fPulsewidth) |
21400688 | 0:22391cd705e2 | 71 | { |
21400688 | 0:22391cd705e2 | 72 | pwmB = fPulsewidth; |
21400688 | 0:22391cd705e2 | 73 | } |
21400688 | 0:22391cd705e2 | 74 | |
21400688 | 0:22391cd705e2 | 75 | void TB6612FNG::standby(void) |
21400688 | 0:22391cd705e2 | 76 | { |
21400688 | 0:22391cd705e2 | 77 | nStby = SIGNAL_LOW; |
21400688 | 0:22391cd705e2 | 78 | } |
21400688 | 0:22391cd705e2 | 79 | |
21400688 | 0:22391cd705e2 | 80 | void TB6612FNG::motorA_stop(void) |
21400688 | 0:22391cd705e2 | 81 | { |
21400688 | 0:22391cd705e2 | 82 | Ain1 = SIGNAL_LOW; |
21400688 | 0:22391cd705e2 | 83 | Ain2 = SIGNAL_LOW; |
21400688 | 0:22391cd705e2 | 84 | } |
21400688 | 0:22391cd705e2 | 85 | |
21400688 | 0:22391cd705e2 | 86 | void TB6612FNG::motorA_ccw(void) |
21400688 | 0:22391cd705e2 | 87 | { |
21400688 | 0:22391cd705e2 | 88 | Ain1 = SIGNAL_LOW; |
21400688 | 0:22391cd705e2 | 89 | Ain2 = SIGNAL_HIGH; |
21400688 | 0:22391cd705e2 | 90 | nStby = SIGNAL_HIGH; |
21400688 | 0:22391cd705e2 | 91 | } |
21400688 | 0:22391cd705e2 | 92 | |
21400688 | 0:22391cd705e2 | 93 | void TB6612FNG::motorA_cw(void) |
21400688 | 0:22391cd705e2 | 94 | { |
21400688 | 0:22391cd705e2 | 95 | Ain1 = SIGNAL_HIGH; |
21400688 | 0:22391cd705e2 | 96 | Ain2 = SIGNAL_LOW; |
21400688 | 0:22391cd705e2 | 97 | nStby = SIGNAL_HIGH; |
21400688 | 0:22391cd705e2 | 98 | } |
21400688 | 0:22391cd705e2 | 99 | |
21400688 | 0:22391cd705e2 | 100 | void TB6612FNG::motorB_stop(void) |
21400688 | 0:22391cd705e2 | 101 | { |
21400688 | 0:22391cd705e2 | 102 | Bin1 = SIGNAL_LOW; |
21400688 | 0:22391cd705e2 | 103 | Bin2 = SIGNAL_LOW; |
21400688 | 0:22391cd705e2 | 104 | } |
21400688 | 0:22391cd705e2 | 105 | |
21400688 | 0:22391cd705e2 | 106 | void TB6612FNG::motorB_ccw(void) |
21400688 | 0:22391cd705e2 | 107 | { |
21400688 | 0:22391cd705e2 | 108 | Bin1 = SIGNAL_LOW; |
21400688 | 0:22391cd705e2 | 109 | Bin2 = SIGNAL_HIGH; |
21400688 | 0:22391cd705e2 | 110 | nStby = SIGNAL_HIGH; |
21400688 | 0:22391cd705e2 | 111 | } |
21400688 | 0:22391cd705e2 | 112 | |
21400688 | 0:22391cd705e2 | 113 | void TB6612FNG::motorB_cw(void) |
21400688 | 0:22391cd705e2 | 114 | { |
21400688 | 0:22391cd705e2 | 115 | Bin1 = SIGNAL_HIGH; |
21400688 | 0:22391cd705e2 | 116 | Bin2 = SIGNAL_LOW; |
21400688 | 0:22391cd705e2 | 117 | nStby = SIGNAL_HIGH; |
21400688 | 0:22391cd705e2 | 118 | } |