Simple Interface for Toshiba's TB6612FNG H-Bridge Motor Driver

Committer:
humlet
Date:
Tue Mar 12 19:22:49 2013 +0000
Revision:
3:1ae4f0bb91c6
Parent:
2:73d5d7514e4c
Child:
4:5aec3b59fc10
almost final

Who changed what in which revision?

UserRevisionLine numberNew contents of line
humlet 0:30d6828516f5 1 #ifndef TB6612FNG_H
humlet 0:30d6828516f5 2 #define TB6612FNG_H
humlet 0:30d6828516f5 3
humlet 0:30d6828516f5 4 #include "mbed.h"
humlet 0:30d6828516f5 5
humlet 2:73d5d7514e4c 6 /// Simple Interface for Toshiba's TB6612FNG H-Bridge Motor Driver
humlet 0:30d6828516f5 7 class TB6612FNG
humlet 0:30d6828516f5 8 {
humlet 0:30d6828516f5 9 PwmOut m_pwm;
humlet 0:30d6828516f5 10 DigitalOut m_ctrl1;
humlet 0:30d6828516f5 11 DigitalOut m_ctrl2;
humlet 1:3dd9137a5cec 12 int m_pw;
humlet 0:30d6828516f5 13 bool m_on;
humlet 1:3dd9137a5cec 14 bool m_brakeOnZeroDC;
humlet 1:3dd9137a5cec 15 int m_period;
humlet 0:30d6828516f5 16
humlet 0:30d6828516f5 17 public:
humlet 0:30d6828516f5 18 /** Create TB6612FNG object connected to the specified mbed pins
humlet 2:73d5d7514e4c 19 * @param pwm PwmOut pin name
humlet 2:73d5d7514e4c 20 * @param ctrl1/ctrl2 DigitalOut control pin name
humlet 2:73d5d7514e4c 21 * @param pwmPeriod sets the PWM period (µs)
humlet 2:73d5d7514e4c 22 * @param brakeOnZeroDC true: The motor brakes on zero pulse width setting.
humlet 2:73d5d7514e4c 23 * false: The motor output is set to high impedance
humlet 0:30d6828516f5 24 */
humlet 3:1ae4f0bb91c6 25 TB6612FNG(PinName pwm, PinName ctrl1, PinName ctrl2, int pwmPeriod=100, bool brakeOnZeroDC=true);
humlet 2:73d5d7514e4c 26 /** Sets the PWM pulse width
humlet 3:1ae4f0bb91c6 27 * @param pw is the PWM pulse width setting in µs. With the default PWM period of 100µs (f=10kHz) this value is equivalent to the duty cycle.
humlet 2:73d5d7514e4c 28 */
humlet 1:3dd9137a5cec 29 void setPulseWidth(int pw);
humlet 1:3dd9137a5cec 30 /// activates the motor at duty cycle adjusted with setPulseWidth
humlet 0:30d6828516f5 31 void on();
humlet 1:3dd9137a5cec 32 /// deactivates the motor (sets the motor output to high impedance, no short brake)
humlet 0:30d6828516f5 33 void off();
humlet 1:3dd9137a5cec 34 /// brakes the motor by shorting it
humlet 0:30d6828516f5 35 void brake();
humlet 2:73d5d7514e4c 36 /** pulse width assignment
humlet 2:73d5d7514e4c 37 * @param pw is the PWM pulse width setting in µs
humlet 2:73d5d7514e4c 38 */
humlet 1:3dd9137a5cec 39 void operator=(int pw) {
humlet 1:3dd9137a5cec 40 setPulseWidth(pw);
humlet 0:30d6828516f5 41 }
humlet 0:30d6828516f5 42 };
humlet 0:30d6828516f5 43
humlet 0:30d6828516f5 44 #endif