C51 COMPILER V9.52.0.0   FOCCONTROL                                                        09/25/2018 17:39:38 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>
  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   1          switch(mcState)
  42   1          {
  43   2              case mcInit:                                                            // 初始化状态，进入mcCharge状态
  44   2                                              
  45   2                                                      VariablesPreInit();                           // 电机相关变量初始化
  46   2                                      
  47   2                                                      //初始化方向
  48   2                                                      //mcHall.GivenFRStatus          = SetDirection;// ~RollBack;        
  49   2                                                      
  50   2                                              
  51   2                                                      if(mcCurOffset.OffsetFlag != 3)
  52   2                                                      {
C51 COMPILER V9.52.0.0   FOCCONTROL                                                        09/25/2018 17:39:38 PAGE 2   

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

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

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


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    107    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =     87    ----
   PDATA SIZE       =   ----    ----
   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)
