Tripple Controller for the TLE5206 H Bridge motor controller

Revision:
2:c5fbe0cb8a97
Parent:
0:e2433ca2ce59
Child:
5:bfc5c5cc161e
--- a/src/SimpleTLE5206.cpp	Tue Jul 05 09:27:36 2011 +0000
+++ b/src/SimpleTLE5206.cpp	Tue Jul 05 13:50:45 2011 +0000
@@ -31,19 +31,36 @@
     // Start initially as GPIO and both on (no drive, no speed).
     _in1 = in1;
     _in2 = in2;
-    init();
+    init(0);
+}
+
+SimpleTLE5206::SimpleTLE5206(SimpleTLE5206Output *in1, SimpleTLE5206Output *in2, int duty_cycle_hz)
+{
+    // Start initially as GPIO and both on (no drive, no speed).
+    _in1 = in1;
+    _in2 = in2;
+    init((uint32_t)(12000000UL / duty_cycle_hz * 2));
 }
 
 void
-SimpleTLE5206::init()
+SimpleTLE5206::init(uint32_t duty)
 {
-    setDuty(240000UL);
+    if (duty != 0) setDuty(duty);
     setSpeed(0.0);
 }
 
 void
 SimpleTLE5206::setDuty(uint32_t duty)
 {
+
+    _duty = duty;
+    
+    // Skip the setup if teh duty has already been set
+    // by a previous instance of controller.
+    if (LPC_PWM1->MR0 == duty) {
+        return;
+    }
+    
     // Ensure powered up (default is 1)  
     LPC_SC->PCONP |= (1UL << 6);  
         
@@ -53,8 +70,6 @@
     // Reset.
     LPC_PWM1->TCR   = 2; 
     
-    _duty = duty;
-    
     LPC_PWM1->PR    = 0;
     LPC_PWM1->MR0   = _duty;
     LPC_PWM1->MR1   = 0;