一、内容
本期的学习内容主要是:结合原理,对比PMSM有霍尔传感器和无霍尔传感器在程序上的区别,就有/无霍尔传感器程序中速度/位置检测的相关代码进行学习。
二、知识点
1.有霍尔传感器程序中速度/位置检测
在PMSM中有霍尔传感器的程序中,主函数中定义了HALL_SENSORS,则执行HALL_HallTimerInit()函数,代码如下:
#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 defined(TIMER2_HANDLES_HALL)
/* TIM2 clock source enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
/* Enable GPIOA, clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_StructInit(&GPIO_InitStructure);
/* Configure PA.00,01 ,02 as Hall sensors input */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;// GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
#elif defined(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);
/* Enable GPIOB, clock */
//RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
GPIO_StructInit(&GPIO_InitStructure);
/* Configure PA.06,07 PB.00 as Hall sensors input */
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);
//GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
//GPIO_Init(GPIOB,&GPIO_InitStructure);
#else // TIMER4_HANDLES_HALL
/* TIM4 clock source enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4,ENABLE);
/* Enable GPIOB, clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
/* Configure PB.06,07,08 as Hall sensors input */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6,GPIO_Pin_7, GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
#endif
// Timer configuration in Clear on capture mode
TIM_DeInit(HALL_TIMER);
TIM_TimeBaseStructInit(&TIM_HALLTimeBaseInitStructure);
// Set full 16-bit working range
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);
// Force the HALL_TIMER prescaler with immediate access (no need of an update event)
T

本文深入探讨了PMSM电机在有霍尔传感器和无霍尔传感器两种情况下,转子位置和速度检测的算法原理及程序实现。在有霍尔传感器的情况下,通过霍尔传感器反馈的位置信息,利用滚动识别方式计算转子速度和电角度;而在无霍尔传感器的情况下,采用状态观测器和数字锁相环方法,通过计算反电动势来估算转子速度和角度。
最低0.47元/天 解锁文章
5831





