Mbed library to control a motor via DRV8833 H-bridge motor controller. Uses two Pwmouts.
Diff: DRV8833.cpp
- Revision:
- 0:80e26be59f41
- Child:
- 2:ccc9acaebd38
diff -r 000000000000 -r 80e26be59f41 DRV8833.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DRV8833.cpp Tue Oct 15 12:25:34 2013 +0000 @@ -0,0 +1,61 @@ +/* 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 +**/ + + +#include "DRV8833.h" + +DRV8833::DRV8833(PinName pwm1, PinName pwm2): + _pwm1(pwm1), _pwm2(pwm2) +{ + + // Set initial condition of PWM + _pwm1.period(0.001); + _pwm1 = 0; + _pwm2.period(0.001); + _pwm2 = 0; + +} + +void DRV8833::speed(float speed) +{ + if (speed > 0.0) + { + _pwm1 = abs(speed); + _pwm2 = 0; + } + else + { + _pwm1 = 0; + _pwm2 = abs(speed); + } +} +void DRV8833::period(float period){ + + _pwm1.period(period); + _pwm2.period(period); +} + +void DRV8833::brake(int highLow){ + + if(highLow == BRAKE_FAST) + { + _pwm1 = 0; + _pwm2 = 0; + } + else if(highLow == BRAKE_SLOW){ + _pwm1 = 1; + _pwm2 = 1; + } + +}