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@14:193c422498bf, 2018-04-10 (annotated)
- Committer:
- mbedoguz
- Date:
- Tue Apr 10 21:30:47 2018 +0000
- Revision:
- 14:193c422498bf
- Parent:
- 6:c8343fa0f3b4
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 | } |