C51 COMPILER V9.52.0.0   FOCCONTROL                                                        09/21/2018 10:43:21 PAGE 1   


C51 COMPILER V9.52.0.0, COMPILATION OF MODULE FOCCONTROL
OBJECT MODULE PLACED IN .\Output\FocControl.obj
COMPILER INVOKED BY: F:\keil\C51\BIN\C51.EXE ..\User\Source\Function\FocControl.c LARGE OMF2 WARNINGLEVEL(0) BROWSE INCD
                    -IR(..\Library\FU68xx_Hardware_Driver\Include;..\User\Include) DEBUG PRINT(.\Listing\FocControl.lst) OBJECT(.\Output\FocC
                    -ontrol.obj)

line level    source

   1          /**************************** (C) COPYRIGHT 2017 Fortiortech shenzhen *****************************
   2          * File Name          : FocControl.c
   3          * Author             : Fortiortech  Appliction Team
   4          * Version            : V1.0
   5          * Date               : 2017-12-26
   6          * Description        : This file contains all the foc control framework used for Motor Control.
   7          ***************************************************************************************************
   8          * All Rights Reserved
   9          **************************************************************************************************/
  10          
  11          
  12          /* Includes -------------------------------------------------------------------------------------*/
  13          // #include <FocControl.h>
  14          #include <FU68xx_2.h>
  15          #include <Myproject.h>
*** ERROR C129 IN LINE 27 OF ..\User\Include\FocControlFunction.h: missing ';' before 'idata'
  16          
  17          /* Private variables ----------------------------------------------------------------------------*/
  18          MotStaType mcState;
  19          //MotStaTim  MotorStateTime;
  20          MotStaM    McStaSet;
  21          //TailWindSet xdata  mcTailwind;
  22          
  23          MotStaTim  MotorStateTime;
  24          
  25          //uint16 TimeCnt;
  26          
  27          TimeCnt Time;
  28          
  29          mcHall_TypeDef  xdata mcHall;
  30          
  31          char StopFlag = 0;
  32          
  33          /*---------------------------------------------------------------------------*/
  34          /* Name     :   void MC_Control(void)
  35          /* Input    :   NO
  36          /* Output   :   NO
  37          /* Description: 电机状态机函数，包括初始化、预充电、顺风逆风判断、预定位、启
             -动、运行、故障等
  38          /*---------------------------------------------------------------------------*/
  39          void MC_Control(void)
  40          {
  41              switch(mcState)
  42              {
  43                  case mcInit:                                                            // 初始化状态，进入mcCharge状态
  44                                                  
  45                                                          VariablesPreInit();                           // 电机相关变量初始化
  46                                          
  47                                                          //初始化方向
  48                                                          //mcHall.GivenFRStatus          = SetDirection;// ~RollBack;        
  49                                                          
  50                                                  
  51                                                          if(mcCurOffset.OffsetFlag != 3)
C51 COMPILER V9.52.0.0   FOCCONTROL                                                        09/21/2018 10:43:21 PAGE 2   

  52                                                          {
  53                                                                  mcCurOffset.OffsetFlag = 2;
  54                                                          }                                                       
  55                                                                                                                                  
  56          //                                              if(mcHall.LastHallSpeed < Q15(50.0/MOTOR_SPEED_BASE))
  57          //                                              {
  58                                                                  if(mcHall.GivenFRStatus == CW) 
  59                                                                   {
  60                                                                          mcHall.StartAngleOffset   = StartAngleCW;
  61                                                                   }
  62                                                                   else if(mcHall.GivenFRStatus == CCW) 
  63                                                                   {
  64                                                                          mcHall.StartAngleOffset   = StartAngleCCW;
  65                                                                   }
  66                                                                   
  67                                                                          mcState = mcStart;
  68                                                                                                           
  69                                                                          MotorStateTime.InitOneTime    = 0;                              
  70                                                                          MotorStateTime.OpenOneTime    =0;
  71          //                                              }
  72          //                                              else 
  73          //                                              {
  74          //                                                      mcHall.HallDirectStartStatus = 1;
  75          //                                                      
  76          //                                                      Time.mcRunStateCount=0;
  77          //                                                                                                                                                      
  78          //                                                      mcState = mcCharge;
  79          //                                              
  80          //                                                      MotorStateTime.InitOneTime    = 0;
  81          //                                                      
  82          //                                                      MotorStateTime.OpenOneTime    =0;
  83          //                                              }
  84                  break;
  85          
  86                  case mcCharge:                                                                                  // 预充电状态，MCU输出固定频率占空比，预充电结束后�
             -��跳入mcTailWind
  87                      Motor_Charge();
  88                      #if (IPMState == NormalRun)                                                 // 正常按电机状态机运行
  89                                                          //if( mcFocCtrl.State_Count == 0)
  90                                                          {
  91                                                                  mcState = mcStart;
  92                                                                  //MOE = 0;                                                                      // 关闭输出
  93          
  94                                                                  //mcState               = mcTailWind;
  95                                                                  //mcFocCtrl.State_Count = 0;
  96                                                          }
  97                                                          #elif (IPMState == IPMtest)
                                                              {
                                                                      while(1);
                                                              }
                          #endif
 102                  break;
 103          
 104                  case mcTailWind:
 105          //                                      
 106          //            #if (TailWind_Mode == NoTailWind)                                 // 无顺逆风处理的，直接跳入下一个状态
 107          //                mcState                           = mcPosiCheck;
 108          //                McStaSet.SetFlag.PosiCheckSetFlag = 0;
 109          //                mcFocCtrl.mcPosCheckAngle         = 0xffff;           // 角度赋初值
 110          
 111          //            #elif (TailWind_Mode == TailWind)
 112          //                Motor_TailWind();
C51 COMPILER V9.52.0.0   FOCCONTROL                                                        09/21/2018 10:43:21 PAGE 3   

 113          
 114          //            #endif
 115          //        break;
 116          
 117          //        case mcPosiCheck:
 118          //                                      
 119          //            #if (PosCheckEnable==0)                                                           //初始位置检测不使能时初始角度为预定位角�
             -�
 120          //                mcFocCtrl.mcPosCheckAngle = Align_Angle;
 121          //                mcState = mcAlign;
 122          //                mcFocCtrl.State_Count = Align_Time;
 123          
 124          //            #else
 125          //                RPD();
 126          
 127          //            #endif
 128          //        break;
 129          
 130          //        case mcAlign:       // 预定位时间结束后，直接启动; AlignTestMode=1用于初始位�
             -�检测调试用
 131          //            Motor_Align();
 132          
 133          //            #if (AlignTestMode==1)
 134          //                while(1);
 135          
 136          //            #else
 137          //                if(mcFocCtrl.State_Count == 0) mcState = mcStart;
 138          
 139          //            #endif
 140          //        break;
 141          
 142                  case mcStart:                           // 配置电机启动参数，进入mcRun状态。
 143                      Motor_Open();
 144                                          
 145                                                          mcState = mcRun;
 146                  break;
 147          
 148          //                              case mcPllTect:                           // 配置电机启动参数，进入mcRun状态。
 149          //                                              #if (EstimateAlgorithm == PLL)
 150          //                                                              Motor_PllStart();
 151          
 152          //                                              #endif
 153          //                              break;
 154          
 155                  case mcRun:                             // 运行状态，若运行状态的给定变为0，进入
             -mcStop状态。
 156          
 157                  break;
 158          
 159                  case mcStop:
 160                                                                  
 161                                                                  
 162                                                          MotorStop();
 163          
 164          //                                                      FOC_CR1 = 0x00;
 165          //                                                      MOE = 0;
 166          //                                                      /*关闭FOC*/
 167          //                                                      ClrBit(DRV_CR, FOCEN);                          
 168                         
 169                  break;
 170          
 171                  case mcBrake:
C51 COMPILER V9.52.0.0   FOCCONTROL                                                        09/21/2018 10:43:21 PAGE 4   

 172          
 173                  break;
 174          
 175                  case mcFault:
 176                  break;
 177              }
 178          }
 179          
 180          

C51 COMPILATION COMPLETE.  0 WARNING(S),  1 ERROR(S)
