Mbed library to control a motor via DRV8833 H-bridge motor controller. Uses two Pwmouts.
DRV8833.h@2:ccc9acaebd38, 2013-12-02 (annotated)
- Committer:
- xeta05
- Date:
- Mon Dec 02 08:02:08 2013 +0000
- Revision:
- 2:ccc9acaebd38
- Parent:
- 1:048f85990e31
- Child:
- 3:0aa2cdeb2e2b
Clarifications done in braking mode
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
xeta05 | 0:80e26be59f41 | 1 | /* mbed simple DRV8833 H-bridge motor controller |
xeta05 | 0:80e26be59f41 | 2 | * |
xeta05 | 0:80e26be59f41 | 3 | * |
xeta05 | 0:80e26be59f41 | 4 | * PWM a un puente en H(DRV8833) conectado a los motores. |
xeta05 | 1:048f85990e31 | 5 | * El comportamiento del driver es el siguiente: |
xeta05 | 0:80e26be59f41 | 6 | * |
xeta05 | 0:80e26be59f41 | 7 | * x_PWM1 x_PWM2 Mode |
xeta05 | 0:80e26be59f41 | 8 | * 0 0 Coast/Fast decay |
xeta05 | 0:80e26be59f41 | 9 | * 0 1 Reverse |
xeta05 | 0:80e26be59f41 | 10 | * 1 0 Forward |
xeta05 | 0:80e26be59f41 | 11 | * 1 1 Brake/slow decay |
xeta05 | 0:80e26be59f41 | 12 | *15/10/2013 |
xeta05 | 0:80e26be59f41 | 13 | */ |
xeta05 | 0:80e26be59f41 | 14 | |
xeta05 | 0:80e26be59f41 | 15 | #ifndef MBED_DRV8833 |
xeta05 | 0:80e26be59f41 | 16 | #define MBED_DRV8833 |
xeta05 | 0:80e26be59f41 | 17 | |
xeta05 | 0:80e26be59f41 | 18 | #include "mbed.h" |
xeta05 | 0:80e26be59f41 | 19 | |
xeta05 | 2:ccc9acaebd38 | 20 | #define COAST 1 |
xeta05 | 2:ccc9acaebd38 | 21 | #define BRAKE 0 |
xeta05 | 0:80e26be59f41 | 22 | |
xeta05 | 0:80e26be59f41 | 23 | /** Interface to control a standard DC motor |
xeta05 | 0:80e26be59f41 | 24 | * with an DRV8833 H-bridge motor controller |
xeta05 | 0:80e26be59f41 | 25 | * using 2 PwmOuts |
xeta05 | 0:80e26be59f41 | 26 | */ |
xeta05 | 0:80e26be59f41 | 27 | class DRV8833 { |
xeta05 | 0:80e26be59f41 | 28 | public: |
xeta05 | 0:80e26be59f41 | 29 | |
xeta05 | 1:048f85990e31 | 30 | /** Creates a DRV8833(H-bridge motor controller) control interface |
xeta05 | 0:80e26be59f41 | 31 | * |
xeta05 | 1:048f85990e31 | 32 | * @param pwm1 A PwmOut pin, tied to the AIN1 Logic input, controls state of AOUT1 |
xeta05 | 1:048f85990e31 | 33 | * @param pwm2 A PwmOut pin, tied to the AIN2 Logic input controls state of AOUT2 |
xeta05 | 0:80e26be59f41 | 34 | * |
xeta05 | 0:80e26be59f41 | 35 | */ |
xeta05 | 0:80e26be59f41 | 36 | DRV8833(PinName pwm1, PinName pwm2); |
xeta05 | 0:80e26be59f41 | 37 | |
xeta05 | 0:80e26be59f41 | 38 | /** Set the speed of the motor |
xeta05 | 0:80e26be59f41 | 39 | * |
xeta05 | 0:80e26be59f41 | 40 | * @param speed The speed of the motor as a normalised value between -1.0 and 1.0 |
xeta05 | 0:80e26be59f41 | 41 | */ |
xeta05 | 0:80e26be59f41 | 42 | void speed(float speed); |
xeta05 | 0:80e26be59f41 | 43 | |
xeta05 | 0:80e26be59f41 | 44 | /** Set the period of the pwm duty cycle. |
xeta05 | 0:80e26be59f41 | 45 | * |
xeta05 | 0:80e26be59f41 | 46 | * Wrapper for PwmOut::period() |
xeta05 | 0:80e26be59f41 | 47 | * |
xeta05 | 0:80e26be59f41 | 48 | * @param seconds - Pwm duty cycle in seconds. |
xeta05 | 0:80e26be59f41 | 49 | */ |
xeta05 | 0:80e26be59f41 | 50 | void period(float period); |
xeta05 | 0:80e26be59f41 | 51 | |
xeta05 | 2:ccc9acaebd38 | 52 | /** Brake the H-bridge coast or brake. |
xeta05 | 0:80e26be59f41 | 53 | * |
xeta05 | 2:ccc9acaebd38 | 54 | * Defaults to coast. |
xeta05 | 0:80e26be59f41 | 55 | * |
xeta05 | 2:ccc9acaebd38 | 56 | * Coast => pwm1 = pwm2 = 0 |
xeta05 | 2:ccc9acaebd38 | 57 | * Brake => pwm1 = pwm2 = 1 |
xeta05 | 0:80e26be59f41 | 58 | */ |
xeta05 | 2:ccc9acaebd38 | 59 | void brake(int mode = COAST); |
xeta05 | 0:80e26be59f41 | 60 | |
xeta05 | 0:80e26be59f41 | 61 | protected: |
xeta05 | 0:80e26be59f41 | 62 | PwmOut _pwm1; |
xeta05 | 0:80e26be59f41 | 63 | PwmOut _pwm2; |
xeta05 | 0:80e26be59f41 | 64 | |
xeta05 | 0:80e26be59f41 | 65 | }; |
xeta05 | 0:80e26be59f41 | 66 | |
xeta05 | 0:80e26be59f41 | 67 | #endif |