temp repo

Dependencies:   mbed

Fork of priustroller_2 by N K

Committer:
nki
Date:
Mon Mar 09 07:44:57 2015 +0000
Revision:
22:46d164aa4f1c
Parent:
21:da41c08e51bc
Child:
23:7366022ea0ab
SVM table now correct.  2.05A at 65V,; todo: correct 50% dtc at 0 throttle; incorporate PI control

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;
nki 22:46d164aa4f1c 19 InverseClarke(valpha, vbeta, &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
nki 22:46d164aa4f1c 24 t1 = 0;
nki 22:46d164aa4f1c 25 t2 = 0;
nki 22:46d164aa4f1c 26 dtcA = 0.0f;
nki 22:46d164aa4f1c 27 dtcB = 0.0f;
nki 22:46d164aa4f1c 28 dtcC = 0.0f;
nki 22:46d164aa4f1c 29
nki 22:46d164aa4f1c 30 //for positive dtheta/dt, t1 is decreasing. t2 is increasing.
bwang 19:280c62c71cf8 31 if (va >= 0){ // (xx1)
bwang 19:280c62c71cf8 32 if (vb >= 0){ // (x11)
nki 22:46d164aa4f1c 33 //300-360 degrees
nki 22:46d164aa4f1c 34 t1 = va; //was -vc
nki 22:46d164aa4f1c 35 t2 = -vb; //was -va
nki 22:46d164aa4f1c 36 dtcA = 0.5f - t1/2.0f;
nki 22:46d164aa4f1c 37 dtcB = 0.5f + t2/2.0f;
nki 22:46d164aa4f1c 38 dtcC = 1.5f - dtcA - dtcB;
bwang 19:280c62c71cf8 39 }
bwang 19:280c62c71cf8 40 else { // (x01)
nki 22:46d164aa4f1c 41 if (vc >= 0){ // Sector 5: (1,0,1) 180-240 degrees
nki 22:46d164aa4f1c 42 t1 = -vc;
nki 22:46d164aa4f1c 43 t2 = va;
nki 22:46d164aa4f1c 44 dtcA = 0.5f - t2/2.0f;
nki 22:46d164aa4f1c 45 dtcC = 0.5f + t1/2.0f;
nki 22:46d164aa4f1c 46 dtcB = 1.5f - dtcA - dtcC;
nki 22:46d164aa4f1c 47
bwang 19:280c62c71cf8 48 }
nki 22:46d164aa4f1c 49 else {// Sector 1: (0,0,1) 240-300 degrees
nki 22:46d164aa4f1c 50 t1 = -vb; //was -vb
nki 22:46d164aa4f1c 51 t2 = -vc; //was -vc
nki 22:46d164aa4f1c 52 dtcC = 0.5f + t2/2.0f;
nki 22:46d164aa4f1c 53 dtcB = 0.5f + t1/2.0f;
nki 22:46d164aa4f1c 54 dtcA = 1.5f - dtcC - dtcB;
bwang 19:280c62c71cf8 55 }
bwang 19:280c62c71cf8 56 }
bwang 19:280c62c71cf8 57 } else { // (xx0)
bwang 19:280c62c71cf8 58 if (vb >= 0) { // (x10)
nki 22:46d164aa4f1c 59 if (vc >= 0) { // Sector 6: (1,1,0) 60-120 degrees
nki 22:46d164aa4f1c 60 t1 = vb;
nki 22:46d164aa4f1c 61 t2 = vc;
nki 22:46d164aa4f1c 62 dtcB = 0.5f - t1 / 2.0f;
nki 22:46d164aa4f1c 63 dtcC = 0.5f - t2 / 2.0f;
nki 22:46d164aa4f1c 64 dtcA = 1.5f - dtcC - dtcB;
bwang 19:280c62c71cf8 65 }
nki 22:46d164aa4f1c 66 else {// Sector 2: (0,1,0) 0-60 degrees
nki 22:46d164aa4f1c 67 t1 = -vc;
nki 22:46d164aa4f1c 68 t2 = -va;
nki 22:46d164aa4f1c 69 dtcC = 0.5f + t1/2.0f;
nki 22:46d164aa4f1c 70 dtcA = 0.5f + t2/2.0f;
nki 22:46d164aa4f1c 71 dtcB = 1.5f - dtcC - dtcA;
bwang 19:280c62c71cf8 72 }
bwang 19:280c62c71cf8 73 }
bwang 19:280c62c71cf8 74 else { // (x00)
bwang 19:280c62c71cf8 75 // Must be Sector 4 since Sector 0 not allowed
nki 22:46d164aa4f1c 76 // Sector 4: (1,0,0) 120-180 degrees
nki 22:46d164aa4f1c 77 t1 = -va; //was -va
nki 22:46d164aa4f1c 78 t2 = -vb; //was -vb
nki 22:46d164aa4f1c 79 dtcA = 0.5f + t1/2.0f;
nki 22:46d164aa4f1c 80 dtcB = 0.5f + t2/2.0f;
nki 22:46d164aa4f1c 81 dtcC = 1.5f - dtcA - dtcB;
bwang 19:280c62c71cf8 82 }
bwang 19:280c62c71cf8 83 }
nki 22:46d164aa4f1c 84
nki 22:46d164aa4f1c 85
nki 22:46d164aa4f1c 86
bwang 19:280c62c71cf8 87
bwang 19:280c62c71cf8 88 _inverter->SetDtcA(dtcA);
bwang 19:280c62c71cf8 89 _inverter->SetDtcB(dtcB);
bwang 19:280c62c71cf8 90 _inverter->SetDtcC(dtcC);
nki 22:46d164aa4f1c 91
nki 22:46d164aa4f1c 92 dbg_t1 = t1;
nki 22:46d164aa4f1c 93 dbg_t2 = t2;
nki 21:da41c08e51bc 94
nki 21:da41c08e51bc 95 dbg_dtcA = dtcA;
nki 21:da41c08e51bc 96 dbg_dtcB = dtcB;
nki 21:da41c08e51bc 97 dbg_dtcC = dtcC;
bwang 11:dccbaa9274c5 98 }