temp repo

Dependencies:   mbed

Fork of priustroller_2 by N K

Revision:
19:280c62c71cf8
Parent:
15:d754b71a1290
Child:
20:3a7eae543153
--- a/meta/modulators.cpp	Mon Mar 09 03:11:29 2015 +0000
+++ b/meta/modulators.cpp	Mon Mar 09 03:32:32 2015 +0000
@@ -4,61 +4,12 @@
 #include "fastmath.h"
 #include "transforms.h"
 
-void SinusoidalModulator::Update(float valpha, float vbeta) {
-    
-    //swapping valpha and vbeta for reasons documented in CalcRef.s here: http://ww1.microchip.com/downloads/jp/AppNotes/ACIM%20Vector%20Control%2000908a.pdf
-    float vra = vbeta;
-    float vrb = ((-vbeta + sqrt(3.0f)*valpha)/2.0f);
-    float vrc = ((-vbeta - sqrt(3.0f)*valpha)/2.0f);
-    
-    float dtcA;
-    float dtcB;
-    float dtcC;
-    
-    if( vra >= 0 ){  // (xx1)
-        if( vrb >= 0 ){ // (x11) 
-            // Must be Sector 3 since Sector 7 not allowed
-            // Sector 3: (0,1,1) 0-60 degrees
-            T1 = vrb;
-            T2 = vra;
-        }
-        else{  // (x01)
-            if( vrc >= 0 ){  // Sector 5: (1,0,1) 120-180 degrees
-            T1 = vra;
-            T2 = vrc;
-            }
-            else{// Sector 1: (0,0,1) 60-120 degrees
-            T1 = -vrb;
-            T2 = -vrc;
-            }
-        }
-    }
-    else{ // (xx0)
-        if( Vrb >= 0 ){ // (x10)
-            if( Vrc >= 0 ){ // Sector 6: (1,1,0) 240-300 degrees
-            T1 = vrc;
-            T2 = vrb;
-            }
-            else{// Sector 2: (0,1,0) 300-0 degrees
-            T1 = -vrc;
-            T2 = -vra;
-            }
-        }
-        else{ // (x00)
-            // Must be Sector 4 since Sector 0 not allowed
-            // Sector 4: (1,0,0) 180-240 degrees
-            T1 = -vra;
-            T2 = -vrb;
-            }
-        }
-    }
-    
-    dtcA = (1.0f-T1-T2)/2.0f
-    dtcB = dtcA + T1
-    dtcC = dtcB + T2
+void SinusoidalModulator::Update(float valpha, float vbeta) {    
+    float dtcA = 0.0f;
+    float dtcB = 0.0f;
+    float dtcC = 0.0f;
     
     //--hack to make duty cycles positive
-  
     _inverter->SetDtcA(dtcA * 0.5f + 0.5f);
     _inverter->SetDtcB(dtcB * 0.5f + 0.5f);
     _inverter->SetDtcC(dtcC * 0.5f + 0.5f);
@@ -66,6 +17,53 @@
 
 void SvmModulator::Update(float valpha, float vbeta) {
     float va, vb, vc;
-    InverseClarke(valpha, vbeta, &va, &vb);
+    InverseClarke(vbeta, valpha, &va, &vb);
     vc = -(va + vb);
+    
+    float dtcA, dtcB, dtcC, t1, t2;
+    
+    if (va >= 0){  // (xx1)
+        if (vb >= 0){ // (x11) 
+            // Must be Sector 3 since Sector 7 not allowed
+            // Sector 3: (0,1,1) 0-60 degrees
+            t1 = vb;
+            t2 = va;
+        }
+        else {  // (x01)
+            if (vc >= 0){  // Sector 5: (1,0,1) 120-180 degrees
+                t1 = va;
+                t2 = vc;
+            }
+            else {// Sector 1: (0,0,1) 60-120 degrees
+                t1 = -vb;
+                t2 = -vc;
+            }
+        }
+    } else { // (xx0)
+        if (vb >= 0) { // (x10)
+            if (vc >= 0) { // Sector 6: (1,1,0) 240-300 degrees
+                t1 = vc;
+                t2 = vb;
+            }
+            else {// Sector 2: (0,1,0) 300-0 degrees
+                t1 = -vc;
+                t2 = -va;
+            }
+        }
+        else { // (x00)
+            // Must be Sector 4 since Sector 0 not allowed
+            // Sector 4: (1,0,0) 180-240 degrees
+            t1 = -va;
+            t2 = -vb;
+        }
+    }
+    
+    dtcA = (1.0f - t1 - t2)/2.0f;
+    dtcB = dtcA + t1;
+    dtcC = dtcB + t2;
+    
+    _inverter->SetDtcA(dtcA);
+    _inverter->SetDtcB(dtcB);
+    _inverter->SetDtcC(dtcC);
+    
 }
\ No newline at end of file