⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mc_acim_drive.c

📁 STM8S105 BLDC源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
* Input         : None.
* Output        : None.
* Return        : None.
*******************************************************************************/
void ACIM_MTPA_Control(void)
{
  u16 hVoutmax;
    
  //stator electrical frequency = motor speed + constant (optimal) slip speed   
  freqout = actspeed_HzEl + ACIMmotor->pACIM_Var->hMTPAslip;
  
  //with reference to rated V/f ratio and stator electrical frequency to apply,
  //max stator voltage amplitude allowed
  hVoutmax = (u16)(((ACIMmotor->pACIM_Var->hVFConstant * (u32)freqout)/
                    (*pBusVoltage))/256);
  
  if (hVoutmax > 255)
  {
    hVoutmax = 255;
  }      
  
  //Stator voltage managed by the 'MTPA' speed PID regulator
  vout = PID_REG(targetspeed_HzEl,actspeed_HzEl,
                 ACIMmotor->pACIM_Const->pPID_MTPA_Struct);
  
  //Operation mode controller, area1 -> area2 transition:
  //if magnetizing flux > rated flux, switch to V/f and slip control
  if (vout > hVoutmax)
  {
    ACIMmotor->pACIM_Var->Actual_Control_Mode = SPEED_CLOSEDLOOP_VF;
    
    //'V/f' PID regulator integral term initialization
    ACIMmotor->pACIM_Const->pPID_VF_Struct->pPID_Var->wIntegral =
      ACIMmotor->pACIM_Var->hMTPAslip *
      ACIMmotor->pACIM_Const->pPID_VF_Struct->pPID_Const->hKi_Divisor;
    
    vout = hVoutmax;
  }
}

/*******************************************************************************
* Function Name : ACIM_VF_Control
* Description   : With reference to the operation control mode selected (#define
*                 CLOSEDLOOP_CONTROLMODE (MC_ACIM_Drive_Param.h) and the actual
*                 control mode:
*                 SPEED_CLOSEDLOOP_VF mode: this function implements the V/f
*                 and slip control method (constant V/f ratio, slip managed by the
*                 dedicated PID regulator);
*                 SPEED_CLOSEDLOOP_MTA:this function implements the MTPA strategy,
*                 control area 2 (constant V/f, slip managed by the dedicated
*                 PID regulator). The operation mode controller, area2 -> area1
*                 transition, is implemented.
* Input         : None.
* Output        : None.
* Return        : None.
*******************************************************************************/
void ACIM_VF_Control(void)
{
  //Slip speed managed by the 'V/f' speed PID regulator
  hSlip = PID_REG(targetspeed_HzEl,actspeed_HzEl,
                  ACIMmotor->pACIM_Const->pPID_VF_Struct);
  
  if (actspeed_HzEl < (-hSlip))
  {
    //negative (reversed) stator frequency should be avoided 
    freqout = 0;
  }
  else
  {
    //stator electrical frequency = slip speed + motor speed
    freqout = hSlip + actspeed_HzEl;
  }
  
  //stator voltage amplitude calculated according the rated V/f ratio
  vout = (u16)(((ACIMmotor->pACIM_Var->hVFConstant * (u32)freqout)
                /(*pBusVoltage))/256);
  
  //vout saturation and flux weakening;
  if (vout > 255)
  {
    vout = 255;
  }

  if (OperationControlMode == SPEED_CLOSEDLOOP_MTA)
  {    
    //Operation mode controller, area2 -> area1 transition:
    //if slip speed < optimum slip, switch to constant slip and V/f control
    if (hSlip > 0)  //deceleration in V/f mode should not give way to MTPA
    {
      if (ACIMmotor->pACIM_Var->hMTPAslip > hSlip)
      {
        ACIMmotor->pACIM_Var->Actual_Control_Mode = SPEED_CLOSEDLOOP_MTA;
        
        //'MTPA' PID regulator integral term initialization
        ACIMmotor->pACIM_Const->pPID_MTPA_Struct->pPID_Var->wIntegral =
          vout * ACIMmotor->pACIM_Const->pPID_MTPA_Struct->pPID_Const->hKi_Divisor;
      }
    }
  }
}

/*******************************************************************************
* Function Name : ACIM_StartUp_ClosedLoop
* Description   : This function implements the closed loop start-up strategy.
*                 It has three phases:
*                 1. enabling: virtual timer ACIMSTARTUP is loaded, start-up
*                 voltage boost is calculated and applied;
*                 2. startup is on going: motor speed is checked vs parameter
*                 STARTUP_VAL_SPEED (MC_ACIM_Drive_Param.h) but it's lower than
*                 the threshold;
*                 2. startup is ended: motor speed is checked vs parameter
*                 STARTUP_VAL_SPEED (MC_ACIM_Drive_Param.h) and it's higher than
*                 the threshold: PID regulators initial integral terms are
*                 calculated on the basis of last applied V/f ratio of slip
* Input         : None.
* Output        : None.
* Return        : None.
*******************************************************************************/
void ACIM_StartUp_ClosedLoop(void)
{
  u16 hVoutmax;
	
  if (vtimer_TimerElapsed(V_TIM_ACIMSTARTUP))
  //enabling: virtual timer ACIMSTARTUP is loaded
  {
    vtimer_SetTimer(V_TIM_ACIMSTARTUP,ACIMmotor->pACIM_Const->hStartup_duration,
                    (void*)(&ACIM_StartupEnded));
    
    //start-up voltage boost is calculated
    vout = (u8)(((ACIMmotor->pACIM_Const->hV_Constant *
                  ACIMmotor->pACIM_Const->bStartup_V0)/(*pBusVoltage))/10);
    
    bV0 = (u8)vout;
    freqout = 0;
  }
  else if (actspeed_HzMec > ACIMmotor->pACIM_Const->hStartup_val_speed)
  //startup procedure ended successfully, speed is higher than STARTUP_VAL_SPEED  
  {
    DriveStatus = FUNCTION_ENDED;
    vtimer_KillTimer(V_TIM_ACIMSTARTUP);
    
    //Speed PID regulator integral term initialization
    if (OperationControlMode == SPEED_CLOSEDLOOP_VF)
    {
      ACIMmotor->pACIM_Const->pPID_VF_Struct->pPID_Var->wIntegral = 
        ACIMmotor->pACIM_Var->hStartUpSlip *
        ACIMmotor->pACIM_Const->pPID_VF_Struct->pPID_Const->hKi_Divisor;
    }
    else if (OperationControlMode == SPEED_CLOSEDLOOP_MTA)
    {
      ACIMmotor->pACIM_Const->pPID_MTPA_Struct->pPID_Var->wIntegral =
        vout * ACIMmotor->pACIM_Const->pPID_MTPA_Struct->pPID_Const->hKi_Divisor;
    }
  }
  else
  //start-up procedure is on going 
  {
    DriveStatus = FUNCTION_RUNNING;        
    
    //stator electrical frequency = startup slip speed + motor speed
    freqout = ACIMmotor->pACIM_Var->hStartUpSlip + actspeed_HzEl;
 
    vout = vout + 1;    //startup ramp
    
    //with reference to startup V/f ratio and stator electrical frequency
    //to apply, max stator voltage amplitude allowed    
    hVoutmax = (u16)(((ACIMmotor->pACIM_Var->hStartUpVFConstant * (u32)freqout)/
                      (*pBusVoltage))/256)+ bV0;
    
    if (hVoutmax > 255)
    {
      hVoutmax = 255;
    }    
    
    if (vout > hVoutmax)
    {
      vout = hVoutmax;
    } 
  }
}
#endif


#if ((defined SPEED_OPEN_LOOP)||(defined SPEED_OPEN_LOOP_TACHO_SENSING))
/*******************************************************************************
* Function Name : ACIM_StartUp_OpenLoop
* Description   : This function implements the open loop start-up strategy.
*                 It has two phases:
*                 1. enabling: virtual timer ACIMSTARTUP is loaded, start-up
*                 voltage boost is calculated and applied;
*                 2. startup is on going:
* Input         : None.
* Output        : None.
* Return        : None.
*******************************************************************************/
void ACIM_StartUp_OpenLoop(void)
{  
  if (vtimer_TimerElapsed(V_TIM_ACIMSTARTUP))
  //enabling: virtual timer ACIMSTARTUP is loaded  
  {
    vtimer_SetTimer(V_TIM_ACIMSTARTUP,ACIMmotor->pACIM_Const->hStartup_duration,
                    (void*)(&ACIM_StartupEnded));
    
    ACIMmotor->pACIM_Var->hActual_rotor_speed_HzEl = 0;
    act_targetspeed_HzEl = 0;
    targetspeed_HzEl = ACIMmotor->pACIM_Const->hStartUpFinalSpeed_HzEl;
    
    hVFConstant = ACIMmotor->pACIM_Var->hStartUpVFConstant;
    
    hSlip = ACIMmotor->pACIM_Var->hStartUpSlip;
    
    //start-up voltage boost is calculated
    bV0 = (u8)(((ACIMmotor->pACIM_Const->hV_Constant *
                  ACIMmotor->pACIM_Const->bStartup_V0)/(*pBusVoltage))/10);
    
  } 
  else
  {
    //ACTIONS DURING STARTUP, if any
  }
  ACIM_OpenLoop();
}

/*******************************************************************************
* Function Name : ACIM_OpenLoop
* Description   : This function implements the open loop control strategy.
* Input         : None.
* Output        : None.
* Return        : None.
*******************************************************************************/
void ACIM_OpenLoop(void)
{
  //chech if needed to accelerate the motor
  if (targetspeed_HzEl != ACIMmotor->pACIM_Var->hActual_rotor_speed_HzEl)
  {
    //check if target speed has changed
    if (targetspeed_HzEl != act_targetspeed_HzEl)
    {
      //Calculate the new parameters for the acceleration
      s32 wDeltaSpeed;
  
      act_targetspeed_HzEl = targetspeed_HzEl;
      hInitialSpeed = ACIMmotor->pACIM_Var->hActual_rotor_speed_HzEl;
      wDeltaSpeed = ((s32)(targetspeed_HzEl - ACIMmotor->pACIM_Var->hActual_rotor_speed_HzEl))*1024;
      wAccelerationSteps = (wDeltaSpeed/ACIMmotor->pACIM_Var->hAccelerationSlope);
      
      if (wAccelerationSteps < 0)
      {
        wAccelerationSteps = - wAccelerationSteps;
      }
      
      hDeltaSpeedStep = (s16)(wDeltaSpeed/wAccelerationSteps);
      wDeltaSpeedIncr = 0;
      hSpeedReference = hInitialSpeed;
    }
    
    if (wAccelerationSteps == 0)
    {
      hSpeedReference = act_targetspeed_HzEl;
      ACIMmotor->pACIM_Var->hActual_rotor_speed_HzEl = act_targetspeed_HzEl;
    }
    else
    {
      wAccelerationSteps --;
      ACIMmotor->pACIM_Var->hActual_rotor_speed_HzEl = hSpeedReference;
      wDeltaSpeedIncr += hDeltaSpeedStep;
      hSpeedReference = hInitialSpeed + (s16)(wDeltaSpeedIncr/1024);
    }
  }
  
  if (DriveState == DRIVE_STARTUP)
  {
    //start-up voltage boost is applied
    vout = bV0;
  }
  else
  {
    vout = 0;
  }

  freqout = hSpeedReference + hSlip;
  vout += (u16)(((hVFConstant * (u32)freqout)/(*pBusVoltage))/256);
  
  //vout saturation and flux weakening;
  if (vout > 255)
  {
    vout = 255;
  }
}
#endif


#if (((defined SPEED_OPEN_LOOP)||(defined SPEED_OPEN_LOOP_TACHO_SENSING))&&\
    (OPENLOOP_CONTROLMODE==SPEED_OPENLOOP_LOAD_COMPENSATION))
s16 ACIM_LoadCompensation(s16 hTargetSpeedHzEl)
{
  s16 hSlipRef;
  u8 bSegment;
  
  s16 hTargetSpeedRPM;
  
  hTargetSpeedRPM = (hTargetSpeedHzEl*6)/ACIMmotor->pACIM_Const->bMotor_pole_Pairs;
    
  bSegment = (u8)(hTargetSpeedRPM/ACIMmotor->pACIM_Const->hSegdiv);
  if (bSegment > (u8)SEGMNUM)
  {
    bSegment = (u8)SEGMNUM;
  }
  
  hSlipRef = (s16)((ACIMmotor->pACIM_Const->wangc[bSegment]*hTargetSpeedRPM)
                   /32768 + ACIMmotor->pACIM_Const->wofst[bSegment]);
 
  return (hSlipRef);  
}
#endif

/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -