这个是参考STM32F103单片机配置的一个N32G032的单霍尔测速程序,为什么程序没反应?
有弄过这个的大佬吗?求帮忙看一下是什么问题
/*定时器8-CH1 输入的编码信号*/
void EncodeTimeInit(void)
{
GPIO_InitType GPIO_InitStructure;
NVIC_InitType NVIC_InitStructure;
TIM_TimeBaseInitType TIM_TimeBaseStructure;
TIM_ICInitType TIM_ICInitStructure;
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_TIM8, ENABLE);
/*GPIOB clock enable */
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_AFIO,ENABLE);
GPIO_InitStruct(&GPIO_InitStructure);
/*PB12 - Encode Signal Input port1*/
GPIO_InitStructure.Pin = GPIO_PIN_12;
GPIO_InitStructure.GPIO_Mode =GPIO_MODE_INPUT;
GPIO_InitStructure.GPIO_Speed =GPIO_SPEED_HIGH;
GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure);
TIM_InitTimBaseStruct(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.Period = 65536- 1;
TIM_TimeBaseStructure.Prescaler = 0;
TIM_TimeBaseStructure.ClkDiv = TIM_CLK_DIV1;
TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP;
TIM_InitTimeBase(TIM8, &TIM_TimeBaseStructure);
TIM_InitIcStruct(&TIM_ICInitStructure);
TIM_ICInitStructure.Channel =TIM_CH_1;
TIM_ICInitStructure.IcPolarity =TIM_IC_POLARITY_RISING;
TIM_ICInitStructure.IcSelection =TIM_IC_SELECTION_DIRECTTI;
TIM_ICInitStructure.IcPrescaler =TIM_IC_PSC_DIV1;
TIM_ICInitStructure.IcFilter =6;
TIM_ICInit(TIM8, &TIM_ICInitStructure);
// TIM_ConfigArPreload(TIM8, ENABLE);
TIM_ClrIntPendingBit(TIM8,TIM_INT_CC1);
// TIM_ClearFlag(TIM8, TIM_FLAG_CC1);
TIM_ConfigInt(TIM8, TIM_INT_CC1, ENABLE);
/* Enable the TIM8 global Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM8_CC_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_Enable(TIM8, ENABLE);
}
/*判断电机转动方向*/
FlagStatus TIM_IsCountingDown(void)
{
if(TIM8->CTRL1 & TIM_CNT_MODE_UP)
{
return SET;
}
else
{
return RESET;
}
}
/*获取编码器数据*/
void TIM8_IRQHandler(void)
{
if(TIM_GetIntStatus(TIM8, TIM_INT_CC1) != RESET)
{
TIM_ClrIntPendingBit(TIM8, TIM_INT_CC1);
if(TIM_IsCountingDown() != RESET)
{
Encoder_Overflow_Count--;
}
else
{
Encoder_Overflow_Count++;
}
}
} |