A class for driving a DC motor using a full-bridge (H-bridge) driver.
Dependencies: RateLimiter
Dependents: L298N-Breakout-Test Zavrsni_rad_NXP_cup
HBridgeDCMotor.h@1:fb5553d9ff4c, 2015-01-14 (annotated)
- Committer:
- tbjazic
- Date:
- Wed Jan 14 10:37:57 2015 +0000
- Revision:
- 1:fb5553d9ff4c
- Parent:
- 0:d3f1d0d52615
- Child:
- 2:1675a4c00925
Configure function added.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tbjazic | 0:d3f1d0d52615 | 1 | #include "mbed.h" |
tbjazic | 0:d3f1d0d52615 | 2 | #include "RateLimiter.h" |
tbjazic | 0:d3f1d0d52615 | 3 | |
tbjazic | 0:d3f1d0d52615 | 4 | /** A class for driving a DC motor using full-bridge MOSFET/IGBT H-driver. |
tbjazic | 0:d3f1d0d52615 | 5 | * All four transistors' gates are driven separately by four PwmOuts. |
tbjazic | 0:d3f1d0d52615 | 6 | * |
tbjazic | 0:d3f1d0d52615 | 7 | * Author(s): TVZ Mechatronics Team |
tbjazic | 0:d3f1d0d52615 | 8 | * |
tbjazic | 0:d3f1d0d52615 | 9 | */ |
tbjazic | 0:d3f1d0d52615 | 10 | class HBridgeDCMotor { |
tbjazic | 0:d3f1d0d52615 | 11 | public: |
tbjazic | 0:d3f1d0d52615 | 12 | /** Constructor receives the pin names at which the gates are connected. |
tbjazic | 0:d3f1d0d52615 | 13 | * H stands for high side gate and L for low side. |
tbjazic | 0:d3f1d0d52615 | 14 | * A and B designate the individual half-bridges. |
tbjazic | 0:d3f1d0d52615 | 15 | */ |
tbjazic | 0:d3f1d0d52615 | 16 | HBridgeDCMotor(PinName GH_A, PinName GL_A, PinName GH_B, PinName GL_B); |
tbjazic | 1:fb5553d9ff4c | 17 | /** Configure the parameters (sample time in seconds, switching frequency in Hz). */ |
tbjazic | 1:fb5553d9ff4c | 18 | void configure(float sampleTime, float switchingFrequency, float rampUpSlope, float rampDownSlope); |
tbjazic | 0:d3f1d0d52615 | 19 | /** Set the duty cycle value in range (-1, 1). Negative value means opposite direction. */ |
tbjazic | 0:d3f1d0d52615 | 20 | void setDutyCycle(float dutyCycle); |
tbjazic | 0:d3f1d0d52615 | 21 | /** Put the drive in a coast mode. */ |
tbjazic | 0:d3f1d0d52615 | 22 | void coast(); |
tbjazic | 0:d3f1d0d52615 | 23 | /** Get the current duty cycle. */ |
tbjazic | 0:d3f1d0d52615 | 24 | float getDutyCycle(); |
tbjazic | 0:d3f1d0d52615 | 25 | private: |
tbjazic | 0:d3f1d0d52615 | 26 | PwmOut GH_A, GL_A, GH_B, GL_B; |
tbjazic | 0:d3f1d0d52615 | 27 | RateLimiter rl; |
tbjazic | 0:d3f1d0d52615 | 28 | float switchingPeriod, dutyCycle, tempDutyCycle, sampleTime; |
tbjazic | 0:d3f1d0d52615 | 29 | Ticker ticker; |
tbjazic | 0:d3f1d0d52615 | 30 | void adjustDutyCycle(); |
tbjazic | 0:d3f1d0d52615 | 31 | }; |