Tripple Controller for the TLE5206 H Bridge motor controller

Revision:
0:e2433ca2ce59
Child:
1:e6f43157c7db
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inc/example1.h	Tue Jul 05 07:43:28 2011 +0000
@@ -0,0 +1,107 @@
+
+#include "mbed.h"
+#include "SimpleTLE5206.h"
+
+Serial pc(USBTX, USBRX);
+
+/* NOTE! The SimpleTLE5206 library supports the TLE5206 in 
+ * Mode 2 Sign/Magnitude Control using two PWM outputs to
+ * control speed and direction. 
+ *
+ * Pins that be be used are p21, p22, p23, p24, p25 and/or p26
+ * in pairs. So the library supports upto 3 TLE5206 devices/motors.
+ *
+ * All PWM outputs use a common duty cycle which defaults to 100Hz/10ms.
+ * There is no way to have differing duty cycles for different output
+ * pin pairs as the hardware only supports a common duty cycle in single
+ * ended mode. It may be possible to refactor the library to use a different
+ * duty cycle system (paired outputs). But single/common duty cycle was the
+ * easiest and simplest way to get the library done in a short period of time.
+ *
+ * Additionally you can use LED1, LED2, LED3 and.or LED4 as mimics.
+ * However, if using:-
+ *  LED1 you cannot use p26 to drive an in to TLE5206
+ *  LED2 you cannot use p25 to drive an in to TLE5206
+ *  LED3 you cannot use p24 to drive an in to TLE5206
+ *  LED4 you cannot use p23 to drive an in to TLE5206
+ *
+ * The function SimpleTLE5206::setSpeed() takes a single arg, a double,
+ * and should be in the range +1.0 to -1.0 where +1.0 is full speed in
+ * a CW direction, -1.0 is full speed in a CCW direction and 0 is stopped.
+ */
+
+// Create a motor "A" driven by a TLE5206 on pins 21 and 22.
+SimpleTLE5206Output Ain1(p21);      // TLE5206 In1 is connected to p21
+SimpleTLE5206Output Ain2(p22);      // TLE5206 In2 is connected to p22
+SimpleTLE5206 motorA(&Ain1, &Ain2); // Create the TLE5206 controller using these pins.
+
+// Create a motor "B" driven by a TLE5206 but on LEDs as a mimic.
+SimpleTLE5206Output Bin1(LED3);     // TLE5206 In1 is connected to LED3
+SimpleTLE5206Output Bin2(LED4);     // TLE5206 In2 is connected to LED4
+SimpleTLE5206 motorB(&Bin1, &Bin2); // Create the TLE5206 controller using these pins.
+
+DigitalOut myled(LED1);
+
+Ticker myLedFlasher;
+
+void myLedFlasherCallback(void) {
+    myled = !myled;
+}
+
+int main() {
+    double speed;
+    
+    pc.baud(115200);
+
+    // Just flashes LED1 similar to a normal initial Mbed program.
+    myLedFlasher.attach(myLedFlasherCallback, 0.2);
+
+    // The main loop just demos a linear ramp up/ramp down repeatedly.
+    while(1) {    
+        motorA.setSpeed(0);
+        motorB.setSpeed(0);
+    
+        wait(2);
+        
+        // Go from zero to +1.0 (+1.0 is full speed)
+        pc.printf("Going from zero to full CW speed...");
+        for(speed = 0.0; speed <= 1.0; speed += 0.005) {
+            if (speed > 1.0)  speed =  1.0; // Never let the speed go over 1!
+            if (speed < -1.0) speed = -1.0; // Never let the speed go below -1!
+            motorA.setSpeed(speed);
+            motorB.setSpeed(speed);
+            wait(0.05);
+        }
+        pc.printf(" done.\n");
+    
+        // Hold the motor at full speed for 5seconds.
+        wait(2);
+        
+        // Now slow the motor down to zero and then reverse direction to -1.0 
+        pc.printf("Going from full CW speed to full CCW speed...");
+        for( ; speed >= -1.0; speed -= 0.005) {
+            if (speed > 1.0)  speed =  1.0; // Never let the speed go over 1!
+            if (speed < -1.0) speed = -1.0; // Never let the speed go below -1!
+            motorA.setSpeed(speed);
+            motorB.setSpeed(speed);
+            wait(0.05);
+        }
+        pc.printf(" done.\n");
+    
+        // Hold the motor at full speed in ccw for 5seconds.
+        wait(2);
+        
+        // Now bring the motor to a stop.
+        pc.printf("Bringing the motor to a halt...");
+        for( ; speed <= 0.0; speed += 0.005) {
+            if (speed > 1.0)  speed =  1.0; // Never let the speed go over 1!
+            if (speed < -1.0) speed = -1.0; // Never let the speed go below -1!
+            motorA.setSpeed(speed);
+            motorB.setSpeed(speed);
+            wait(0.05);
+        }
+        pc.printf(" done.\n");
+    }
+}
+
+