Changeset 326 for applications/pmsm/simulator_zdenek
- Timestamp:
- 04/25/09 22:22:00 (16 years ago)
- Location:
- applications/pmsm/simulator_zdenek
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/pmsm/simulator_zdenek/ekf_example/simul.cpp
r278 r326 22 22 #define CHYBA_POLOHY (0./180.*M_PI) // chyba +/-8 stupnu elektrickych pro senzorovany loziskovy stit 23 23 24 #define MODULACE 1// 0...sinusova PWM, 1...PWM se 3.harmonickou24 #define MODULACE 0 // 0...sinusova PWM, 1...PWM se 3.harmonickou 25 25 #define REZIM_REGULACE 1 // 0...reg. momentu, 1...reg.rychlosti, 2... Isqw=sqrt(Imax^2-Id^2) - max. moment 26 26 -
applications/pmsm/simulator_zdenek/simulator.cpp
r318 r326 7 7 Z. Peroutka 8 8 9 Rev. 16.3.20089 Rev. 25.4.2009 10 10 11 11 */ … … 13 13 #define _USE_MATH_DEFINES 14 14 15 #include <stdio.h> 15 16 #include <math.h> 16 17 #include <stdlib.h> //na linuxu je abs v stdlib … … 77 78 static double ualfa=0., ubeta=0.; 78 79 80 // PWM - improvement of dead-time effect emulation 81 static unsigned int start_pwm=1; 82 static int uact[3]={1,1,1}; 83 static int ureq[3]={1,1,1}; 84 static unsigned int DT_counter[3]={0,0,0}; 85 static unsigned int DT_counter_mez; 86 87 // debug 88 static double debug_pwm; 89 FILE *fdebug; 79 90 80 91 /////////////////// POMOCNE FUNKCE ////////////////////////////////// … … 137 148 citac2=abs(0-(int)(DT/h)); //VS: oprava, je to spravne? 138 149 citac_PR=h_reg_counter_mez; 150 DT_counter_mez = (int)(DT/h); 139 151 140 152 // first interrupt occur after first period match => add 1 to both counter registers … … 142 154 citac2--; 143 155 144 modulace= 1; // THIPWM156 modulace=0; // THIPWM 145 157 if (modulace==1) 146 158 U_modulace=Ucn/sqrt(3.); … … 154 166 155 167 init_regulace(Ls,Fmag,kp,p,h_reg_real); 168 169 // !!d!! 170 // fdebug=fopen("data_debug.txt","w"); 156 171 } 157 172 … … 172 187 // emulation of carrier - timer 173 188 up=((double)citac/citac_PR-0.5)*Ucn; 174 up2=((double)citac2/citac_PR-0.5)*Ucn; 175 189 176 190 iabc[0]=*x; 177 191 iabc[1]=(-*x+sqrt(3.)**(x+1))/2.; … … 196 210 dd[i]=dtr[i]*.73; 197 211 } 198 199 // implementation of voltage drops and dead-times 212 213 // mitigation of the voltage drops 214 /* for (i=0;i<3;i++) 215 { 216 dtr[i]=0.; 217 dd[i]=0.; 218 } 219 /**/ 220 221 // PWM compare emulation 200 222 for (i=0;i<3;i++) 201 if (iabc[i]>=0) 202 if ((ur[i]>up) && (ur[i]>up2)) 203 ustr[i]=Uc/2-dtr[i]; 223 if (ur[i]>up) 224 ureq[i]=1; 204 225 else 205 ustr[i]=-(Uc/2+dd[i]); 226 ureq[i]=-1; 227 228 // First entrace into PWM - actual switching combination is initiated with required switching state 229 if (start_pwm == 1) 230 { 231 for (i=0;i<3;i++) 232 uact[i]=ureq[i]; 233 start_pwm=0; 234 } 235 236 // Dead-time effect has no impact on switching combination, when switching from transistor to diode 237 for (i=0;i<3;i++) 238 { 239 if ((iabc[i]>0.5) && (uact[i]==1)) 240 uact[i]=ureq[i]; 241 242 if ((iabc[i]<-0.5) && (uact[i]==-1)) 243 uact[i]=ureq[i]; 244 } 245 /**/ 246 247 /* for (i=0;i<3;i++) 248 uact[i]=ureq[i];*/ 249 250 // Dead-time effect emulation 251 for (i=0;i<3;i++) 252 if ((uact[i]!=ureq[i]) && (DT_counter[i]<DT_counter_mez)) 253 DT_counter[i]++; 206 254 else 207 if ((ur[i]<up) && (ur[i]<up2)) 208 ustr[i]=-(Uc/2-dtr[i]); 209 else 210 ustr[i]=Uc/2+dd[i]; 211 212 // phase voltages 255 { 256 uact[i]=ureq[i]; 257 DT_counter[i]=0; 258 } 259 260 // inverter phase voltage computation 261 for (i=0;i<3;i++) 262 ustr[i]=uact[i]*Uc/2.; 263 264 // implementation of voltage drops 265 for (i=0;i<3;i++) 266 if (iabc[i]>0) 267 if (uact[i]==1) 268 ustr[i]-=dtr[i]; 269 else 270 ustr[i]-=dd[i]; 271 else 272 if (uact[i]==-1) 273 ustr[i]+=dtr[i]; 274 else 275 ustr[i]+=dd[i]; 276 /**/ 277 // phase voltages 213 278 ua=(2.*ustr[0]-ustr[1]-ustr[2])/3.; 214 279 ub=(2.*ustr[1]-ustr[0]-ustr[2])/3.; … … 218 283 *us=(2.*ua-ub-uc)/3.; 219 284 *(us+1)=(ub-uc)/sqrt(3.); 285 286 // sinusoidal inverter!!!! 287 // *us=ur[0]; 288 // *(us+1)=(ur[1]-ur[2])/sqrt(3.); 220 289 221 290 // emulation of DSP timers … … 253 322 sum_isx_av+=*x; 254 323 sum_isy_av+=*(x+1); 324 325 debug_pwm = ur[0]; // !!!! 326 // !!d!! 327 // fprintf(fdebug,"%f %f %f \n",ustr[0],*us,x[0]); 255 328 } 256 329 … … 349 422 // ualfa=Umk*cos(*(u+1)); 350 423 // ub=Umk*cos(*(u+1)-2./3.*M_PI); 351 KalmanObs[0]=ualfa; // usx424 KalmanObs[0]=ualfa; //debug_pwm; // usx 352 425 //KalmanObs[1]=(ualfa+2.*ub)/sqrt(3.); // usy 353 426 KalmanObs[1]=ubeta; // usy … … 368 441 KalmanObs[9]=isy_av; 369 442 370 vektor_regulace(0,0,Urm_max,Ww,u,Isx,Isy,theta,speed,U_modulace,Uc,Ucn,REZIM_REGULACE); // rezim=1 ... reg. rychlosti, rezim=0 ... reg. momentu443 vektor_regulace(0,0,Urm_max,Ww,u,Isx,Isy,theta,speed,U_modulace,Uc,Ucn,REZIM_REGULACE); // rezim=1 ... reg. rychlosti, rezim=0 ... reg. momentu 371 444 // rezim=2 ... Iqw=sqrt(Imax^2-Idw^2) 372 // emulation of the real sampling of A/D converter 445 446 /* *u=2*15.0; 447 *(u+1)+=2*0.00157;*/ 448 // emulation of the real sampling of A/D converter 373 449 Isx=x[0];Isy=x[1];speed=x[2];theta=x[3]; 374 450 375 451 // include ideal commanded stator voltage 376 Umk=*u*Uc/Ucn; 452 Umk=*u*Uc/Ucn;// !!!! 377 453 ualfa=Umk*cos(*(u+1)); // usx = usa 378 454 ub=Umk*cos(*(u+1)-2./3.*M_PI); … … 393 469 double kor_Uc; 394 470 395 *u=sqrt(ua*ua+ub*ub); 396 *(u+1)=uhel(ua,ub); 397 471 *u=sqrt(ua*ua+ub*ub); 472 *(u+1)=uhel(ua,ub); 473 474 /* *u=5.0; 475 *(u+1)+=0.00157;*/ 398 476 // uprava velikosti vzhledem k Uc!=Ucn 399 477 kor_Uc=Ucn/230.;