Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: ROBot TB6612FNG_Sample TB6612FNG_Sample
TB6612FNG.cpp
00001 /* File: TB6612FNG.h 00002 * Author: Robert Abad Copyright (c) 2013 00003 * 00004 * Desc: driver for TB6612FNG Motor Driver. For further details see 00005 * header file, TB6612FNG.h 00006 */ 00007 00008 #include "mbed.h" 00009 #include "TB6612FNG.h" 00010 00011 #define SIGNAL_HIGH (1) 00012 #define SIGNAL_LOW (0) 00013 00014 TB6612FNG::TB6612FNG( PinName pinPwmA, PinName pinAin1, PinName pinAin2, 00015 PinName pinPwmB, PinName pinBin1, PinName pinBin2, 00016 PinName pinNStby ) : 00017 pwmA(pinPwmA), 00018 Ain1(pinAin1), 00019 Ain2(pinAin2), 00020 pwmB(pinPwmB), 00021 Bin1(pinBin1), 00022 Bin2(pinBin2), 00023 nStby(pinNStby) 00024 { 00025 Ain1 = SIGNAL_LOW; 00026 Ain2 = SIGNAL_LOW; 00027 Bin1 = SIGNAL_LOW; 00028 Bin2 = SIGNAL_LOW; 00029 pwmA.period(TB6612FNG_PWM_PERIOD_DEFAULT); 00030 pwmA = TB6612FNG_PWM_PULSEWIDTH_DEFAULT; 00031 pwmB.period(TB6612FNG_PWM_PERIOD_DEFAULT); 00032 pwmB = TB6612FNG_PWM_PULSEWIDTH_DEFAULT; 00033 nStby = SIGNAL_LOW; 00034 } 00035 00036 void TB6612FNG::setPwmA(float fPeriod, float fPulsewidth) 00037 { 00038 pwmA.period(fPeriod); 00039 pwmA = fPulsewidth; 00040 } 00041 00042 void TB6612FNG::setPwmAperiod(float fPeriod) 00043 { 00044 pwmA.period(fPeriod); 00045 } 00046 00047 void TB6612FNG::setPwmApulsewidth(float fPulsewidth) 00048 { 00049 pwmA = fPulsewidth; 00050 } 00051 00052 void TB6612FNG::setPwmB(float fPeriod, float fPulsewidth) 00053 { 00054 pwmB.period(fPeriod); 00055 pwmB = fPulsewidth; 00056 } 00057 00058 void TB6612FNG::setPwmBperiod(float fPeriod) 00059 { 00060 pwmB.period(fPeriod); 00061 } 00062 00063 void TB6612FNG::setPwmBpulsewidth(float fPulsewidth) 00064 { 00065 pwmB = fPulsewidth; 00066 } 00067 00068 void TB6612FNG::standby(void) 00069 { 00070 nStby = SIGNAL_LOW; 00071 } 00072 00073 void TB6612FNG::motorA_stop(void) 00074 { 00075 Ain1 = SIGNAL_LOW; 00076 Ain2 = SIGNAL_LOW; 00077 } 00078 00079 void TB6612FNG::motorA_ccw(void) 00080 { 00081 Ain1 = SIGNAL_LOW; 00082 Ain2 = SIGNAL_HIGH; 00083 nStby = SIGNAL_HIGH; 00084 } 00085 00086 void TB6612FNG::motorA_cw(void) 00087 { 00088 Ain1 = SIGNAL_HIGH; 00089 Ain2 = SIGNAL_LOW; 00090 nStby = SIGNAL_HIGH; 00091 } 00092 00093 void TB6612FNG::motorB_stop(void) 00094 { 00095 Bin1 = SIGNAL_LOW; 00096 Bin2 = SIGNAL_LOW; 00097 } 00098 00099 void TB6612FNG::motorB_ccw(void) 00100 { 00101 Bin1 = SIGNAL_LOW; 00102 Bin2 = SIGNAL_HIGH; 00103 nStby = SIGNAL_HIGH; 00104 } 00105 00106 void TB6612FNG::motorB_cw(void) 00107 { 00108 Bin1 = SIGNAL_HIGH; 00109 Bin2 = SIGNAL_LOW; 00110 nStby = SIGNAL_HIGH; 00111 } 00112 00113
Generated on Tue Jul 19 2022 00:25:29 by
1.7.2