Default mbed pwm doesn't have enough resolution at high frequencies, thats why I implemented VNH5019 Motor carrier with FastPWM.
Fork of VNH5019 by
VNH5019.h@0:5d3ab0ea7f27, 2014-02-01 (annotated)
- Committer:
- ianmcc
- Date:
- Sat Feb 01 13:48:28 2014 +0000
- Revision:
- 0:5d3ab0ea7f27
- Child:
- 1:5e8d9ed18f0f
Initial checkin
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ianmcc | 0:5d3ab0ea7f27 | 1 | #ifndef DualVNH5019MotorShield_h |
ianmcc | 0:5d3ab0ea7f27 | 2 | #define DualVNH5019MotorShield_h |
ianmcc | 0:5d3ab0ea7f27 | 3 | |
ianmcc | 0:5d3ab0ea7f27 | 4 | #include <mbed.h> |
ianmcc | 0:5d3ab0ea7f27 | 5 | |
ianmcc | 0:5d3ab0ea7f27 | 6 | class DualVNH5019MotorShield |
ianmcc | 0:5d3ab0ea7f27 | 7 | { |
ianmcc | 0:5d3ab0ea7f27 | 8 | public: |
ianmcc | 0:5d3ab0ea7f27 | 9 | // default pin selection |
ianmcc | 0:5d3ab0ea7f27 | 10 | DualVNH5019MotorShield(); // Default pin selection. |
ianmcc | 0:5d3ab0ea7f27 | 11 | |
ianmcc | 0:5d3ab0ea7f27 | 12 | // User-defined pin selection. |
ianmcc | 0:5d3ab0ea7f27 | 13 | DualVNH5019MotorShield(PinName INA1_, PinName INB1_, PinName ENDIAG1_, PinName CS1_, PinName PWM1_, |
ianmcc | 0:5d3ab0ea7f27 | 14 | PinName INA2_, PinName INB2_, PinName ENDIAG2_, PinName CS2_, PinName PWM2_); |
ianmcc | 0:5d3ab0ea7f27 | 15 | |
ianmcc | 0:5d3ab0ea7f27 | 16 | // Set motor speeds, from -1.0 to +1.0 |
ianmcc | 0:5d3ab0ea7f27 | 17 | void setM1Speed(float Speed); |
ianmcc | 0:5d3ab0ea7f27 | 18 | void setM2Speed(float Speed); |
ianmcc | 0:5d3ab0ea7f27 | 19 | void setSpeeds(float m1Speed, float m2Speed); |
ianmcc | 0:5d3ab0ea7f27 | 20 | |
ianmcc | 0:5d3ab0ea7f27 | 21 | // stop (no current to the motors) |
ianmcc | 0:5d3ab0ea7f27 | 22 | void setM1Stop(); |
ianmcc | 0:5d3ab0ea7f27 | 23 | void setM2Stop(); |
ianmcc | 0:5d3ab0ea7f27 | 24 | |
ianmcc | 0:5d3ab0ea7f27 | 25 | // brake, with strength 0..1 |
ianmcc | 0:5d3ab0ea7f27 | 26 | void setM1Brake(float Brake); |
ianmcc | 0:5d3ab0ea7f27 | 27 | void setM2Brake(float Brake); |
ianmcc | 0:5d3ab0ea7f27 | 28 | void setBrakes(float m1Brake, float m2Brake); |
ianmcc | 0:5d3ab0ea7f27 | 29 | |
ianmcc | 0:5d3ab0ea7f27 | 30 | // return the current supplied to the motors |
ianmcc | 0:5d3ab0ea7f27 | 31 | float getM1CurrentMA(); |
ianmcc | 0:5d3ab0ea7f27 | 32 | float getM2CurrentMA(); |
ianmcc | 0:5d3ab0ea7f27 | 33 | |
ianmcc | 0:5d3ab0ea7f27 | 34 | // fault |
ianmcc | 0:5d3ab0ea7f27 | 35 | bool isM1Fault(); |
ianmcc | 0:5d3ab0ea7f27 | 36 | bool isM2Fault(); |
ianmcc | 0:5d3ab0ea7f27 | 37 | |
ianmcc | 0:5d3ab0ea7f27 | 38 | // If a fault occurs, then we follow the procedure from the data sheet to clear it |
ianmcc | 0:5d3ab0ea7f27 | 39 | void clearM1Fault(); |
ianmcc | 0:5d3ab0ea7f27 | 40 | void clearM2Fault(); |
ianmcc | 0:5d3ab0ea7f27 | 41 | |
ianmcc | 0:5d3ab0ea7f27 | 42 | // disable / enable (isFault() will return true if the motor is disabled). |
ianmcc | 0:5d3ab0ea7f27 | 43 | // Disabling the motor also sets the speed to 0 and brakes to LOW. |
ianmcc | 0:5d3ab0ea7f27 | 44 | void disableM1(); |
ianmcc | 0:5d3ab0ea7f27 | 45 | void disableM2(); |
ianmcc | 0:5d3ab0ea7f27 | 46 | |
ianmcc | 0:5d3ab0ea7f27 | 47 | void enableM1(bool Enable = true); |
ianmcc | 0:5d3ab0ea7f27 | 48 | void enableM2(bool Enable = true); |
ianmcc | 0:5d3ab0ea7f27 | 49 | |
ianmcc | 0:5d3ab0ea7f27 | 50 | private: |
ianmcc | 0:5d3ab0ea7f27 | 51 | void init(); // Initialize TIMER 1, set the PWM to 20kHZ. |
ianmcc | 0:5d3ab0ea7f27 | 52 | |
ianmcc | 0:5d3ab0ea7f27 | 53 | DigitalOut INA1; |
ianmcc | 0:5d3ab0ea7f27 | 54 | DigitalOut INB1; |
ianmcc | 0:5d3ab0ea7f27 | 55 | DigitalInOut ENDIAG1; |
ianmcc | 0:5d3ab0ea7f27 | 56 | AnalogIn CS1; |
ianmcc | 0:5d3ab0ea7f27 | 57 | PwmOut PWM1; |
ianmcc | 0:5d3ab0ea7f27 | 58 | |
ianmcc | 0:5d3ab0ea7f27 | 59 | DigitalOut INA2; |
ianmcc | 0:5d3ab0ea7f27 | 60 | DigitalOut INB2; |
ianmcc | 0:5d3ab0ea7f27 | 61 | DigitalInOut ENDIAG2; |
ianmcc | 0:5d3ab0ea7f27 | 62 | AnalogIn CS2; |
ianmcc | 0:5d3ab0ea7f27 | 63 | PwmOut PWM2; |
ianmcc | 0:5d3ab0ea7f27 | 64 | }; |
ianmcc | 0:5d3ab0ea7f27 | 65 | |
ianmcc | 0:5d3ab0ea7f27 | 66 | #endif |