Default mbed pwm doesn't have enough resolution at high frequencies, thats why I implemented VNH5019 Motor carrier with FastPWM.
Fork of VNH5019 by
VNH5019Accel.cpp@5:b5f360a16354, 2014-08-07 (annotated)
- Committer:
- ianmcc
- Date:
- Thu Aug 07 12:23:30 2014 +0000
- Revision:
- 5:b5f360a16354
- Child:
- 6:c8343fa0f3b4
Added VNH5019Accel for a drop-in replacement for the VNH5019 but has a built-in acceleration limiter. Default maximum acceleration will result in ramping up to maximum speed in 1/4 second.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ianmcc | 5:b5f360a16354 | 1 | #include "VNH5019Accel.h" |
ianmcc | 5:b5f360a16354 | 2 | |
ianmcc | 5:b5f360a16354 | 3 | void VNH5019Accel::Interrupt() |
ianmcc | 5:b5f360a16354 | 4 | { |
ianmcc | 5:b5f360a16354 | 5 | float MyRequestedSpeed = RequestedSpeed; |
ianmcc | 5:b5f360a16354 | 6 | if (CurrentSpeed != MyRequestedSpeed) |
ianmcc | 5:b5f360a16354 | 7 | { |
ianmcc | 5:b5f360a16354 | 8 | if (std::abs(CurrentSpeed-MyRequestedSpeed) < VNH5019ChangePerTick) |
ianmcc | 5:b5f360a16354 | 9 | CurrentSpeed = MyRequestedSpeed; |
ianmcc | 5:b5f360a16354 | 10 | else if (MyRequestedSpeed > CurrentSpeed) |
ianmcc | 5:b5f360a16354 | 11 | CurrentSpeed += VNH5019ChangePerTick; |
ianmcc | 5:b5f360a16354 | 12 | else |
ianmcc | 5:b5f360a16354 | 13 | CurrentSpeed -= VNH5019ChangePerTick; |
ianmcc | 5:b5f360a16354 | 14 | Driver.speed(CurrentSpeed); |
ianmcc | 5:b5f360a16354 | 15 | } |
ianmcc | 5:b5f360a16354 | 16 | else |
ianmcc | 5:b5f360a16354 | 17 | { |
ianmcc | 5:b5f360a16354 | 18 | float MyRequestedBrake = RequestedBrake; |
ianmcc | 5:b5f360a16354 | 19 | if (CurrentBrake != MyRequestedBrake) |
ianmcc | 5:b5f360a16354 | 20 | { |
ianmcc | 5:b5f360a16354 | 21 | if (std::abs(CurrentBrake-MyRequestedBrake) < VNH5019BrakeChangePerTick) |
ianmcc | 5:b5f360a16354 | 22 | CurrentBrake = MyRequestedBrake; |
ianmcc | 5:b5f360a16354 | 23 | else if (MyRequestedBrake > CurrentBrake) |
ianmcc | 5:b5f360a16354 | 24 | CurrentBrake += VNH5019BrakeChangePerTick; |
ianmcc | 5:b5f360a16354 | 25 | else |
ianmcc | 5:b5f360a16354 | 26 | CurrentBrake -= VNH5019BrakeChangePerTick; |
ianmcc | 5:b5f360a16354 | 27 | Driver.brake(CurrentBrake); |
ianmcc | 5:b5f360a16354 | 28 | } |
ianmcc | 5:b5f360a16354 | 29 | } |
ianmcc | 5:b5f360a16354 | 30 | } |
ianmcc | 5:b5f360a16354 | 31 | |
ianmcc | 5:b5f360a16354 | 32 | DualVNH5019AccelMotorShield::DualVNH5019AccelMotorShield() |
ianmcc | 5:b5f360a16354 | 33 | : m1(PTD4, PTA4, PTC8, PTB0, PTD5), |
ianmcc | 5:b5f360a16354 | 34 | m2(PTC9, PTA13, PTD3, PTB1, PTD0) |
ianmcc | 5:b5f360a16354 | 35 | { |
ianmcc | 5:b5f360a16354 | 36 | } |