- 积分
- 59
- 回帖
- 0
- 西莫币
-
- 贡献
-
- 威望
-
- 存款
-
- 阅读权限
- 5
- 最后登录
- 1970-1-1
该用户从未签到
|
发表于 2012-4-6 15:43
|
显示全部楼层
来自: 中国广东佛山
我也发现这个问题了,原本ST的2.0电机库的霍尔传感器检测方式确实存在问题,那样配置只能进入一次中断,进过仔细看数据手册发现IC1的扑捉有一个TRC的选择,TRC的输入可以选择三个霍尔传感器的异或,就可以了!搞了一天。
源码:
TIM_TimeBaseInitTypeDef TIM_HALLTimeBaseInitStructure;
TIM_ICInitTypeDef TIM_HALLICInitStructure;
NVIC_InitTypeDef NVIC_InitHALLStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/* 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_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
// Timer configuration in Clear on capture mode
TIM_DeInit(TIM2);
TIM_TimeBaseStructInit(&TIM_HALLTimeBaseInitStructure);
// Set full 16-bit working range
TIM_HALLTimeBaseInitStructure.TIM_Period = 0xFFFF;
TIM_HALLTimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM2,&TIM_HALLTimeBaseInitStructure);
TIM_ICStructInit(&TIM_HALLICInitStructure);
TIM_HALLICInitStructure.TIM_Channel = TIM_Channel_1;
TIM_HALLICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM_HALLICInitStructure.TIM_ICSelection = TIM_ICSelection_TRC; //增加TRC的选择
TIM_HALLICInitStructure.TIM_ICFilter = 0x0B;
TIM_ICInit(TIM2,&TIM_HALLICInitStructure);
// Force the HALL_TIMER prescaler with immediate access (no need of an update event)
TIM_PrescalerConfig(TIM2, (u16) 800,
TIM_PSCReloadMode_Immediate);
TIM_InternalClockConfig(TIM2);
//Enables the XOR of channel 1, channel2 and channel3
TIM_SelectHallSensor(TIM2, ENABLE);
TIM_SelectInputTrigger(TIM2, TIM_TS_TI1F_ED); //输入触发方式改为异或信号
TIM_SelectSlaveMode(TIM2,TIM_SlaveMode_Reset);
// Source of Update event is only counter overflow/underflow
TIM_UpdateRequestConfig(TIM2, TIM_UpdateSource_Regular);
/* Enable the HALL_TIMER IRQChannel*/
NVIC_InitHALLStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitHALLStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitHALLStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitHALLStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitHALLStructure);
// Clear the TIMx's pending flags
TIM_ClearFlag(TIM2, 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);
// Selected input capture and Update (overflow) events generate interrupt
TIM_ITConfig(TIM2, TIM_IT_CC1, ENABLE);
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
TIM_SetCounter(TIM2, 0);
TIM_Cmd(TIM2, ENABLE); |
|