a fork of priustroller

Dependencies:   mbed

Fork of priustroller_current by N K

Committer:
bwang
Date:
Mon Mar 09 03:36:59 2015 +0000
Revision:
20:3a7eae543153
Parent:
19:280c62c71cf8
Child:
21:da41c08e51bc
restored SinusoidalModulator::Update to its nominal state (2.19A@20V); SVM does not work in this revision

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