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.
Dependents: Tourobo2022_TBCMotorDriver
Diff: motorDrive_SMB.cpp
- Revision:
- 0:db4f58345725
- Child:
- 1:30665f088188
diff -r 000000000000 -r db4f58345725 motorDrive_SMB.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/motorDrive_SMB.cpp Wed Mar 25 09:22:53 2020 +0000 @@ -0,0 +1,30 @@ +#include "motorDrive_SMB.h" + +motorDriveSMB::motorDriveSMB (PinName PwmH,PinName Phase) : pwmh(PwmH),phase(Phase) { + lowerLimitDuty = -1.0f; + upperLimitDuty = 1.0f; +} + +void motorDriveSMB::setupFrequency(float frequency) { + pwmh.period(1.0f / frequency); +} + +void motorDriveSMB::setupLimitDuty(float lowerLimit,float upperLimit) { + lowerLimitDuty = lowerLimit; + upperLimitDuty = upperLimit; +} + +void motorDriveSMB::output(float duty) { + if(duty > 0.0f) { + if(duty > upperLimitDuty) duty = upperLimitDuty; + pwmh.write(fabs(duty)); + phase.write(false); + } else if(duty < 0.0f){ + if(duty < lowerLimitDuty) duty = lowerLimitDuty; + pwmh.write(fabs(duty)); + phase.write(true); + } else { + pwmh.write(0.0f); + phase.write(false); + } +} \ No newline at end of file