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:
- 0:d3f1d0d52615
- Child:
- 1:fb5553d9ff4c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HBridgeDCMotor.h Wed Jan 14 08:51:14 2015 +0000 @@ -0,0 +1,29 @@ +#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 + * + */ +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. + * A and B designate the individual half-bridges. + */ + HBridgeDCMotor(PinName GH_A, PinName GL_A, PinName GH_B, PinName GL_B); + /** Set the duty cycle value in range (-1, 1). Negative value means opposite direction. */ + void setDutyCycle(float dutyCycle); + /** Put the drive in a coast mode. */ + void coast(); + /** Get the current duty cycle. */ + float getDutyCycle(); + private: + PwmOut GH_A, GL_A, GH_B, GL_B; + RateLimiter rl; + float switchingPeriod, dutyCycle, tempDutyCycle, sampleTime; + Ticker ticker; + void adjustDutyCycle(); +}; \ No newline at end of file