Yuta Togashi / motorDrive_LAP

Dependents:   Tourobo2022_TBCMotorDriver

Revision:
0:6a48e14ebdfa
diff -r 000000000000 -r 6a48e14ebdfa motorDrive_LAP.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/motorDrive_LAP.cpp	Wed Mar 25 09:25:28 2020 +0000
@@ -0,0 +1,28 @@
+#include "motorDrive_LAP.h"
+
+motorDriveLAP::motorDriveLAP(PinName PwmH,PinName Phase) : pwmh(PwmH),phase(Phase) {
+    lowerLimitDuty = -1.0f;
+    upperLimitDuty = 1.0f;
+    pwmh.write(1);
+}
+
+void motorDriveLAP::setupFrequency(float frequency) {
+    phase.period(1.0f / frequency);   
+}
+
+void motorDriveLAP::setupLimitDuty(float lowerLimit,float upperLimit) {
+    lowerLimitDuty = lowerLimit;
+    upperLimitDuty = upperLimit;
+}
+
+void motorDriveLAP::output(float duty) {
+    if(duty > 0.0f) {
+        if(duty > upperLimitDuty)   duty = upperLimitDuty;
+        phase.write(fabs(0.50f + (duty *0.50f)));
+    } else if(duty < 0.0f){
+        if(duty < lowerLimitDuty)   duty = lowerLimitDuty;
+        phase.write(fabs(0.50f + (duty * 0.50f)));
+    } else {
+        phase.write(fabs(0.50f));
+    }
+}
\ No newline at end of file