使用stm32中TIM3_ETR 来对外部脉冲计数,可是总是发出的是0,求香主帮忙看看,下面是配置:
void TIM3_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
//Config PD2 为浮空输入
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;//测左电机转速
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOD, &GPIO_InitStructure);
//配置TIMER3作为计数器
TIM_DeInit(TIM3);
TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
TIM_TimeBaseStructure.TIM_Prescaler = 0x00;
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
// TIM_TimeBaseStructure.TIM_channel = TIM_Channel_1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); // Time base configuration
TIM_ETRClockMode2Config(TIM3, TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_Inverted, 0);
//使用ETR时钟作为计数时钟需要设置为外部时钟模式2
//TIM_ExtTRGPSC_OFF: TIM ETRP 预分频 OFF(范围:0,2,4,6)
//TIM_ExtTRGPolarity_NonInverted: TIM外部触发极性非翻转:高电平或上升沿有
//ExtTRGFilter: 外部触发滤波器。该参数取值在0x0和0xF之间。
TIM_SetCounter(TIM3, 0);
TIM_Cmd(TIM3, ENABLE);
// COUN3 = TIM_GetCounter(TIM3);
}
在main()中将COUN3 = TIM_GetCounter(TIM3);
然后通过串口发出去!
求解答~~ |