a fork of priustroller

Dependencies:   mbed

Fork of priustroller_current by N K

Committer:
nki
Date:
Mon Mar 09 03:07:10 2015 +0000
Revision:
15:d754b71a1290
Parent:
14:1cc975207995
Child:
19:280c62c71cf8
Added SVM code to modulators.cpp;

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 14:1cc975207995 7 void SinusoidalModulator::Update(float valpha, float vbeta) {
nki 15:d754b71a1290 8
nki 15:d754b71a1290 9 //swapping valpha and vbeta for reasons documented in CalcRef.s here: http://ww1.microchip.com/downloads/jp/AppNotes/ACIM%20Vector%20Control%2000908a.pdf
nki 15:d754b71a1290 10 float vra = vbeta;
nki 15:d754b71a1290 11 float vrb = ((-vbeta + sqrt(3.0f)*valpha)/2.0f);
nki 15:d754b71a1290 12 float vrc = ((-vbeta - sqrt(3.0f)*valpha)/2.0f);
nki 15:d754b71a1290 13
nki 15:d754b71a1290 14 float dtcA;
nki 15:d754b71a1290 15 float dtcB;
nki 15:d754b71a1290 16 float dtcC;
nki 15:d754b71a1290 17
nki 15:d754b71a1290 18 if( vra >= 0 ){ // (xx1)
nki 15:d754b71a1290 19 if( vrb >= 0 ){ // (x11)
nki 15:d754b71a1290 20 // Must be Sector 3 since Sector 7 not allowed
nki 15:d754b71a1290 21 // Sector 3: (0,1,1) 0-60 degrees
nki 15:d754b71a1290 22 T1 = vrb;
nki 15:d754b71a1290 23 T2 = vra;
nki 15:d754b71a1290 24 }
nki 15:d754b71a1290 25 else{ // (x01)
nki 15:d754b71a1290 26 if( vrc >= 0 ){ // Sector 5: (1,0,1) 120-180 degrees
nki 15:d754b71a1290 27 T1 = vra;
nki 15:d754b71a1290 28 T2 = vrc;
nki 15:d754b71a1290 29 }
nki 15:d754b71a1290 30 else{// Sector 1: (0,0,1) 60-120 degrees
nki 15:d754b71a1290 31 T1 = -vrb;
nki 15:d754b71a1290 32 T2 = -vrc;
nki 15:d754b71a1290 33 }
nki 15:d754b71a1290 34 }
nki 15:d754b71a1290 35 }
nki 15:d754b71a1290 36 else{ // (xx0)
nki 15:d754b71a1290 37 if( Vrb >= 0 ){ // (x10)
nki 15:d754b71a1290 38 if( Vrc >= 0 ){ // Sector 6: (1,1,0) 240-300 degrees
nki 15:d754b71a1290 39 T1 = vrc;
nki 15:d754b71a1290 40 T2 = vrb;
nki 15:d754b71a1290 41 }
nki 15:d754b71a1290 42 else{// Sector 2: (0,1,0) 300-0 degrees
nki 15:d754b71a1290 43 T1 = -vrc;
nki 15:d754b71a1290 44 T2 = -vra;
nki 15:d754b71a1290 45 }
nki 15:d754b71a1290 46 }
nki 15:d754b71a1290 47 else{ // (x00)
nki 15:d754b71a1290 48 // Must be Sector 4 since Sector 0 not allowed
nki 15:d754b71a1290 49 // Sector 4: (1,0,0) 180-240 degrees
nki 15:d754b71a1290 50 T1 = -vra;
nki 15:d754b71a1290 51 T2 = -vrb;
nki 15:d754b71a1290 52 }
nki 15:d754b71a1290 53 }
nki 15:d754b71a1290 54 }
nki 15:d754b71a1290 55
nki 15:d754b71a1290 56 dtcA = (1.0f-T1-T2)/2.0f
nki 15:d754b71a1290 57 dtcB = dtcA + T1
nki 15:d754b71a1290 58 dtcC = dtcB + T2
nki 15:d754b71a1290 59
bwang 13:79e247e54d78 60 //--hack to make duty cycles positive
nki 15:d754b71a1290 61
bwang 13:79e247e54d78 62 _inverter->SetDtcA(dtcA * 0.5f + 0.5f);
bwang 13:79e247e54d78 63 _inverter->SetDtcB(dtcB * 0.5f + 0.5f);
bwang 13:79e247e54d78 64 _inverter->SetDtcC(dtcC * 0.5f + 0.5f);
bwang 14:1cc975207995 65 }
bwang 14:1cc975207995 66
bwang 14:1cc975207995 67 void SvmModulator::Update(float valpha, float vbeta) {
bwang 14:1cc975207995 68 float va, vb, vc;
bwang 14:1cc975207995 69 InverseClarke(valpha, vbeta, &va, &vb);
bwang 14:1cc975207995 70 vc = -(va + vb);
bwang 11:dccbaa9274c5 71 }