Mbed library to control a motor via DRV8833 H-bridge motor controller. Uses two Pwmouts.
DRV8833.h
- Committer:
- xeta05
- Date:
- 2013-12-02
- Revision:
- 2:ccc9acaebd38
- Parent:
- 1:048f85990e31
- Child:
- 3:0aa2cdeb2e2b
File content as of revision 2:ccc9acaebd38:
/* mbed simple DRV8833 H-bridge motor controller * * * PWM a un puente en H(DRV8833) conectado a los motores. * El comportamiento del driver es el siguiente: * * x_PWM1 x_PWM2 Mode * 0 0 Coast/Fast decay * 0 1 Reverse * 1 0 Forward * 1 1 Brake/slow decay *15/10/2013 */ #ifndef MBED_DRV8833 #define MBED_DRV8833 #include "mbed.h" #define COAST 1 #define BRAKE 0 /** Interface to control a standard DC motor * with an DRV8833 H-bridge motor controller * using 2 PwmOuts */ class DRV8833 { public: /** Creates a DRV8833(H-bridge motor controller) control interface * * @param pwm1 A PwmOut pin, tied to the AIN1 Logic input, controls state of AOUT1 * @param pwm2 A PwmOut pin, tied to the AIN2 Logic input controls state of AOUT2 * */ DRV8833(PinName pwm1, PinName pwm2); /** Set the speed of the motor * * @param speed The speed of the motor as a normalised value between -1.0 and 1.0 */ void speed(float speed); /** Set the period of the pwm duty cycle. * * Wrapper for PwmOut::period() * * @param seconds - Pwm duty cycle in seconds. */ void period(float period); /** Brake the H-bridge coast or brake. * * Defaults to coast. * * Coast => pwm1 = pwm2 = 0 * Brake => pwm1 = pwm2 = 1 */ void brake(int mode = COAST); protected: PwmOut _pwm1; PwmOut _pwm2; }; #endif