在使用带霍尔编码器的电机时,需要捕获脉冲,来达到测电机的转速的目的,捕获脉冲的方式有很多,我刚开始选用的是定时器捕获,后因需要测度多个电机的速度,STM32F103的定时器感觉不够用,所以选择EXTI以达到捕获高电平的目的,再用TIM定时器中断计时。
以下为EXTI配置
uint16_t motor_1_At = 0;
uint16_t motor_1_Bt = 0;
uint16_t speed_motor_1;
void speed_measure_extix(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG|RCC_APB2Periph_GPIOD, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
GPIO_Init(GPIOG, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8