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


C51 COMPILER V9.52.0.0, COMPILATION OF MODULE MC_INIT
OBJECT MODULE PLACED IN .\obj\MC_init.obj
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE User\Source\MC_init.c LARGE OMF2 WARNINGLEVEL(0) OPTIMIZE(SIZE) BROWSE NOAR
                    -EGS INCDIR(.\Library\Include;.\User\Include) DEBUG PRINT(.\obj\MC_init.lst) TABS(2) OBJECT(.\obj\MC_init.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 <ESC_PPM.h>
  22          #include <ESC_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          
  30          /* Private typedef -----------------------------------------------------------*/
  31          /* Private define ------------------------------------------------------------*/
  32          /* Private macro -------------------------------------------------------------*/
  33          /* Private variables ---------------------------------------------------------*/
  34          //全关，UH->VL,UH->WL,VH->WL,VH->UL,WH->UL,WH->VL,刹车
  35          /* Private function prototypes -----------------------------------------------*/
  36          
  37          void SoftwareInit(void);          //软件初始化
  38          static void GPIO_Config(void);    //静态函数
  39          static void Interrupt_Config(void);
  40          static void EXTI_Config(void);
  41          void MCL_ModuleInit(void);        //初始化
  42          void MCL_ModuleDefault(void);     //默认值
  43          void gDelayus(u16 timer);
  44          void gDelayms(u16 timer);
  45          
  46          static void PWMinit(void);
  47          static void Bemfinit(void);
  48          static void HallDefault(void);
  49          static void BemfDefault(void);
  50          static void TimNmsDefault(void);
  51          
  52          /* Private functions ---------------------------------------------------------*/
  53          
  54          /*******************************************************************************
C51 COMPILER V9.52.0.0   MC_INIT                                                           08/21/2018 12:02:27 PAGE 2   

  55          * Function Name  : ApplicationInit   Peripheral
  56          * Description    :外设初始化
  57          * Input          : None
  58          * Output         : None
  59          * Return         : None
  60          *******************************************************************************/
  61          void SoftwareInit(void)
  62          {   
  63   1        // GPIO Configuration 
  64   1        GPIO_Config(); 
  65   1        // EXTI Configuration 
  66   1        //EXTI_Config();
  67   1        // Time1 Configuration 
  68   1        TIM1_Config();
  69   1        // TIM2 Configuration 
  70   1        //TIM2_Config();
  71   1        // TIM3 Configuration 
  72   1        #if(ESC_PPMSREFEN)
                TIM3_Config();
                ESC_PPMInit();
                #endif
  76   1        // TIM4 Configuration 
  77   1        TIM4_Config();
  78   1        // TIM5 Configuration 
  79   1        //TIM5_Config();  
  80   1        // AD Configuration 
  81   1        ADC_Config();
  82   1        // CMP Configuration
  83   1        CMP_Config();
  84   1        // AMP Configuration
  85   1        AMP_Config();
  86   1        // SPI Configuration
  87   1      //  SPI_Config();
  88   1       
  89   1        //KEY Configuration 
  90   1        Key_Config();
  91   1       
  92   1        //Hall Configuration
  93   1        #if (POS_FB_MODE == HallSensor)
                Hall_Init();
                #endif
  96   1        //USRT Configuration
  97   1        #if(UARTSREF_EN)
                USRT_Config();
                #endif
 100   1        //DMA Configuration
 101   1      //  DMA_Config();
 102   1        Set_DBG_DMA(0x4082);
 103   1        //Pid Configuration
 104   1        Pid_Config();
 105   1        //mdu Configuration
 106   1        MDU_Config();
 107   1        
 108   1        //INT Configuration
 109   1        Interrupt_Config();  
 110   1        //上电等待模块，等待电源稳定后启动
 111   1        Ctl.Tim.PowerOnNms = 0;                //
 112   1        Ctl.gPowerOnF == 0XFF;
 113   1      
 114   1      //  while(Ctl.Tim.PowerOnNms <= POWER_ON_NMS){}; 
 115   1      
 116   1        EA = 0;
C51 COMPILER V9.52.0.0   MC_INIT                                                           08/21/2018 12:02:27 PAGE 3   

 117   1        gDelayms(POWER_ON_NMS);
 118   1        EA = 1; 
 119   1        
 120   1        PDELAY_OFF;
 121   1        GP42 = 1;
 122   1          
 123   1        Ctl.gPowerOnF = 0x7F;//                              //上电完成
 124   1        Ctl.SysError = NONE;   
 125   1      
 126   1      }
 127          
 128          /*******************************************************************************
 129          * Function Name  : Interrupt_Config   
 130          * Description    : 中断优先级判断
 131          * Input          : None
 132          * Output         : None
 133          * Return         : None
 134          *******************************************************************************/
 135          void Interrupt_Config(void)
 136          {
 137   1        EA = 0;                                                    // 禁止全局中断
 138   1        #if (EFAL == FO_CMP)  
                  PCMP1 = 1;                                               // 中断优先级别为3
                  PCMP0 = 1;                                               
                #elif (EFAL == FO_INT)
                  ClrBit(P0_OE, P0_OE);                                   // config P00 as input
                  SetBit(P0_PU, P0_OE,);                                   // enable P00 pull up  
                  IF0 =0;
                  PX01 = 1;                                            
                  PX00 = 1; 
                #elif (EFAL == FO_CMPINT)
 148   1          PCMP1 = 1;                                               // 中断优先级别为3
 149   1          PCMP0 = 1;   
 150   1         /*EXTI中断配置*/                                          // 中断优先级别为3
 151   1          ClrBit(P0_OE, P0_OE);                                   // config P00 as input
 152   1          SetBit(P0_PU, P0_OE);                                   // enable P00 pull up 
 153   1          IF0 =0;
 154   1          PX01 = 1;                                            
 155   1          PX00 = 1;  
 156   1        #endif
 157   1      
 158   1        //drv中断
 159   1        PDRV1 = 1;                                              // 中断优先级设置为2，优先级低于FO硬件过流
 160   1        PDRV0 = 0;
 161   1          
 162   1        //TIM1 有HALL/CMP位置捕获用
 163   1        PTIM11 = 1;
 164   1        PTIM10 = 1;                                              // 中断优先级别为2
 165   1      
 166   1        //SYS_TICK&TIM4 100us定时器
 167   1        PTIM4S1 = 0;
 168   1        PTIM4S0 = 1;                                           // 中断优先级别为1
 169   1      
 170   1        //PWMIN 输入
 171   1        PTIM31 = 0;
 172   1        PTIM30 = 0;                                             // 中断优先级别为1
 173   1      
 174   1        #if(UARTSREF_EN)                                        //DMA
                PUART1 = 0;
                PUART0 = 0;                                             // 中断优先级别为1
                #endif                                                     
 178   1      
C51 COMPILER V9.52.0.0   MC_INIT                                                           08/21/2018 12:02:27 PAGE 4   

 179   1        //ADC中断配置 电流采样自动采样 PWMON
 180   1        PADC1 = 0;
 181   1        PADC0 = 0;                                              // 中断优先级别为0
 182   1      
 183   1        EA = 1;                                                 // 使能全局中断
 184   1      }
 185          
 186          /*******************************************************************************
 187          * Function Name  : EXTI_Config   
 188          * Description    : 中断优先级判断
 189          * Input          : None
 190          * Output         : None
 191          * Return         : None
 192          *******************************************************************************/
 193          
 194          void EXTI_Config(void)
 195          {
 196   1        ClrBit(P0_OE, P00);  // config P00 as input
 197   1        ClrBit(P0_PU, P00);  // diasable P00 Pull Up
 198   1        //  ClrBit(P0_AN, P00_AN);  // diasable P00 analog function
 199   1        IF0 = 0;               // clear P00 interrupt flag  
 200   1        //  SetBit(P1IE, P10);   // config P00 as the source of EXTI1
 201   1      
 202   1        IT11 = 0;
 203   1        IT10 = 0;               // 00: posedge mode interrupt，01: negedge mode interrupt，1x: edge-change mode 
             -interrupt
 204   1      
 205   1        PX11 = 1;
 206   1        PX10 = 0;               // 中断优先级别2，中断优先级最高
 207   1      
 208   1        EX0 = 1;                // 使能外部中断0
 209   1      }
 210          /*******************************************************************************
 211          * Function Name  : GPIO_Config
 212          * Description    : GPIO配置
 213          * Input          : None
 214          * Output         : None
 215          * Return         : None
 216          *******************************************************************************/
 217          void GPIO_Config(void)
 218          {    
 219   1        //-------------------------------------  
 220   1        //FD6536 使能 
 221   1      //  #if(FD6536PIN_EN)  
 222   1      //  SetBit(P0_OE,P01);  //输入使能
 223   1      ////  SetBit(X0_PU,X0_PIN);         //上拉电阻
 224   1      //  GP01 = 1;
 225   1      //  #endif
 226   1        SetBit(P4_OE,P42);  //输入使能
 227   1        
 228   1        
 229   1        //------------------------------------  
 230   1        SetBit(PDELAY_GPIO_PORT,PDELAY_PIN); 
 231   1        PDELAY_ON;
 232   1        
 233   1        //-------------------------------------  
 234   1        //FG
 235   1        SetBit(FG_GPIO_PORT,FG_PIN); 
 236   1        //TIM2
 237   1        SetBit(P1_OE,P10);
 238   1        GP10 = 1;
 239   1      //  //-------------------------------------  
C51 COMPILER V9.52.0.0   MC_INIT                                                           08/21/2018 12:02:27 PAGE 5   

 240   1      //  //故障输出
 241   1        SetBit(FAULT_GPIO_PORT,FAULT_PIN);
 242   1        FAULT_OFF;
 243   1      
 244   1        SetBit(NSS_GPIO_PORT,NSS_PIN); 
 245   1        SetBit(MOSI_GPIO_PORT,MOSI_PIN); 
 246   1        SetBit(SCLK_GPIO_PORT,SCLK_PIN); 
 247   1        SetBit(MISO_GPIO_PORT,MISO_PIN);   
 248   1          
 249   1        //LED显示设置       电量显示
 250   1        SetBit(LED1_GPIO_PORT,LED1_PIN); 
 251   1        SetBit(LED2_GPIO_PORT,LED2_PIN); 
 252   1        SetBit(LED3_GPIO_PORT,LED3_PIN); 
 253   1      //  LED1_OFF;  
 254   1        LED2_OFF; 
 255   1        LED3_OFF; 
 256   1        gDelayms(200);
 257   1        LED1_ON;  
 258   1        LED2_ON; 
 259   1        LED3_ON; 
 260   1        gDelayms(200);
 261   1        LED1_OFF;  
 262   1        LED2_OFF; 
 263   1        LED3_OFF; 
 264   1        gDelayms(200);
 265   1        LED1_ON;  
 266   1        LED2_ON; 
 267   1        LED3_ON; 
 268   1      }
 269          
 270          /*******************************************************************************
 271          * Function Name  : LED_show
 272          * Description    : 
 273          * Input          : 
 274          * Output         : None
 275          * Return         : None
 276          *******************************************************************************/
 277          void MCL_ModuleInit(void)
 278          {
 279   1        //----------------------------------
 280   1        Ctl.SysError = NONE; 
 281   1        
 282   1        #if (CURRENT_CLOSE_EN==3)
                Power.ref = CURRENT_REF_TAR; 
                #endif
 285   1        #if(LAMP_EN) //扳手螺丝批，延时掉电程序
                Rom.ReadValue = Flash_GetAddress();    //4.88ms 
                Rom.WriteValue = Rom.ReadValue;  
                if(Rom.WriteValue == 0x7F)
                {
                  Ctl.Spd.SpeedShift = 3;
                }
                else
                {
                  Ctl.Spd.SpeedShift = Rom.WriteValue;
                }
                #endif
 297   1      
 298   1        //----------------------------------
 299   1        //控制参数初始化  
 300   1        Ctl.Tim.numTicksPerCurrent = 2;                   //2
 301   1        Ctl.Tim.numTicksPerSpeed = SPEED_CTL_CNT;         //6
C51 COMPILER V9.52.0.0   MC_INIT                                                           08/21/2018 12:02:27 PAGE 6   

 302   1        
 303   1        //----------------------------------
 304   1        // 电机运行方向设置 端子控制
 305   1        Ui.flg.FR = DIRECTION ;  
 306   1      
 307   1        Ctl.gStopmodeC = STOPMODE;
 308   1      
 309   1        DRV_CMR = PWMOUT_OFF;
 310   1      
 311   1        //----------------------------------
 312   1        // 母线电压增益  电流增益   BEMF增益
 313   1        ADCInit();
 314   1        //----------------------------------
 315   1        //PWM初始化
 316   1        PWMinit();
 317   1        //----------------------------------
 318   1        //速度闭环 加减速时间  
 319   1        #if(SPEED_CLOSE_EN)
                Ctl.Spd.refCur = 0;  
                Ctl.Spd.refTar = SPEED_REF_TAR;
                Ctl.Spd.IncValue = SPEED_INCVALUE;
                Ctl.Spd.DecValue = SPEED_DECVALUE;
                pid_spd.Kp = SPEED_PTERM; //Q15格式
                pid_spd.Ki = SPEED_ITERM; //Q15格式
                Pid_spdInit(); 
                #endif
 328   1        //----------------------------------  
 329   1        #if (CURRENT_CLOSE_EN >1)
                //电流环初始化
                Ctl.Is.refCur = _IQ(0.01);  
                Ctl.Is.refTar = _IQ(0.01);
                pid_is.Kp = CURRENT_PTERM; //Q15格式
                pid_is.Ki = CURRENT_ITERM; //Q15格式
                Pid_isInit(); 
                #endif
 337   1        //----------------------------------  
 338   1        #if(MOTORCIRCLECALEEN)     
                Ctl.Spd.ComNum  = 0;
                Ctl.Spd.MechCircleNum = 0;
                #endif
 342   1        //----------------------------------
 343   1        //速度计算模块初始化
 344   1        Drv.speed.EventPeriod = 0;    
 345   1        Drv.speed.InputSelect = 1;
 346   1        Drv.speed.BaseRpm = BASE_SPEED; 
 347   1        Drv.speed.SpeedScaler = SPEEDSCALER ;
 348   1        
 349   1        //----------------------------------
 350   1        #if (POS_FB_MODE == SensorLess) 
 351   1        Bemfinit();
 352   1        #else
                HallDefault();
                #endif
 355   1        //==================================
 356   1        #if(OCRESTART_EN)
                Ctl.OC.u16Runms = 0;
                Ctl.OC.u16nmsCount = 0;
                Ctl.OC.u8ReNum = 0;
                #endif
 361   1        //----------------------------------
 362   1        #if(OVERLOAD_EN)
                MCL_OverLoadInit(MECASEOVERLOAD0,MECASEOVERLOAD1,MECASEOVERLOAD2,MECASEOVERLOAD3,OL0NMS,OL1NMS,OL2NMS,OL
C51 COMPILER V9.52.0.0   MC_INIT                                                           08/21/2018 12:02:27 PAGE 7   

             -3NMS);  
                #endif
 365   1        
 366   1        BeepRequestFun(PWMINinit);
 367   1      }
 368          
 369          /*******************************************************************************
 370          * Function Name  : MCL_ModuleDefault
 371          * Description    : ready状态执行一次
 372          * Input          : 
 373          * Output         : None
 374          * Return         : None
 375          *******************************************************************************/
 376          void MCL_ModuleDefault(void)
 377          {
 378   1        //----------------------------------
 379   1        //电机运行方向设置 端子控制
 380   1      
 381   1        if(Ui.flg.FR == CW)
 382   1        {
 383   2          Ctl.gDirectionC = Ui.flg.FR;    //方向控制
 384   2          ClrBit(DRV_CR, DDIR);
 385   2        }
 386   1        else if(Ui.flg.FR == CCW)
 387   1        {
 388   2          Ctl.gDirectionC = Ui.flg.FR;    //方向控制
 389   2          SetBit(DRV_CR, DDIR); 
 390   2        }
 391   1        //----------------------------------
 392   1        //Step 清零
 393   1        Ctl.gStepCur = 5;
 394   1        Ctl.gStepPre = 0;
 395   1      
 396   1        #if(STALLRESTARTNUM)     //堵转重启
 397   1        Ctl.Stall.WaitReatartNms = 0;              
 398   1        #endif
 399   1        
 400   1        #if (POS_FB_MODE == SensorLess) 
 401   1        BemfDefault();           //BEMF清零
 402   1        #else
                HallDefault();
                #endif
 405   1      //----------------------------------
 406   1        #if(SPEED_CLOSE_EN)     //速度闭环
                Ctl.Spd.refCur = 0;  
                Pid_spdInit();  
                #else       
 410   1        Ctl.Spd.refTar = MOTOR_TARGRT_DUTY;
 411   1        Drv.PWM.DutyTar = Ctl.Spd.refTar;
 412   1        Drv.PWM.DutyCur    = 0;  
 413   1        #endif
 414   1      
 415   1        #if(CURRENT_CLOSE_EN>1)
                Pid_isInit();          //电流闭环
                #endif
 418   1      //----------------------------------
 419   1        TimNmsDefault();       //计时器清零
 420   1        Key_init();            //端子清零
 421   1      
 422   1      //==================================
 423   1        #if(MOTORCIRCLECALEEN)  //运行圈数计算
                Ctl.Spd.ComNum  = 0;
C51 COMPILER V9.52.0.0   MC_INIT                                                           08/21/2018 12:02:27 PAGE 8   

                Ctl.Spd.MechCircleNum = 0;
                #endif
 427   1        
 428   1        #if(FAILSTOREEN) //故障记录
                Ctl.E_message.State = MOTOR_NONE;
                Ctl.E_message.ErrorF = 0;
                #endif
 432   1        
 433   1        #if(OVERLOAD_EN) //过载
                MCL_OverLoadInit(MECASEOVERLOAD0,MECASEOVERLOAD1,MECASEOVERLOAD2,MECASEOVERLOAD3,OL0NMS,OL1NMS,OL2NMS,OL
             -3NMS);  
                #endif
 436   1        
 437   1        #if(FO_EN)   //逐波限流
                Ctl.FO.FoCounter = 0;
                Ctl.FO.ReCounter = 0;
                #endif
 441   1        
 442   1        #if(BEEPSCAN_EN) //电机发声
                Beep.BeepRequest = 0xFF;
                Beep.BeepType = 0;
                #endif
 446   1      }
 447          
 448          
 449          void Bemfinit(void)
 450          {
 451   1        Ctl.Bemf.TestOut = BEMF_DEBUG;
 452   1        
 453   1        Ctl.Ramp.cpmode = RAMP_MODE;
 454   1        //定位，拖动参数设定
 455   1        #if (MOTORROTORCALC == 2)
                Ctl.Alig.duty   = 0; 
                Ctl.Alig.timNms = 0;
                #else
 459   1        Ctl.Alig.duty   = ALIGNMENTDUTY; 
 460   1        Ctl.Alig.timNms = ALIGNMENTNMS;  
 461   1        #endif
 462   1      
 463   1        //启动参数调整区
 464   1        Ctl.Ramp.ComCnt = 0;
 465   1        Ctl.Ramp.cpNms = RAMP_TIM_STA;
 466   1        Ctl.Ramp.cpNmsCount = 0;
 467   1        Ctl.Ramp.TimSta   = RAMP_TIM_STA;
 468   1        Ctl.Ramp.TimEnd   = RAMP_TIM_END;
 469   1        Ctl.Ramp.TimStep  = RAMP_TIM_STEP;       
 470   1        Ctl.Ramp.DutySta  = RAMP_DUTY_STA;
 471   1        Ctl.Ramp.DutyEnd  = RAMP_DUTY_END;
 472   1        Ctl.Ramp.Dutystep = RAMP_DUTY_INC;
 473   1        Ctl.Ramp.ComNum   = RAMP_COM_CNT;
 474   1        Ctl.Ramp.BemfErrCnt = 0;
 475   1        Ctl.Ramp.FailCnt = 0;
 476   1        Ctl.Ramp.BemfTureNum = RAMP_TURE_NUM ;
 477   1        Ctl.Ramp.BemfTureCnt = 0;
 478   1        Ctl.Ramp.BemfErrNum = RAMP_ERR_NUM;
 479   1        Ctl.Ramp.MaskTime =  TempRampMaskTime;
 480   1        Ctl.Bemf.CTAngle =   RUN_ANGLE_MASK;
 481   1        Ctl.Bemf.MaskAngle = RUN_ANGLE_DELAY;
 482   1      
 483   1        Drv.Stk.Calcnms = 0x7F;  
 484   1        Drv.Stk.Calcnum = SRKBNUM;
 485   1      
C51 COMPILER V9.52.0.0   MC_INIT                                                           08/21/2018 12:02:27 PAGE 9   

 486   1        MDUControl.DelayAngle = 0;
 487   1      }
 488          
 489          void PWMinit(void)
 490          {
 491   1      
 492   1        Ctl.Spd.IncValue = SPEED_INCVALUE;
 493   1        Ctl.Spd.DecValue = SPEED_DECVALUE;
 494   1        Drv.PWM.DutyCur    = 0;
 495   1        Drv.PWM.DutyTar     = 0;  
 496   1        Drv.PWM.DutyIncValue  = SPEED_INCVALUE;
 497   1        Drv.PWM.DutyDecValue  = SPEED_DECVALUE;
 498   1        Drv.PWM.DutyMax = MOTOR_VS_MAX;
 499   1        Drv.PWM.DutyMin = MOTOR_VS_MIN;
 500   1        Drv.PWM.DutyLimitMaxRef = MECASECURRENTLIMITMAXREF;
 501   1        Drv.PWM.DutyLimitValue = LIMIT_DUTYINCDEC;
 502   1      }
 503          void HallDefault(void)
 504          {
 505   1        ANGLE_MASK(0);
 506   1        ClrBit(TIM1_CR0, T1OPS0);    //00 软件触发 01重载触发 10位置检测触发 11重载/基本上溢触发
 507   1        ClrBit(TIM1_CR0, T1OPS1);
 508   1        Drv.Hall.u8ChangePhaseNum = 0;  
 509   1      
 510   1        #if ((HALLADVANCEEANGLE_CW)||(HALLADVANCEEANGLE_CCW))
                if(Ctl.gDirectionC == CW)
                {
                  Drv.Hall.s16AdvanceEangle = TEMPHALLADVANCEEANGLE_CW; //HALL位置反馈换相超前角度
                }
                else
                {
                  Drv.Hall.s16AdvanceEangle = TEMPHALLADVANCEEANGLE_CCW; //HALL位置反馈换相超前角度
                }    
                
                if(Drv.Hall.s16AdvanceEangle < -50.0/60.0*32767)
                {
                  Drv.Hall.s16AdvanceEangle = -50.0/60.0*32767;
                }
                else if(Drv.Hall.s16AdvanceEangle == 0)
                {
                  Drv.Hall.s16AdvanceEangle = 0;
                }
                else if(Drv.Hall.s16AdvanceEangle > 30/60.0*32767)
                {
                  Drv.Hall.s16AdvanceEangle = 30.0/60.0*32767;
                }
                #endif
 533   1      }
 534          
 535          void BemfDefault(void)
 536          {
 537   1        
 538   1        //----------------------------------
 539   1        //电机运行方向设置 端子控制
 540   1        if(Ui.flg.FR == CW)
 541   1        {
 542   2          Ctl.gDirectionC = Ui.flg.FR;    //方向控制
 543   2          ClrBit(DRV_CR, DDIR);
 544   2        }
 545   1        else if(Ui.flg.FR == CCW)
 546   1        {
 547   2          Ctl.gDirectionC = Ui.flg.FR;    //方向控制
C51 COMPILER V9.52.0.0   MC_INIT                                                           08/21/2018 12:02:27 PAGE 10  

 548   2          SetBit(DRV_CR, DDIR); 
 549   2        }  
 550   1      
 551   1        if(Ctl.gDirectionC == CCW)
 552   1        {//正反转 CCW 反转
 553   2          TIM1_DBR1 = UH_VLB + CMP_W_DO;
 554   2          TIM1_DBR2 = UH_WLB + CMP_V_UP;
 555   2          TIM1_DBR3 = VH_WLB + CMP_U_DO;
 556   2          TIM1_DBR4 = VH_ULB + CMP_W_UP;
 557   2          TIM1_DBR5 = WH_ULB + CMP_V_DO;
 558   2          TIM1_DBR6 = WH_VLB + CMP_U_UP;
 559   2          TIM1_DBR7 = CMP_UVW_UPDO_PWMOFF;
 560   2        }
 561   1        else //(Ctl.gDirectionC == CW)
 562   1        { //正反转 CW  正转
 563   2          TIM1_DBR1 = UH_VLA + CMP_W_DO;
 564   2          TIM1_DBR2 = UH_WLA + CMP_V_UP;
 565   2          TIM1_DBR3 = VH_WLA + CMP_U_DO;
 566   2          TIM1_DBR4 = VH_ULA + CMP_W_UP;
 567   2          TIM1_DBR5 = WH_ULA + CMP_V_DO;
 568   2          TIM1_DBR6 = WH_VLA + CMP_U_UP;
 569   2          
 570   2          TIM1_DBR7 = CMP_UVW_UPDO_PWMOFF;
 571   2        }  
 572   1        
 573   1        Drv.Stk.BemfTabA = 0;
 574   1        Drv.Stk.BemfTabB = 0;
 575   1        Drv.Stk.RefNumX = 0;
 576   1        Drv.Stk.RefNumY = 0;
 577   1        Drv.Stk.RefNumZ = 0;
 578   1        Drv.Stk.BemfFR = 0xFF;
 579   1      
 580   1        //启动参数调整区
 581   1        Ctl.Ramp.ComCnt = 0;
 582   1        Ctl.Ramp.cpNms = Ctl.Ramp.TimSta;
 583   1        Ctl.Ramp.cpNmsCount = 0;
 584   1        Ctl.Ramp.BemfErrCnt = 0;
 585   1        Ctl.Ramp.FailCnt = 0;
 586   1      
 587   1        Ctl.Ramp.BemfTureCnt = 0;  
 588   1        //Ctl.Bemf.MaskTime = TempRampMaskTime;
 589   1        Drv.speed.EventPeriodPer = 0;
 590   1      
 591   1        MDUControl.DelayAngle = 0;
 592   1      
 593   1        ClrBit(CMP_CR3, SAMSEL1);     // 使能ON OFF全部采样
 594   1        ClrBit(CMP_CR3, SAMSEL0);   
 595   1      
 596   1        CMP_SAMR = 0;
 597   1        ANGLE_MASK(0);
 598   1          
 599   1        TIM1_DBR7 = CMP_UVW_UPDO_PWMOFF;        //检测UVW反电势
 600   1        TIM1_CR4 = 7;                    //选择 TIM1_DBR7
 601   1      
 602   1        ClrBit(TIM1_CR0, T1OPS0);       //软件触发UPD
 603   1        ClrBit(TIM1_CR0, T1OPS1);
 604   1        SetBit(TIM1_IER, T1UPD);       //位置检测中断
 605   1        
 606   1      }
 607          void TimNmsDefault(void)
 608          {
 609   1        //----------------------------------
C51 COMPILER V9.52.0.0   MC_INIT                                                           08/21/2018 12:02:27 PAGE 11  

 610   1        //过压欠压判断时间，堵转 参数清零
 611   1        Ctl.Tim.OVnms = 0;
 612   1        Ctl.Tim.UVnms = 0;
 613   1        Ctl.Tim.Nonms = 0;
 614   1        Ctl.Tim.OCnms = 0;
 615   1        Ctl.Tim.OH1nms = 0;
 616   1        Ctl.Tim.OH1REnms = 0;
 617   1        Ctl.Tim.OH2nms = 0;
 618   1        Ctl.Tim.OH2REnms = 0;
 619   1      
 620   1        Ctl.Tim.STAnms = 0;           //堵转
 621   1        Ctl.Tim.STB1nms = 0;          //失速1
 622   1        Ctl.Tim.STB2nms = 0;          //失速2
 623   1      }
 624          
 625          
 626          void gDelayus(u16 timer)        //1.042us+n*1us
 627          {
 628   1        while(timer--) 
 629   1        {
 630   2          _nop_();_nop_();_nop_();_nop_();_nop_();
 631   2          _nop_();_nop_();_nop_();_nop_();_nop_(); 
 632   2        }
 633   1      }
 634          
 635          void gDelayms(u16 timer)       //1ms
 636          {
 637   1        while(timer--) gDelayus(999);
 638   1      }


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