永磁同步电机(正弦无感)学习 (12)

一、内容
开始正弦波无霍尔程序的学习。
二、知识点
正弦波无霍尔程序和有霍尔程序大致相似,只在部分程序上面有所差别,主要通过对比正弦波无霍尔和有霍尔程序的区别进行学习
1.速度/位置检测
1.1霍尔传感器反馈处理:
1.1.1位置测量:

当程序定义了HALL_SENSORS,则程序会选择程序进行执行:

#elif defined HALL_SENSORS
 HALL_HallTimerInit();
 #endif
	HALL_HallTimerInit()函数的功能是初始化霍尔传感器反馈过程中的外设,主要程序如下所示:
void HALL_HallTimerInit(void)
{
  TIM_TimeBaseInitTypeDef TIM_HALLTimeBaseInitStructure;
  TIM_ICInitTypeDef       TIM_HALLICInitStructure;
  NVIC_InitTypeDef        NVIC_InitHALLStructure;
  GPIO_InitTypeDef        GPIO_InitStructure;
 #if defineddefined(TIMER3_HANDLES_HALL)
	GPIO_PinRemapConfig(GPIO_FullRemap_TIM3, ENABLE);
    /* TIM3 clock source enable */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
    /* Enable GPIOA, clock */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO, ENABLE);
    GPIO_StructInit(&GPIO_InitStructure);
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7| GPIO_Pin_8;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOC, &GPIO_InitStructure);
  #endif
    TIM_DeInit(HALL_TIMER); 
    TIM_TimeBaseStructInit(&TIM_HALLTimeBaseInitStructure);
    TIM_HALLTimeBaseInitStructure.TIM_Period = U16_MAX;
    TIM_HALLTimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
    TIM_TimeBaseInit(HALL_TIMER,&TIM_HALLTimeBaseInitStructure); 
    TIM_ICStructInit(&TIM_HALLICInitStructure);
    TIM_HALLICInitStructure.TIM_Channel = TIM_Channel_1;
    TIM_HALLICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;
    TIM_HALLICInitStructure.TIM_ICFilter = ICx_FILTER; 
    TIM_ICInit(HALL_TIMER,&TIM_HALLICInitStructure); 
TIM_PrescalerConfig(HALL_TIMER,(u16)HALL_MAX_RATIO,TIM_PSCReloadMode_Immediate);
    TIM_InternalClockConfig(HALL_TIMER); 
    TIM_SelectHallSensor(HALL_TIMER, ENABLE); 
    TIM_SelectInputTrigger(HALL_TIMER, TIM_TS_TI1FP1);
    TIM_SelectSlaveMode(HALL_TIMER,TIM_SlaveMode_Reset);
    TIM_UpdateRequestConfig(HALL_TIMER, TIM_UpdateSource_Regular);
#if defined(TIMER2_HANDLES_HALL)
    NVIC_InitHALLStructure.NVIC_IRQChannel = TIM2_IRQChannel;
#elif defined(TIMER3_HANDLES_HALL)
    NVIC_InitHALLStructure.NVIC_IRQChannel = TIM3_IRQChannel;
#else // TIMER4_HANDLES_HALL
    NVIC_InitHALLStructure.NVIC_IRQChannel = TIM4_IRQChannel;
#endif
    NVIC_InitHALLStructure.NVIC_IRQChannelPreemptionPriority = TIMx_PRE_EMPTION_PRIORITY;
    NVIC_InitHALLStructure.NVIC_IRQChannelSubPriority = TIMx_SUB_PRIORITY;
    NVIC_InitHALLStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitHALLStructure);
    TIM_ClearFlag(HALL_TIMER, TIM_FLAG_Update + TIM_FLAG_CC1 + TIM_FLAG_CC2 + \ TIM_FLAG_CC3 + TIM_FLAG_CC4 + TIM_FLAG_Trigger + TIM_FLAG_CC1OF + \TIM_FLAG_CC2OF + TIM_FLAG_CC3OF + TIM_FLAG_CC4OF);
    TIM_ITConfig(HALL_TIMER, TIM_IT_CC1, ENABLE);
    TIM_ITConfig(HALL_TIMER, TIM_IT_Update, ENABLE);
    TIM_SetCounter(HALL_TIMER, HALL_COUNTER_RESET);
    TIM_Cmd(HALL_TIMER, ENABLE);
} 

这里通过定义TIMER3_HANDLES_HALL,来选择定时器3来作为“接口定时器”来连接霍尔传感器。
并且通过对GPIOD重映射,让PD6、PD7和PD8来作为定时器引脚输入。
对定时器设置计数器自动重装值为65535,内部时钟分频因子为1,即不分频。并设置定时器捕获模式。
1.1.2速度测量:
滚动识别:

bPrevHallState = bHallState;
bHallState = ReadHallState();
#if (HALL_SENSORS_PLACEMENT == DEGREES_120)    
    switch(bHallState)
    {
      case STATE_5:
        if (bPrevHallState == STATE_5)
        {
         if(bSpeed<0)
         {
           bSpeed = POSITIVE_SWAP;
         }
         else
         {
           bSpeed = NEGATIVE_SWAP;
         }
        }
        else   
          if (bPrevHallState == STATE_6)
          {
           bSpeed = POSITIVE;
          }
          else 
            if (bPrevHallState == STATE_3)
            {
              bSpeed = NEGATIVE;
            }
		// Update angle
        if(bSpeed<0)
        {
          hElectrical_Angle = (s16)(S16_PHASE_SHIFT+S16_60_PHASE_SHIFT);
        }
        else if(bSpeed!= ERROR)
        {
          hElectrical_Angle = S16_PHASE_SHIFT;  
        }
        break; 
    case STATE_3:
        if (bPrevHallState == STATE_3)
        {
		 //a speed reversal occured
         if(bSpeed<0)
         {
           bSpeed = POSITIVE_SWAP;
         }
         else
         {
           bSpeed = NEGATIVE_SWAP;
         }
        }
        else
          if (bPrevHallState == STATE_5)
          {
           bSpeed = POSITIVE;
          }
          else 
            if (bPrevHallState == STATE_6)
            {
              bSpeed = NEGATIVE;
            }
		// Update of the electrical angle
        if(bSpeed<0)
        {
          hElectrical_Angle = (s16)(S16_PHASE_SHIFT+S16_120_PHASE_SHIFT+
                                                            S16_60_PHASE_SHIFT);
        }
        else if(bSpeed!= ERROR)
        {
          hElectrical_Angle =(s16)(S16_PHASE_SHIFT + S16_120_PHASE_SHIFT);
        }
        break; 
      case STATE_6: 
        if (bPrevHallState == STATE_6)
        {
         if(bSpeed<0)
         {
           bSpeed = POSITIVE_SWAP;
         }
         else
         {
           bSpeed = NEGATIVE_SWAP;
         }
        }
        if (bPrevHallState == STATE_3)
        {
         bSpeed = POSITIVE; 
        }
        else 
          if (bPrevHallState == STATE_5)
          {
            bSpeed = NEGATIVE;
          }  
        if(bSpeed<0)
        {
          hElectrical_Angle =(s16)(S16_PHASE_SHIFT - S16_60_PHASE_SHIFT);  
        }
        else if(bSpeed!= ERROR)
        {
          hElectrical_Angle =(s16)(S16_PHASE_SHIFT - S16_120_PHASE_SHIFT); 
        }
        break;
      default:
        bSpeed = ERROR;
        break;
}

本段程序中,通过比较当前状态和前一个状态推断出转子的转动方向,且转子转动的方向的序列必定为图1中的1种。

永磁同步电机(正弦无感)学习 (12)_第1张图片
同时由于霍尔传感器的绝对性,使得,当得知霍尔传感器的输出状态,便可以重建转子位置。程序中也是每次霍尔传感器发生变化,产生中断,就会更新转子的电角度,根据电机的转向和霍尔传感器的状态,通过初始化软件变量,便可以计算出当前电角度,用于Park变化。其中霍尔传感器的状态是通过函数ReadHallState()获得的。

永磁同步电机(正弦无感)学习 (12)_第2张图片
转子机械频率

s16 HALL_GetSpeed ( void )
{ 
  s32 wAux;
  if( hRotorFreq_dpp == HALL_MAX_PSEUDO_SPEED)
  {
    return (HALL_MAX_SPEED);
  }
  else
  {
    wAux = ((hRotorFreq_dpp* SAMPLING_FREQ * 10)/(65536*POLE_PAIR_NUM));
    return (s16)wAux;
  }
}

其中转子电频率hRotorFreq_dpp通过函数HALL_GetRotorFreq()获得,POLE_PAIR_NUM为极对数,65536为预分频值。
1.2无传感器检测
首先最重要的就是STO_Calc_Rotor_Angle函数,它获取测量的定子电流(Stat_Curr_alfa_beta),施加的电压命令(Stat_Volt_alfa_beta)和测量的直流母线电压(hBusVoltage)当作第K步的输入;得出离散状态检测方程的第K+1步,从而实现电机反电动式 的计算(eα的和 eβ)。从而通过一个数字锁相环的方法,根据反电动势计算转子速度和角度。

void STO_Calc_Rotor_Angle(Volt_Components Stat_Volt_alfa_beta, Curr_ComponentsStat_Curr_alfa_beta, s16 hBusVoltage) 
{ 
s32 wIalfa_est_Next,wIbeta_est_Next;
s32 wBemf_alfa_est_Next, wBemf_beta_est_Next; 
s16 hValfa,hVbeta; 
s16 hIalfa_err, hIbeta_err; 
s16 hRotor_Speed; 
s32 bDirection; 
if (wBemf_alfa_est > (s32)(S16_MAX*hF2)) 
{ 
wBemf_alfa_est = S16_MAX*hF2; 
} 
else if (wBemf_alfa_est <= (s32)(S16_MIN*hF2)) 
{ 
wBemf_alfa_est = -S16_MAX*hF2; 
} 
if (wBemf_beta_est > (s32)(S16_MAX*hF2)) 
{ 
wBemf_beta_est = S16_MAX*hF2; 
} 
else if (wBemf_beta_est <= (s32)(S16_MIN*hF2)) 
{ 
wBemf_beta_est = -S16_MAX*hF2; 
} 
if (wIalfa_est > (s32)(S16_MAX*hF1)) 
{ 
wIalfa_est = S16_MAX*hF1; 
} 
else if (wIalfa_est <= (s32)(S16_MIN*hF1)) 
{ 
wIalfa_est = -S16_MAX*hF1; 
} 
if (wIbeta_est > S16_MAX*hF1) 
{ 
wIbeta_est = S16_MAX*hF1; 
} 
else if (wIbeta_est <= S16_MIN*hF1) 
{ 
wIbeta_est = -S16_MAX*hF1; 
} 
hIalfa_err = (s16)((wIalfa_est/hF1)-Stat_Curr_alfa_beta.qI_Component1); 
hIbeta_err = (s16)((wIbeta_est/hF1)-Stat_Curr_alfa_beta.qI_Component2); 
hValfa = (s16)((Stat_Volt_alfa_beta.qV_Component1*hBusVoltage)/32768); 
hVbeta = (s16)((Stat_Volt_alfa_beta.qV_Component2*hBusVoltage)/32768); 
/*alfa axes observer*/ 
wIalfa_est_Next = (s32)(wIalfa_est-(s32)(hC1*(s16)(wIalfa_est/hF1))+ 
(s32)(hC2*hIalfa_err)+ 
(s32)(hC5*hValfa)- 
(s32)(hC3*(s16)(wBemf_alfa_est/hF2))); 
//I(n+1)=I(n)-rs*T/Ls*I(n)+K1*(I(n)-i(n))+T/Ls*V-T/Ls*emf 
wBemf_alfa_est_Next = (s32)(wBemf_alfa_est+(s32)(hC4*hIalfa_err)+ 
(s32)(hC6*hRotor_Speed_dpp*(wBemf_beta_est/(hF2*hF3)))); 
//emf(n+1)=emf(n)+K2*(I(n)-i(n))+p*w*emfb*T 
/*beta axes observer*/ 
wIbeta_est_Next = (s32)(wIbeta_est-(s32)(hC1*(s16)(wIbeta_est/hF1))+ 
(s32)(hC2*hIbeta_err)+ 
(s32)(hC5*hVbeta)- 
(s32)(hC3*(s16)(wBemf_beta_est/hF2))); 
wBemf_beta_est_Next = (s32)(wBemf_beta_est+(s32)(hC4*hIbeta_err)- 
(s32)(hC6*hRotor_Speed_dpp*(wBemf_alfa_est/(hF2*hF3)))); 
/* Extrapolation of present rotation direction, necessary for PLL */ 
if (hRotor_Speed_dpp >=0) 
{ 
bDirection = 1; 
} 
else 
{ 
bDirection = -1; 
} 
/*Calls the PLL blockset*/ 
hBemf_alfa_est = wBemf_alfa_est/hF2; 
hBemf_beta_est = wBemf_beta_est/hF2; 
hRotor_Speed = Calc_Rotor_Speed((s16)(hBemf_alfa_est*bDirection), 
(s16)(-hBemf_beta_est*bDirection)); 
Store_Rotor_Speed(hRotor_Speed); 
hRotor_El_Angle = (s16)(hRotor_El_Angle + hRotor_Speed); 
/*storing previous values of currents and bemfs*/ 
wIalfa_est = wIalfa_est_Next; 
wBemf_alfa_est = wBemf_alfa_est_Next; 
wIbeta_est = wIbeta_est_Next; 
wBemf_beta_est = wBemf_beta_est_Next; 
}

同时函数 STO_Get_Electrical_Angle返回转子电角度,函数STO_Get_Mechanical_Angle返回转子机械角度(电角度和机械角度之间为极对数倍数关系)

s16 STO_Get_Mechanical_Angle(void)
{
  return ((s16)(STO_Get_Electrical_Angle()/POLE_PAIR_NUM));
}
函数STO_Get_Speed()返回转子电速度,STO_Get_Speed_Hz()返回转子机械速度,他们之间的关系为
s16 STO_Get_Speed_Hz(void)
{
  return (s16)((STO_Get_Speed()* SAMPLING_FREQ * 10)/(65536*POLE_PAIR_NUM));
}

和有霍尔传感器的转子机械频率与转子电频率的计算公式相同。
函数STO_Start_Up()是启动程序,用以实现点电机由静止到旋转的启动根据 MC_State_Observer_param.h 中设置参数,三相对称电流会产生一个旋转定子磁场,引起转子跟随转动。在这些操作中,会调用 STO_Calc_Rotor_Angle 函数:如果观测的可靠度在固定的范围内,主要机状态是允许切换至运行状态。
三、学习总结
结合相关资料,对无传感器的位置和速度的检测方法有了初步的认识,部分程序上还存在着理解的问题。
为了能适应实习工作,后续会加大学习硬件方面的学习,结合原理图和AD,加深自己在硬件方面的知识。

你可能感兴趣的:(电力电子-电机)