Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
MC33926.cpp
00001 /******************************************************************************************** 00002 00003 Filename: MC33926.cpp 00004 00005 Original Author: Steven Kay 00006 00007 Development Group: Steve!! 00008 00009 Original Creation Date: April 2017 00010 00011 Description: <Desc> 00012 00013 Revision History: Version 1.0 - Initial Release 00014 00015 *********************************************************************************************/ 00016 #include "mbed.h" 00017 #include "MC33926.h" 00018 00019 00020 MC33926::MC33926(PinName pinIN1, PinName pinIN2, PinName pinFB, PinName pinSF) 00021 { 00022 // _pinSF.disable_irq(); 00023 _pinIN1 = new PwmOut(pinIN1); 00024 _pinIN2 = new PwmOut(pinIN2); 00025 _pinFB = new AnalogIn(pinFB); 00026 _pinSF = new InterruptIn(pinSF); 00027 00028 // Set period to 2ms (frequency 500Hz) 00029 _pinIN1 -> period_ms(DRIVER_PWM_PERIOD); 00030 _pinIN2 -> period_ms(DRIVER_PWM_PERIOD); 00031 00032 // Initialise to 0% Duty Cycle 00033 SetPWMPulsewidth(RESET,0); 00034 SetPWMPulsewidth(RESET,0); 00035 00036 } 00037 00038 00039 00040 void MC33926::SetPWMPulsewidth(int direction, float PWM_Pulsewidth) 00041 { 00042 // FORWARD = 1 00043 if(direction == FORWARD) 00044 { 00045 _pinIN1 -> write(PWM_Pulsewidth); 00046 _pinIN2 -> write(0); 00047 } 00048 // REVERSE = 0 00049 else if(direction == REVERSE) 00050 { 00051 _pinIN1 -> write(0); 00052 _pinIN2 -> write(PWM_Pulsewidth); 00053 } 00054 // DEFAUULT or RESET != 1 OR 0 00055 else 00056 { 00057 _pinIN1 -> write(0); 00058 _pinIN2 -> write(0); 00059 } 00060 } 00061 00062 00063 00064 float MC33926::ReadCurrentFeedback() 00065 { 00066 float temp = _pinFB -> read(); 00067 00068 // Insert some conversion formats 00069 float currentValue = temp; 00070 00071 return currentValue; 00072 } 00073 00074 00075 00076 //void MC33926::StatusFlagWatch(bool latchPol) 00077 //{ 00078 // // if == 1, enable IRQ 00079 // if(latchPol) 00080 // { 00081 // _pinSF -> enable_irq(); 00082 // _pinSF -> fall(this,&MC33926::StatusFlagISR); 00083 // } 00084 // // if == 0, disable IRQ 00085 // else 00086 // { 00087 // _pinSF -> disable_irq(); 00088 // } 00089 //} 00090 // 00091 // 00092 //void MC33926::ResetStatus() 00093 //{ 00094 // statusFlag = 0; 00095 //} 00096 // 00097 // 00098 // 00099 //bool MC33926::GetStatus() 00100 //{ 00101 // return statusFlag; 00102 //} 00103 // 00104 // 00105 // 00106 //void MC33926::StatusFlagISR() 00107 //{ 00108 // // An Interrupt has been generated 00109 // statusFlag = 1; 00110 //}
Generated on Wed Jul 13 2022 18:31:33 by
1.7.2