Yuta Togashi / motorDrive_SMB

Dependents:   Tourobo2022_TBCMotorDriver

Revision:
0:db4f58345725
Child:
1:30665f088188
--- /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