N K
/
GaNtroller
a fork of priustroller
Fork of priustroller_current by
meta/modulators.cpp@55:f102d271e808, 2015-05-21 (annotated)
- Committer:
- nki
- Date:
- Thu May 21 02:19:25 2015 +0000
- Revision:
- 55:f102d271e808
- Parent:
- 49:0603121a0538
still testing;
Who changed what in which revision?
User | Revision | Line number | New 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 | 23:7366022ea0ab | 18 | float va, vb; |
nki | 22:46d164aa4f1c | 19 | InverseClarke(valpha, vbeta, &va, &vb); |
bwang | 19:280c62c71cf8 | 20 | |
bwang | 23:7366022ea0ab | 21 | float t1, t2, dtcA, dtcB, dtcC; |
nki | 22:46d164aa4f1c | 22 | |
bwang | 23:7366022ea0ab | 23 | /* |
nki | 22:46d164aa4f1c | 24 | //for positive dtheta/dt, t1 is decreasing. t2 is increasing. |
bwang | 19:280c62c71cf8 | 25 | if (va >= 0){ // (xx1) |
bwang | 19:280c62c71cf8 | 26 | if (vb >= 0){ // (x11) |
nki | 22:46d164aa4f1c | 27 | //300-360 degrees |
bwang | 23:7366022ea0ab | 28 | t1 = va; |
bwang | 23:7366022ea0ab | 29 | t2 = vb; |
bwang | 23:7366022ea0ab | 30 | dtcA = 0.5f - t1 / 2.0f; |
bwang | 23:7366022ea0ab | 31 | dtcB = 0.5f - t2 / 2.0f; |
nki | 22:46d164aa4f1c | 32 | dtcC = 1.5f - dtcA - dtcB; |
bwang | 19:280c62c71cf8 | 33 | } |
bwang | 19:280c62c71cf8 | 34 | else { // (x01) |
nki | 22:46d164aa4f1c | 35 | if (vc >= 0){ // Sector 5: (1,0,1) 180-240 degrees |
bwang | 23:7366022ea0ab | 36 | t1 = va; |
bwang | 23:7366022ea0ab | 37 | t2 = vb; |
bwang | 23:7366022ea0ab | 38 | dtcA = 0.5f - t1 / 2.0f; |
bwang | 23:7366022ea0ab | 39 | dtcB = 0.5f - t2 / 2.0f; |
bwang | 23:7366022ea0ab | 40 | dtcC = 1.5f - dtcA - dtcB; |
nki | 22:46d164aa4f1c | 41 | |
bwang | 19:280c62c71cf8 | 42 | } |
nki | 22:46d164aa4f1c | 43 | else {// Sector 1: (0,0,1) 240-300 degrees |
bwang | 23:7366022ea0ab | 44 | t1 = va; |
bwang | 23:7366022ea0ab | 45 | t2 = vb; |
bwang | 23:7366022ea0ab | 46 | dtcA = 0.5f - t1 / 2.0f; |
bwang | 23:7366022ea0ab | 47 | dtcB = 0.5f - t2 / 2.0f; |
bwang | 23:7366022ea0ab | 48 | dtcC = 1.5f - dtcA - dtcB; |
bwang | 19:280c62c71cf8 | 49 | } |
bwang | 19:280c62c71cf8 | 50 | } |
bwang | 19:280c62c71cf8 | 51 | } else { // (xx0) |
bwang | 19:280c62c71cf8 | 52 | if (vb >= 0) { // (x10) |
nki | 22:46d164aa4f1c | 53 | if (vc >= 0) { // Sector 6: (1,1,0) 60-120 degrees |
bwang | 23:7366022ea0ab | 54 | t1 = va; |
bwang | 23:7366022ea0ab | 55 | t2 = vb; |
bwang | 23:7366022ea0ab | 56 | dtcA = 0.5f - t1 / 2.0f; |
bwang | 23:7366022ea0ab | 57 | dtcB = 0.5f - t2 / 2.0f; |
bwang | 23:7366022ea0ab | 58 | dtcC = 1.5f - dtcA - dtcB; |
bwang | 19:280c62c71cf8 | 59 | } |
nki | 22:46d164aa4f1c | 60 | else {// Sector 2: (0,1,0) 0-60 degrees |
bwang | 23:7366022ea0ab | 61 | t1 = va; |
bwang | 23:7366022ea0ab | 62 | t2 = vb; |
bwang | 23:7366022ea0ab | 63 | dtcA = 0.5f - t1 / 2.0f; |
bwang | 23:7366022ea0ab | 64 | dtcB = 0.5f - t2 / 2.0f; |
bwang | 23:7366022ea0ab | 65 | dtcC = 1.5f - dtcA - dtcB; |
bwang | 19:280c62c71cf8 | 66 | } |
bwang | 19:280c62c71cf8 | 67 | } |
bwang | 19:280c62c71cf8 | 68 | else { // (x00) |
bwang | 19:280c62c71cf8 | 69 | // Must be Sector 4 since Sector 0 not allowed |
nki | 22:46d164aa4f1c | 70 | // Sector 4: (1,0,0) 120-180 degrees |
bwang | 23:7366022ea0ab | 71 | t1 = va; |
bwang | 23:7366022ea0ab | 72 | t2 = vb; |
bwang | 23:7366022ea0ab | 73 | dtcA = 0.5f - t1 / 2.0f; |
bwang | 23:7366022ea0ab | 74 | dtcB = 0.5f - t2 / 2.0f; |
nki | 22:46d164aa4f1c | 75 | dtcC = 1.5f - dtcA - dtcB; |
bwang | 19:280c62c71cf8 | 76 | } |
bwang | 19:280c62c71cf8 | 77 | } |
bwang | 23:7366022ea0ab | 78 | */ |
bwang | 23:7366022ea0ab | 79 | |
bwang | 23:7366022ea0ab | 80 | t1 = va; |
bwang | 23:7366022ea0ab | 81 | t2 = vb; |
bwang | 23:7366022ea0ab | 82 | dtcA = 0.5f - t1 / 2.0f; |
bwang | 23:7366022ea0ab | 83 | dtcB = 0.5f - t2 / 2.0f; |
bwang | 23:7366022ea0ab | 84 | dtcC = 1.5f - dtcA - dtcB; |
nki | 22:46d164aa4f1c | 85 | |
bwang | 19:280c62c71cf8 | 86 | _inverter->SetDtcA(dtcA); |
nki | 49:0603121a0538 | 87 | _inverter->SetDtcC(dtcB); |
nki | 48:28edb4c5c04b | 88 | _inverter->SetDtcB(dtcC); |
nki | 22:46d164aa4f1c | 89 | |
nki | 22:46d164aa4f1c | 90 | dbg_t1 = t1; |
nki | 22:46d164aa4f1c | 91 | dbg_t2 = t2; |
nki | 21:da41c08e51bc | 92 | |
nki | 21:da41c08e51bc | 93 | dbg_dtcA = dtcA; |
nki | 21:da41c08e51bc | 94 | dbg_dtcB = dtcB; |
nki | 21:da41c08e51bc | 95 | dbg_dtcC = dtcC; |
bwang | 11:dccbaa9274c5 | 96 | } |