Simple Interface for Toshiba's TB6612FNG H-Bridge Motor Driver
TB6612FNG.h@5:535c74e61e36, 2013-03-21 (annotated)
- Committer:
- humlet
- Date:
- Thu Mar 21 17:06:45 2013 +0000
- Revision:
- 5:535c74e61e36
- Parent:
- 4:5aec3b59fc10
final !?
Who changed what in which revision?
User | Revision | Line number | New 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 | 5:535c74e61e36 | 9 | PwmOut m_pwm; |
humlet | 0:30d6828516f5 | 10 | DigitalOut m_ctrl1; |
humlet | 0:30d6828516f5 | 11 | DigitalOut m_ctrl2; |
humlet | 5:535c74e61e36 | 12 | int m_pw; // PWM pulse width setting |
humlet | 5:535c74e61e36 | 13 | bool m_on; // motor satus |
humlet | 5:535c74e61e36 | 14 | bool m_brakeOnZeroDC; // behaviour for zero duty cycle |
humlet | 5:535c74e61e36 | 15 | int m_period; // PWM period setting |
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 | 4:5aec3b59fc10 | 26 | |
humlet | 4:5aec3b59fc10 | 27 | /// Sets the PWM pulse width |
humlet | 5:535c74e61e36 | 28 | /// @param pw is the PWM pulse width setting in µs. |
humlet | 5:535c74e61e36 | 29 | /// The sign of the given pulsewidth defines the direction. |
humlet | 5:535c74e61e36 | 30 | /// With the default PWM period of 100µs (f=10kHz) this value is equivalent to the duty cycle. |
humlet | 1:3dd9137a5cec | 31 | void setPulseWidth(int pw); |
humlet | 4:5aec3b59fc10 | 32 | |
humlet | 4:5aec3b59fc10 | 33 | /// activates the motor at the duty cycle selected with setPulseWidth() |
humlet | 0:30d6828516f5 | 34 | void on(); |
humlet | 4:5aec3b59fc10 | 35 | |
humlet | 1:3dd9137a5cec | 36 | /// deactivates the motor (sets the motor output to high impedance, no short brake) |
humlet | 0:30d6828516f5 | 37 | void off(); |
humlet | 4:5aec3b59fc10 | 38 | |
humlet | 1:3dd9137a5cec | 39 | /// brakes the motor by shorting it |
humlet | 0:30d6828516f5 | 40 | void brake(); |
humlet | 4:5aec3b59fc10 | 41 | |
humlet | 5:535c74e61e36 | 42 | /// set behaviour for zero DC setting |
humlet | 5:535c74e61e36 | 43 | /// @param brakeOnZeroDC true: The motor brakes on zero pulse width setting. |
humlet | 5:535c74e61e36 | 44 | /// false: The motor output is set to high impedance |
humlet | 5:535c74e61e36 | 45 | void setZeroDCReaction(bool brakeOnZeroDC); |
humlet | 5:535c74e61e36 | 46 | |
humlet | 4:5aec3b59fc10 | 47 | /// pulse width assignment |
humlet | 5:535c74e61e36 | 48 | /// @param pw is the PWM pulse width setting in µs |
humlet | 5:535c74e61e36 | 49 | /// @see setPulseWidth(int pw) |
humlet | 1:3dd9137a5cec | 50 | void operator=(int pw) { |
humlet | 1:3dd9137a5cec | 51 | setPulseWidth(pw); |
humlet | 0:30d6828516f5 | 52 | } |
humlet | 0:30d6828516f5 | 53 | }; |
humlet | 0:30d6828516f5 | 54 | |
humlet | 0:30d6828516f5 | 55 | #endif |