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

📄 idc.lst

📁 FOC motor control demo code
💻 LST
📖 第 1 页 / 共 2 页
字号:
C166 COMPILER V4.27, IDC                                                                   12/19/2003 11:51:11 PAGE 1   


C166 COMPILER V4.27, COMPILATION OF MODULE IDC
OBJECT MODULE PLACED IN IDC.OBJ
COMPILER INVOKED BY: C:\Program Files\Keil\C166\BIN\C166.EXE IDC.C MODV2 BROWSE MODV2 DEBUG

 stmt lvl     source

    1         #include "MAIN.H"
    2         #include "DEF.H"
    3         #include "TABLES.H"
    4         #include "TableQ15.h"
    5         
    6         extern void SVM(TComplex *m, char *Sector);
    7         extern void PI_Controller(TPI * PI, int NewInput,int * Result);
    8         
    9         void Clarke_Park_Trans(TPhaseCurrent * In, TComplex * angle, TComplex * Result);
   10         void Park_Rev(TComplex * Frame_dq, TComplex * angle, TComplex  * Result);
   11         void InitPIController(TPI * Data, int Kp, int Ki,int Limit);
   12         
   13         const int T_sample = 0x000D;  /* 400us  Q1.15 */
   14         
   15         char Sector;
   16         int period_number=1;
   17         int count=0;
   18         int QuadratureCurrent = 0x0;
   19         int DirectCurrent  = 0x0;
   20         int RotorSpeedSet = 0x0;
   21         int RotorSpeed;
   22         int oldposition;
   23         int deltaposition;
   24         int deltagammaQ15;      
   25         int omega;
   26         
   27         unsigned int decoval;
   28         unsigned long int decoder_wert;
   29         
   30         TPhaseCurrent PhaseCurrent;
   31         TPhaseCurrent PhaseCurrentQ15;
   32         TComplex Gamma;
   33         TComplex RotorCurrentQ15;
   34         TComplex PIRotorCurrentQ15;
   35         TComplex StatorCurrentQ15;
   36         
   37         TPI PI_Data_Id;         // PI Current Direct
   38         TPI PI_Data_Iq;         // PI Current Quadrature
   39         TPI PI_Data_Speed;      // PI control speed
   40         
   41         //****************************************************************************
   42         // @Function      void InitPIController(TPI * Data, int Kp, int Ki,int Limit)
   43         //
   44         //----------------------------------------------------------------------------
   45         // @Description   Initialation for PI Controller 
   46         //                                      
   47         //----------------------------------------------------------------------------
   48         // @Returnvalue   none
   49         //
   50         //----------------------------------------------------------------------------
   51         // @Parameters    TPI *Data
   52         //                                int Kp 
   53         //                                int Ki 
   54         //                                int Limit 
   55         //
C166 COMPILER V4.27, IDC                                                                   12/19/2003 11:51:11 PAGE 2   

   56         //----------------------------------------------------------------------------
   57         // @Date          01.10.2003
   58         //
   59         //****************************************************************************
   60         void InitPIController(TPI * Data, int Kp, int Ki,int Limit)
   61         {       
   62  1              Data->SetValue = 0;
   63  1              Data->A0 = Kp;
   64  1              Data->A1 = ((((long)Ki << 4)*(long)T_sample) >> 15) - Kp; /* Q16.0 format */
   65  1              Data->Limit = Limit;
   66  1              Data->Integral = 0;
   67  1              Data->Error = 0;
   68  1      }
   69         
   70         //****************************************************************************
   71         // @Function      void InitFOC (void) 
   72         //
   73         //----------------------------------------------------------------------------
   74         // @Description   This Function is makeing settings for PI-Controller 
   75         //
   76         //
   77         //----------------------------------------------------------------------------
   78         // @Returnvalue   None
   79         //
   80         //----------------------------------------------------------------------------
   81         // @Parameters    int Sector
   82         //
   83         //----------------------------------------------------------------------------
   84         // @Date          01.10.2003
   85         //
   86         //****************************************************************************
   87         void InitFOC(void)
   88         {       
   89  1              InitPIController(&PI_Data_Speed, 0x3000, 0x0020, 0x5000);
   90  1              InitPIController(&PI_Data_Id, 0x1200, 0x0080,0x5000);
   91  1              InitPIController(&PI_Data_Iq, 0x1200, 0x0080,0x5000);
   92  1      
   93  1              DirectCurrent   =       0x0000;         // no field-weaking
   94  1              QuadratureCurrent=      0x0000;
   95  1      }
   96         
   97         
   98         
   99         //****************************************************************************
  100         // @Function      void ClarkeParkTrans (TPhaseCurrent * In, TComplex * angle, TComplex * Result) 
  101         //
  102         //----------------------------------------------------------------------------
  103         // @Description   Implemants the Clark and Park Transformation 
  104         //                                (Three Phase Frame -> Rotor Frame Transformation)
  105         //                                Execution time 2.2us @ 40MHz  
  106         //----------------------------------------------------------------------------
  107         // @Returnvalue   Tcomplex *Result (Current in rotating Frame)
  108         //
  109         //----------------------------------------------------------------------------
  110         // @Parameters    TPhaseCurrent *In (Current in 3 Phases frame)
  111         //                                Tcomplex *angle 
  112         //
  113         //----------------------------------------------------------------------------
  114         // @Date          04.10.2003
  115         //
  116         //****************************************************************************
  117         void ClarkeParkTrans(TPhaseCurrent *In, TComplex *angle, TComplex *Result)
C166 COMPILER V4.27, IDC                                                                   12/19/2003 11:51:11 PAGE 3   

  118         {
  119  1              int Ibeta;
  120  1              TComplex IsPark;
  121  1      
  122  1              Ibeta = ((long)In->iv - (long)In->iw)*(long)SQRT3INV >> 15;
  123  1              IsPark.real = ((long)In->iu)*((long)angle->real) + ((long)Ibeta)*((long)angle->imag) >> 15;
  124  1              IsPark.imag = ((long)Ibeta)*((long)angle->real) - ((long)In->iu)*((long)angle->imag) >> 15;
  125  1      
  126  1              * Result =IsPark; 
  127  1       
  128  1      }
  129         
  130         //****************************************************************************
  131         // @Function      void ParkInverse (TComplex *Frame_dq, TComplex *angle, TComplex  *Result) 
  132         //
  133         //----------------------------------------------------------------------------
  134         // @Description   Implemants the reverse Park Transformation 
  135         //                                (Rotor Frame -> Stator Frame Transformation)
  136         //                                Execution time 1.45us @ 40MHz 
  137         //----------------------------------------------------------------------------
  138         // @Returnvalue   Tcomplex *Result (Current in Stator Frame)
  139         //
  140         //----------------------------------------------------------------------------
  141         // @Parameters    Tcomplex *Frame_dq (Current in rotating frame)
  142         //                                Tcomplex *angle 
  143         //
  144         //----------------------------------------------------------------------------
  145         // @Date          04.10.2003
  146         //
  147         //****************************************************************************
  148         void ParkInverse (TComplex *Frame_dq, TComplex *angle, TComplex  *Result)
  149         {
  150  1              TComplex Is_rev_Park;
  151  1      
  152  1              Is_rev_Park.real = ((long)Frame_dq->real)*((long)angle->real) - ((long)Frame_dq->imag)*((long)angle->imag
             -) >> 15;
  153  1              Is_rev_Park.imag = ((long)Frame_dq->real)*((long)angle->imag) + ((long)Frame_dq->imag)*((long)angle->real
             -) >> 15;
  154  1      
  155  1              *Result=Is_rev_Park;
  156  1       
  157  1      }
  158         
  159         //****************************************************************************
  160         // @Function      void GetRotorPosition (void) 
  161         //
  162         //----------------------------------------------------------------------------
  163         // @Description   This Function calculates the actual position of the Rotor of 
  164         //                                the PMSM in degrees   
  165         //                                Execution time 1.8us @ 40MHz  
  166         //
  167         //----------------------------------------------------------------------------
  168         // @Returnvalue     
  169         //
  170         //----------------------------------------------------------------------------
  171         // @Parameters    None
  172         //
  173         //----------------------------------------------------------------------------
  174         // @Globals               
  175         //
  176         //----------------------------------------------------------------------------
  177         // @Date          03.11.2003
C166 COMPILER V4.27, IDC                                                                   12/19/2003 11:51:11 PAGE 4   

  178         //
  179         //****************************************************************************
  180         int GetRotorPosition(void)
  181         {
  182  1              int decoval;
  183  1      
  184  1              decoval=GPT12E_T3;              
  185  1              if(!(decoval>=0&&decoval<=2000))                
  186  1                      decoval=decoval-0xF830;                 
  187  1      
  188  1              decoval=decoval%1000;
  189  1              decoval=decoval+ENC_OFFSET;     
  190  1              
  191  1              if (decoval>1000)
  192  1              {
  193  2                      decoval=decoval-1000;
  194  2              }
  195  1      
  196  1              // Sinus and Cosine Function of Rotor Angle
  197  1              // for Park Transformation
  198  1              Gamma.imag=sin_table[decoval];
  199  1              Gamma.real=cos_table[decoval];
  200  1                      
  201  1              return decoval;
  202  1      }
  203         
  204         //****************************************************************************
  205         // @Function      void Iphases (void) 
  206         //
  207         //----------------------------------------------------------------------------
  208         // @Description   Measure the phase currents with LEMs in phases 
  209         //                                FUNCTION NOT USED WHEN MEASUREMENT IN DC LINK
  210         //
  211         //----------------------------------------------------------------------------
  212         // @Returnvalue   None
  213         //
  214         //----------------------------------------------------------------------------
  215         // @Parameters    None
  216         //
  217         //----------------------------------------------------------------------------
  218         // @Date          04.11.2003
  219         //
  220         //****************************************************************************
  221         /*
  222         void Iphases (void) 
  223         {
  224                 int adciu;
  225                 int adciv;
  226         
  227                 // Set the ADC and start the conversion
  228                 PECC0          =  0x0202;       // load PECC0 control register
  229                 DSTP0=_sof_(&adc_result[0]);
  230                 ADC_CON_ADST   =  1;            // set start bit for phases measurement
  231         
  232                 adciu=adc_result[0]&0x03FF;             
  233                 adciu=adciu-LEM_OFFSET;
  234                 adciv=adc_result[1]&0x03FF;             
  235                 adciv=adciv-LEM_OFFSET;
  236                 

⌨️ 快捷键说明

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