a fork of priustroller

Dependencies:   mbed

Fork of priustroller_current by N K

Committer:
bwang
Date:
Mon Mar 09 03:32:32 2015 +0000
Revision:
19:280c62c71cf8
Parent:
15:d754b71a1290
Child:
20:3a7eae543153
stylistic changes (SVM code in the right class now); NOTE: SinusoidalModulator currently does nothing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bwang 11:dccbaa9274c5 1 #include "includes.h"
bwang 11:dccbaa9274c5 2 #include "core.h"
bwang 11:dccbaa9274c5 3 #include "meta.h"
bwang 14:1cc975207995 4 #include "fastmath.h"
bwang 14:1cc975207995 5 #include "transforms.h"
bwang 11:dccbaa9274c5 6
bwang 19:280c62c71cf8 7 void SinusoidalModulator::Update(float valpha, float vbeta) {
bwang 19:280c62c71cf8 8 float dtcA = 0.0f;
bwang 19:280c62c71cf8 9 float dtcB = 0.0f;
bwang 19:280c62c71cf8 10 float dtcC = 0.0f;
nki 15:d754b71a1290 11
bwang 13:79e247e54d78 12 //--hack to make duty cycles positive
bwang 13:79e247e54d78 13 _inverter->SetDtcA(dtcA * 0.5f + 0.5f);
bwang 13:79e247e54d78 14 _inverter->SetDtcB(dtcB * 0.5f + 0.5f);
bwang 13:79e247e54d78 15 _inverter->SetDtcC(dtcC * 0.5f + 0.5f);
bwang 14:1cc975207995 16 }
bwang 14:1cc975207995 17
bwang 14:1cc975207995 18 void SvmModulator::Update(float valpha, float vbeta) {
bwang 14:1cc975207995 19 float va, vb, vc;
bwang 19:280c62c71cf8 20 InverseClarke(vbeta, valpha, &va, &vb);
bwang 14:1cc975207995 21 vc = -(va + vb);
bwang 19:280c62c71cf8 22
bwang 19:280c62c71cf8 23 float dtcA, dtcB, dtcC, t1, t2;
bwang 19:280c62c71cf8 24
bwang 19:280c62c71cf8 25 if (va >= 0){ // (xx1)
bwang 19:280c62c71cf8 26 if (vb >= 0){ // (x11)
bwang 19:280c62c71cf8 27 // Must be Sector 3 since Sector 7 not allowed
bwang 19:280c62c71cf8 28 // Sector 3: (0,1,1) 0-60 degrees
bwang 19:280c62c71cf8 29 t1 = vb;
bwang 19:280c62c71cf8 30 t2 = va;
bwang 19:280c62c71cf8 31 }
bwang 19:280c62c71cf8 32 else { // (x01)
bwang 19:280c62c71cf8 33 if (vc >= 0){ // Sector 5: (1,0,1) 120-180 degrees
bwang 19:280c62c71cf8 34 t1 = va;
bwang 19:280c62c71cf8 35 t2 = vc;
bwang 19:280c62c71cf8 36 }
bwang 19:280c62c71cf8 37 else {// Sector 1: (0,0,1) 60-120 degrees
bwang 19:280c62c71cf8 38 t1 = -vb;
bwang 19:280c62c71cf8 39 t2 = -vc;
bwang 19:280c62c71cf8 40 }
bwang 19:280c62c71cf8 41 }
bwang 19:280c62c71cf8 42 } else { // (xx0)
bwang 19:280c62c71cf8 43 if (vb >= 0) { // (x10)
bwang 19:280c62c71cf8 44 if (vc >= 0) { // Sector 6: (1,1,0) 240-300 degrees
bwang 19:280c62c71cf8 45 t1 = vc;
bwang 19:280c62c71cf8 46 t2 = vb;
bwang 19:280c62c71cf8 47 }
bwang 19:280c62c71cf8 48 else {// Sector 2: (0,1,0) 300-0 degrees
bwang 19:280c62c71cf8 49 t1 = -vc;
bwang 19:280c62c71cf8 50 t2 = -va;
bwang 19:280c62c71cf8 51 }
bwang 19:280c62c71cf8 52 }
bwang 19:280c62c71cf8 53 else { // (x00)
bwang 19:280c62c71cf8 54 // Must be Sector 4 since Sector 0 not allowed
bwang 19:280c62c71cf8 55 // Sector 4: (1,0,0) 180-240 degrees
bwang 19:280c62c71cf8 56 t1 = -va;
bwang 19:280c62c71cf8 57 t2 = -vb;
bwang 19:280c62c71cf8 58 }
bwang 19:280c62c71cf8 59 }
bwang 19:280c62c71cf8 60
bwang 19:280c62c71cf8 61 dtcA = (1.0f - t1 - t2)/2.0f;
bwang 19:280c62c71cf8 62 dtcB = dtcA + t1;
bwang 19:280c62c71cf8 63 dtcC = dtcB + t2;
bwang 19:280c62c71cf8 64
bwang 19:280c62c71cf8 65 _inverter->SetDtcA(dtcA);
bwang 19:280c62c71cf8 66 _inverter->SetDtcB(dtcB);
bwang 19:280c62c71cf8 67 _inverter->SetDtcC(dtcC);
bwang 19:280c62c71cf8 68
bwang 11:dccbaa9274c5 69 }