![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Open Loop Vector Space Vector PWM
Fork of Vector_Open_SVPWM by
main.cpp@1:e42c15be2dda, 2017-12-22 (annotated)
- Committer:
- oguro
- Date:
- Fri Dec 22 07:38:29 2017 +0000
- Revision:
- 1:e42c15be2dda
- Parent:
- 0:e72e6efebdd3
20171222
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
oguro | 0:e72e6efebdd3 | 1 | #include "mbed.h" |
oguro | 0:e72e6efebdd3 | 2 | #include "rtos.h" |
oguro | 0:e72e6efebdd3 | 3 | #include <math.h> |
oguro | 0:e72e6efebdd3 | 4 | #define TS1 0.2 |
oguro | 0:e72e6efebdd3 | 5 | |
oguro | 0:e72e6efebdd3 | 6 | float PI=3.141592; |
oguro | 0:e72e6efebdd3 | 7 | int t=0,q=0,i=0; |
oguro | 0:e72e6efebdd3 | 8 | int START=7; |
oguro | 1:e42c15be2dda | 9 | PwmOut mypwmA(PA_8); |
oguro | 1:e42c15be2dda | 10 | PwmOut mypwmB(PA_9); |
oguro | 1:e42c15be2dda | 11 | PwmOut mypwmC(PA_10); |
oguro | 0:e72e6efebdd3 | 12 | |
oguro | 0:e72e6efebdd3 | 13 | PwmOut Current_Ref(PB_4); |
oguro | 0:e72e6efebdd3 | 14 | |
oguro | 0:e72e6efebdd3 | 15 | DigitalOut Vector(PC_4); |
oguro | 0:e72e6efebdd3 | 16 | DigitalOut EN1(PC_10); |
oguro | 0:e72e6efebdd3 | 17 | DigitalOut EN2(PC_11); |
oguro | 0:e72e6efebdd3 | 18 | DigitalOut EN3(PC_12); |
oguro | 0:e72e6efebdd3 | 19 | |
oguro | 0:e72e6efebdd3 | 20 | |
oguro | 0:e72e6efebdd3 | 21 | |
oguro | 0:e72e6efebdd3 | 22 | //AnalogIn V_adc(PB_1); //volume |
oguro | 0:e72e6efebdd3 | 23 | AnalogIn V_adc(PC_2); // Gaibu Potention |
oguro | 0:e72e6efebdd3 | 24 | |
oguro | 0:e72e6efebdd3 | 25 | AnalogIn Vshuntu(PA_1); |
oguro | 0:e72e6efebdd3 | 26 | AnalogIn Vshuntv(PA_0); |
oguro | 0:e72e6efebdd3 | 27 | AnalogIn Vshuntw(PB_0); |
oguro | 0:e72e6efebdd3 | 28 | |
oguro | 0:e72e6efebdd3 | 29 | AnalogIn BEMF1(PC_3);//C7_37 |
oguro | 0:e72e6efebdd3 | 30 | AnalogIn BEMF2(PB_0);//C7_34 |
oguro | 0:e72e6efebdd3 | 31 | AnalogIn BEMF3(PA_7);//C10_26 |
oguro | 0:e72e6efebdd3 | 32 | |
oguro | 0:e72e6efebdd3 | 33 | DigitalIn GPIO_BEMF(PC_9); |
oguro | 0:e72e6efebdd3 | 34 | DigitalIn CPOUT(PA_12); |
oguro | 0:e72e6efebdd3 | 35 | AnalogIn Curr_ui(PA_0); |
oguro | 0:e72e6efebdd3 | 36 | AnalogIn Curr_vi(PC_1); |
oguro | 0:e72e6efebdd3 | 37 | AnalogIn Curr_wi(PA_1); |
oguro | 0:e72e6efebdd3 | 38 | |
oguro | 0:e72e6efebdd3 | 39 | InterruptIn HA(PA_15); |
oguro | 0:e72e6efebdd3 | 40 | InterruptIn HB(PB_3); |
oguro | 0:e72e6efebdd3 | 41 | InterruptIn HC(PB_10); |
oguro | 0:e72e6efebdd3 | 42 | Timer uT; |
oguro | 0:e72e6efebdd3 | 43 | Timer vT; |
oguro | 0:e72e6efebdd3 | 44 | Timer wT; |
oguro | 0:e72e6efebdd3 | 45 | |
oguro | 0:e72e6efebdd3 | 46 | AnalogOut SWAVE(PA_4); |
oguro | 0:e72e6efebdd3 | 47 | |
oguro | 0:e72e6efebdd3 | 48 | Serial pc(USBTX,USBRX); |
oguro | 0:e72e6efebdd3 | 49 | |
oguro | 0:e72e6efebdd3 | 50 | DigitalOut myled(LED1); |
oguro | 0:e72e6efebdd3 | 51 | float sq32=sqrt(3.0f/2.0f); |
oguro | 0:e72e6efebdd3 | 52 | float sq23=2.0f/sqrt(3.0f); |
oguro | 0:e72e6efebdd3 | 53 | float sq3=1.0f/sqrt(3.0f); |
oguro | 0:e72e6efebdd3 | 54 | float VDC=1.8; |
oguro | 0:e72e6efebdd3 | 55 | float Vdlink=1/VDC; |
oguro | 0:e72e6efebdd3 | 56 | float aVa; |
oguro | 0:e72e6efebdd3 | 57 | float a3Vb; |
oguro | 0:e72e6efebdd3 | 58 | float Vr_adc; |
oguro | 0:e72e6efebdd3 | 59 | |
oguro | 0:e72e6efebdd3 | 60 | Timer Timer1; |
oguro | 0:e72e6efebdd3 | 61 | float freq=0; |
oguro | 0:e72e6efebdd3 | 62 | float z=1.0; //0.5 |
oguro | 0:e72e6efebdd3 | 63 | float Wt,Va,Vb,Vq,Vd; |
oguro | 0:e72e6efebdd3 | 64 | float d1,d2,d3,d4,d5,d6,d07; |
oguro | 0:e72e6efebdd3 | 65 | float du,dv,dw; |
oguro | 0:e72e6efebdd3 | 66 | bool cu,cv,cw; |
oguro | 0:e72e6efebdd3 | 67 | float ave=0,aveo=0,avsum=0; |
oguro | 0:e72e6efebdd3 | 68 | |
oguro | 0:e72e6efebdd3 | 69 | float ut=0,ut1=0,ut2=0,usi=0; |
oguro | 0:e72e6efebdd3 | 70 | float vt=0,vt1=0,vt2=0,vsi=0; |
oguro | 0:e72e6efebdd3 | 71 | float wt=0,wt1=0,wt2=0,wsi=0; |
oguro | 0:e72e6efebdd3 | 72 | float Speed; |
oguro | 0:e72e6efebdd3 | 73 | |
oguro | 0:e72e6efebdd3 | 74 | void HAH(){ |
oguro | 0:e72e6efebdd3 | 75 | |
oguro | 0:e72e6efebdd3 | 76 | ut1=uT.read_us(); |
oguro | 0:e72e6efebdd3 | 77 | ut=0; |
oguro | 0:e72e6efebdd3 | 78 | |
oguro | 0:e72e6efebdd3 | 79 | } |
oguro | 0:e72e6efebdd3 | 80 | void HAL(){ |
oguro | 0:e72e6efebdd3 | 81 | |
oguro | 0:e72e6efebdd3 | 82 | ut2=uT.read_us(); |
oguro | 0:e72e6efebdd3 | 83 | uT.reset(); |
oguro | 0:e72e6efebdd3 | 84 | |
oguro | 0:e72e6efebdd3 | 85 | } |
oguro | 0:e72e6efebdd3 | 86 | void HBH(){ |
oguro | 0:e72e6efebdd3 | 87 | |
oguro | 0:e72e6efebdd3 | 88 | vt1=vT.read_us(); |
oguro | 0:e72e6efebdd3 | 89 | |
oguro | 0:e72e6efebdd3 | 90 | } |
oguro | 0:e72e6efebdd3 | 91 | void HBL(){ |
oguro | 0:e72e6efebdd3 | 92 | |
oguro | 0:e72e6efebdd3 | 93 | vt2=vT.read_us(); |
oguro | 0:e72e6efebdd3 | 94 | |
oguro | 0:e72e6efebdd3 | 95 | vT.reset(); |
oguro | 0:e72e6efebdd3 | 96 | } |
oguro | 0:e72e6efebdd3 | 97 | void HCH(){ |
oguro | 0:e72e6efebdd3 | 98 | wt1=wT.read_us(); |
oguro | 0:e72e6efebdd3 | 99 | |
oguro | 0:e72e6efebdd3 | 100 | } |
oguro | 0:e72e6efebdd3 | 101 | |
oguro | 0:e72e6efebdd3 | 102 | void HCL(){ |
oguro | 0:e72e6efebdd3 | 103 | wt2=wT.read_us(); |
oguro | 0:e72e6efebdd3 | 104 | |
oguro | 0:e72e6efebdd3 | 105 | wT.reset(); |
oguro | 0:e72e6efebdd3 | 106 | } |
oguro | 0:e72e6efebdd3 | 107 | |
oguro | 0:e72e6efebdd3 | 108 | |
oguro | 0:e72e6efebdd3 | 109 | |
oguro | 0:e72e6efebdd3 | 110 | void CPLT(){ |
oguro | 0:e72e6efebdd3 | 111 | pc.printf("%.3f , %.3f \r" ,Speed ,Vr_adc); |
oguro | 0:e72e6efebdd3 | 112 | } |
oguro | 0:e72e6efebdd3 | 113 | |
oguro | 0:e72e6efebdd3 | 114 | void timerTS1(void const*argument){ |
oguro | 0:e72e6efebdd3 | 115 | CPLT(); |
oguro | 0:e72e6efebdd3 | 116 | } |
oguro | 0:e72e6efebdd3 | 117 | int main() { |
oguro | 0:e72e6efebdd3 | 118 | Timer1.start(); |
oguro | 0:e72e6efebdd3 | 119 | EN1=1; |
oguro | 0:e72e6efebdd3 | 120 | EN2=1; |
oguro | 0:e72e6efebdd3 | 121 | EN3=1; |
oguro | 0:e72e6efebdd3 | 122 | uT.start(); |
oguro | 0:e72e6efebdd3 | 123 | vT.start(); |
oguro | 0:e72e6efebdd3 | 124 | wT.start(); |
oguro | 0:e72e6efebdd3 | 125 | |
oguro | 0:e72e6efebdd3 | 126 | mypwmA.period_us(20); |
oguro | 0:e72e6efebdd3 | 127 | |
oguro | 0:e72e6efebdd3 | 128 | mypwmB.period_us(20); |
oguro | 0:e72e6efebdd3 | 129 | |
oguro | 0:e72e6efebdd3 | 130 | mypwmC.period_us(20); |
oguro | 0:e72e6efebdd3 | 131 | |
oguro | 0:e72e6efebdd3 | 132 | pc.baud(128000); |
oguro | 0:e72e6efebdd3 | 133 | RtosTimer RtosTimerTS1(timerTS1); |
oguro | 0:e72e6efebdd3 | 134 | RtosTimerTS1.start((unsigned int)(TS1*5000)); //3000 |
oguro | 0:e72e6efebdd3 | 135 | Thread::wait(100); |
oguro | 0:e72e6efebdd3 | 136 | |
oguro | 0:e72e6efebdd3 | 137 | |
oguro | 0:e72e6efebdd3 | 138 | while(1) { |
oguro | 0:e72e6efebdd3 | 139 | |
oguro | 0:e72e6efebdd3 | 140 | HA.rise(&HAH); |
oguro | 0:e72e6efebdd3 | 141 | HC.fall(&HCL); |
oguro | 0:e72e6efebdd3 | 142 | HB.rise(&HBH); |
oguro | 0:e72e6efebdd3 | 143 | HA.fall(&HAL); |
oguro | 0:e72e6efebdd3 | 144 | HC.rise(&HCH); |
oguro | 0:e72e6efebdd3 | 145 | HB.fall(&HBL); |
oguro | 0:e72e6efebdd3 | 146 | Speed=60*(1/(7.0*2.0*usi*1E-6)); |
oguro | 0:e72e6efebdd3 | 147 | usi=ut2-ut1; |
oguro | 0:e72e6efebdd3 | 148 | vsi=vt2-vt1; |
oguro | 0:e72e6efebdd3 | 149 | wsi=wt2-wt1; |
oguro | 0:e72e6efebdd3 | 150 | Vd=0; |
oguro | 0:e72e6efebdd3 | 151 | |
oguro | 0:e72e6efebdd3 | 152 | float s = Timer1.read(); |
oguro | 0:e72e6efebdd3 | 153 | Vr_adc=V_adc.read(); |
oguro | 0:e72e6efebdd3 | 154 | myled = ((int)s) % 2 == 0; /* LED output(0.5Hz) */ |
oguro | 0:e72e6efebdd3 | 155 | |
oguro | 0:e72e6efebdd3 | 156 | |
oguro | 0:e72e6efebdd3 | 157 | if((Vr_adc>0.08f)&&(q==0)){ |
oguro | 0:e72e6efebdd3 | 158 | while(q<30){ |
oguro | 0:e72e6efebdd3 | 159 | |
oguro | 0:e72e6efebdd3 | 160 | mypwmA.write(0.5f); |
oguro | 0:e72e6efebdd3 | 161 | mypwmB.write(0); |
oguro | 0:e72e6efebdd3 | 162 | mypwmC.write(0); |
oguro | 0:e72e6efebdd3 | 163 | wait_ms(START); |
oguro | 0:e72e6efebdd3 | 164 | |
oguro | 0:e72e6efebdd3 | 165 | mypwmA.write(0); |
oguro | 0:e72e6efebdd3 | 166 | mypwmB.write(0.5f); |
oguro | 0:e72e6efebdd3 | 167 | mypwmC.write(0.0); |
oguro | 0:e72e6efebdd3 | 168 | wait_ms(START); |
oguro | 0:e72e6efebdd3 | 169 | |
oguro | 0:e72e6efebdd3 | 170 | mypwmA.write(0); |
oguro | 0:e72e6efebdd3 | 171 | mypwmB.write(0.0); |
oguro | 0:e72e6efebdd3 | 172 | mypwmC.write(0.5f); |
oguro | 0:e72e6efebdd3 | 173 | wait_ms(START); |
oguro | 0:e72e6efebdd3 | 174 | q++; |
oguro | 0:e72e6efebdd3 | 175 | |
oguro | 0:e72e6efebdd3 | 176 | } |
oguro | 0:e72e6efebdd3 | 177 | } |
oguro | 0:e72e6efebdd3 | 178 | if(Vr_adc < 0.05f){ |
oguro | 0:e72e6efebdd3 | 179 | q=0; |
oguro | 0:e72e6efebdd3 | 180 | Vr_adc=0; |
oguro | 0:e72e6efebdd3 | 181 | |
oguro | 0:e72e6efebdd3 | 182 | } |
oguro | 0:e72e6efebdd3 | 183 | |
oguro | 0:e72e6efebdd3 | 184 | aveo=Vr_adc; |
oguro | 0:e72e6efebdd3 | 185 | |
oguro | 0:e72e6efebdd3 | 186 | if((aveo<=0.15)&&(aveo>0.1)){ |
oguro | 0:e72e6efebdd3 | 187 | Wt=fmodf(s * 50, 1) * PI* 2; |
oguro | 0:e72e6efebdd3 | 188 | Vq=0.4; |
oguro | 0:e72e6efebdd3 | 189 | } |
oguro | 0:e72e6efebdd3 | 190 | if((aveo<=0.2)&&(aveo>0.15)){ |
oguro | 0:e72e6efebdd3 | 191 | Wt=fmodf(s * 55, 1) * PI* 2; |
oguro | 0:e72e6efebdd3 | 192 | Vq=0.45; |
oguro | 0:e72e6efebdd3 | 193 | } |
oguro | 0:e72e6efebdd3 | 194 | if((aveo<=0.25)&&(aveo>0.2)){ |
oguro | 0:e72e6efebdd3 | 195 | Wt=fmodf(s * 60, 1) * PI* 2; |
oguro | 0:e72e6efebdd3 | 196 | Vq=0.5; |
oguro | 0:e72e6efebdd3 | 197 | } |
oguro | 0:e72e6efebdd3 | 198 | if((aveo<=0.3)&&(aveo>0.25)){ |
oguro | 0:e72e6efebdd3 | 199 | Wt=fmodf(s * 70, 1) * PI* 2; |
oguro | 0:e72e6efebdd3 | 200 | Vq=0.55; |
oguro | 0:e72e6efebdd3 | 201 | } |
oguro | 0:e72e6efebdd3 | 202 | if((aveo<=0.35)&&(aveo>0.3)){ |
oguro | 0:e72e6efebdd3 | 203 | Wt=fmodf(s * 80, 1) * PI* 2; |
oguro | 0:e72e6efebdd3 | 204 | Vq=0.6; |
oguro | 0:e72e6efebdd3 | 205 | } |
oguro | 0:e72e6efebdd3 | 206 | if((aveo<=0.4)&&(aveo>0.35)){ |
oguro | 0:e72e6efebdd3 | 207 | Wt=fmodf(s * 90, 1) * PI* 2; |
oguro | 0:e72e6efebdd3 | 208 | Vq=0.65; |
oguro | 0:e72e6efebdd3 | 209 | } |
oguro | 0:e72e6efebdd3 | 210 | if((aveo<=0.45)&&(aveo>0.4)){ |
oguro | 0:e72e6efebdd3 | 211 | Wt=fmodf(s * 100, 1) * PI* 2; |
oguro | 0:e72e6efebdd3 | 212 | Vq=0.7; |
oguro | 0:e72e6efebdd3 | 213 | } |
oguro | 0:e72e6efebdd3 | 214 | if((aveo<=0.5)&&(aveo>0.45)){ |
oguro | 0:e72e6efebdd3 | 215 | Wt=fmodf(s * 110, 1) * PI* 2; |
oguro | 0:e72e6efebdd3 | 216 | Vq=0.7; |
oguro | 0:e72e6efebdd3 | 217 | } |
oguro | 0:e72e6efebdd3 | 218 | if((aveo<=0.55)&&(aveo>0.5)){ |
oguro | 0:e72e6efebdd3 | 219 | Wt=fmodf(s * 120, 1) * PI* 2; |
oguro | 0:e72e6efebdd3 | 220 | Vq=0.7; |
oguro | 0:e72e6efebdd3 | 221 | } |
oguro | 0:e72e6efebdd3 | 222 | if((aveo<=0.6)&&(aveo>0.55)){ |
oguro | 0:e72e6efebdd3 | 223 | Wt=fmodf(s * 130, 1) * PI* 2; |
oguro | 0:e72e6efebdd3 | 224 | Vq=0.7; |
oguro | 0:e72e6efebdd3 | 225 | } |
oguro | 0:e72e6efebdd3 | 226 | if((aveo<=0.65)&&(aveo>0.6)){ |
oguro | 0:e72e6efebdd3 | 227 | Wt=fmodf(s * 140, 1) * PI* 2; |
oguro | 0:e72e6efebdd3 | 228 | Vq=0.7; |
oguro | 0:e72e6efebdd3 | 229 | } |
oguro | 0:e72e6efebdd3 | 230 | if((aveo<=0.7)&&(aveo>0.65)){ |
oguro | 0:e72e6efebdd3 | 231 | Wt=fmodf(s * 150, 1) * PI* 2; |
oguro | 0:e72e6efebdd3 | 232 | Vq=0.8; |
oguro | 0:e72e6efebdd3 | 233 | } |
oguro | 0:e72e6efebdd3 | 234 | if((aveo<=0.75)&&(aveo>0.7)){ |
oguro | 0:e72e6efebdd3 | 235 | Wt=fmodf(s * 160, 1) * PI* 2; |
oguro | 0:e72e6efebdd3 | 236 | Vq=0.8; |
oguro | 0:e72e6efebdd3 | 237 | } |
oguro | 0:e72e6efebdd3 | 238 | if((aveo<=0.8)&&(aveo>0.75)){ |
oguro | 0:e72e6efebdd3 | 239 | Wt=fmodf(s * 170, 1) * PI* 2; |
oguro | 0:e72e6efebdd3 | 240 | Vq=0.8; |
oguro | 0:e72e6efebdd3 | 241 | } |
oguro | 0:e72e6efebdd3 | 242 | if((aveo<=0.85)&&(aveo>0.8)){ |
oguro | 0:e72e6efebdd3 | 243 | Wt=fmodf(s * 180, 1) * PI* 2; |
oguro | 0:e72e6efebdd3 | 244 | Vq=0.8; |
oguro | 0:e72e6efebdd3 | 245 | } |
oguro | 0:e72e6efebdd3 | 246 | if((aveo<=0.9)&&(aveo>0.85)){ |
oguro | 0:e72e6efebdd3 | 247 | Wt=fmodf(s * 190, 1) * PI* 2; |
oguro | 0:e72e6efebdd3 | 248 | Vq=0.9; |
oguro | 0:e72e6efebdd3 | 249 | } |
oguro | 0:e72e6efebdd3 | 250 | if((aveo<=0.95)&&(aveo>0.9)){ |
oguro | 0:e72e6efebdd3 | 251 | Wt=fmodf(s * 200, 1) * PI* 2; |
oguro | 0:e72e6efebdd3 | 252 | Vq=0.9; |
oguro | 0:e72e6efebdd3 | 253 | } |
oguro | 0:e72e6efebdd3 | 254 | if(aveo>0.95){ |
oguro | 0:e72e6efebdd3 | 255 | Wt=fmodf(s * 210, 1) * PI* 2; |
oguro | 0:e72e6efebdd3 | 256 | Vq=0.9; |
oguro | 0:e72e6efebdd3 | 257 | } |
oguro | 0:e72e6efebdd3 | 258 | |
oguro | 0:e72e6efebdd3 | 259 | if(aveo<0.1){ |
oguro | 0:e72e6efebdd3 | 260 | mypwmA.write(0); |
oguro | 0:e72e6efebdd3 | 261 | mypwmB.write(0); |
oguro | 0:e72e6efebdd3 | 262 | mypwmC.write(0); |
oguro | 0:e72e6efebdd3 | 263 | |
oguro | 0:e72e6efebdd3 | 264 | } |
oguro | 0:e72e6efebdd3 | 265 | else{ |
oguro | 0:e72e6efebdd3 | 266 | Va=cos(Wt)*Vd-sin(Wt)*Vq; |
oguro | 0:e72e6efebdd3 | 267 | Vb=sin(Wt)*Vd+cos(Wt)*Vq; |
oguro | 0:e72e6efebdd3 | 268 | aVa=abs(Va); |
oguro | 0:e72e6efebdd3 | 269 | a3Vb=abs(sq3*Vb); |
oguro | 0:e72e6efebdd3 | 270 | |
oguro | 0:e72e6efebdd3 | 271 | if((Va>=0)&&(Vb>=0)&&(aVa>=a3Vb)){ //sect 0 |
oguro | 0:e72e6efebdd3 | 272 | |
oguro | 0:e72e6efebdd3 | 273 | d1=sq32*(Va-sq3*Vb)*Vdlink; |
oguro | 0:e72e6efebdd3 | 274 | d2=sq32*(sq23*Vb)*Vdlink; |
oguro | 0:e72e6efebdd3 | 275 | d07=(z-(d1+d2))*0.5; |
oguro | 0:e72e6efebdd3 | 276 | // d07=0; |
oguro | 0:e72e6efebdd3 | 277 | du=d1+d2+d07; |
oguro | 0:e72e6efebdd3 | 278 | dv=d2+d07; |
oguro | 0:e72e6efebdd3 | 279 | dw=d07; |
oguro | 0:e72e6efebdd3 | 280 | |
oguro | 0:e72e6efebdd3 | 281 | } |
oguro | 0:e72e6efebdd3 | 282 | if((aVa<=sq3*Vb)){ //sect 1 |
oguro | 0:e72e6efebdd3 | 283 | |
oguro | 0:e72e6efebdd3 | 284 | d3=sq32*(-Va+sq3*Vb)*Vdlink; |
oguro | 0:e72e6efebdd3 | 285 | d2=sq32*(Va+sq3*Vb)*Vdlink; |
oguro | 0:e72e6efebdd3 | 286 | d07=(z-(d2+d3))*0.5; |
oguro | 0:e72e6efebdd3 | 287 | //d07=0; |
oguro | 0:e72e6efebdd3 | 288 | du=d2+d07; |
oguro | 0:e72e6efebdd3 | 289 | dv=d2+d3+d07; |
oguro | 0:e72e6efebdd3 | 290 | dw=d07; |
oguro | 0:e72e6efebdd3 | 291 | } |
oguro | 0:e72e6efebdd3 | 292 | |
oguro | 0:e72e6efebdd3 | 293 | if((Va<=0)&&(Vb>=0)&&(aVa>=a3Vb)){ //sect 2 |
oguro | 0:e72e6efebdd3 | 294 | |
oguro | 0:e72e6efebdd3 | 295 | d3=sq32*sq23*Vb*Vdlink; |
oguro | 0:e72e6efebdd3 | 296 | d4=sq32*(-Va-sq3*Vb)*Vdlink; |
oguro | 0:e72e6efebdd3 | 297 | d07=(z-(d3+d4))*0.5; |
oguro | 0:e72e6efebdd3 | 298 | // d07=0; |
oguro | 0:e72e6efebdd3 | 299 | du=d07; |
oguro | 0:e72e6efebdd3 | 300 | dv=d3+d4+d07; |
oguro | 0:e72e6efebdd3 | 301 | dw=d4+d07; |
oguro | 0:e72e6efebdd3 | 302 | } |
oguro | 0:e72e6efebdd3 | 303 | |
oguro | 0:e72e6efebdd3 | 304 | if((Va<=0)&&(Vb<=0)&&(aVa>=a3Vb)){ //sect 3 |
oguro | 0:e72e6efebdd3 | 305 | |
oguro | 0:e72e6efebdd3 | 306 | d5=-sq32*sq23*Vb*Vdlink; |
oguro | 0:e72e6efebdd3 | 307 | d4=sq32*(-Va+sq3*Vb)*Vdlink; |
oguro | 0:e72e6efebdd3 | 308 | d07=(z-(d4+d5))*0.5; |
oguro | 0:e72e6efebdd3 | 309 | //d07=0; |
oguro | 0:e72e6efebdd3 | 310 | du=d07; |
oguro | 0:e72e6efebdd3 | 311 | dv=d4+d07; |
oguro | 0:e72e6efebdd3 | 312 | dw=d4+d5+d07; |
oguro | 0:e72e6efebdd3 | 313 | } |
oguro | 0:e72e6efebdd3 | 314 | |
oguro | 0:e72e6efebdd3 | 315 | if((aVa<=-sq3*Vb)){ //sect 4 |
oguro | 0:e72e6efebdd3 | 316 | |
oguro | 0:e72e6efebdd3 | 317 | d5=sq32*(-Va-sq3*Vb)*Vdlink;; |
oguro | 0:e72e6efebdd3 | 318 | d6=sq32*(Va-sq3*Vb)*Vdlink; |
oguro | 0:e72e6efebdd3 | 319 | d07=(z-(d5+d6))*0.5; |
oguro | 0:e72e6efebdd3 | 320 | //d07=0; |
oguro | 0:e72e6efebdd3 | 321 | du=d6+d07; |
oguro | 0:e72e6efebdd3 | 322 | dv=d07; |
oguro | 0:e72e6efebdd3 | 323 | dw=d5+d6+d07; |
oguro | 0:e72e6efebdd3 | 324 | } |
oguro | 0:e72e6efebdd3 | 325 | |
oguro | 0:e72e6efebdd3 | 326 | if((Va>=0)&&(Vb<=0)&&(aVa>=a3Vb)){ //sect 5 |
oguro | 0:e72e6efebdd3 | 327 | |
oguro | 0:e72e6efebdd3 | 328 | d1=sq32*(Va+sq3*Vb)*Vdlink;; |
oguro | 0:e72e6efebdd3 | 329 | d6=-sq32*sq23*Vb*Vdlink;; |
oguro | 0:e72e6efebdd3 | 330 | d07=(z-(d1+d6))*0.5; |
oguro | 0:e72e6efebdd3 | 331 | //d07=0; |
oguro | 0:e72e6efebdd3 | 332 | du=d1+d6+d07; |
oguro | 0:e72e6efebdd3 | 333 | dv=d07; |
oguro | 0:e72e6efebdd3 | 334 | dw=d6+d07; |
oguro | 0:e72e6efebdd3 | 335 | } |
oguro | 0:e72e6efebdd3 | 336 | |
oguro | 0:e72e6efebdd3 | 337 | mypwmA.write(du); |
oguro | 0:e72e6efebdd3 | 338 | mypwmB.write(dv); |
oguro | 0:e72e6efebdd3 | 339 | mypwmC.write(dw); |
oguro | 0:e72e6efebdd3 | 340 | } |
oguro | 0:e72e6efebdd3 | 341 | |
oguro | 0:e72e6efebdd3 | 342 | SWAVE=dw; |
oguro | 0:e72e6efebdd3 | 343 | |
oguro | 0:e72e6efebdd3 | 344 | } |
oguro | 0:e72e6efebdd3 | 345 | } |