⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 idc.lst

📁 PMSM电机的磁场定向控制
💻 LST
📖 第 1 页 / 共 2 页
字号:
  237                 adciu=adc_result[0]&0x03FF;             
  238                 adciu=adciu-LEM_OFFSET;
  239                 adciv=adc_result[1]&0x03FF;             
  240                 adciv=adciv-LEM_OFFSET;
  241                 
  242                 if (adciu>0)
  243                 {
  244                         PhaseCurrentQ15.iu =ScaleQ15(adciu);
  245                 }
  246                 else
  247                 {
  248                         adciu=-adciu;
  249                         PhaseCurrentQ15.iu =ScaleQ15Neg(adciu);
  250                 }
  251                 if (adciv>0)
  252                 {
  253                         PhaseCurrentQ15.iv =ScaleQ15(adciv);
  254                 }
  255                 else
  256                 {
  257                         adciv=-adciv;
  258                         PhaseCurrentQ15.iv =ScaleQ15Neg(adciv);
  259                 }
  260                 PhaseCurrentQ15.iw = -PhaseCurrentQ15.iu - PhaseCurrentQ15.iv;
  261         }
  262         */
  263         
  264         //****************************************************************************
  265         // @Function      void Idc_Iphases (void) 
  266         //
  267         //----------------------------------------------------------------------------
  268         // @Description   This Function calculates the current in all 3 phases about 
  269         //                                the current in the DC-link 
  270         //                                Execution time 2.30us @ 40MHz 
  271         //
  272         //----------------------------------------------------------------------------
  273         // @Returnvalue   None
  274         //
  275         //----------------------------------------------------------------------------
  276         // @Parameters    int Sector
  277         //
  278         //----------------------------------------------------------------------------
  279         // @Date          27.10.2003
  280         //
  281         //****************************************************************************
  282         
  283         void Idc_Iphases (int Sector) 
  284         {
  285  1              int adc0_10b;
  286  1              int adc1_10b;
  287  1              TPhaseCurrent CurrentQ15;
  288  1              
  289  1              adc0_10b=(adc_dclink_res[0]>>2);                // ADDAT2 is a 12 Bit value 
  290  1              adc1_10b=(adc_dclink_res[1]>>2);                // Conversion to a 10 Bit value and mult with 2 
  291  1      
  292  1              switch (Sector)
  293  1              { 
  294  2              case 0:
  295  2                      CurrentQ15.iu = ScaleQ15(adc1_10b);
C166 COMPILER V6.04, IDC                                                                   07/02/2007 15:03:32 PAGE 6   

  296  2                      CurrentQ15.iw = ScaleQ15Neg(adc0_10b);
  297  2                      CurrentQ15.iv = - CurrentQ15.iu - CurrentQ15.iw;
  298  2                      break;  
  299  2              case 1:
  300  2                      CurrentQ15.iv = ScaleQ15(adc1_10b);
  301  2                      CurrentQ15.iw = ScaleQ15Neg(adc0_10b);
  302  2                      CurrentQ15.iu = - CurrentQ15.iv - CurrentQ15.iw;
  303  2                      break;
  304  2              case 2:
  305  2                      CurrentQ15.iv = ScaleQ15(adc1_10b);
  306  2                      CurrentQ15.iu = ScaleQ15Neg(adc0_10b);
  307  2                      CurrentQ15.iw = -CurrentQ15.iv - CurrentQ15.iu;
  308  2                      break;
  309  2              case 3:
  310  2                      CurrentQ15.iw = ScaleQ15(adc1_10b);
  311  2                      CurrentQ15.iu = ScaleQ15Neg(adc0_10b);
  312  2                      CurrentQ15.iv = - CurrentQ15.iu - CurrentQ15.iw;
  313  2                      break;
  314  2              case 4: 
  315  2                      CurrentQ15.iw = ScaleQ15(adc1_10b);
  316  2                      CurrentQ15.iv = ScaleQ15Neg(adc0_10b);
  317  2                      CurrentQ15.iu = - CurrentQ15.iw - CurrentQ15.iv;
  318  2                      break;
  319  2              case 5:
  320  2                      CurrentQ15.iu = ScaleQ15(adc1_10b);
  321  2                      CurrentQ15.iv = ScaleQ15Neg(adc0_10b);
  322  2                      CurrentQ15.iw = -CurrentQ15.iu - CurrentQ15.iv;
  323  2                      break;
  324  2              }
  325  1      
  326  1              // p.u. quantities: I=Imeasured/Iref; Iref=Inominal*sqrt2
  327  1              PhaseCurrentQ15.iu = ((long)CurrentQ15.iu)*((long)SQRT2INV) >> 15;      
*** WARNING C192 IN LINE 327 OF IDC.C: '=': value truncated
  328  1              PhaseCurrentQ15.iv = ((long)CurrentQ15.iv)*((long)SQRT2INV) >> 15;
*** WARNING C192 IN LINE 328 OF IDC.C: '=': value truncated
  329  1              PhaseCurrentQ15.iw = ((long)CurrentQ15.iw)*((long)SQRT2INV) >> 15;
*** WARNING C192 IN LINE 329 OF IDC.C: '=': value truncated
  330  1      
  331  1              //  Show Current in Phases U, V or W (TEST)
  332  1              //      CC1_CC2 = 0xFFFF-(ShowQ15(PhaseCurrentQ15.iu));
  333  1              //      CC1_CC3 = 0xFFFF-(ShowQ15(PhaseCurrentQ15.iv));
  334  1              //      CC1_CC4 = 0xFFFF-(ShowQ15(PhaseCurrentQ15.iw));
  335  1      }
  336         
  337         //****************************************************************************
  338         // @Function      int GetSpeed (int actpos) 
  339         //
  340         //----------------------------------------------------------------------------
  341         // @Description   
  342         //                                Execution time 2.15us @ 40MHz 
  343         // 
  344         //
  345         //----------------------------------------------------------------------------
  346         // @Returnvalue   int speed
  347         //
  348         //----------------------------------------------------------------------------
  349         // @Parameters    int actpos
  350         //
  351         //----------------------------------------------------------------------------
  352         // @Globals               int deltagammaQ15
  353         //
  354         //----------------------------------------------------------------------------
C166 COMPILER V6.04, IDC                                                                   07/02/2007 15:03:32 PAGE 7   

  355         // @Date          18.11.2003
  356         //
  357         //****************************************************************************
  358         int GetSpeed(int actpos)
  359         {
  360  1              int olddeltagamma;
  361  1              
  362  1              olddeltagamma=deltagammaQ15;
  363  1      
  364  1              deltaposition=actpos-oldposition;
  365  1      
  366  1              if (deltaposition>500)  // overflow in left direction?
  367  1              {
  368  2                      deltaposition= deltaposition-1000;
  369  2              }
  370  1              if (deltaposition < (-500))  // overflow in right direction?
  371  1              {
  372  2                      deltaposition= deltaposition+1000;
  373  2              }
  374  1      
  375  1              if (deltaposition>=0)   // direction?
  376  1              {
  377  2                      deltagammaQ15=(deltaposition & 0xFF)<<7;
  378  2              }
  379  1              else 
  380  1              {
  381  2                      deltagammaQ15= 0x8000 + ((deltaposition & 0xFF)<<7);
  382  2              }
  383  1              omega=deltagammaQ15;
  384  1      
  385  1              deltagammaQ15=(((long)omega*(long)ONEOVER4)+((long)olddeltagamma*(long)THREEOVER4))>>15;
*** WARNING C192 IN LINE 385 OF IDC.C: '=': value truncated
  386  1      
  387  1              oldposition=actpos;
  388  1              return deltagammaQ15;
  389  1      }
  390         
  391         
  392         //****************************************************************************
  393         // @Function      void Pmsm_Foc (void) 
  394         //
  395         //----------------------------------------------------------------------------
  396         // @Description   This Function is called upon each Period Match of Timer 12
  397         // 
  398         //
  399         //----------------------------------------------------------------------------
  400         // @Returnvalue   None
  401         //
  402         //----------------------------------------------------------------------------
  403         // @Parameters    None
  404         //
  405         //----------------------------------------------------------------------------
  406         // @Date          27.10.2003
  407         //
  408         //****************************************************************************
  409         void Pmsm_Foc(void)
  410         {
  411  1              int actpos;
  412  1              int position;
  413  1              
  414  1              switch (period_number)
  415  1              {
C166 COMPILER V6.04, IDC                                                                   07/02/2007 15:03:32 PAGE 8   

  416  2              case 1:
  417  2                      Idc_Iphases(Sector);                    // Get 3 phase currents from dc current
  418  2                      position=GetRotorPosition();    // Get new rotor position
  419  2                      if (count >= 22)                                // execute the speed controller each 4.2ms
  420  2                      {
  421  3                              actpos=position;
  422  3                              RotorSpeed=GetSpeed(actpos);
  423  3                              if (dir_flag)
  424  3                              {
  425  4                                      RotorSpeedSet=ScaleQ15(speed);
  426  4                              }
  427  3                              else
  428  3                              {
  429  4                                      RotorSpeedSet=ScaleQ15Neg(speed);
  430  4                              }
  431  3                              PI_Data_Speed.SetValue = RotorSpeedSet; 
  432  3                              PI_Controller(&PI_Data_Speed, RotorSpeed, &QuadratureCurrent);
  433  3                              CC1_CC3 = 0xFFFF-(ShowQ15(RotorSpeed));   //??  
  434  3                              count=0;                                        
  435  3                      }
  436  2                      count++;
  437  2                      if( RotorSpeedSet == 0 )
  438  2                      {
  439  3                              QuadratureCurrent = 0;
  440  3                              DirectCurrent = 0;
  441  3                      }
  442  2                      // Execute the clarke & park transformation
  443  2                      ClarkeParkTrans(&PhaseCurrentQ15, &Gamma ,&RotorCurrentQ15);
  444  2      
  445  2                      period_number=2; 
  446  2              break;
  447  2                      
  448  2              case 2: 
  449  2                      // Execute the two PI controller for the current
  450  2                      PI_Data_Id.SetValue = DirectCurrent;
  451  2                      PI_Data_Iq.SetValue = QuadratureCurrent;
  452  2                      PI_Controller(&PI_Data_Id, RotorCurrentQ15.real,&PIRotorCurrentQ15.real);                                                               // 12,8祍
  453  2                      PI_Controller(&PI_Data_Iq, RotorCurrentQ15.imag,&PIRotorCurrentQ15.imag);                                                               // 12,8祍
  454  2                      // Execute the reverse park transformation
  455  2                      ParkInverse(&PIRotorCurrentQ15, &Gamma, &StatorCurrentQ15);
  456  2                      SVM(&StatorCurrentQ15, &Sector);
  457  2      
  458  2                      period_number=1; 
  459  2                      break;
  460  2      
  461  2              default: period_number=1;
  462  2              }                                                               
  463  1      }


MODULE INFORMATION:   INITIALIZED  UNINITIALIZED
  CODE SIZE        =        1288     --------
  NEAR-CONST SIZE  =        4006     --------
  FAR-CONST SIZE   =    --------     --------
  HUGE-CONST SIZE  =    --------     --------
  XHUGE-CONST SIZE =    --------     --------
  NEAR-DATA SIZE   =         101     --------
  FAR-DATA SIZE    =    --------     --------
  XHUGE-DATA SIZE  =    --------     --------
  IDATA-DATA SIZE  =    --------     --------
  SDATA-DATA SIZE  =    --------     --------
  BDATA-DATA SIZE  =    --------     --------
C166 COMPILER V6.04, IDC                                                                   07/02/2007 15:03:32 PAGE 9   

  HUGE-DATA SIZE   =    --------     --------
  BIT SIZE         =    --------     --------
  INIT'L SIZE      =          36     --------
END OF MODULE INFORMATION.


C166 COMPILATION COMPLETE.  10 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -