A class for driving a DC motor using a full-bridge (H-bridge) driver.

Dependencies:   RateLimiter

Dependents:   L298N-Breakout-Test Zavrsni_rad_NXP_cup

Revision:
1:fb5553d9ff4c
Parent:
0:d3f1d0d52615
Child:
2:1675a4c00925
--- a/HBridgeDCMotor.cpp	Wed Jan 14 08:51:14 2015 +0000
+++ b/HBridgeDCMotor.cpp	Wed Jan 14 10:37:57 2015 +0000
@@ -8,6 +8,20 @@
     rl.setLimits(0.1, -0.1, 0, sampleTime); // initial 10 second ramp
 }
 
+void HBridgeDCMotor::configure(float sampleTime, float switchingFrequency, float rampUpSlope, float rampDownSlope) {
+    if (sampleTime < 1e-6)
+        sampleTime = 1e-3;
+    if (switchingFrequency < 100)
+        switchingFrequency = 20e3;
+    if (rampUpSlope < 0 || rampUpSlope > 1)
+        rampUpSlope = 0.1;
+    if (rampDownSlope > 0 || rampDownSlope < -1)
+        rampDownSlope = -0.1;
+    this->sampleTime = sampleTime;
+    switchingPeriod = 1.0 / switchingFrequency;
+    rl.setLimits(rampUpSlope, rampDownSlope, 0, sampleTime);
+}
+
 void HBridgeDCMotor::adjustDutyCycle() {
     dutyCycle = rl.out(tempDutyCycle);
     if (dutyCycle >= 0 && dutyCycle <= 1) {