[278] | 1 | /* modul PWM modulace |
---|
| 2 | ubytky a mrtve casy |
---|
| 3 | |
---|
| 4 | shodna verze s PWM_FULL_LC |
---|
| 5 | |
---|
| 6 | 31.5. 2007 |
---|
| 7 | |
---|
| 8 | VER. zmenena metoda vypoctu pily (nove funkce) |
---|
| 9 | 31.5.2007 Doplnena PWM se treti harmonickou - fce pwm_full_new_3h(...) - prepinani mezi sinusovou PWM a 3. harmonickou pomoci priznaku mod! |
---|
| 10 | */ |
---|
| 11 | |
---|
| 12 | #define _USE_MATH_DEFINES |
---|
| 13 | #include <math.h> |
---|
| 14 | #include <stdlib.h> |
---|
| 15 | #include "pwm.h" |
---|
| 16 | |
---|
| 17 | void pwm_full_init(double Ucn, double fc, double DT); |
---|
| 18 | void pwm_full(double *us, double *u, double *Iz,double Ucn, double Uc, double *i, double fc, double *va_char,unsigned int pocet, double h); |
---|
| 19 | |
---|
| 20 | void pwm_full_new_init(double h, double fc, double DT, int citac_init, int D_smer, int D_smer2); |
---|
| 21 | void pwm_full_new(double *us, double *u, double *Iz, double Ucn, double Uc, double *is, double *va_char, unsigned int pocet); |
---|
| 22 | |
---|
| 23 | // PWM se treti harmonickou |
---|
| 24 | void pwm_full_new_init_3h(double h, double fc, double DT, int citac_init, int D_smer, int D_smer2); |
---|
| 25 | void pwm_full_new_3h(double *us, double *u, double *Iz, double Ucn, double Uc, double *is, double *va_char, unsigned int pocet, unsigned int mod); |
---|
| 26 | |
---|
| 27 | static double ubytek(double *va_char, double I, unsigned int pocet); |
---|
| 28 | |
---|
| 29 | static double up, up2, dup; |
---|
| 30 | static int smer, smer2; |
---|
| 31 | |
---|
| 32 | static int citac, citac2, citac_PR; |
---|
| 33 | |
---|
| 34 | double ladeni_pila, ladeni_ur; |
---|
| 35 | |
---|
| 36 | void pwm_full_init(double Ucn, double fc, double DT) |
---|
| 37 | /* |
---|
| 38 | Ucn ... jmenovite napeti kondenzatoru v ss obvodu |
---|
| 39 | fc ... spinaci frekvence |
---|
| 40 | h ... krok simulace |
---|
| 41 | DT ... velikost mrtveho casu |
---|
| 42 | */ |
---|
| 43 | { |
---|
| 44 | smer=-1; smer2=1; |
---|
| 45 | up=Ucn/2; |
---|
| 46 | // up=0.; |
---|
| 47 | up2=up-2*Ucn*fc*DT; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | void pwm_full(double *us, double *u, double *Iz,double Ucn, double Uc, double *is, double fc, double *va_char,unsigned int pocet, double h) |
---|
| 51 | /* |
---|
| 52 | u ... pozadovane napeti |
---|
| 53 | us ... [usx, usy]...vystupni napeti stridace v (x,y) |
---|
| 54 | Iz ... proud v ss obvodu |
---|
| 55 | Ucn ... jmenovite nap. v ss obvodu |
---|
| 56 | Uc ... skutecne napeti na C |
---|
| 57 | is ... [isx, isy]...proud motorem |
---|
| 58 | va_char ... VA-char vykonovych spinacu |
---|
| 59 | pocet ... pocet bodu VA-charky |
---|
| 60 | h ... krok simulace |
---|
| 61 | */ |
---|
| 62 | { |
---|
| 63 | unsigned int i; |
---|
| 64 | double iabc[3], ur[3],ustr[3],ua,ub,uc; |
---|
| 65 | double dtr[3],dd[3]; // ubytky na polovodicich |
---|
| 66 | |
---|
| 67 | ladeni_pila=up; |
---|
| 68 | |
---|
| 69 | iabc[0]=*is; |
---|
| 70 | iabc[1]=(-*is+sqrt(3.)**(is+1))/2.; |
---|
| 71 | iabc[2]=(-*is-sqrt(3.)**(is+1))/2.; |
---|
| 72 | |
---|
| 73 | ur[0]=*u; |
---|
| 74 | ur[1]=(-*u+sqrt(3.)**(u+1))/2.; |
---|
| 75 | ur[2]=(-*u-sqrt(3.)**(u+1))/2.; |
---|
| 76 | |
---|
| 77 | for (i=0;i<3;i++) |
---|
| 78 | { dtr[i]=ubytek(va_char,fabs(iabc[i]),pocet); |
---|
| 79 | dd[i]=dtr[i]*.73; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | // implementace ubytku a mrtvych casu |
---|
| 83 | for (i=0;i<3;i++) |
---|
| 84 | if (iabc[i]>=0) |
---|
| 85 | if ((ur[i]>up) && (ur[i]>up2)) |
---|
| 86 | ustr[i]=Uc/2-dtr[i]; |
---|
| 87 | else |
---|
| 88 | ustr[i]=-(Uc/2+dd[i]); |
---|
| 89 | else |
---|
| 90 | if ((ur[i]<up) && (ur[i]<up2)) |
---|
| 91 | ustr[i]=-(Uc/2-dtr[i]); |
---|
| 92 | else |
---|
| 93 | ustr[i]=Uc/2+dd[i]; |
---|
| 94 | |
---|
| 95 | // fazova napeti zateze |
---|
| 96 | ua=(2*ustr[0]-ustr[1]-ustr[2])/3; |
---|
| 97 | ub=(2*ustr[1]-ustr[0]-ustr[2])/3; |
---|
| 98 | uc=(2*ustr[2]-ustr[0]-ustr[1])/3; |
---|
| 99 | |
---|
| 100 | // vystupni napeti stridace v (x,y) |
---|
| 101 | *us=(2.*ua-ub-uc)/3.; |
---|
| 102 | *(us+1)=(ub-uc)/sqrt(3.); |
---|
| 103 | |
---|
| 104 | // vypocet pily pro PWM a pily pro mrtve casy |
---|
| 105 | dup=2.*Ucn*fc*h; |
---|
| 106 | up+=smer*dup; |
---|
| 107 | if (up>Ucn/2) |
---|
| 108 | { up-=2*dup; |
---|
| 109 | smer=-1; |
---|
| 110 | } |
---|
| 111 | if (up<-Ucn/2) |
---|
| 112 | { up+=2.*dup; |
---|
| 113 | smer=1; |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | up2+=smer2*dup; |
---|
| 117 | if (up2>Ucn/2) |
---|
| 118 | { up2-=2.*dup; |
---|
| 119 | smer2=-1; |
---|
| 120 | } |
---|
| 121 | if (up2<-Ucn/2) |
---|
| 122 | { up2+=2.*dup; |
---|
| 123 | smer2=1; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | *Iz=(ustr[0]>0)*iabc[0]+(ustr[1]>0)*iabc[1]+(ustr[2]>0)*iabc[2]; |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | static double ubytek(double *va_char, double I, unsigned int pocet) |
---|
| 130 | { |
---|
| 131 | unsigned int ii; |
---|
| 132 | double delta_u; |
---|
| 133 | |
---|
| 134 | ii=0; |
---|
| 135 | while ((*(va_char+ii)<I) && (ii<(pocet-1))) |
---|
| 136 | ii++; |
---|
| 137 | |
---|
| 138 | if (ii==(pocet-1)) // konec va_char - predpoklad nasyceni charky |
---|
| 139 | delta_u=*(va_char+ii+pocet); |
---|
| 140 | else |
---|
| 141 | if (ii==0) |
---|
| 142 | delta_u=0; |
---|
| 143 | else |
---|
| 144 | delta_u=*(va_char+ii-1+pocet)+(I-*(va_char+ii-1))/(*(va_char+ii)-*(va_char+ii-1))*(*(va_char+ii+pocet)-*(va_char+ii-1+pocet)); |
---|
| 145 | |
---|
| 146 | return delta_u; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | |
---|
| 150 | void pwm_full_new(double *us, double *u, double *Iz, double Ucn, double Uc, double *is, double *va_char, unsigned int pocet) |
---|
| 151 | /* |
---|
| 152 | u ... pozadovane napeti |
---|
| 153 | us ... [usx, usy]...vystupni napeti stridace v (x,y) |
---|
| 154 | Iz ... proud v ss obvodu |
---|
| 155 | Ucn ... jmenovite nap. v ss obvodu |
---|
| 156 | Uc ... skutecne napeti na C |
---|
| 157 | is ... [isx, isy]...proud motorem |
---|
| 158 | va_char ... VA-char vykonovych spinacu |
---|
| 159 | pocet ... pocet bodu VA-charky |
---|
| 160 | t ... aktualni cas simulace |
---|
| 161 | */ |
---|
| 162 | { |
---|
| 163 | unsigned int i; |
---|
| 164 | double iabc[3], ur[3],ustr[3],ua,ub,uc; |
---|
| 165 | double dtr[3],dd[3]; // ubytky na polovodicich |
---|
| 166 | |
---|
| 167 | // vypocet pily |
---|
| 168 | up=(double)citac/citac_PR*Ucn/2.; |
---|
| 169 | up2=(double)citac2/citac_PR*Ucn/2.; |
---|
| 170 | |
---|
| 171 | ladeni_pila=up; |
---|
| 172 | |
---|
| 173 | iabc[0]=*is; |
---|
| 174 | iabc[1]=(-*is+sqrt(3.)**(is+1))/2.; |
---|
| 175 | iabc[2]=(-*is-sqrt(3.)**(is+1))/2.; |
---|
| 176 | |
---|
| 177 | ur[0]=*u; |
---|
| 178 | ur[1]=(-*u+sqrt(3.)**(u+1))/2.; |
---|
| 179 | ur[2]=(-*u-sqrt(3.)**(u+1))/2.; |
---|
| 180 | |
---|
| 181 | for (i=0;i<3;i++) |
---|
| 182 | { dtr[i]=ubytek(va_char,fabs(iabc[i]),pocet); |
---|
| 183 | dd[i]=dtr[i]*.73; |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | // implementace ubytku a mrtvych casu |
---|
| 187 | for (i=0;i<3;i++) |
---|
| 188 | if (iabc[i]>=0) |
---|
| 189 | if ((ur[i]>up) && (ur[i]>up2)) |
---|
| 190 | ustr[i]=Uc/2-dtr[i]; |
---|
| 191 | else |
---|
| 192 | ustr[i]=-(Uc/2+dd[i]); |
---|
| 193 | else |
---|
| 194 | if ((ur[i]<up) && (ur[i]<up2)) |
---|
| 195 | ustr[i]=-(Uc/2-dtr[i]); |
---|
| 196 | else |
---|
| 197 | ustr[i]=Uc/2+dd[i]; |
---|
| 198 | |
---|
| 199 | // fazova napeti zateze |
---|
| 200 | ua=(2*ustr[0]-ustr[1]-ustr[2])/3; |
---|
| 201 | ub=(2*ustr[1]-ustr[0]-ustr[2])/3; |
---|
| 202 | uc=(2*ustr[2]-ustr[0]-ustr[1])/3; |
---|
| 203 | |
---|
| 204 | // vystupni napeti stridace v (x,y) |
---|
| 205 | *us=(2.*ua-ub-uc)/3.; |
---|
| 206 | *(us+1)=(ub-uc)/sqrt(3.); |
---|
| 207 | |
---|
| 208 | *Iz=(ustr[0]>0)*iabc[0]+(ustr[1]>0)*iabc[1]+(ustr[2]>0)*iabc[2]; |
---|
| 209 | |
---|
| 210 | // posun pily ... inkrement citacu |
---|
| 211 | if ((citac==citac_PR)||(citac==-citac_PR)) smer*=-1; |
---|
| 212 | if ((citac2==citac_PR)||(citac2==-citac_PR)) smer2*=-1; |
---|
| 213 | citac+=smer; |
---|
| 214 | citac2+=smer2; |
---|
| 215 | } |
---|
| 216 | |
---|
| 217 | void pwm_full_new_init(double h, double fc, double DT, int citac_init, int D_smer, int D_smer2) |
---|
| 218 | /* |
---|
| 219 | fc ... spinaci frekvence |
---|
| 220 | h ... krok simulace |
---|
| 221 | DT ... velikost mrtveho casu |
---|
| 222 | citac_init ... pocatecni nastaveni citace |
---|
| 223 | D_smer, D_smer1 ... pocatecni nastaveni smeru citani |
---|
| 224 | */ |
---|
| 225 | { |
---|
| 226 | smer=D_smer; smer2=D_smer2; |
---|
| 227 | citac=citac_init; |
---|
| 228 | citac2=citac_init-(int)(DT/h); |
---|
| 229 | citac_PR=(int)(1./4./fc/h); |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | |
---|
| 233 | void pwm_full_new_init_3h(double h, double fc, double DT, int citac_init, int D_smer, int D_smer2) |
---|
| 234 | /* |
---|
| 235 | fc ... spinaci frekvence |
---|
| 236 | h ... krok simulace |
---|
| 237 | DT ... velikost mrtveho casu |
---|
| 238 | citac_init ... pocatecni nastaveni citace |
---|
| 239 | D_smer, D_smer1 ... pocatecni nastaveni smeru citani |
---|
| 240 | */ |
---|
| 241 | { |
---|
| 242 | smer=D_smer; smer2=D_smer2; |
---|
| 243 | citac=citac_init; |
---|
| 244 | citac2=abs(citac_init-(int)(DT/h)); |
---|
| 245 | citac_PR=(int)(1./2./fc/h); |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | |
---|
| 249 | void pwm_full_new_3h(double *us, double *u, double *Iz, double Ucn, double Uc, double *is, double *va_char, unsigned int pocet, unsigned int mod) |
---|
| 250 | /* |
---|
| 251 | u ... pozadovane napeti ve formatu u={Um, beta} |
---|
| 252 | us ... [usx, usy]...vystupni napeti stridace v (x,y) |
---|
| 253 | Iz ... proud v ss obvodu |
---|
| 254 | Ucn ... jmenovite nap. v ss obvodu |
---|
| 255 | Uc ... skutecne napeti na C |
---|
| 256 | is ... [isx, isy]...proud motorem |
---|
| 257 | va_char ... VA-char vykonovych spinacu |
---|
| 258 | pocet ... pocet bodu VA-charky |
---|
| 259 | t ... aktualni cas simulace |
---|
| 260 | mod ... mod= - sinusova PWM; mod=1 - PWM se 3. harmonickou |
---|
| 261 | */ |
---|
| 262 | { |
---|
| 263 | unsigned int i; |
---|
| 264 | double iabc[3], ur[3],ustr[3],ua,ub,uc; |
---|
| 265 | double dtr[3],dd[3]; // ubytky na polovodicich |
---|
| 266 | double Um, beta; |
---|
| 267 | double U3; // korekce 3. harmonickou |
---|
| 268 | |
---|
| 269 | |
---|
| 270 | Um=*u; |
---|
| 271 | beta=*(u+1); |
---|
| 272 | |
---|
| 273 | // vypocet pily |
---|
| 274 | // up=(double)citac/citac_PR*Ucn/2.; |
---|
| 275 | // up2=(double)citac2/citac_PR*Ucn/2.; |
---|
| 276 | // vypocet pily presne jako v procesoru |
---|
| 277 | up=((double)citac/citac_PR-0.5)*Ucn; |
---|
| 278 | up2=((double)citac2/citac_PR-0.5)*Ucn; |
---|
| 279 | |
---|
| 280 | ladeni_pila=up; |
---|
| 281 | |
---|
| 282 | iabc[0]=*is; |
---|
| 283 | iabc[1]=(-*is+sqrt(3.)**(is+1))/2.; |
---|
| 284 | iabc[2]=(-*is-sqrt(3.)**(is+1))/2.; |
---|
| 285 | |
---|
| 286 | if (mod==0) // sinusova PWM |
---|
| 287 | { |
---|
| 288 | ur[0]=Um*cos(beta); |
---|
| 289 | ur[1]=Um*cos(beta-2./3.*M_PI); |
---|
| 290 | ur[2]=Um*cos(beta+2./3.*M_PI); |
---|
| 291 | } |
---|
| 292 | else // PWM se 3. harmonickou |
---|
| 293 | { |
---|
| 294 | // dle Karla |
---|
| 295 | // U3=0.13*cos(3.*beta); |
---|
| 296 | // moje |
---|
| 297 | U3=0.17*cos(3.*beta); |
---|
| 298 | ur[0]=Um*(cos(beta)-U3); |
---|
| 299 | ur[1]=Um*(cos(beta-2./3.*M_PI)-U3); |
---|
| 300 | ur[2]=Um*(cos(beta+2./3.*M_PI)-U3); |
---|
| 301 | } |
---|
| 302 | |
---|
| 303 | ladeni_ur=ur[0]; |
---|
| 304 | |
---|
| 305 | for (i=0;i<3;i++) |
---|
| 306 | { dtr[i]=ubytek(va_char,fabs(iabc[i]),pocet); |
---|
| 307 | dd[i]=dtr[i]*.73; |
---|
| 308 | } |
---|
| 309 | |
---|
| 310 | // implementace ubytku a mrtvych casu |
---|
| 311 | for (i=0;i<3;i++) |
---|
| 312 | if (iabc[i]>=0) |
---|
| 313 | if ((ur[i]>up) && (ur[i]>up2)) |
---|
| 314 | ustr[i]=Uc/2-dtr[i]; |
---|
| 315 | else |
---|
| 316 | ustr[i]=-(Uc/2+dd[i]); |
---|
| 317 | else |
---|
| 318 | if ((ur[i]<up) && (ur[i]<up2)) |
---|
| 319 | ustr[i]=-(Uc/2-dtr[i]); |
---|
| 320 | else |
---|
| 321 | ustr[i]=Uc/2+dd[i]; |
---|
| 322 | |
---|
| 323 | // fazova napeti zateze |
---|
| 324 | ua=(2.*ustr[0]-ustr[1]-ustr[2])/3.; |
---|
| 325 | ub=(2.*ustr[1]-ustr[0]-ustr[2])/3.; |
---|
| 326 | uc=(2.*ustr[2]-ustr[0]-ustr[1])/3.; |
---|
| 327 | |
---|
| 328 | // vystupni napeti stridace v (x,y) |
---|
| 329 | *us=(2.*ua-ub-uc)/3.; |
---|
| 330 | *(us+1)=(ub-uc)/sqrt(3.); |
---|
| 331 | |
---|
| 332 | *Iz=(ustr[0]>0)*iabc[0]+(ustr[1]>0)*iabc[1]+(ustr[2]>0)*iabc[2]; |
---|
| 333 | |
---|
| 334 | // posun pily ... inkrement citacu |
---|
| 335 | // if ((citac==citac_PR)||(citac==-citac_PR)) smer*=-1; |
---|
| 336 | // if ((citac2==citac_PR)||(citac2==-citac_PR)) smer2*=-1; |
---|
| 337 | if ((citac==citac_PR)||(citac==0)) smer*=-1; |
---|
| 338 | if ((citac2==citac_PR)||(citac2==0)) smer2*=-1; |
---|
| 339 | citac+=smer; |
---|
| 340 | citac2+=smer2; |
---|
| 341 | } |
---|