通过读取霍尔传感器 HU、HV、HW的状态判断在六步法的哪一步!
u8 hall_get_state(void){
u8 state=0;//获取六步法的第几步
/* 读取霍尔传感器 U 的状态 */
if(GPIO_ReadInputDataBit(HALL_U_GPIO_PORT, HALL_U_PIN)!= RESET)
{
state |= 0x01U << 2;
TIM_OC1PolarityConfig(HALL_TIM,TIM_ICPolarity_Falling);//引脚为1,当引脚变0进入中断(下降沿检测)
}
else{
TIM_OC1PolarityConfig(HALL_TIM,TIM_ICPolarity_Rising); //引脚为0,当引脚变1进入中断(上升沿检测)
}
/* 读取霍尔传感器 V 的状态 */
if(GPIO_ReadInputDataBit(HALL_V_GPIO_PORT, HALL_V_PIN)!= RESET)
{
state |= 0x01U << 1;
TIM_OC2PolarityConfig(HALL_TIM,TIM_ICPolarity_Falling);
}
else{
TIM_OC2PolarityConfig(HALL_TIM,TIM_ICPolarity_Rising);
}
/* 读取霍尔传感器 W 的状态 */
if(GPIO_ReadInputDataBit(HALL_W_GPIO_PORT, HALL_W_PIN)!= RESET)
{
state |= 0x01U << 0;
TIM_OC3PolarityConfig(HALL_TIM,TIM_ICPolarity_Falling);
}
else{
TIM_OC3PolarityConfig(HALL_TIM,TIM_ICPolarity_Rising);
}
//printf("statel:%d\r\n",state);
return state;
}
这里是针对前文说的通用TIMx的通道不能进行双边沿触发,进行手工实现双边沿触发。