C51 COMPILER V9.52.0.0   FOCCONTROL                                                        09/26/2018 08:26:32 PAGE 1   


C51 COMPILER V9.52.0.0, COMPILATION OF MODULE FOCCONTROL
OBJECT MODULE PLACED IN .\Output\FocControl.obj
COMPILER INVOKED BY: C:\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             : Vina Peng,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>
  16          
  17          /* Private variables ----------------------------------------------------------------------------*/
  18          MotStaType mcState;
*** ERROR C129 IN LINE 18 OF ..\User\Source\Function\FocControl.c: missing ';' before 'mcState'
  19          //MotStaTim  MotorStateTime;
  20          MotStaM    McStaSet;
  21          //TailWindSet xdata  mcTailwind;
  22          TimeCnt         Time;
  23          
  24          /*---------------------------------------------------------------------------*/
  25          /* Name     :   void MC_Control(void)
  26          /* Input    :   NO
  27          /* Output   :   NO
  28          /* Description: 电机状态机函数，包括初始化、预充电、顺风逆风判断、预定位、启
             -动、运行、故障等
  29          /*---------------------------------------------------------------------------*/
  30          void MC_Control(void)
  31          {
  32              switch(mcState)
  33              {
  34                  case mcReady:    // 关闭输出,上电会对电流进行采集校准,当采样校准结束标志�
             -��1且启动指令置1后，才跳转到mcInit
  35                      Motor_Ready();
  36                      if((mcCurOffset.OffsetFlag == 1) && (mcSpeedRamp.FlagONOFF == 1)) mcState = mcInit;
  37                  break;
  38          
  39                  case mcInit:                                                            // 初始化状态，进入mcCharge状态
  40                      Motor_Init();
  41                                  mcState         = mcCharge;
  42                      mcFocCtrl.State_Count = 0;
  43          //            mcState               =  mcCharge;                                        // 跳入mcCharge状态
  44          //            mcFocCtrl.State_Count = Charge_Time;
  45                  break;
  46          
  47                  case mcCharge:                                                                                  // 预充电状态，MCU输出固定频率占空比，预充电结束后�
             -��跳入mcTailWind
  48                      Motor_Charge();
  49                      #if (IPMState == NormalRun)                                                 // 正常按电机状态机运行
C51 COMPILER V9.52.0.0   FOCCONTROL                                                        09/26/2018 08:26:32 PAGE 2   

  50                                  if( mcFocCtrl.State_Count == 0)
  51                                  {
  52                                          //顺逆风检测
  53                                          if(mcFocCtrl.mcChargeStep == 0)
  54                                          {
  55                                                  MOE = 0;                                                                                // 关闭输出
  56                                                  mcState         = mcTailWind;
  57                              mcFocCtrl.State_Count = 40;
  58                                          }
  59                                          //初始位置检测启动
  60                                          else if(mcFocCtrl.mcChargeStep == 1)
  61                                          {
  62                                                  MOE = 0;
  63                                                  mcState = mcPosiCheck;
  64                                          }
  65                                  }
  66          
  67                      #endif
  68                  break;
  69          
  70                  case mcTailWind:
  71                      #if (TailWind_Mode == NoTailWind)                                   // 无顺逆风处理的，直接跳入下一个状态
                              mcState                           = mcPosiCheck;
                              McStaSet.SetFlag.PosiCheckSetFlag = 0;
                              mcFocCtrl.mcPosCheckAngle         = 0xffff;             // 角度赋初值
              
                          #elif (TailWind_Mode == TailWind)
  77                          Motor_TailWind();
  78          
  79                      #endif
  80                  break;
  81          
  82                  case mcPosiCheck:
  83                      #if (PosCheckEnable==0)                                                             //初始位置检测不使能时初始角度为预定位角度
                              mcFocCtrl.mcPosCheckAngle = Align_Angle;
                              mcState = mcAlign;
                              mcFocCtrl.State_Count = Align_Time;
              
                          #else
  89                          RPD();
  90          
  91                      #endif
  92                  break;
  93          
  94                  case mcAlign:       // 预定位时间结束后，直接启动; AlignTestMode=1用于初始位置�
             -��测调试用
  95                      Motor_Align();
  96          
  97                      #if (AlignTestMode==1)
  98                          while(1);
  99          
 100                      #else
                              if(mcFocCtrl.State_Count == 0) mcState = mcStart;
              
                          #endif
 104                  break;
 105          
 106                  case mcStart:                           // 配置电机启动参数，进入mcRun状态。
 107                      Motor_Open();
 108                  break;
 109          
 110                  case mcPllTect:                           // 配置电机启动参数，进入mcRun状态。
C51 COMPILER V9.52.0.0   FOCCONTROL                                                        09/26/2018 08:26:32 PAGE 3   

 111                      #if (EstimateAlgorithm == PLL)
                              Motor_PllStart();
              
                          #endif
 115                  break;
 116          
 117                  case mcRun:                             // 运行状态，若运行状态的给定变为0，进入
             -mcStop状态。
 118                      if(mcSpeedRamp.TargetValue == 0)
 119                      {
 120                          mcState               = mcStop;
 121                          mcFocCtrl.State_Count = 6000;
 122                          GP07 = 0;
 123          //                FOC_IQREF             = 0;
 124                      }
 125                  break;
 126          
 127                  case mcStop:
 128                      if((mcFocCtrl.SpeedFlt<Motor_Min_Speed)||(mcFocCtrl.State_Count==0))
 129                      {
 130                          #if (StopBrakeFlag == 0)
 131                              mcState = mcReady;
 132                              MOE=0;
 133                              FOC_CR1 = 0x00;
 134                              /*关闭FOC*/
 135                              ClrBit(DRV_CR, FOCEN);
 136          
 137                          #else
                                  if(mcFocCtrl.SpeedFlt < Motor_Stop_Speed)
                                  {
                                      MOE = 0;
                                      FOC_CR1 = 0x00;
                                      ClrBit(DRV_CR, FOCEN);
                                      DRV_DR  = DRV_ARR+1;
                                      DRV_CMR &= 0xFFC0;
                                      DRV_CMR |= 0x015;            // 三相下桥臂通，刹车
                                      ClrBit(DRV_CR, OCS);         // OCS = 0, DRV_COMR;OCS = 1, FOC/SVPWM/SPWM
                                      MOE = 1;
                                      mcState               = mcBrake;
                                      mcFocCtrl.State_Count = StopWaitTime;
                                  }
              
                              #endif
 153                      }
 154                      else if(mcSpeedRamp.TargetValue > 0)
 155                      {
 156                          mcState            = mcRun;
 157                                          mcFocCtrl.State_Count = 0;
 158          //                mcFocCtrl.CtrlMode = 0;
 159                      }
 160                  break;
 161          
 162                  case mcBrake:
 163                      if(mcFocCtrl.State_Count == 0)
 164                      {
 165                          mcState = mcReady;
 166                          MOE=0;
 167                          ClrBit(DRV_CR, FOCEN);
 168                      }
 169                  break;
 170          
 171                  case mcFault:
C51 COMPILER V9.52.0.0   FOCCONTROL                                                        09/26/2018 08:26:32 PAGE 4   

 172                  break;
 173              }
 174          }
 175          
 176          

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