2013-03-22 08:28 AM
Hi,
does some one know how to reduce timer counter clock? I need to measure some pulse width around 1ms using 16bit timer. I have already configured the timer but I get an overflow.
TIM_ICInitStructure_sensor_echo.TIM_Channel = TIM_Channel_1;
TIM_ICInitStructure_sensor_echo.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM_ICInitStructure_sensor_echo.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM_ICInitStructure_sensor_echo.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM_ICInitStructure_sensor_echo.TIM_ICFilter = 0x0;
TIM_PWMIConfig(TIM9, &TIM_ICInitStructure_sensor_echo);
/* Select the TIM9 Input Trigger: TI1FP1 */
TIM_SelectInputTrigger(TIM9, TIM_TS_TI1FP1);
/* Select the slave Mode: Reset Mode */
TIM_SelectSlaveMode(TIM9, TIM_SlaveMode_Reset);
TIM_SelectMasterSlaveMode(TIM9,TIM_MasterSlaveMode_Enable);
/* TIM enable counter */
TIM_Cmd(TIM9, ENABLE);
/* Enable the CC2 Interrupt Request */
TIM_ITConfig(TIM9, TIM_IT_CC2, ENABLE);
+
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Connect TIM9 pins to AF2 */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_TIM5);
NVIC_InitTypeDef NVIC_InitStructure;
/* TIM9 clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM9, ENABLE);
/* Connect TIM pin to AF2 */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_TIM9);
/* Enable the TIM9 global Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM1_BRK_TIM9_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
#stm32-timer-counter
2015-07-31 12:44 AM
Thank you very much, all it's ok.