A class for driving a DC motor using a full-bridge (H-bridge) driver.
Dependencies: RateLimiter
Dependents: L298N-Breakout-Test Zavrsni_rad_NXP_cup
Diff: HBridgeDCMotor.h
- Revision:
- 2:1675a4c00925
- Parent:
- 1:fb5553d9ff4c
- Child:
- 3:a99a538c067d
--- a/HBridgeDCMotor.h Wed Jan 14 10:37:57 2015 +0000 +++ b/HBridgeDCMotor.h Fri Dec 11 13:08:15 2015 +0000 @@ -1,31 +1,58 @@ #include "mbed.h" #include "RateLimiter.h" -/** A class for driving a DC motor using full-bridge MOSFET/IGBT H-driver. - * All four transistors' gates are driven separately by four PwmOuts. - * - * Author(s): TVZ Mechatronics Team +/** A class for driving a DC motor using a full-bridge driver (H-bridge). * + * The class has an option to drive all 4 transistors gates independently by using 4 PwmOut objects, + * or to drive the H-bridge with complementary driven transistors using only 2 PwmOut objects. */ class HBridgeDCMotor { public: - /** Constructor receives the pin names at which the gates are connected. - * H stands for high side gate and L for low side. + /** Constructor for independently driven transistors. + * H stands for high side and L for low side transistor. * A and B designate the individual half-bridges. + * @param GH_A PWM signal for driving the high side transistor of the half-bridge A + * @param GL_A PWM signal for driving the low side transistor of the half-bridge A + * @param GH_B PWM signal for driving the high side transistor of the half-bridge B + * @param GL_B PWM signal for driving the low side transistor of the half-bridge B */ HBridgeDCMotor(PinName GH_A, PinName GL_A, PinName GH_B, PinName GL_B); - /** Configure the parameters (sample time in seconds, switching frequency in Hz). */ - void configure(float sampleTime, float switchingFrequency, float rampUpSlope, float rampDownSlope); - /** Set the duty cycle value in range (-1, 1). Negative value means opposite direction. */ + + /** Constructor for complementary driven transistors. + * The high side transistors are driven directly, while the low side transistors are + * complemented by the driver itself using logic circuits. + * A and B designate the individual half-bridges. + * @param GH_A PWM signal for driving the high side transistor of the half-bridge A + * @param GH_B PWM signal for driving the high side transistor of the half-bridge B + */ + HBridgeDCMotor(PinName GH_A, PinName GH_B); + + /** Configure the parameters. + * @param sampleTime sample time in seconds + * @param switchingFrequency switching frequency in Hz + * @param rampUpTime set the ramp up time (in seconds) from 0 to maximum speed + * @param rampDownTime set the ramp down time (in seconds) from maximum speed to 0 + */ + void configure(float sampleTime, float switchingFrequency, float rampUpTime, float rampDownTime); + + /** Set the motor speed by changing a duty cycle value. + * @param dutyCycle Duty cycle value in a range of (-1, 1). Negative value means opposite direction. */ void setDutyCycle(float dutyCycle); - /** Put the drive in a coast mode. */ + + /** Set the drive in a coast mode. */ void coast(); - /** Get the current duty cycle. */ + + /** Get the current duty cycle. + * @returns the current value of the duty cycle. + */ float getDutyCycle(); + private: - PwmOut GH_A, GL_A, GH_B, GL_B; + PwmOut *GH_A, *GL_A, *GH_B, *GL_B; // pointers to PwmOut objects RateLimiter rl; float switchingPeriod, dutyCycle, tempDutyCycle, sampleTime; + bool independentGates; Ticker ticker; void adjustDutyCycle(); + void init(); }; \ No newline at end of file