C51 COMPILER V9.52.0.0   FOCCONTROL                                                        09/06/2018 16:05:13 PAGE 1   


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

  51   3              MOE = 0;                  // 关闭输出
  52   3      
  53   3              mcState   = mcTailWind;
  54   3              mcFocCtrl.State_Count = 0;
  55   3            }
  56   2      
  57   2                  #endif
  58   2              break;
  59   2      
  60   2              case mcTailWind:
  61   2                  #if (TailWind_Mode == NoTailWind)         // 无顺逆风处理的，直接跳入下一个状态
                              mcState                           = mcPosiCheck;
                              McStaSet.SetFlag.PosiCheckSetFlag = 0;
                              mcFocCtrl.mcPosCheckAngle         = 0xffff;   // 角度赋初值
              
                          #elif (TailWind_Mode == TailWind)
  67   2                      Motor_TailWind();
  68   2      
  69   2                  #endif
  70   2              break;
  71   2      
  72   2              case mcPosiCheck:
  73   2                  #if (PosCheckEnable==0)               //初始位置检测不使能时初始角度为预定位角度
  74   2                      mcFocCtrl.mcPosCheckAngle = Align_Angle;
  75   2                      mcState = mcAlign;
  76   2                      mcFocCtrl.State_Count = Align_Time;
  77   2      
  78   2                  #else
                              RPD();
              
                          #endif
  82   2              break;
  83   2      
  84   2              case mcAlign:       // 预定位时间结束后，直接启动; AlignTestMode=1用于初始位置�
             -��测调试用
  85   2                  Motor_Align();
  86   2      
  87   2                  #if (AlignTestMode==1)
                              while(1);
              
                          #else
  91   2                      if(mcFocCtrl.State_Count == 0) mcState = mcStart;
  92   2      
  93   2                  #endif
  94   2              break;
  95   2      
  96   2              case mcStart:                           // 配置电机启动参数，进入mcRun状态。
  97   2                  Motor_Open();
  98   2              break;
  99   2      
 100   2              case mcPllTect:                           // 配置电机启动参数，进入mcRun状态。
 101   2                  #if (EstimateAlgorithm == PLL)
                              Motor_PllStart();
              
                          #endif
 105   2              break;
 106   2      
 107   2              case mcRun:                             // 运行状态，若运行状态的给定变为0，进入
             -mcStop状态。
 108   2                  if(mcSpeedRamp.TargetValue == 0)
 109   2                  {
 110   3                      mcState               = mcStop;
C51 COMPILER V9.52.0.0   FOCCONTROL                                                        09/06/2018 16:05:13 PAGE 3   

 111   3                      mcFocCtrl.State_Count = 1900;
 112   3              GP07 = 0;
 113   3      //                FOC_IQREF             = 0;
 114   3                  }
 115   2              break;
 116   2      
 117   2              case mcStop:
 118   2                  if((mcFocCtrl.SpeedFlt<Motor_Min_Speed)||(mcFocCtrl.State_Count==0))
 119   2                  {
 120   3                      #if (StopBrakeFlag == 0)
 121   3                          mcState = mcReady;
 122   3                          FOC_CR1 = 0x00;
 123   3                          /*关闭FOC*/
 124   3                          ClrBit(DRV_CR, FOCEN);
 125   3      
 126   3                      #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
 142   3                  }
 143   2                  else if(mcSpeedRamp.TargetValue > 0)
 144   2                  {
 145   3                      mcState            = mcRun;
 146   3                      mcFocCtrl.CtrlMode = 0;
 147   3                      FOC_IQREF          = IQ_RUN_CURRENT;
 148   3                  }
 149   2              break;
 150   2      
 151   2              case mcBrake:
 152   2                  if(mcFocCtrl.State_Count == 0)
 153   2                  {
 154   3                      mcState = mcReady;
 155   3                      MOE=0;
 156   3                      ClrBit(DRV_CR, FOCEN);
 157   3                  }
 158   2              break;
 159   2      
 160   2              case mcFault:
 161   2              break;
 162   2          }
 163   1      }
 164          
 165          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    318    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =      4    ----
   PDATA SIZE       =   ----    ----
C51 COMPILER V9.52.0.0   FOCCONTROL                                                        09/06/2018 16:05:13 PAGE 4   

   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
   EDATA SIZE       =   ----    ----
   HDATA SIZE       =   ----    ----
   XDATA CONST SIZE =   ----    ----
   FAR CONST SIZE   =   ----    ----
END OF MODULE INFORMATION.


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