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

📄 idc.lst

📁 这是英飞凌公司基于xc166开发的foc方式控制的pmsm电机例程 非常有参加价值
💻 LST
📖 第 1 页 / 共 2 页
字号:
  237                 if (adciu>0)
  238                 {
  239                         PhaseCurrentQ15.iu =ScaleQ15(adciu);
C166 COMPILER V4.27, IDC                                                                   12/19/2003 11:51:11 PAGE 5   

  240                 }
  241                 else
  242                 {
  243                         adciu=-adciu;
  244                         PhaseCurrentQ15.iu =ScaleQ15Neg(adciu);
  245                 }
  246                 if (adciv>0)
  247                 {
  248                         PhaseCurrentQ15.iv =ScaleQ15(adciv);
  249                 }
  250                 else
  251                 {
  252                         adciv=-adciv;
  253                         PhaseCurrentQ15.iv =ScaleQ15Neg(adciv);
  254                 }
  255                 PhaseCurrentQ15.iw = -PhaseCurrentQ15.iu - PhaseCurrentQ15.iv;
  256         }
  257         */
  258         
  259         //****************************************************************************
  260         // @Function      void Idc_Iphases (void) 
  261         //
  262         //----------------------------------------------------------------------------
  263         // @Description   This Function calculates the current in all 3 phases about 
  264         //                                the current in the DC-link 
  265         //                                Execution time 2.30us @ 40MHz 
  266         //
  267         //----------------------------------------------------------------------------
  268         // @Returnvalue   None
  269         //
  270         //----------------------------------------------------------------------------
  271         // @Parameters    int Sector
  272         //
  273         //----------------------------------------------------------------------------
  274         // @Date          27.10.2003
  275         //
  276         //****************************************************************************
  277         
  278         void Idc_Iphases (int Sector) 
  279         {
  280  1              int adc0_10b;
  281  1              int adc1_10b;
  282  1              TPhaseCurrent CurrentQ15;
  283  1              
  284  1              adc0_10b=(adc_dclink_res[0]>>2);                // ADDAT2 is a 12 Bit value 
  285  1              adc1_10b=(adc_dclink_res[1]>>2);                // Conversion to a 10 Bit value and mult with 2 
  286  1      
  287  1              switch (Sector)
  288  1              { 
  289  2              case 0:
  290  2                      CurrentQ15.iu = ScaleQ15(adc1_10b);
  291  2                      CurrentQ15.iw = ScaleQ15Neg(adc0_10b);
  292  2                      CurrentQ15.iv = - CurrentQ15.iu - CurrentQ15.iw;
  293  2                      break;  
  294  2              case 1:
  295  2                      CurrentQ15.iv = ScaleQ15(adc1_10b);
  296  2                      CurrentQ15.iw = ScaleQ15Neg(adc0_10b);
  297  2                      CurrentQ15.iu = - CurrentQ15.iv - CurrentQ15.iw;
  298  2                      break;
  299  2              case 2:
  300  2                      CurrentQ15.iv = ScaleQ15(adc1_10b);
  301  2                      CurrentQ15.iu = ScaleQ15Neg(adc0_10b);
C166 COMPILER V4.27, IDC                                                                   12/19/2003 11:51:11 PAGE 6   

  302  2                      CurrentQ15.iw = -CurrentQ15.iv - CurrentQ15.iu;
  303  2                      break;
  304  2              case 3:
  305  2                      CurrentQ15.iw = ScaleQ15(adc1_10b);
  306  2                      CurrentQ15.iu = ScaleQ15Neg(adc0_10b);
  307  2                      CurrentQ15.iv = - CurrentQ15.iu - CurrentQ15.iw;
  308  2                      break;
  309  2              case 4: 
  310  2                      CurrentQ15.iw = ScaleQ15(adc1_10b);
  311  2                      CurrentQ15.iv = ScaleQ15Neg(adc0_10b);
  312  2                      CurrentQ15.iu = - CurrentQ15.iw - CurrentQ15.iv;
  313  2                      break;
  314  2              case 5:
  315  2                      CurrentQ15.iu = ScaleQ15(adc1_10b);
  316  2                      CurrentQ15.iv = ScaleQ15Neg(adc0_10b);
  317  2                      CurrentQ15.iw = -CurrentQ15.iu - CurrentQ15.iv;
  318  2                      break;
  319  2              }
  320  1      
  321  1              // p.u. quantities: I=Imeasured/Iref; Iref=Inominal*sqrt2
  322  1              PhaseCurrentQ15.iu = ((long)CurrentQ15.iu)*((long)SQRT2INV) >> 15;      
  323  1              PhaseCurrentQ15.iv = ((long)CurrentQ15.iv)*((long)SQRT2INV) >> 15;
  324  1              PhaseCurrentQ15.iw = ((long)CurrentQ15.iw)*((long)SQRT2INV) >> 15;
  325  1      
  326  1              //  Show Current in Phases U, V or W (TEST)
  327  1              //      CC1_CC2 = 0xFFFF-(ShowQ15(PhaseCurrentQ15.iu));
  328  1              //      CC1_CC3 = 0xFFFF-(ShowQ15(PhaseCurrentQ15.iv));
  329  1              //      CC1_CC4 = 0xFFFF-(ShowQ15(PhaseCurrentQ15.iw));
  330  1      }
  331         
  332         //****************************************************************************
  333         // @Function      int GetSpeed (int actpos) 
  334         //
  335         //----------------------------------------------------------------------------
  336         // @Description   
  337         //                                Execution time 2.15us @ 40MHz 
  338         // 
  339         //
  340         //----------------------------------------------------------------------------
  341         // @Returnvalue   int speed
  342         //
  343         //----------------------------------------------------------------------------
  344         // @Parameters    int actpos
  345         //
  346         //----------------------------------------------------------------------------
  347         // @Globals               int deltagammaQ15
  348         //
  349         //----------------------------------------------------------------------------
  350         // @Date          18.11.2003
  351         //
  352         //****************************************************************************
  353         int GetSpeed(int actpos)
  354         {
  355  1              int olddeltagamma;
  356  1              
  357  1              olddeltagamma=deltagammaQ15;
  358  1      
  359  1              deltaposition=actpos-oldposition;
  360  1      
  361  1              if (deltaposition>500)  // overflow in left direction?
  362  1              {
  363  2                      deltaposition= deltaposition-1000;
C166 COMPILER V4.27, IDC                                                                   12/19/2003 11:51:11 PAGE 7   

  364  2              }
  365  1              if (deltaposition < (-500))  // overflow in right direction?
  366  1              {
  367  2                      deltaposition= deltaposition+1000;
  368  2              }
  369  1      
  370  1              if (deltaposition>=0)   // direction?
  371  1              {
  372  2                      deltagammaQ15=(deltaposition & 0xFF)<<7;
  373  2              }
  374  1              else 
  375  1              {
  376  2                      deltagammaQ15= 0x8000 + ((deltaposition & 0xFF)<<7);
  377  2              }
  378  1              omega=deltagammaQ15;
  379  1      
  380  1              deltagammaQ15=(((long)omega*(long)ONEOVER4)+((long)olddeltagamma*(long)THREEOVER4))>>15;
  381  1      
  382  1              oldposition=actpos;
  383  1              return deltagammaQ15;
  384  1      }
  385         
  386         
  387         //****************************************************************************
  388         // @Function      void Pmsm_Foc (void) 
  389         //
  390         //----------------------------------------------------------------------------
  391         // @Description   This Function is called upon each Period Match of Timer 12
  392         // 
  393         //
  394         //----------------------------------------------------------------------------
  395         // @Returnvalue   None
  396         //
  397         //----------------------------------------------------------------------------
  398         // @Parameters    None
  399         //
  400         //----------------------------------------------------------------------------
  401         // @Date          27.10.2003
  402         //
  403         //****************************************************************************
  404         void Pmsm_Foc(void)
  405         {
  406  1              int actpos;
  407  1              int position;
  408  1              
  409  1              switch (period_number)
  410  1              {
  411  2              case 1:
  412  2                      Idc_Iphases(Sector);                    // Get 3 phase currents from dc current
  413  2                      position=GetRotorPosition();    // Get new rotor position
  414  2                      if (count >= 22)                                // execute the speed controller each 4.2ms
  415  2                      {
  416  3                              actpos=position;
  417  3                              RotorSpeed=GetSpeed(actpos);
  418  3                              if (dir_flag)
  419  3                              {
  420  4                                      RotorSpeedSet=ScaleQ15(speed);
  421  4                              }
  422  3                              else
  423  3                              {
  424  4                                      RotorSpeedSet=ScaleQ15Neg(speed);
  425  4                              }
C166 COMPILER V4.27, IDC                                                                   12/19/2003 11:51:11 PAGE 8   

  426  3                              PI_Data_Speed.SetValue = RotorSpeedSet; 
  427  3                              PI_Controller(&PI_Data_Speed, RotorSpeed, &QuadratureCurrent);
  428  3                              CC1_CC3 = 0xFFFF-(ShowQ15(RotorSpeed)); 
  429  3                              count=0;                                        
  430  3                      }
  431  2                      count++;
  432  2                      if( RotorSpeedSet == 0 )
  433  2                      {
  434  3                              QuadratureCurrent = 0;
  435  3                              DirectCurrent = 0;
  436  3                      }
  437  2                      // Execute the clarke & park transformation
  438  2                      ClarkeParkTrans(&PhaseCurrentQ15, &Gamma ,&RotorCurrentQ15);
  439  2      
  440  2                      period_number=2; 
  441  2              break;
  442  2                      
  443  2              case 2: 
  444  2                      // Execute the two PI controller for the current
  445  2                      PI_Data_Id.SetValue = DirectCurrent;
  446  2                      PI_Data_Iq.SetValue = QuadratureCurrent;
  447  2                      PI_Controller(&PI_Data_Id, RotorCurrentQ15.real,&PIRotorCurrentQ15.real);                                                               // 12,8祍
  448  2                      PI_Controller(&PI_Data_Iq, RotorCurrentQ15.imag,&PIRotorCurrentQ15.imag);                                                               // 12,8祍
  449  2                      // Execute the reverse park transformation
  450  2                      ParkInverse(&PIRotorCurrentQ15, &Gamma, &StatorCurrentQ15);
  451  2                      SVM(&StatorCurrentQ15, &Sector);
  452  2      
  453  2                      period_number=1; 
  454  2                      break;
  455  2      
  456  2              default: period_number=1;
  457  2              }                                                               
  458  1      }


MODULE INFORMATION:   INITIALIZED  UNINITIALIZED
  CODE SIZE        =        1282     --------
  NEAR-CONST SIZE  =        4006     --------
  FAR-CONST SIZE   =    --------     --------
  HUGE-CONST SIZE  =    --------     --------
  XHUGE-CONST SIZE =    --------     --------
  NEAR-DATA SIZE   =          97     --------
  FAR-DATA SIZE    =    --------     --------
  XHUGE-DATA SIZE  =    --------     --------
  IDATA-DATA SIZE  =    --------     --------
  SDATA-DATA SIZE  =    --------     --------
  BDATA-DATA SIZE  =    --------     --------
  HUGE-DATA SIZE   =    --------     --------
  BIT SIZE         =    --------     --------
  INIT'L SIZE      =          30     --------
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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