C51 COMPILER V9.52.0.0   MC_USERINTERFACE_LAYER                                            08/21/2018 12:02:27 PAGE 1   


C51 COMPILER V9.52.0.0, COMPILATION OF MODULE MC_USERINTERFACE_LAYER
OBJECT MODULE PLACED IN .\obj\MC_UserInterface_layer.obj
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE User\Source\MC_UserInterface_layer.c LARGE OMF2 WARNINGLEVEL(0) OPTIMIZE(SI
                    -ZE) BROWSE NOAREGS INCDIR(.\Library\Include;.\User\Include) DEBUG PRINT(.\obj\MC_UserInterface_layer.lst) TABS(2) OBJECT
                    -(.\obj\MC_UserInterface_layer.obj)

line level    source

   1          
   2          /************************ (C) COPYRIGHT 2015 FT *******************************
   3          * File Name          : 
   4          * Author             : Application Team  Tom.wang 
   5          * Version            : V2.0.0
   6          * Date               : 06/15/2015
   7          * Description        : 用户接口层
   8          ********************************************************************************
   9          /*******************************************************************************
  10          * All Rights Reserved
  11          *******************************************************************************/
  12          
  13          /* Includes ------------------------------------------------------------------*/
  14          #include <FU6812_MCU.h>
  15          #include <sys_conf.h>
  16          #include <fu681x_Device.h>
  17          #include <interrupt.h>
  18          #include <Ftech_BLDC.h>
  19          #include <MC_Led.h>
  20          #include <MC_key.h>
  21          #include <MC_PwmIn.h>
  22          #include <MC_Beep.h>
  23          #include <MC_init.h>
  24          #include <MC_UserInterface_layer.h>
  25          #include <MC_MotorCotrol_layer.h>  
  26          #include <MC_MotorFunction_layer.h> 
  27          #include <MC_MotorDriver_layer.h>   
  28          
  29          /** @addtogroup FT68xx
  30            * @{
  31            */
  32          
  33          /* Private typedef -----------------------------------------------------------*/
  34          /* Private define ------------------------------------------------------------*/
  35          /* Private macro -------------------------------------------------------------*/
  36          /* Private variables ---------------------------------------------------------*/
  37          Ui_TypeDef xdata Ui;                  //变量定义
  38          float xdata tSpeedShiftcoefficient;   //速度系数
  39          s16 xdata tChipIDLEConter;            //低功耗
  40          /* Private function prototypes -----------------------------------------------*/
  41          void Ui_Function(void);            //全局函数  声明
  42          
  43          /* Private functions ---------------------------------------------------------*/
  44          
  45          /*******************************************************************************
  46          * Function Name  : UI
  47          * Description    : a、故障指示、温度计算、ADC转换、速度实际值计算 
  48                             b、正反转命令给定、速度命令给定
  49                             c、命令执行
  50          * Input          : None
  51          * Output         : None
  52          * Return         : None
  53          *******************************************************************************/
C51 COMPILER V9.52.0.0   MC_USERINTERFACE_LAYER                                            08/21/2018 12:02:27 PAGE 2   

  54          void Ui_Function(void)        //函数定义
  55          {  
  56   1        u16 xdata trefTar;
  57   1      //-----------------------------------------
  58   1      //故障指示
  59   1        Fault_Led(Ctl.SysError);
  60   1        
  61   1      //-----------------------------------------
  62   1      //档位指示，电量显示
  63   1        LED_show();
  64   1        
  65   1      //-----------------------------------------
  66   1      //ADC实际值转换
  67   1        ADCGetConversionValue();
  68   1      
  69   1      //-----------------------------------------  
  70   1      //实际转速 rpm 
  71   1      #if (SPEED_CALC_EN == 2)
  72   1        MDUFlag.CalcSpeedRpm = 1;    
  73   1      #endif
  74   1      //-----------------------------------------
  75   1      //过载判断
  76   1      #if(OVERLOAD_EN) 
                Ctl.OL.Value = MCL_OverLoadCalc(Drv.AdcMeas.ImeasBus);
              #endif
  79   1      
  80   1      //-----------------------------------------
  81   1      //温度计算  
  82   1      #if(OH1_EN)
                Drv.AdcMeas.Therm1 = Drv_PowerThermCalc(Drv.AdcMeas.Vth1);
              #endif
  85   1      
  86   1      #if(OH2_EN)
                Drv.AdcMeas.Therm2 = Drv_PowerThermCalc(Drv.AdcMeas.Vth2); //温度采样
              #endif
  89   1      
  90   1      #if(ESC_PPMSREFEN)
                MDUFlag.TargetSpeed = 1;  
                if(Ctl.State >= MOTOR_STOP)
                {
                  ESC_PPMSwitch();
                }
                BeepResponse();
              #endif
  98   1      //=====================================================
  99   1      //开关机 命令  速度给定 正反转给定
 100   1      //-----------------------------------------------------
 101   1      //ON/OFF 测试模式
 102   1      #if(0)
                if((Ctl.Tim.OnOffnms < 3000))   
                {
                  Ui.flg.START = FALSE;
                  
                  Ctl.SysError = NONE;  //清除故障
                  DRV_OE_ON;
                  Ctl.State = MOTOR_STOP; 
                }
                else if (Ctl.Tim.OnOffnms < 6000)
                {
                  if((Ctl.SysError == NONE)&&(Ui.flg.START == FALSE))
                  {
                    Ui.flg.START = TRUE;
C51 COMPILER V9.52.0.0   MC_USERINTERFACE_LAYER                                            08/21/2018 12:02:27 PAGE 3   

                  }
                }     
                else
                {
                  Ctl.Tim.OnOffnms = 0; 
                }
                #endif
 123   1      //=====================================================
 124   1      //---------------------------------------------------
 125   1      //正反转，档位命令给定
 126   1      ////Xn按键命令给定  -> 命令执行 轻触型开发
 127   1      #if(0)
                if(X1.Kflg == TRUE)
                {
                  X1.Kflg = FALSE;
                  X1.KNum = FALSE;
                  Ctl.Spd.SpeedShift++;
              
                 if(Ctl.Spd.SpeedShift > 3)
                  {
                    Ctl.Spd.SpeedShift = 1;
                  }
                  Rom.WriteValue = (u8)Ctl.Spd.SpeedShift;//掉电档位存储
                }
              
                if(Ctl.Spd.SpeedShift == 1)
                {
                  tSpeedShiftcoefficient = 0.8;
                }
                else if(Ctl.Spd.SpeedShift == 2)
                {
                 tSpeedShiftcoefficient = 0.9;
                }
                else if(Ctl.Spd.SpeedShift == 3)
                {
                  tSpeedShiftcoefficient = 1.0;
                }
              #endif
 154   1      //Xn端子命令给定  -> 命令执行   常开常闭型
 155   1      #if(0)
                if(X1.XCount == KEY_FILTERCOUNT)
                { 
                  Ui.flg.FR = CCW;
                }
                else if(X1.XCount == -KEY_FILTERCOUNT)
                {
                  Ui.flg.FR = CW;
                }
              #endif
 165   1      
 166   1      //Xn按键命令给定  -> 命令执行 轻触型开发
 167   1      #if(0)
                if(X0.Kflg == TRUE)
                {
                  X0.Kflg = FALSE;
                  X0.KNum = FALSE;
                   
                  if(Ui.flg.FR == CW)
                  {
                    Ui.flg.FR = CCW;
              //      Ctl.gDirectionC = Ui.flg.FR;    //方向控制
              //      SetBit(DRV_CR, DDIR); 
C51 COMPILER V9.52.0.0   MC_USERINTERFACE_LAYER                                            08/21/2018 12:02:27 PAGE 4   

              
                  }
                  else if(Ui.flg.FR == CCW)
                  {
                    Ui.flg.FR = CW;
              //      Ctl.gDirectionC = Ui.flg.FR;    //方向控制
              //      ClrBit(DRV_CR, DDIR);
                  }
                }
              
                if(X3.Kflg == TRUE)
                {
                  X3.Kflg = FALSE;
                  X3.KNum = FALSE;
                   
              //    if( Ctl.Is.refCur == 2000)
              //    {
              //      Ctl.Is.refCur = 10000;  
              //      Ctl.Is.refTar = 10000;
              //    }
              //    else
              //    {
              //      Ctl.Is.refCur = 2000;  
              //      Ctl.Is.refTar = 2000;    
              //    }
                }  
              #endif
 205   1      
 206   1        //Drv.AdcMeas.Sref = _IQ(1.0);  
 207   1      //---------------------------------------------------
 208   1      //启动命令给定 ADC启动、按键启动、端子启动
 209   1      //Xn按键命令给定  -> 命令执行 轻触型开发
 210   1      #if (KEYONOFF_EN == 1) 
                if(X2.Kflg == TRUE)
                {
                  X2.Kflg = FALSE;
                  X2.KNum = FALSE;
                  
                  if(Ui.flg.START == TRUE)
                  {
                    Ui.flg.START = FALSE;
                    if((Ctl.SysError != NONE)&&(Ctl.SysError !=E_ERR9))
                    {  
                      Ctl.SysError = NONE;  //清除故障
                      Ctl.State = MOTOR_STOP; 
                      DRV_OE_ON;
                    }      
                  }
                  else
                  {
                    Ui.flg.START = TRUE;
                  }      
                }
              #elif (KEYONOFF_EN == 2)
                if(X0.XCount == KEY_FILTERCOUNT)
                { 
                  Ui.flg.START = TRUE;
                  tChipIDLEConter = 0;
                }
                else if(X0.XCount == -KEY_FILTERCOUNT)
                {
                  Ui.flg.START = FALSE;
C51 COMPILER V9.52.0.0   MC_USERINTERFACE_LAYER                                            08/21/2018 12:02:27 PAGE 5   

              //    if(tChipIDLEConter >= 5000)        //5秒后进入低功耗模式 芯片睡眠电流1mA 不睡眠9mA
              //    {                                  //外部中断唤醒睡眠模式 需要打开外部中断
              //      tChipIDLEConter = 5000;
              //      SetBit(PCON, STOP);           //芯片休眠
              //    }
                }
              #elif(ADCONOFF_EN)
 247   1        //电位计开关
 248   1        //Drv.AdcMeas.Sref = _IQ(0.8);
 249   1        if(Drv.AdcMeas.Sref > SREF_IN_ONVALUE)
 250   1        {
 251   2          Ctl.Spd.SwitchCount++;
 252   2        }
 253   1        //else if((Drv.AdcMeas.Sref < _IQ(0.02))&&(Drv.PWM.DutyCur < _IQ(0.02)))
 254   1        else if(Drv.AdcMeas.Sref < SREF_IN_OFFVALUE)
 255   1        {
 256   2          Ctl.Spd.SwitchCount--;
 257   2        }
 258   1        if(Ctl.Spd.SwitchCount > SREFCOUNT)
 259   1        {
 260   2          Ctl.Spd.SwitchCount = SREFCOUNT;
 261   2          Ui.flg.START = TRUE;
 262   2        }   
 263   1        else if(Ctl.Spd.SwitchCount < -SREFCOUNT) 
 264   1        {
 265   2          Ctl.Spd.SwitchCount = -SREFCOUNT;
 266   2          Ui.flg.START = FALSE;
 267   2          Ctl.Spd.MechCircleNum = 0;
 268   2          if((Ctl.SysError != NONE)&&(Ctl.SysError !=E_ERR9))
 269   2          {  
 270   3           Ctl.SysError = NONE;  //清除故障
 271   3           Ctl.State = MOTOR_STOP; 
 272   3            DRV_OE_ON;
 273   3          }
 274   2        }  
 275   1      #endif
 276   1      
 277   1      //============================================================
 278   1      //速度给定
 279   1      #if(ADCSREF_EN) //ADC 调速
 280   1        //ADC->>MDUControl.SpeedSref->>MDUControl.TargetSpeed->>Ctl.Spd.refTar
 281   1        
 282   1        MDUFlag.TargetSpeed = 1;  //速度给定计算请求 
 283   1        //MDUControl.SpeedSref = Drv.AdcMeas.Sref*tSpeedShiftcoefficient;
 284   1        MDUControl.SpeedSref = Drv.AdcMeas.Sref;
 285   1        trefTar = MDUControl.TargetSpeed;
 286   1        
 287   1        #if(SPEED_CLOSE_EN) //速度闭环限速
                  if(trefTar > SPEED_INMAX)
                  {
                    Ctl.Spd.refTar = trefTar;
                  }
                #endif
 293   1        
 294   1         Ctl.Spd.refTar = (Ui.flg.FR == CCW)?  -trefTar: trefTar;
 295   1      
 296   1      #endif
 297   1      //=====================================================
 298   1      //无HALL 输出限幅 比较器触发模式
 299   1      #if (POS_FB_MODE == SensorLess) 
 300   1      
 301   1        #if (SPEED_CLOSE_EN)
C51 COMPILER V9.52.0.0   MC_USERINTERFACE_LAYER                                            08/21/2018 12:02:27 PAGE 6   

                  if(Ctl.Spd.refTar < Ctl.Ramp.DutyEnd)
                  {
                    Ctl.Spd.refTar = Ctl.Ramp.DutyEnd ;
                  }  
                #endif  
 307   1      
 308   1        if(Ctl.State == MOTOR_NORMAL)
 309   1        {
 310   2          Drv.PWM.DutyTar = Ctl.Spd.refTar;
 311   2          //高速关闭位置捕获中断 TOM++
 312   2          if(TIM1__BCCR < STB6C)
 313   2          {
 314   3            ClrBit(TIM1_IER, T1PDIE);       
 315   3          }
 316   2          else if(TIM1__BCCR > STB5C)
 317   2          {                                                                    
 318   3            SetBit(TIM1_IER, T1PDIE);      
 319   3          }    
 320   2        }
 321   1      #else
                Drv.PWM.DutyTar = Ctl.Spd.refTar;
              #endif
 324   1        
 325   1      //-----------------------------------------
 326   1      //命令执行
 327   1        if((Ui.flg.START == TRUE)&&(Ui.flg.FR != NONE))  
 328   1        {
 329   2          Ctl.gStartC = TRUE;
 330   2          gUserNoOperationDelaynms = 0;
 331   2        } 
 332   1        else if(Ui.flg.START == FALSE)
 333   1        {                   
 334   2          if(Ctl.gStopmodeC == FREE_DOWN)
 335   2          {
 336   3            Ctl.gStartC = FALSE;
 337   3          }
 338   2          else if(Ctl.gStopmodeC == SLOWING_DOWN)
 339   2          {
 340   3            Ctl.Spd.refTar = 0;
 341   3            if(Ctl.State == MOTOR_NORMAL)
 342   3            {
 343   4              #if(SPEED_CLOSE_EN)
              //        if(((Ctl.Spd.refCur<_IQ(0.05))))
              //        {
              //          Ctl.gStartC = FALSE;
              //        }      
              //        #else
              //        if((Drv.PWM.DutyCur < _IQ(0.05)))
              //        {
              //          Ctl.gStartC = FALSE;
              //        }      
                      #endif
 354   4            }
 355   3            else
 356   3            {
 357   4              Ctl.gStartC = FALSE;
 358   4            }
 359   3          } 
 360   2          else if(Ctl.gStopmodeC == BREAK_DOWN)
 361   2          {
 362   3            Ctl.gStartC = FALSE;
 363   3          }      
C51 COMPILER V9.52.0.0   MC_USERINTERFACE_LAYER                                            08/21/2018 12:02:27 PAGE 7   

 364   2        }
 365   1      }


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