查看了很多资料讲解到stm32编码器,自己也做学习了一下,用stm32外接as5047测试电动机的转速,经过调试可以测出来,但是问题在于 电机的速度为什么和串口打印延时有关???路过的大神求教。。。
#include "encoder.h"
#include "usart.h"
#include "usart.h"
#define TRUE 1
#define FALSE 0
s16 hPrevious_angle, hSpeed_Buffer[SPEED_BUFFER_SIZE], hRot_Speed;
static u8 bSpeed_Buffer_Index = 0;
static volatile u16 hEncoder_Timer_Overflow;
static unsigned char bIs_First_Measurement = TRUE;
void ENC_Init(void)
{
<span style="white-space:pre"> </span>TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
<span style="white-space:pre"> </span>TIM_ICInitTypeDef TIM_ICInitStructure;
<span style="white-space:pre"> </span>GPIO_InitTypeDef GPIO_InitStructure;
<span style="white-space:pre"> </span>NVIC_InitTypeDef NVIC_InitStructure;
<span style="white-space:pre"> </span>RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
<span style="white-space:pre"> </span>RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
<span style="white-space:pre"> </span>GPIO_StructInit(&GPIO_InitStructure);
<span style="white-space:pre"> </span>GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
<span style="white-space:pre"> </span>GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
<span style="white-space:pre"> </span>GPIO_Init(GPIOA, &GPIO_InitStructure);
<span style="white-space:pre"> </span>NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
<span style="white-space:pre"> </span>NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
<span style="white-space:pre"> </span>NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
<span style="white-space:pre"> </span>NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
<span style="white-space:pre"> </span>NVIC_Init(&NVIC_InitStructure);
<span style="white-space:pre"> </span>TIM_DeInit(ENCODER_TIMER);
<span style="white-space:pre"> </span>TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
<span style=