|
void initVar() { Idsref=IdsrefBase; /* 1.4 A */ } |
double IdsrefBase=1.4; |
|
|
#define inputI_E( i1, i2, E1, E2) \ { \ i1 = -0.03 + 20.0*ds1102_ad(1); \ i2 = 0.002 + 20.0*ds1102_ad(2); \ E1 = 20.0*ds1102_ad(3); \ E2 = 200.0*ds1102_ad(4); \ } |
#define C22t( Xa, Xb, Xalpha, Xbeta ) \ { \ Xalpha=Xa; \ Xbeta=0.5773502692*Xa+1.154700538*Xb; \ } #define CalcPark( th, sin_th, cos_th) \ { \ sin_th=sin(th); \ cos_th=cos(th); \ } #define ParkInv( Xalpha, Xbeta, sin_th, cos_th, Xd, Xq) \ { \ Xd=Xalpha*cos_th+Xbeta*sin_th; \ Xq=Xbeta*cos_th-Xalpha*sin_th; \ } |
/* calcul de thetas, Wsl, Ws et du flux */ #define Calc_thetas \ { \ Wsl= Iqsref / Tr / Idsref; \ Phidr+=DT*( M*Ids-Phidr)/ Tr; \ \ /* Commune */ \ if (VectorControlFlag==1) Ws=P*Wm+Wsl; \ if (VectorControlFlag!=1) Ws=Wsref; \ th+=DT*Ws; /* 200 us */ \ if ( th > PI) th-=TWOPI; \ if ( th < -PI) th+=TWOPI; \ } |
#define inputWm \ { \ /* read incremental encoder counter */ \ inc_k = read_inc( 1); \ \ /* calculate mechanical angle rd _ avec inversion _*/ \ mpos=POStoRD*(float)inc_k; \ \ /* calculate mechanical speed rd/s */ \ FIR_Wm[0]=POStoRD_S*(float)( inc_k - inc_kOld ); \ inc_kOld = inc_k; \ \ WmMesure=0.2*(FIR_Wm[0]+FIR_Wm[1]+FIR_Wm[2]+FIR_Wm[3]+FIR_Wm[4]); \ FIR_Wm[4]=FIR_Wm[3]; \ FIR_Wm[3]=FIR_Wm[2]; \ FIR_Wm[2]=FIR_Wm[1]; \ FIR_Wm[1]=FIR_Wm[0]; \ } |
VqsrefMax=sqrt(E_2*E_2-Vdsref*Vdsref); |
void BoucleIq() { e=Iqsref-Iqs; Vqsref = Kpq*e + xeq; if ( fabs(Vqsref)<=VqsrefMax ) xeq += Kiq*e; Vqsref+=sigma*Ls*Ws*Ids+M/Lr*Ws*Phidr; /* decouplage */ /* limiteur de tension */ if ( Vqsref>VqsrefMax) Vqsref=VqsrefMax; if ( Vqsref<-VqsrefMax) Vqsref=-VqsrefMax; } |
if ( fabs(Vqsref)<=VqsrefMax ) xeq += Kiq*e; |
Vqsref+=sigma*Ls*Ws*Ids+M/Lr*Ws*Phidr; /* decouplage */ |
Vdsref-=sigma*Ls*Ws*Iqs; /* decouplage */ |
#define Park( Xd, Xq, sin_th, cos_th, Xalpha, Xbeta) \ { \ Xalpha=Xd*cos_th-Xq*sin_th; \ Xbeta=Xd*sin_th+Xq*cos_th; \ } #define C32( Xalpha, Xbeta, Xa, Xb, Xc ) \ { \ Xa=Xalpha; \ Xb=0.8660254038*Xbeta-0.5*Xalpha; \ Xc=-0.5*Xalpha-0.8660254038*Xbeta; \ } |
tau=TMLI/4*(1-Vasref/Es2); if ( tm<tau || tm>TMLI-tau ) VaMLI=-Es2; else VaMLI=Es2; |
|
void BouclePosition() { /* regul P classique */ Wmref= KpP * ( mposref-mpos); /* limiteur de vitesse */ if ( Wmref>WmrefMax) Wmref=WmrefMax; if ( Wmref<-WmrefMax) Wmref=-WmrefMax; } |
/* attention regul sur la vitesse Wm ! */ void BoucleVitesse() { /* La vitesse a ete calculee juste avant ds une macro */ /* regul IP anti Windup */ xeW += KiW / KpW*( Wmref - Wm - KTiW*(OldSortie - OldSortieSat) ); /* limite le non sature pour eviter tt pb de debordement !!! */ if ( xeW>xeWMax) xeW=xeWMax; if ( xeW<-xeWMax) xeW=-xeWMax; OldSortie = KpW*( xeW -Wm); OldSortieSat=OldSortie; if ( OldSortieSat>IqsrefMax) OldSortieSat=IqsrefMax; if ( OldSortieSat<-IqsrefMax) OldSortieSat=-IqsrefMax; Iqsref=OldSortieSat; /* limiteur de courant */ /* regul IP classique */ /* Iqsref=KpW*(xeW-Wm); if ( fabs(Iqsref)<=IqsrefMax ) xeW+=KiW/KpW*(Wmref-Wm); if ( Iqsref>IqsrefMax) Iqsref=IqsrefMax; if ( Iqsref<-IqsrefMax) Iqsref=-IqsrefMax; */ } |
|
ds1104_dac_write( 2, -0.5); |
/* write PWM Duty cycle to slave DSP and test for error */ if (InhibFlag) { /* met les tensions à 0 */ duty1=0.5; duty2=0.5; duty3=0.5; } else { duty1=Vas*BY_2E_2+0.5; duty2=Vbs*BY_2E_2+0.5; duty3=Vcs*BY_2E_2+0.5; } ds1104_slave_dsp_pwm3_duty_write(task_id, index, duty1, duty2, duty3); |
/****************************************************************************** * MODULE * TMS320F240 slave DSP user module template. * FILE * usrdsp.h * RELATED FILES * usrdsp.c * * DESCRIPTION * This module may contain user defined functions for the TMS320F240 slave DSP. * Each additional function must be registered in the fw240.c module by * using the function slvdsp_usrfct_install(). * AUTHOR(S) * M. Heier, V. Lang (dSPACE) * & L. BAGHLI (GREEN-UHP) ******************************************************************************/ #ifndef __USRDSP_H__ #define __USRDSP_H__ /*------------------- user firmware revision numbers ------------------------*/ #define USER_MAJOR_RELEASE 0 #define USER_MINOR_RELEASE 1 #define USER_SUBMINOR_RELEASE 2 #ifndef _DS1104 #include <slvdsp.h> #endif /* !_DS1104 */ /****************************************************************************** * constants and defines ******************************************************************************/ /*------------- opcodes for user functions (0x0300 - 0x03FF -----------------*/ #define SLVDSP_USRFCT_SIMPLEPWMSYNCH 0x301 #define SLVDSP_USRFCT_SIMPLEPWMUPDATE 0x302 /* parameters for user defined functions */ #define SLVDSP_USRFCT_SIMPLEPWMUPDATE_PCNT 3 /* parameter count */ #define SLVDSP_USRFCT_SIMPLEPWMUPDATE_DUTY1_LOC 0 /* phase 1 SCMPR1 duty cycle */ #define SLVDSP_USRFCT_SIMPLEPWMUPDATE_DUTY2_LOC 1 /* phase 2 SCMPR2 duty cycle */ #define SLVDSP_USRFCT_SIMPLEPWMUPDATE_DUTY3_LOC 2 /* phase 3 SCMPR3 duty cycle */ #define SLVDSP_USRFCT_SIMPLEPWMUPDATE_DINCNT 0 /* no input data */ #define SLVDSP_USRFCT_SIMPLEPWMUPDATE_DOUTCNT 3 /* output data count */ #ifndef _DS1104 /****************************************************************************** * global objects and variables ******************************************************************************/ #define slvdsp_usr_firmware_rev_set() { \ user_major_release = USER_MAJOR_RELEASE; \ user_minor_release = USER_MINOR_RELEASE; \ user_subminor_release = USER_SUBMINOR_RELEASE; } /****************************************************************************** * function prototypes ******************************************************************************/ void slvdsp_usrfct_simplePWMsynch(UInt16 index); void slvdsp_usrfct_simplePWMupdate(UInt16 index); #endif /* !_DS1104 */ #endif /* __USRDSP_H__ */ |
/****************************************************************************** * MODULE * Common TMS320F240 slave DSP user module. * FILE * usrdsp.c * RELATED FILES * usrdsp.h, reg240.h, fw240.c * * DESCRIPTION * This module may contain user defined functions for the TMS320F240 slave DSP. * Each additional function must be registered in the fw240.c module by * using the function slvdsp_usrfct_install(). * AUTHOR(S) * M. Heier (dSPACE) * & L. BAGHLI (GREEN-UHP) ******************************************************************************/ #include <usrdsp.h> /* related header file */ #include <dstypes.h> /* data type definitions */ #include <dsscom.h> /* general master-slave communication functions */ #include <slvdsp.h> /* slave DSP functions */ #include <reg240.h> /* TMS320C240 register defines */ /****************************************************************************** * user functions ******************************************************************************/ /****************************************************************************** * FUNCTION * Utilise le meme timer (1) pour la Simple que pour la full PWM * * SYNTAX * slvdsp_usrfct_simplePWMsynch(UInt16 index) * * DESCRIPTION * * PARAMETERS * aucun ******************************************************************************/ void slvdsp_usrfct_simplePWMsynch(UInt16 index) { // pour voir si ça marche, faudrait sortir un IOPA0 à 5V puis 0V... *COMCON=0x0307; // FIRST enable PWM operation // Reload Full Compare when T1CNT=0 // Disable Space Vector // Reload Full Compare Action when T1CNT=0 // Enable Full Compare Outputs // Enable Simple Compare Outputs // GPTimer 1 for simple PWM // Reload SIMPLE Compare Action when T1CNT=0 // Full Compare Units in PWM Mode *COMCON=0x8307; // THEN enable Compare operation } /****************************************************************************** * FUNCTION * Mise à jour des SCMPRx de la Simple PWM (transmission * des 3 SCMPRX à la fois) * * SYNTAX * slvdsp_usrfct_simplePWMupdate(UInt16 index) * * DESCRIPTION * * PARAMETERS * index command table index * parms parametres contenant les SCMPRx values ******************************************************************************/ void slvdsp_usrfct_simplePWMupdate(UInt16 index) { UInt16 parms[SLVDSP_USRFCT_SIMPLEPWMUPDATE_PCNT]; slvdsp_usrfct_comm_read(SLVDSP_USRFCT_SIMPLEPWMUPDATE_PCNT, parms); /* read parameters from communication buffer */ *SCMPR1 = parms[SLVDSP_USRFCT_SIMPLEPWMUPDATE_DUTY1_LOC]; /* update PWM1 compare register */ *SCMPR2 = parms[SLVDSP_USRFCT_SIMPLEPWMUPDATE_DUTY2_LOC]; /* update PWM2 compare register */ *SCMPR3 = parms[SLVDSP_USRFCT_SIMPLEPWMUPDATE_DUTY3_LOC]; /* update PWM3 compare register */ } |
/* write PWM Duty cycle to slave DSP and test for error */ if (InhibFlag) { // met les tensions à 0 duty1=0.5; duty2=0.5; duty3=0.5; dduty1=0.5; // double étoile dduty2=0.5; dduty3=0.5; } else { duty1=Vas*BY_2E_2+0.5; duty2=Vbs*BY_2E_2+0.5; duty3=Vcs*BY_2E_2+0.5; // double étoile dduty1=dVas*BY_2E_2+0.5; dduty2=dVbs*BY_2E_2+0.5; dduty3=dVcs*BY_2E_2+0.5; } ds1104_slave_dsp_pwm3_duty_write(task_id, index, duty1, duty2, duty3); scmpr_duties[SLVDSP_USRFCT_SIMPLEPWMUPDATE_DUTY1_LOC]=(1-dduty1)*1000; scmpr_duties[SLVDSP_USRFCT_SIMPLEPWMUPDATE_DUTY2_LOC]=(1-dduty2)*1000; scmpr_duties[SLVDSP_USRFCT_SIMPLEPWMUPDATE_DUTY3_LOC]=(1-dduty3)*1000; ds1104_slave_dsp_usrfct_execute(task_id, SLVDSP_USRFCT_SIMPLEPWMUPDATE, SLVDSP_USRFCT_SIMPLEPWMUPDATE_PCNT, scmpr_duties); |
Last update : 20/01/2007