A simple motor driver for the MC33926 chip, commonly found on the Polulu md11a breakout https://www.pololu.com/product/1213.
Revision 0:3163bb06484b, committed 2017-04-30
- Comitter:
- sk398
- Date:
- Sun Apr 30 16:14:35 2017 +0000
- Commit message:
- Library for driving the MC33926 Motor Driver chip which is commonly found on the Polulu md11a, with two MC33926 drivers https://www.pololu.com/product/1213
Changed in this revision
MC33926.cpp | Show annotated file Show diff for this revision Revisions of this file |
MC33926.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MC33926.cpp Sun Apr 30 16:14:35 2017 +0000 @@ -0,0 +1,110 @@ +/******************************************************************************************** + + Filename: MC33926.cpp + + Original Author: Steven Kay + + Development Group: Steve!! + + Original Creation Date: April 2017 + + Description: <Desc> + + Revision History: Version 1.0 - Initial Release + + *********************************************************************************************/ + #include "mbed.h" + #include "MC33926.h" + + +MC33926::MC33926(PinName pinIN1, PinName pinIN2, PinName pinFB, PinName pinSF) +{ +// _pinSF.disable_irq(); + _pinIN1 = new PwmOut(pinIN1); + _pinIN2 = new PwmOut(pinIN2); + _pinFB = new AnalogIn(pinFB); + _pinSF = new InterruptIn(pinSF); + + // Set period to 2ms (frequency 500Hz) + _pinIN1 -> period_ms(DRIVER_PWM_PERIOD); + _pinIN2 -> period_ms(DRIVER_PWM_PERIOD); + + // Initialise to 0% Duty Cycle + SetPWMPulsewidth(RESET,0); + SetPWMPulsewidth(RESET,0); + +} + + + +void MC33926::SetPWMPulsewidth(int direction, float PWM_Pulsewidth) +{ + // FORWARD = 1 + if(direction == FORWARD) + { + _pinIN1 -> write(PWM_Pulsewidth); + _pinIN2 -> write(0); + } + // REVERSE = 0 + else if(direction == REVERSE) + { + _pinIN1 -> write(0); + _pinIN2 -> write(PWM_Pulsewidth); + } + // DEFAUULT or RESET != 1 OR 0 + else + { + _pinIN1 -> write(0); + _pinIN2 -> write(0); + } +} + + + +float MC33926::ReadCurrentFeedback() +{ + float temp = _pinFB -> read(); + + // Insert some conversion formats + float currentValue = temp; + + return currentValue; +} + + + +//void MC33926::StatusFlagWatch(bool latchPol) +//{ +// // if == 1, enable IRQ +// if(latchPol) +// { +// _pinSF -> enable_irq(); +// _pinSF -> fall(this,&MC33926::StatusFlagISR); +// } +// // if == 0, disable IRQ +// else +// { +// _pinSF -> disable_irq(); +// } +//} +// +// +//void MC33926::ResetStatus() +//{ +// statusFlag = 0; +//} +// +// +// +//bool MC33926::GetStatus() +//{ +// return statusFlag; +//} +// +// +// +//void MC33926::StatusFlagISR() +//{ +// // An Interrupt has been generated +// statusFlag = 1; +//} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MC33926.h Sun Apr 30 16:14:35 2017 +0000 @@ -0,0 +1,64 @@ +/******************************************************************************************** + + Filename: MC33926.h + + Original Author: Steven Kay + + Development Group: Steve!! + + Original Creation Date: April 2017 + + Description: <Desc> + + Revision History: Version 1.0 - Initial Release + + *********************************************************************************************/ + +#ifndef MC33926_H +#define MC33926_H + + +#include "mbed.h" + + +#define DRIVER_PWM_PERIOD 2 + + +#define RESET 2 +#define FORWARD 1 +#define REVERSE 0 + + +class MC33926 +{ + + public: + + MC33926(PinName pinIN1, PinName pinIN2, PinName pinFB, PinName pinSF); + + + void SetPWMPulsewidth(int direction, float PWM_Pulsewidth); + + float ReadCurrentFeedback(); + + // Implemented on v2.0 +// void StatusFlagWatch(bool latchPol); +// bool GetStatus(); +// void ResetStatus(); + + protected: + + PwmOut *_pinIN1; + PwmOut *_pinIN2; + AnalogIn *_pinFB; + InterruptIn *_pinSF; + + volatile bool statusFlag; + + + void StatusFlagISR(); + + +}; + +#endif