Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of priustroller_2 by
modulators.cpp
00001 #include "includes.h" 00002 #include "core.h" 00003 #include "meta.h" 00004 #include "fastmath.h" 00005 #include "transforms.h" 00006 00007 void SinusoidalModulator::Update(float valpha, float vbeta) { 00008 //--hack to make duty cycles positive 00009 float dtcA = valpha; 00010 float dtcB = ((-valpha + sqrt(3.0f) * vbeta) / 2.0f); 00011 float dtcC = ((-valpha - sqrt(3.0f) * vbeta) / 2.0f); 00012 _inverter->SetDtcA(dtcA * 0.5f + 0.5f); 00013 _inverter->SetDtcB(dtcB * 0.5f + 0.5f); 00014 _inverter->SetDtcC(dtcC * 0.5f + 0.5f); 00015 } 00016 00017 void SvmModulator::Update(float valpha, float vbeta) { 00018 float va, vb; 00019 InverseClarke(valpha, vbeta, &va, &vb); 00020 00021 float t1, t2, dtcA, dtcB, dtcC; 00022 00023 /* 00024 //for positive dtheta/dt, t1 is decreasing. t2 is increasing. 00025 if (va >= 0){ // (xx1) 00026 if (vb >= 0){ // (x11) 00027 //300-360 degrees 00028 t1 = va; 00029 t2 = vb; 00030 dtcA = 0.5f - t1 / 2.0f; 00031 dtcB = 0.5f - t2 / 2.0f; 00032 dtcC = 1.5f - dtcA - dtcB; 00033 } 00034 else { // (x01) 00035 if (vc >= 0){ // Sector 5: (1,0,1) 180-240 degrees 00036 t1 = va; 00037 t2 = vb; 00038 dtcA = 0.5f - t1 / 2.0f; 00039 dtcB = 0.5f - t2 / 2.0f; 00040 dtcC = 1.5f - dtcA - dtcB; 00041 00042 } 00043 else {// Sector 1: (0,0,1) 240-300 degrees 00044 t1 = va; 00045 t2 = vb; 00046 dtcA = 0.5f - t1 / 2.0f; 00047 dtcB = 0.5f - t2 / 2.0f; 00048 dtcC = 1.5f - dtcA - dtcB; 00049 } 00050 } 00051 } else { // (xx0) 00052 if (vb >= 0) { // (x10) 00053 if (vc >= 0) { // Sector 6: (1,1,0) 60-120 degrees 00054 t1 = va; 00055 t2 = vb; 00056 dtcA = 0.5f - t1 / 2.0f; 00057 dtcB = 0.5f - t2 / 2.0f; 00058 dtcC = 1.5f - dtcA - dtcB; 00059 } 00060 else {// Sector 2: (0,1,0) 0-60 degrees 00061 t1 = va; 00062 t2 = vb; 00063 dtcA = 0.5f - t1 / 2.0f; 00064 dtcB = 0.5f - t2 / 2.0f; 00065 dtcC = 1.5f - dtcA - dtcB; 00066 } 00067 } 00068 else { // (x00) 00069 // Must be Sector 4 since Sector 0 not allowed 00070 // Sector 4: (1,0,0) 120-180 degrees 00071 t1 = va; 00072 t2 = vb; 00073 dtcA = 0.5f - t1 / 2.0f; 00074 dtcB = 0.5f - t2 / 2.0f; 00075 dtcC = 1.5f - dtcA - dtcB; 00076 } 00077 } 00078 */ 00079 00080 t1 = va; 00081 t2 = vb; 00082 dtcA = 0.5f - t1 / 2.0f; 00083 dtcB = 0.5f - t2 / 2.0f; 00084 dtcC = 1.5f - dtcA - dtcB; 00085 00086 _inverter->SetDtcA(dtcA); 00087 _inverter->SetDtcC(dtcB); 00088 _inverter->SetDtcB(dtcC); 00089 00090 dbg_t1 = t1; 00091 dbg_t2 = t2; 00092 00093 dbg_dtcA = dtcA; 00094 dbg_dtcB = dtcB; 00095 dbg_dtcC = dtcC; 00096 }
Generated on Tue Jul 12 2022 18:31:15 by
1.7.2
