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

Committer:
tbjazic
Date:
2015-01-14
Revision:
0:d3f1d0d52615
Child:
1:fb5553d9ff4c

File content as of revision 0:d3f1d0d52615:

#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();
};