GD32F130X TIM3配置成外部计数器怎么配置?
我想要检测1秒钟内TIM3_CH2引脚触发次数,1秒钟的定时我用其它定时器来做。
现在我只能配置TIM3_CH2引脚触发重新开始计数,跟我想要的不一样。
以下调试情况:触发测试过LQFP64的54脚(PD2/TM3_ETR)和57脚(PB5/TM3_CH2)
配置TIM3_CH2引脚触发重新开始计数:测试结果可以每次触发重新开始计数
RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_GPIOA,ENABLE);
RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_GPIOB,ENABLE);
RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_GPIOC,ENABLE);
RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_GPIOD,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_PIN_2;
GPIO_InitStructure.GPIO_Mode=GPIO_MODE_AF;
GPIO_Init(GPIOD , &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_PIN_5;
GPIO_Init(GPIOB , &GPIO_InitStructure);
/* TIMERS clock enable */
RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_TIMER3,ENABLE);
/* TIMER3 configuration */
TIMER_DeInit(TIMER3);
TIM_TimeBaseStructure.TIMER_Prescaler = 35999;
TIM_TimeBaseStructure.TIMER_CounterMode = TIMER_COUNTER_UP;
TIM_TimeBaseStructure.TIMER_Period = 65535;
TIM_TimeBaseStructure.TIMER_ClockDivision = TIMER_CDIV_DIV1;
TIMER_BaseInit(TIMER3,&TIM_TimeBaseStructure);
/* Slave Mode selection: TIMER3 */
TIMER_SelectInputTrigger(TIMER3,TIMER_TS_ETRF);
TIMER_SelectSlaveMode(TIMER3,TIMER_SLAVE_MODE_RESET);//这里不一样
/* Select the Master Slave Mode */
TIMER_SelectMasterSlaveMode(TIMER3,TIMER_MASTER_SLAVE_MODE_ENABLE);
/* TIMER enable counter */
TIMER_Enable( TIMER3, ENABLE );
配置TIM3_CH2引脚触发次数计数:测试结果触发多次计数器一直是0
RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_GPIOA,ENABLE);
RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_GPIOB,ENABLE);
RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_GPIOC,ENABLE);
RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_GPIOD,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_PIN_2;
GPIO_InitStructure.GPIO_Mode=GPIO_MODE_AF;
GPIO_Init(GPIOD , &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_PIN_5;
GPIO_Init(GPIOB , &GPIO_InitStructure);
/* TIMERS clock enable */
RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_TIMER3,ENABLE);
/* TIMER3 configuration */
TIMER_DeInit(TIMER3);
TIM_TimeBaseStructure.TIMER_Prescaler = 35999;
TIM_TimeBaseStructure.TIMER_CounterMode = TIMER_COUNTER_UP;
TIM_TimeBaseStructure.TIMER_Period = 65535;
TIM_TimeBaseStructure.TIMER_ClockDivision = TIMER_CDIV_DIV1;
TIMER_BaseInit(TIMER3,&TIM_TimeBaseStructure);
/* Slave Mode selection: TIMER3 */
TIMER_SelectInputTrigger(TIMER3,TIMER_TS_ETRF);
TIMER_SelectSlaveMode(TIMER3,TIMER_SLAVE_MODE_EXTERNAL1);//这里不一样
/* Select the Master Slave Mode */
TIMER_SelectMasterSlaveMode(TIMER3,TIMER_MASTER_SLAVE_MODE_ENABLE);
/* TIMER enable counter */
TIMER_Enable( TIMER3, ENABLE );
在网上看STM32关于计数器的相关配置加入下面的配置还是没有用
TIMER_ETRClockMode1Config(TIMER3,TIMER_EXT_TRI_PSC_OFF,TIMER_EXT_TRI_POLARITY_NONINVERTED,0); |