Default mbed pwm doesn't have enough resolution at high frequencies, thats why I implemented VNH5019 Motor carrier with FastPWM.
Fork of VNH5019 by
Diff: VNH5019Accel.cpp
- Revision:
- 5:b5f360a16354
- Child:
- 6:c8343fa0f3b4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/VNH5019Accel.cpp Thu Aug 07 12:23:30 2014 +0000 @@ -0,0 +1,36 @@ +#include "VNH5019Accel.h" + +void VNH5019Accel::Interrupt() +{ + float MyRequestedSpeed = RequestedSpeed; + if (CurrentSpeed != MyRequestedSpeed) + { + if (std::abs(CurrentSpeed-MyRequestedSpeed) < VNH5019ChangePerTick) + CurrentSpeed = MyRequestedSpeed; + else if (MyRequestedSpeed > CurrentSpeed) + CurrentSpeed += VNH5019ChangePerTick; + else + CurrentSpeed -= VNH5019ChangePerTick; + Driver.speed(CurrentSpeed); + } + else + { + float MyRequestedBrake = RequestedBrake; + if (CurrentBrake != MyRequestedBrake) + { + if (std::abs(CurrentBrake-MyRequestedBrake) < VNH5019BrakeChangePerTick) + CurrentBrake = MyRequestedBrake; + else if (MyRequestedBrake > CurrentBrake) + CurrentBrake += VNH5019BrakeChangePerTick; + else + CurrentBrake -= VNH5019BrakeChangePerTick; + Driver.brake(CurrentBrake); + } + } +} + +DualVNH5019AccelMotorShield::DualVNH5019AccelMotorShield() +: m1(PTD4, PTA4, PTC8, PTB0, PTD5), + m2(PTC9, PTA13, PTD3, PTB1, PTD0) +{ +}