C51 COMPILER V9.52.0.0   FOCCONTROLFUNCTION                                                09/21/2018 10:42:52 PAGE 1   


C51 COMPILER V9.52.0.0, COMPILATION OF MODULE FOCCONTROLFUNCTION
OBJECT MODULE PLACED IN .\Output\FocControlFunction.obj
COMPILER INVOKED BY: F:\keil\C51\BIN\C51.EXE ..\User\Source\Function\FocControlFunction.c LARGE OMF2 WARNINGLEVEL(0) BRO
                    -WSE INCDIR(..\Library\FU68xx_Hardware_Driver\Include;..\User\Include) DEBUG PRINT(.\Listing\FocControlFunction.lst) OBJE
                    -CT(.\Output\FocControlFunction.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               : 10-Apr-2017
   6          * Description        : This file contains all the foc control function used for motor control.
   7          ***************************************************************************************************
   8          * All Rights Reserved
   9          **************************************************************************************************/
  10          
  11          
  12          /* Includes -------------------------------------------------------------------------------------*/
  13          #include <FU68xx_2.h>
  14          #include <Myproject.h>
*** ERROR C129 IN LINE 27 OF ..\User\Include\FocControlFunction.h: missing ';' before 'idata'
  15          #include <FU68xx_2_DMA.h>
  16          #endif
  17          CurrentOffset xdata mcCurOffset;
  18          
  19          extern int16 RampStepInc;
  20          
  21          
  22          /*---------------------------------------------------------------------------*/
  23          /* Name         :       void FOC_Init(void)
  24          /* Input        :       NO
  25          /* Output       :       NO
  26          /* Description: mcInit状态下，对FOC的相关寄存器进行配置,先清理寄存器，后配置，�
             -�后使能
  27          /*---------------------------------------------------------------------------*/
  28          void FOC_Init(void)
  29          {
  30                  /*使能FOC*/
  31                  ClrBit(DRV_CR, FOCEN);
  32                  SetBit(DRV_CR, FOCEN);
  33                  /*配置FOC寄存器*/
  34                  FOC_CR1                         = 0;                                                                                                                                                    // 清零 FOC_CR1
  35                  FOC_CR2                         = 0;                                                                                                                                                    // 清零 FOC_CR2
  36                  FOC_IDREF               = 0;                                                                                                                                                    // 清零 Id
  37                  FOC_IQREF               = 0;                                                                                                                                                    // 清零 Iq
  38          
  39                  FOC__THETA              = 0;                                                                                                                                                    // 清零 角度
  40                  FOC_RTHEACC     = 0;                                                                                                                                                    // 清零 爬坡函数的初始加速度
  41                  FOC__RTHESTEP = 0;                                                                                                                                              
  42                  FOC__RTHECNT    = 0;                                                                                                                                                    
  43                  FOC__THECOMP    = _Q15(0.0/180.0);                                                                                              // SMO 估算补偿角
  44                  FOC__THECOR             = 0x04;                                                                                                                                 // 误差角度补偿
  45                  
  46                  /*电流环参数配置*/
  47                  
  48                  
  49                  #if (CurrentCycleEnable == 1)//使能电流环
                      {
                                      ClrBit(FOC_CR2, UQD);
C51 COMPILER V9.52.0.0   FOCCONTROLFUNCTION                                                09/21/2018 10:42:52 PAGE 2   

                                      ClrBit(FOC_CR2, UDD);
                      }
                      #elif (CurrentCycleEnable == 0)//不使能电流环
  55                  {
  56                                  SetBit(FOC_CR2, UQD);
  57                                  SetBit(FOC_CR2, UDD);
  58                  }
  59                  #endif //end SVPMW_Mode
  60                  
  61                  
  62                  FOC_DMAX                        = DOUTMAX;
  63                  FOC_DMIN                        = DOUTMIN;
  64          
  65                  FOC_QMAX                        = QOUTMAX;
  66                  FOC_QMIN                        = QOUTMIN;
  67          
  68                          //FOC__UQ = StartPWMDuty;
  69          
  70          //      FOC_QMAX                        = StartPWMDuty;
  71          //      FOC_QMIN                        = StartPWMDuty;
  72          
  73                  /*位置估算参数配置*/
  74                  FOC_EK1                         = OBS_K1T;
  75                  FOC_EK2                         = OBS_K2T;
  76                  FOC_EK3                         = OBS_K3T;
  77                  FOC_EK4                         = OBS_K4T;
  78                  FOC_FBASE               = OBS_FBASE;
  79                  FOC_OMEKLPF     = SPEED_KLPF;
  80                  FOC_EBMFK               = OBS_KLPF;
  81          
  82            FOC_TGLI      = PWM_TGLI_LOAD;
  83          
  84                  /*********PLL或SMO**********/
  85                  #if (EstimateAlgorithm == SMO)
  86                  {
  87                                  ClrBit(FOC_CR2, ESEL);
  88                                  FOC_KSLIDE    = OBS_KSLIDE;
  89                                  FOC_EKLPFMIN    = OBS_EA_KS;
  90                  }
  91                  #elif (EstimateAlgorithm == PLL)
                      {
                                      SetBit(FOC_CR2, ESEL);
                                      FOC_KSLIDE    = OBSE_PLLKP_GAIN;
                                      FOC_EKLPFMIN    = OBSE_PLLKI_GAIN;
                      }
                      #endif //end SVPMW_Mode
  98          
  99                  SetBit(FOC_CR1, SVPWMEN);                                                                                                                       // SVPWM模式
 100          
 101          
 102                  /**过调制**/
 103                  #if (OverModulation == 1)
                      {
                                      SetBit(FOC_CR1,OVMDL);                                                                                                  // 过调制
                      }
                      #endif //end OverModulation
 108          
 109                  /*单电阻采样；需要最小采样窗,FOC_TRGDLY为0，七段式SVPWM方式*/
 110                  #if (Shunt_Resistor_Mode == Single_Resistor)
 111                  {
 112                          SetReg(FOC_CR1, CSM0 | CSM1, 0x00);
 113                          FOC_TSMIN = PWM_TS_LOAD;                                                                                                                        // 最小采样窗口
C51 COMPILER V9.52.0.0   FOCCONTROLFUNCTION                                                09/21/2018 10:42:52 PAGE 3   

 114                          FOC_TRGDLY = 0x05;                                                                                                              // 采样时刻在中点，一般考虑开关噪声影响，会
             -设置延迟；
 115                                                                                // 0x0c表示延迟12个clock，提前用反码形
             -式，如0x84表示提前12个clock。
 116                          ClrBit(FOC_CR2,F5SEG);                                                                                                                    // 7段式
 117                          SetReg(CMP_CR1, CMP3MOD0 | CMP3MOD1, 0x00);
 118                  }
 119                  /*双电阻采样，可设置死区补偿值，在下降沿结束前开始采样Ia，配置81*/
 120                  #elif (Shunt_Resistor_Mode == Double_Resistor)                                  // double resistor sample
                      {
                              SetReg(FOC_CR1, CSM0 | CSM1, CSM0);
              
                              FOC_TSMIN = PWM_DT_LOAD;                                                                                                                        // 死区补偿值
                              FOC_TRGDLY = 0x80;                                                                                                                                        // ADC采样的时刻，采样时刻在计数器零点附近，83�
             -�下降沿结束前3个clock采样Ia，与单电阻不同
                                                                                    // 01为上升沿开始后第一个clock开始采�
             -��。根据实际情况调整。
                              FOC_TBLO=PWM_DLOWL_TIME;                              //下桥臂最小脉冲，保证采样
                              SetReg(CMP_CR1, CMP3MOD0 | CMP3MOD1, 0x00);
              
                              /*五段式或七段式选择*/
                              #if (SVPMW_Mode == SVPWM_7_Segment)
                              {
                                      ClrBit(FOC_CR2,F5SEG);                                                                                                                  // 7段式
                              }
                              #elif (SVPMW_Mode == SVPWM_5_Segment)
                              {
                                      SetBit(FOC_CR2,F5SEG);                                                                                                                  // 7段式
                              }
                              #endif
              
                              #if (DouRes_Sample_Mode == DouRes_1_Cycle)
                              {
                                      ClrBit(FOC_CR2,DSS);                                                                                                                      // 7段式
                              }
                              #elif (DouRes_Sample_Mode == DouRes_2_Cycle)
                              {
                                      SetBit(FOC_CR2,FOC_DSS);                                                                                                                // 7段式
                              }
                              #endif //end DouRes_Sample_Mode
                      }
                      /*三电阻采样*/
                      #elif (Shunt_Resistor_Mode == Three_Resistor)                                     // signel resistor sample
                      {
              
                              SetReg(FOC_CR1, CSM0 | CSM1, CSM0 | CSM1);// 三电阻
              
                              FOC_TSMIN  = PWM_DT_LOAD;                                                                                                                       // 死区补偿值
                              FOC_TRGDLY =06;                                                                                                                                                   // ADC采样的时刻，采样时刻在计数器零点附近，83为
             -下降沿结束前3个clock采样Ia，与单电阻不同。
                                                                                    // 01为上升沿开始后第一个clock开始采�
             -��。根据实际情况调整。
              
                              SetReg(CMP_CR1, CMP3MOD0 | CMP3MOD1, CMP3MOD0 | CMP3MOD1);
                              FOC_TBLO= PWM_OVERMODULE_TIME;                        // 过调制电流采样处理的TB脉宽
              
                              /*五段式或七段式选择*/
                              #if (SVPMW_Mode == SVPWM_7_Segment)
                              {
                                      ClrBit(FOC_CR2,F5SEG);                                                                                                                  // 7段式
                              }
                              #elif (SVPMW_Mode == SVPWM_5_Segment)
C51 COMPILER V9.52.0.0   FOCCONTROLFUNCTION                                                09/21/2018 10:42:52 PAGE 4   

                              {
                                      SetBit(FOC_CR2,F5SEG);                                                                                                                  // 7段式
                              }
                              #endif //end SVPMW_Mode
              
                              #if (DouRes_Sample_Mode == DouRes_1_Cycle)
                              {
                                      ClrBit(FOC_CR2,DSS);                                                                                                                    // 7段式
                              }
                              #elif (DouRes_Sample_Mode == DouRes_2_Cycle)
                              {
                                      SetBit(FOC_CR2,DSS);                                                                                                                    // 7段式
                              }
                              #endif //end DouRes_Sample_Mode
                      }
                      #endif  //end Shunt_Resistor_Mode
 186          
 187                  /* 使能电流基准校正     */
 188                  #if (CalibENDIS == Enable)
 189                  {
 190                          if(mcCurOffset.OffsetFlag>=1)
 191                          {
 192                                  #if (Shunt_Resistor_Mode == Single_Resistor)          // 单电阻校正
 193                                  {
 194                                          /*set ibus current sample offset*/
 195                                          SetReg(FOC_CR2, CSOC0 | CSOC1, 0x00);
 196                                          FOC_CSO = mcCurOffset.Iw_busOffset;                   // 写入Ibus的偏置
 197          
 198                                  }
 199                                  #elif (Shunt_Resistor_Mode == Double_Resistor)                  // 双电阻校正
                                      {
                                              /*set ia, ib current sample offset*/
                                              SetReg(FOC_CR2, CSOC0 | CSOC1, CSOC0);
                                              FOC_CSO  = mcCurOffset.IuOffset;                  // 写入IA的偏置
              
                                              SetReg(FOC_CR2, CSOC0 | CSOC1, CSOC1);
                                              FOC_CSO  = mcCurOffset.IvOffset;                        // 写入IB的偏置
              
                                      }
                                      #elif (Shunt_Resistor_Mode == Three_Resistor)         // 三电阻校正
                                      {
                                              /*set ibus current sample offset*/
                                              SetReg(FOC_CR2, CSOC0 | CSOC1, CSOC0);
                                              FOC_CSO = mcCurOffset.IuOffset;                                                                         // 写入IA的偏置
              
                                              SetReg(FOC_CR2, CSOC0 | CSOC1, CSOC1);
                                              FOC_CSO = mcCurOffset.IvOffset;                   // 写入IB的偏置
              
                                              SetReg(FOC_CR2, CSOC0 | CSOC1, 0x00);
                                              FOC_CSO = mcCurOffset.Iw_busOffset;                   // 写入IC的偏置
                                      }
                                      #endif  //end Shunt_Resistor_Mode
 222                          }
 223                  }
 224                  #endif  //end CalibENDIS
 225                  /*-------------------------------------------------------------------------------------------------
 226                  DRV_CTL：PWM来源选择
 227                  OCS = 0, DRV_COMR
 228                  OCS = 1, FOC/SVPWM/SPWM
 229                  -------------------------------------------------------------------------------------------------*/
 230                  /*计数器比较值来源FOC*/
 231                  SetBit(DRV_CR, OCS);
C51 COMPILER V9.52.0.0   FOCCONTROLFUNCTION                                                09/21/2018 10:42:52 PAGE 5   

 232          }
 233          /*---------------------------------------------------------------------------*/
 234          /* Name         :       void Motor_Charge(void)
 235          /* Input        :       NO
 236          /* Output       :       NO
 237          /* Description: 预充电，当一直处于预充电状态下，不接电机，可用于验证IPM或者Mos
             -。
 238          预充电分三步，第一步是对U相进行预充电，第二步是对U,V两相进行预充电;第三�
             -�是对U、V、W三相进行预充电。
 239          /*---------------------------------------------------------------------------*/
 240          void Motor_Charge(void)
 241          {
 242                  if(McStaSet.SetFlag.ChargeSetFlag==0)
 243                  {
 244                          McStaSet.SetFlag.ChargeSetFlag = 1;
 245                          #if (PWM_Level_Mode == Low_Level)        //用于測試6536
                              {
                                      SetBit(P1_OE, P10);
                                      GP10=1;
                              }
                              #endif
 251                          #if (IPMState == IPMtest)
                              {
                                      DRV_DR = 0.7*DRV_ARR;                                               // IPM 70% duty
                              }
                              #elif (IPMState == NormalRun)                 // 正常按电机状态机运行
 256                          {
 257                                  DRV_DR = 0.1*DRV_ARR;                                   //下桥臂10% duty
 258                          }
 259                          #endif
 260                          /*-------------------------------------------------------------------------------------------------
 261                          DRV_CTL：PWM来源选择
 262                          OCS = 0, DRV_COMR
 263                          OCS = 1, FOC/SVPWM/SPWM
 264                          -------------------------------------------------------------------------------------------------*/
 265                          ClrBit(DRV_CR, OCS);
 266                          mcFocCtrl.ChargeStep = 0;
 267                  }
 268                  if((mcFocCtrl.State_Count < Charge_Time)&&(mcFocCtrl.ChargeStep == 0))
 269                  {
 270                          mcFocCtrl.ChargeStep = 1;
 271                          #if (IPMState == IPMtest)
                              {
                                      DRV_CMR |= 0x03;                         // U相输出
                              }
                              #elif (IPMState == NormalRun)                     // 正常按电机状态机运行
 276                          {
 277                                  DRV_CMR |= 0x01;                         // U相下桥臂通
 278                          }
 279                          #endif
 280                          MOE = 1;
 281                  }
 282                  if(( mcFocCtrl.State_Count <= (Charge_Time<<1)/3)&&(mcFocCtrl.ChargeStep== 1))
 283                  {
 284                          mcFocCtrl.ChargeStep = 2;
 285                          #if (IPMState == IPMtest)
                              {
                                      DRV_CMR |= 0x0F;                         // U、V相输出
                              }
                              #elif (IPMState == NormalRun)                     // 正常按电机状态机运行
 290                          {
 291                                  DRV_CMR |= 0x04;                         // V相下桥臂导通
C51 COMPILER V9.52.0.0   FOCCONTROLFUNCTION                                                09/21/2018 10:42:52 PAGE 6   

 292                          }
 293                          #endif
 294                  }
 295                  if((mcFocCtrl.State_Count <= Charge_Time/3)&&(mcFocCtrl.ChargeStep== 2))
 296                  {
 297                          mcFocCtrl.ChargeStep = 3;
 298                          #if (IPMState == IPMtest)
                              {
                              DRV_CMR |= 0x3F;                         // U、V、W相输出
                              }
                              #elif (IPMState == NormalRun)                     // 正常按电机状态机运行
 303                          {
 304                          DRV_CMR |= 0x10;                         // W相下桥臂导通
 305                          }
 306                          #endif
 307                  }
 308          }
 309          /*---------------------------------------------------------------------------*/
 310          /* Name         :       void Motor_Align(void)
 311          /* Input        :       NO
 312          /* Output       :       NO
 313          /* Description: 预定位函数，当无逆风判断时，采用预定位固定初始位置;当有逆风�
             -�断时，采用预定位刹车
 314          /*---------------------------------------------------------------------------*/
 315          void Motor_Align(void)
 316          {
 317                  if(McStaSet.SetFlag.AlignSetFlag==0)
 318                  {
 319                            McStaSet.SetFlag.AlignSetFlag=1;
 320          
 321                            /*FOC初始化*/
 322                                  FOC_Init();
 323          
 324                            /*配置预定位的电流、KP、KI*/
 325                                  FOC_IDREF = ID_Align_CURRENT;
 326                                  FOC_IQREF = IQ_Align_CURRENT;
 327          
 328                                  FOC_DQKP = DQKP_Alignment;
 329                                  FOC_DQKI = DQKI_Alignment;
 330          
 331                                  FOC_EKP         = OBSW_KP_GAIN;
 332                                  FOC_EKI         = OBSW_KI_GAIN;
 333          
 334                /*配置预定位角度*/
 335                                  #if (AlignTestMode==1)
                                      {
                                              FOC__THETA              = Align_Theta;
                                      }
                                      #else
 340                                  {
 341                                          #if (PosCheckEnable==1)
                                              {
                                                FOC__THETA    = mcFocCtrl.mcPosCheckAngle;
                                              }
                                              #else
 346                                          {
 347                                                  FOC__THETA              =Align_Theta;
 348                                          }
 349                                    #endif        //end PosCheckEnable
 350                                  }
 351                                  #endif  //end AlignTestMode
 352                                                          /*********PLL或SMO**********/
C51 COMPILER V9.52.0.0   FOCCONTROLFUNCTION                                                09/21/2018 10:42:52 PAGE 7   

 353                                  #if (EstimateAlgorithm == SMO)
 354                                  {
 355                                    FOC__ETHETA   = FOC__THETA-4096;
 356                                  }
 357                                  #elif (EstimateAlgorithm == PLL)
                                      {
                                        FOC__ETHETA   = FOC__THETA;
                                      }
                                      #endif //end    EstimateAlgorithm
 362          //                      TimeCnt=FOC__THETA;
 363          
 364                            /*使能输出*/
 365                                  DRV_CMR |= 0x3F;                         // U、V、W相输出
 366                                  MOE = 1;
 367            }
 368          }
 369          
 370          /*---------------------------------------------------------------------------*/
 371          /* Name         :       void Motor_Open(void)
 372          /* Input        :       NO
 373          /* Output       :       NO
 374          /* Description: 开环启动的参数配置
 375          /*---------------------------------------------------------------------------*/
 376          void Motor_Open(void)
 377          {
 378                  static uint8 OpenRampCycles;
 379                  
 380                  uint8 hall_status= 0;
 381                  
 382                  if(MotorStateTime.OpenOneTime==0)
 383                  {
 384                          MotorStateTime.OpenOneTime=1;
 385                          
 386                          /*FOC初始化*/
 387                          FOC_Init();
 388                                                                  
 389                          /*********PLL或SMO**********/
 390                          #if (EstimateAlgorithm == SMO)
 391                          {
 392                                  FOC__ETHETA     = FOC__THETA - 4915;
 393                          }
 394                          #elif (EstimateAlgorithm == PLL)
                              {
                                      FOC__ETHETA     = FOC__THETA;
                              }
                              #endif //end    EstimateAlgorithm
 399          
 400          //              TimeCnt=FOC__ETHETA;                                                    
 401                          /*启动电流、KP、KI、FOC_EKP、FOC_EKI*/
 402                          FOC_IDREF = ID_Start_CURRENT;               // D轴启动电流
 403                          mcFocCtrl.mcIqref= IQ_Start_CURRENT;                // Q轴启动电流
 404                          
 405                          FOC_IQREF = mcFocCtrl.mcIqref;                    // Q轴启动电流
 406          
 407                          FOC_DQKP        = DQKP;
 408                          FOC_DQKI        = DQKI;
 409          
 410                          FOC_EKP         = OBSW_KP_GAIN;
 411                          FOC_EKI         = OBSW_KI_GAIN;
 412          
 413          
 414                          /*启动方式选择*/
C51 COMPILER V9.52.0.0   FOCCONTROLFUNCTION                                                09/21/2018 10:42:52 PAGE 8   

 415                          #if (Open_Start_Mode == Omega_Start)            // Omega 启动
                              {
                                      FOC_EFREQACC    = Motor_Omega_Ramp_ACC;
                                      FOC_EFREQMIN    = Motor_Omega_Ramp_Min;
                                      FOC_EFREQHOLD   = Motor_Omega_Ramp_End;
              
                                      SetBit(FOC_CR1,EFAE);                                           // 估算器强制输出
                                      ClrBit(FOC_CR1,RFAE);                                           // 禁止强拉
                                      SetBit(FOC_CR1,ANGM);                                           // 估算模式
                              }
                              #elif (Open_Start_Mode == Open_Start)
 426                          {
 427          //                      FOC_RTHEACC     = Motor_Open_Ramp_ACC;          // 爬坡函数的初始加速度
 428          //                      FOC__RTHESTEP   = Motor_Open_Ramp_Min;          // 0.62 degree acce speed
 429          //                      RPDPara.ThetaGet=Motor_Open_Ramp_Min;
 430          //                      FOC__RTHECNT    = MOTOR_OPEN_ACC_CNT;           // acce time
 431          
 432                                  ClrBit(FOC_CR1,EFAE);                                           // 估算器强制输出
 433                                  ClrBit(FOC_CR1,RFAE);                                           // 禁止强拉
 434                                  ClrBit(FOC_CR1,ANGM);                                           // 估算模式
 435                          }
 436                          #elif (Open_Start_Mode == Open_Omega_Start)
                              {
                                      FOC_RTHEACC     = Motor_Open_Ramp_ACC;          // 爬坡函数的初始加速度
                                      FOC__RTHESTEP   = Motor_Open_Ramp_Min;          // 0.62 degree acce speed
                                      FOC__RTHECNT    = MOTOR_OPEN_ACC_CNT;           // acce time
              
                                      FOC_EFREQACC    = Motor_Omega_Ramp_ACC;
                                      FOC_EFREQMIN    = Motor_Omega_Ramp_Min;
                                      FOC_EFREQHOLD   = Motor_Omega_Ramp_End;
              
                                      SetBit(FOC_CR1,EFAE);                                           // 估算器强制输出
                                      SetBit(FOC_CR1,RFAE);                                           // 禁止强拉
                                      SetBit(FOC_CR1,ANGM);                                           // 估算模式
                              }
                              #endif //end Open_Start_Mode
 451                  }
 452                  
 453                  /*不同启动方式下，切换到MCRUN状态*/
 454          //      #if (Open_Start_Mode == Open_Start)                                     //OPEN状态启动时拖动多次
 455          //      {
 456          //              if(OpenRampCycles<(MOTOR_OPEN_ACC_CYCLE-1))
 457          //              {
 458          //                      if(!ReadBit(FOC_CR1,RFAE))
 459          //                      {
 460          //                              SetBit(FOC_CR1,RFAE);
 461          //                              OpenRampCycles++;
 462          //                      }
 463          //              }
 464          //              else
 465          //              {
 466          //                      mcFocCtrl.State_Count = 2;                                      //???这里为什么延时2ms
 467          
 468          //                      mcState = mcRun;
 469          //              }
 470          //              FOC_EKP = OBSW_KP_GAIN_RUN4;                    // 估算器里的PI的KP
 471          //              FOC_EKI = OBSW_KI_GAIN_RUN4;                                // 估算器里的PI的KI
 472          //      }
 473          //      #elif (Open_Start_Mode == Open_Omega_Start)
 474          //      {
 475          //              mcFocCtrl.State_Count = 2600;
 476          //              mcState = mcRun;
C51 COMPILER V9.52.0.0   FOCCONTROLFUNCTION                                                09/21/2018 10:42:52 PAGE 9   

 477          //      }
 478          //      #elif (Open_Start_Mode == Omega_Start)
 479          //      {
 480          //              /*********PLL或SMO**********/
 481          //              #if (EstimateAlgorithm == SMO)
 482          //              {
 483          //                      mcFocCtrl.State_Count = 2600;
 484          //              }
 485          //              #elif (EstimateAlgorithm == PLL)
 486          //              {
 487          //                      mcFocCtrl.State_Count = 1400;
 488          //                      FOC_EKP = OBSW_KP_GAIN_RUN1;                    // 估算器里的PI的KP
 489          //                      FOC_EKI = OBSW_KI_GAIN_RUN1;                            // 估算器里的PI的KI
 490          //              }
 491          //              #endif //end    EstimateAlgorithm
 492          //              
 493          //      }
 494          //      #endif //end Open_Start_Mode
 495                  
 496                  if(HALLC)
 497                  {
 498                          hall_status += 4;
 499                  }
 500                  
 501                  if(HALLB)
 502                  {
 503                          hall_status += 2;
 504                  }
 505                  
 506                  if(HALLA)
 507                  {
 508                          hall_status += 1;
 509                  }
 510                          
 511                  mcHall.HallStatus_Result = hall_status;
 512                  
 513                  FOC__RTHESTEP                  = 0; 
 514                  
 515                  FOC__THETA = StartThetaDispose (mcHall.HallStatus_Result,mcHall.GivenFRStatus,TempAngleOffsetCW,TempAngl
             -eOffsetCCW,mcHall.StartAngleOffset);
 516                                          
 517                  mcState = mcRun;
 518                  
 519                  mcHall.HallCommutationCount   = 1;
 520                  
 521                  DRV_CMR |= 0x3F;                         // U、V、W相输出
 522                          
 523          //      if(mcHall.HallDirectStartStatus)
 524          //      {
 525          //              MOE = 0;                
 526          //      }
 527          //      else
 528          //      {
 529                          MOE = 1;
 530                                                  
 531                          //FOC__UQ = 0;
 532          //              FOC_QMAX                        = 0;
 533          //              FOC_QMIN                        = 0;
 534          //      }
 535          }
 536          
 537          /*---------------------------------------------------------------------------*/
C51 COMPILER V9.52.0.0   FOCCONTROLFUNCTION                                                09/21/2018 10:42:52 PAGE 10  

 538          /* Name         :       void Motor_Open(void)
 539          /* Input        :       NO
 540          /* Output       :       NO
 541          /* Description: 开环启动的参数配置
 542          /*---------------------------------------------------------------------------*/
 543          void Motor_PllStart(void)
 544          {
 545                  static uint8 OpenRampCycles;
 546                  if(TailWindDetect.PLLFlag==1)
 547                  {
 548                          TailWindDetect.PLLSpeed=FOC__EOME;
 549                  TailWindDetect.PLLSpeed=Abs_F16(TailWindDetect.PLLSpeed);
 550                          if(Abs_F16(TailWindDetect.PLLSpeed)<350)                //逆风状态下，速度低于100时，计数，达到一定
             -时间后，PLLFlag清零。
 551                          {
 552                                  TailWindDetect.PLLDetectCnt++;
 553                                  if(TailWindDetect.PLLDetectCnt>3000)            //防止估算错误
 554                                  {
 555                                          TailWindDetect.PLLFlag=0;
 556                                          TailWindDetect.PLLTheta=FOC__ETHETA;
 557          //                              FOC_IQREF =0;
 558                                  }
 559                          }
 560                          else
 561                          {
 562                                  if(TailWindDetect.PLLDetectCnt>0)
 563                                  {
 564                                          TailWindDetect.PLLDetectCnt--;
 565                                  }
 566                          }
 567                  }
 568                  if((McStaSet.SetFlag.StartSetFlag==0)&&(TailWindDetect.PLLFlag==0))
 569                  {
 570                          McStaSet.SetFlag.StartSetFlag=1;
 571                          MOE = 0;
 572                          FOC_Init();
 573                          FOC__ETHETA             = TailWindDetect.PLLTheta;//+19668;//16668;//
 574          
 575                          /*启动电流、KP、KI、FOC_EKP、FOC_EKI*/
 576                          FOC_IDREF = ID_Start_CURRENT;                   // D轴启动电流
 577                          FOC_IQREF = mcFocCtrl.mcIqref;                      // Q轴启动电流
 578          
 579                          FOC_DQKP = _Q12(2.0) ;//DQKPStart;
 580                          FOC_DQKI = _Q15(0.16) ;//DQKIStart;
 581          //        FOC__UQ   =_Q15(0.3);
 582          
 583                          /*启动方式选择*/
 584                          #if (Open_Start_Mode == Omega_Start)            // Omega 启动
                              {
                                      FOC_EFREQACC    = Motor_Omega_Ramp_ACC_Antiwind;
                                      FOC_EFREQMIN    = 3*Motor_Omega_Ramp_Min;
                                      FOC_EFREQHOLD   = Motor_Omega_Ramp_End;
              
                                      SetBit(FOC_CR1,EFAE);                                           // 禁止估算器强制输出
                                      ClrBit(FOC_CR1,RFAE);                                           // 使能强拉
                                      SetBit(FOC_CR1,ANGM);                                           // 估算模式
                              }
                              #elif (Open_Start_Mode == Open_Start)
 595                          {
 596          //                      FOC_RTHEACC     = Motor_Open_Ramp_ACC;          // 爬坡函数的初始加速度
 597          //                      FOC__RTHESTEP   = Motor_Open_Ramp_Min;          // 0.62 degree acce speed
 598          //                      FOC__RTHECNT    = MOTOR_OPEN_ACC_CNT;           // acce time
C51 COMPILER V9.52.0.0   FOCCONTROLFUNCTION                                                09/21/2018 10:42:52 PAGE 11  

 599          
 600                                  ClrBit(FOC_CR1,EFAE);                                           // 禁止估算器强制输出
 601                                  ClrBit(FOC_CR1,RFAE);                                           // 使能强拉
 602                                  ClrBit(FOC_CR1,ANGM);                                           // 估算模式
 603                          }
 604                          #elif (Open_Start_Mode == Open_Omega_Start)
                              {
                                      FOC_RTHEACC     = Motor_Open_Ramp_ACC;          // 爬坡函数的初始加速度
                                      FOC__RTHESTEP   = Motor_Open_Ramp_Min;          // 0.62 degree acce speed
                                      FOC__RTHECNT    = MOTOR_OPEN_ACC_CNT;           // acce time
              
                                      FOC_EFREQACC    = Motor_Omega_Ramp_ACC;
                                      FOC_EFREQMIN    = Motor_Omega_Ramp_Min;
                                      FOC_EFREQHOLD = Motor_Omega_Ramp_End;
              
                                      SetBit(FOC_CR1,EFAE);                                           // 禁止估算器强制输出
                                      SetBit(FOC_CR1,RFAE);                                           // 使能强拉
                                      SetBit(FOC_CR1,ANGM);                                           // 估算模式
                              }
                              #endif //end Open_Start_Mode
 619                          DRV_CMR |= 0x3F;                                        // U、V、W相输出
 620                          MOE = 1;
 621                  }
 622          
 623                  if((McStaSet.SetFlag.StartSetFlag==1)&&(TailWindDetect.PLLFlag==0))
 624                  {
 625                          /*不同启动方式下，切换到MCRUN状态*/
 626                          #if (Open_Start_Mode == Open_Start)                             //OPEN状态启动时拖动多次
 627                          {
 628                                  if(OpenRampCycles<(MOTOR_OPEN_ACC_CYCLE-1))
 629                                  {
 630                                          if(!ReadBit(FOC_CR1,RFAE))
 631                                          {
 632                                                  SetBit(FOC_CR1,RFAE);
 633                                                  OpenRampCycles++;
 634                                          }
 635                                  }
 636                                  else
 637                                  {
 638                                          mcFocCtrl.State_Count = 2;
 639                                          mcState = mcRun;
 640                                  }
 641                                  FOC_EKP = OBSW_KP_GAIN_RUN4;                // 估算器里的PI的KP
 642                                  FOC_EKI = OBSW_KI_GAIN_RUN4;                            // 估算器里的PI的KI
 643                          }
 644                          #elif (Open_Start_Mode == Open_Omega_Start)
                              {
                                      mcFocCtrl.State_Count = 2600;
                                      mcState = mcRun;
                              }
                              #elif (Open_Start_Mode == Omega_Start)
                              {
                                      mcFocCtrl.State_Count = 2900;
                                      FOC_EKP = OBSW_KP_GAIN;             // 估算器里的PI的KP
                                      FOC_EKI = OBSW_KI_GAIN;                         // 估算器里的PI的KI
                                      mcState = mcRun;
                              }
                              #endif //end Open_Start_Mode
 657                  }
 658          
 659          }
 660          /*---------------------------------------------------------------------------*/
C51 COMPILER V9.52.0.0   FOCCONTROLFUNCTION                                                09/21/2018 10:42:52 PAGE 12  

 661          /* Name         :       void Motor_Align(void)
 662          /* Input        :       NO
 663          /* Output       :       NO
 664          /* Description: 顺风逆风参数配置函数
 665          /*---------------------------------------------------------------------------*/
 666          void Motor_TailWind(void)
 667          {
 668                  if(mcFocCtrl.State_Count == 0)
 669                  {
 670                          if(McStaSet.SetFlag.TailWindSetFlag  ==0)//初始化
 671                          {
 672                                  McStaSet.SetFlag.TailWindSetFlag =1;
 673          
 674                                  #if (FRDetectMethod==RSDMethod)
                                      {
                                              RSDDetectInit();
                                      }
                                      #elif (FRDetectMethod==BEMFMethod)
                                      {
                                              BEMFDetectInit();
                                      }
                                      #elif (FRDetectMethod==FOCMethod)
 683                                  {
 684                                          TailWindDetectInit();
 685                                  }
 686                                  #endif
 687          
 688                          }
 689                          
 690                          #if (FRDetectMethod==RSDMethod)
                              {
                                      RSDDealwith();
                              }
                              #elif (FRDetectMethod==BEMFMethod)
                              {
                                      BEMFDealwith();
                              }
                              #elif (FRDetectMethod==FOCMethod)
 699                          {
 700                                  FOCTailWindDealwith();
 701                          }
 702                          #endif
 703                  }
 704          }
 705          
 706          /*---------------------------------------------------------------------------*/
 707          /* Name         :       void MC_Stop(void)
 708          /* Input        :       NO
 709          /* Output       :       NO
 710          /* Description: inital motor control parameter
 711          /*---------------------------------------------------------------------------*/
 712          void MC_Stop(void)
 713          {
 714                  MOE     = 0;
 715                  ClrBit(DRV_CR, FOCEN, 0);       //关闭FOC                                                                                                                                                                                                                     // disable FOC output and initial registe
             -r
 716                  mcState = mcInit;
 717          }
 718          
 719          /*-------------------------------------------------------------------------------------------------
 720                  Function Name : void MotorControlInit(void)
 721                  Description   : 控制变量初始化清零,包括保护参数的初始化、电机状态初始化
C51 COMPILER V9.52.0.0   FOCCONTROLFUNCTION                                                09/21/2018 10:42:52 PAGE 13  

 722                  Input         : 输入说明（详细）
 723            Output                                :       输出说明（详细）
 724          -------------------------------------------------------------------------------------------------*/
 725          void MotorcontrolInit(void)
 726          {
 727            /***********保护******************/
 728                  memset(&mcFaultDect,0, sizeof(FaultVarible));                                                                                                                           // FaultVarible变量清零
 729            /******堵转保护*********/
 730          //      mcFaultDect.StallRecover          = 1000;//5s
 731          
 732            /******保护次数*********/
 733                  memset(&mcProtectTime,0, sizeof(ProtectVarible));                                                                                                               // ProtectVarible保护次数清零 
 734            /*******过流保护*****************/
 735                  memset(&mcCurVarible,0, sizeof(CurrentVarible));                                                                                                                // 电流保护的变量清零
 736          
 737            /*****顺逆风判断，FOCMethod不需要在此赋初值*******/
 738                  #if (FRDetectMethod==RSDMethod)
                      {
                 memset(&RSDDetect,0, sizeof(MotorRSDTypeDef));       //      RSDDetect所有变量清零
                      }
                      #elif (FRDetectMethod==BEMFMethod)
                      {
                 memset(&BEMFDetect,0, sizeof(BEMFDetect_TypeDef));           //      BEMFDetect所有变量清零
                      } 
                #endif
 747          
 748                  /*******启停测试的参数***************/
 749                  memset(&ONOFFTest,0, sizeof(ONVarible));
 750          
 751            /*****电机状态机时序变量***********/
 752                  McStaSet.SetMode                   = 0;
 753          
 754            /*****电机目标方向**********/
 755                  mcFRState.TargetFR                 = 0;
 756          
 757            /*****外部控制环*******/
 758                  memset(&mcFocCtrl,0, sizeof(FOCCTRL));                                                                                                                          // mcFocCtrl变量清零
 759          
 760            /******ADC采样滤波值*********/
 761                  memset(&AdcSampleValue,0, sizeof(ADCSample));                                                                                                   // ADCSample变量清零
 762          
 763            /******电流偏置校准变量*****/
 764                  memset(&mcCurOffset,0, sizeof(CurrentOffset));                                                                                          // mcCurOffset变量清零
 765                  mcCurOffset.IuOffsetSum            = 16383;
 766                  mcCurOffset.IvOffsetSum            = 16383;
 767                  mcCurOffset.Iw_busOffsetSum        = 16383;
 768          
 769                  /*****LED灯响应***/
 770                  memset(&mcLedDisplay,0, sizeof(MCLedDisplay));                                                                                          // mcLedDisplay变量清零
 771                  mcLedDisplay.Counttime            = 4999;
 772          
 773                  /*****速度环的响应***/
 774                  memset(&mcSpeedRamp,0, sizeof(MCRAMP));                                                                                                 // mcSpeedRamp变量清零
 775          //      mcSpeedRamp.IncValue              = Motor_Speed_Inc;
 776          //      mcSpeedRamp.DecValue              = Motor_Speed_Dec;
 777          //      mcSpeedRamp.DelayPeriod           = 1;
 778          
 779                  /*PWM调速变量*/
 780                  memset(&mcPwmInput,0, sizeof(PWMINPUTCAL));                                                                                                 // mcPwmInput变量清零
 781          
 782                  /*串口变量*/
 783                  memset(&Uart,0, sizeof(MCUART));                                                                                                              // MCUART变量清零
C51 COMPILER V9.52.0.0   FOCCONTROLFUNCTION                                                09/21/2018 10:42:52 PAGE 14  

 784          
 785                  /*睡眠模式*/  
 786                  memset(&SleepSet,0, sizeof(SLEEPMODE));                                     // 睡眠模式清零
 787                  
 788                  memset(&MotorStateTime,0, sizeof(MotStaTim));                           //清零
 789                  
 790                  memset(&mcHall,0, sizeof(mcHall_TypeDef));                                //清零
 791                  
 792                  /*****环路响应***/  
 793                  #if (Speed_Loop_Mode == Speed_OpenLoop_Enable)
 794                  SpeedRamp.RampInc                                                               = Motor_Voltage_Inc;
 795                  SpeedRamp.RampDec                                                                       =       Motor_Voltage_Dec;
 796                  SpeedRamp.RampTarget                                                    =       StartPWMDuty;
 797                  SpeedRamp.RampStep                                                              =       MinPWMDuty;
 798                  SpeedRamp.SPEEDRampTIMETemp       =  SPEEDRampTIME;
 799                  #endif
 800                  
 801          }
 802          
 803          /*---------------------------------------------------------------------------*/
 804          /* Name         :       void VariablesPreInit(void)
 805          /* Input        :       NO
 806          /* Output       :       NO
 807          /* Description: 初始化电机参数
 808          /*---------------------------------------------------------------------------*/
 809          void VariablesPreInit(void)
 810          {
 811                  /*************UQ爬坡速度**************/
 812                  RampStepInc = 60;
 813                  
 814                  /***********保护******************/
 815                  mcFaultSource = 0;
 816                  
 817                  memset(&mcFaultDect,0, sizeof(FaultVarible));                                                                                                                           // FaultVarible变量清零
 818          
 819            /*****外部控制环*******/
 820          //      memset(&mcFocCtrl,0, sizeof(FOCCTRL));                                                                                                                          // mcFocCtrl变量清零
 821                  mcFocCtrl.FreeStopDecStatus        = 0;
 822            
 823                  mcFocCtrl.OpenDutyCycle            = 0;
 824          
 825                  mcFocCtrl.RMSLimitTargetCurrent    = IQ_RUN_MAX_RMS_CURRENT; 
 826                  
 827          //      mcFocCtrl.mcBrakeStatus            = 0;
 828                          
 829                  mcFocCtrl.mcSpeedVSP               = 0;
 830                  
 831                  mcFocCtrl.mcADCVoltagebus          = 0;
 832                  
 833                  mcFocCtrl.OverCurrentFlag          = 0;
 834                  
 835                  mcFocCtrl.mcBlackOffStopFlag =0;   
 836                  
 837                  mcFocCtrl.mcADCVoltagebus                                        = 0;
 838          
 839                  mcFocCtrl.mcADCCurrentbus                                        = 0;
 840                  
 841                  mcFocCtrl.mcADCProtectCurrentbus   = 0;  
 842          
 843            /*****顺逆风判断*******/
 844                  #if (FRDetectMethod==RSDMethod)
                      {
C51 COMPILER V9.52.0.0   FOCCONTROLFUNCTION                                                09/21/2018 10:42:52 PAGE 15  

                        RSDDetect.RSDCCWTimes    = 0;                             //  CCW刹车次数清零
                      }
                      #elif (FRDetectMethod==BEMFMethod)
                      {
                              
                      }
                      #elif (FRDetectMethod==FOCMethod)
 853                  {
 854                   memset(&TailWindDetect,0, sizeof(MotorTailWindTypeDef));               //      TailWindDetect所有变量清零
 855                  }
 856            #endif
 857            /*****电机状态机时序变量***********/
 858            McStaSet.SetMode                   = 0;
 859          
 860                  /*****LED灯响应***/
 861                  memset(&mcLedDisplay,0, sizeof(MCLedDisplay));                                                                                          // mcLedDisplay变量清零
 862                  mcLedDisplay.Counttime            = 4999;
 863                  
 864                  memset(&MotorStateTime,0, sizeof(MotStaTim));                           //清零
 865                  
 866                  mcHall.HALLLockHCTime             = 0;
 867            mcHall.HALLLockHBTime             = 0;
 868                  mcHall.HALLLockHATime             = 0;
 869                  mcHall.HALLHACWCCWTime            = 0;
 870                  mcHall.HALLHBCWCCWTime            = 0;
 871                  mcHall.HALLHCCWCCWTime            = 0;
 872                  mcHall.HALLLockStatus             = 0;
 873                  mcHall.mcStallTimeCnt             = 0;
 874                  mcHall.mcFallWarningSignal        = 1;   
 875                  mcHall.RTheStep                   = 0;  
 876                  mcHall.PeriodTime                 = 0;  
 877                  mcHall.AngleCompensate            = 0;
 878                  mcHall.HallCommutationCnt         = 0;  
 879                  mcHall.HallFRreverse               =0;  
 880                  mcHall.HallDirectStartStatus                     = 0;                           
 881                  mcHall.StartAngleOffset                                    = 0;
 882                  mcHall.HallSpeedInitStatus         = 0;
 883                  
 884                  /********环路响应*********/ 
 885                  #if (Speed_Loop_Mode == Speed_OpenLoop_Enable)
 886                  SpeedRamp.RampInc                                                               = Motor_Voltage_Inc;
 887                  SpeedRamp.RampDec                                                                       =       Motor_Voltage_Dec;
 888                  SpeedRamp.RampTarget                                                    =       StartPWMDuty;
 889                  SpeedRamp.RampStep                                                              =       MinPWMDuty;
 890                  SpeedRamp.SPEEDRampTIMETemp       =  SPEEDRampTIME;
 891                  #endif
 892                  
 893          }
 894          /*---------------------------------------------------------------------------*/
 895          /* Name         :       void GetCurrentOffset(void)
 896          /* Input        :       NO
 897          /* Output       :       NO
 898          /* Description: 上电时，先对硬件电路的电流进行采集，写入对应的校准寄存器中。
 899                                                                          调试时，需观察mcCurOffset结构体中对应变量是否在范围内。采集结束后，Off
             -setFlag置1。
 900          /*---------------------------------------------------------------------------*/
 901          void GetCurrentOffset(void)
 902          {     
 903                    SetBit(ADC_CR, ADCBSY);                                          // 使能ADC
 904                          
 905                          while(ReadBit(ADC_CR, ADCBSY));
 906                          
C51 COMPILER V9.52.0.0   FOCCONTROLFUNCTION                                                09/21/2018 10:42:52 PAGE 16  

 907                          #if (Shunt_Resistor_Mode == Single_Resistor)                           // 29.2ms 单电阻模式，上电验证硬件电�
             -��时，需观察mcCurOffset.IbusOffset是否为4096
 908                    {
 909                                  mcCurOffset.Iw_busOffsetSum+=((ADC4_DR& 0x0fff) << 3);
 910                                  mcCurOffset.Iw_busOffset = mcCurOffset.Iw_busOffsetSum >> 4;
 911                                  mcCurOffset.Iw_busOffsetSum -= mcCurOffset.Iw_busOffset;
 912                          }
 913                          #elif (Shunt_Resistor_Mode == Double_Resistor)                             //44ms 双电阻模式，上电验证硬件电路�
             -�，需观察mcCurOffset.IaOffset、mcCurOffset.IbOffset是否为4096
                              {
                                      mcCurOffset.IuOffsetSum+=((ADC0_DR& 0x0fff) << 3);
                                      mcCurOffset.IuOffset = mcCurOffset.IuOffsetSum >> 4;
                                      mcCurOffset.IuOffsetSum -= mcCurOffset.IuOffset;
              
                                      mcCurOffset.IvOffsetSum+=((ADC1_DR& 0x0fff) << 3);
                                      mcCurOffset.IvOffset = mcCurOffset.IvOffsetSum >> 4;
                                      mcCurOffset.IvOffsetSum -= mcCurOffset.IvOffset;
                                      
                                      mcCurOffset.Iw_busOffsetSum+=((ADC4_DR& 0x0fff) << 3);
                                      mcCurOffset.Iw_busOffset = mcCurOffset.Iw_busOffsetSum >> 4;
                                      mcCurOffset.Iw_busOffsetSum -= mcCurOffset.Iw_busOffset;
                              }
                              #elif (Shunt_Resistor_Mode == Three_Resistor)                         //58.2ms 三电阻模式，上电验证硬件电�
             -�时，需观察mcCurOffset.IaOffset、mcCurOffset.IbOffset、mcCurOffset.IcOffset是否为4096
                              {
                                      mcCurOffset.IuOffsetSum+=((ADC0_DR& 0x0fff) << 3);
                                      mcCurOffset.IuOffset = mcCurOffset.IuOffsetSum >> 4;
                                      mcCurOffset.IuOffsetSum -= mcCurOffset.IuOffset;
              
                                      mcCurOffset.IvOffsetSum+=((ADC1_DR& 0x0fff) << 3);
                                      mcCurOffset.IvOffset = mcCurOffset.IvOffsetSum >> 4;
                                      mcCurOffset.IvOffsetSum -= mcCurOffset.IvOffset;
              
                                      mcCurOffset.Iw_busOffsetSum+=((ADC4_DR& 0x0fff) << 3);
                                      mcCurOffset.Iw_busOffset = mcCurOffset.Iw_busOffsetSum >> 4;
                                      mcCurOffset.Iw_busOffsetSum -= mcCurOffset.Iw_busOffset;                        
                              }
                              #endif
 942          
 943                          mcCurOffset.OffsetCount++;
 944                          
 945                          if(mcCurOffset.OffsetCount>Calib_Time)
 946                          {
 947                                  mcCurOffset.OffsetFlag=1;
 948              }
 949          }
 950          /*---------------------------------------------------------------------------*/
 951          /* Name         :       void Motor_Ready(void)
 952          /* Input        :       NO
 953          /* Output       :       NO
 954          /* Description: 上电时，关闭输出，先对硬件电路的电流进行采集，在FOC_Init中写入�
             -��应的校准寄存器中。
 955                          调试时，需观察mcCurOffset结构体中对应变量是否在范围内。
 956          /*---------------------------------------------------------------------------*/
 957          //void Motor_Ready(void)
 958          //{
 959          //   if(McStaSet.SetFlag.CalibFlag==0)
 960          //   {
 961          //     McStaSet.SetFlag.CalibFlag=1;
 962          //     ClrBit(DRV_CR, FOCEN);      // 关闭FOC
 963          //     MOE                      = 0;               // 关闭MOE
 964          //     SetBit(ADC_MASK_SYSC, CH7EN |CH4EN | CH3EN | CH2EN | CH1EN | CH0EN);// 开启ADC
C51 COMPILER V9.52.0.0   FOCCONTROLFUNCTION                                                09/21/2018 10:42:52 PAGE 17  

 965          //     mcCurOffset.OffsetFlag=0;   // 开始电流采集
 966          //   }
 967          //}
 968          /*---------------------------------------------------------------------------*/
 969          /* Name         :       void Motor_Init(void)
 970          /* Input        :       NO
 971          /* Output       :       NO
 972          /* Description: 对电机相关变量、PI进行初始化设置
 973          /*---------------------------------------------------------------------------*/
 974          void Motor_Init(void)
 975          {
 976          //   ClrBit(ADC_MASK_SYSC, CH4EN |  CH1EN | CH0EN);// 关闭软件电流采样的ADC
 977                   VariablesPreInit();                           // 电机相关变量初始化
 978          //       PI_Init();                                                    // PI初始化
 979          }
 980          #endif

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