STM32F437 timer input capture
I have attempted to set up timer 4 channel 1 for input capture but unsuccessfully. The scope indicates that my 1KHz, 3vdc, 35 uSec pulses are making it to PD12 (TIM4, ch 1). However, CC1IF is never set. Although channels 2-4 are not configured CC2IF - CC4IF are being set and thus so is UIF but my ISR is never called. So I have two problems no CC1IF and no call to the ISR. Suggestions and advice would be much appreciated. The code follows.
Thanks,
JH
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
uint32_t rpm4;
void RpmTask(void *p_arg);void RpmTask(void *p_arg)
{ static int i = 0; uint16_t itstatus = 0;GPIO_StructInit(&GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_12; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStruct.GPIO_Speed = GPIO_High_Speed; GPIO_Init(GPIOD, &GPIO_InitStruct); GPIO_PinAFConfig(GPIOD, GPIO_PinSource12, GPIO_AF_TIM4);NVIC_InitTypeDef NVIC_InitStruct;
NVIC_InitStruct.NVIC_IRQChannel = TIM4_IRQn; NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0; NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStruct);//RPM timer setups
// APB1PeriphClock - 42 MHz // APB2PeriphClock - 84 MHz RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3 | RCC_APB1Periph_TIM4, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1 | RCC_APB2Periph_TIM9, ENABLE);TIM_TimeBaseInitTypeDef tim4_base;
tim4_base.TIM_Period = 0xFFFFFFFF; tim4_base.TIM_Prescaler = 48; tim4_base.TIM_ClockDivision = TIM_CKD_DIV1; //digital filter clk div, don't care, filtering is off tim4_base.TIM_CounterMode = TIM_CounterMode_Up; tim4_base.TIM_RepetitionCounter = 0; //t1&t8 pwm, don't care TIM_TimeBaseInit(TIM4, &tim4_base);TIM_ICInitTypeDef tim4_icInit;
tim4_icInit.TIM_Channel = TIM_Channel_1; tim4_icInit.TIM_ICPolarity = TIM_ICPolarity_Rising; //r, f, both tim4_icInit.TIM_ICSelection = TIM_ICSelection_DirectTI; //dir, ind, trc tim4_icInit.TIM_ICPrescaler = TIM_ICPSC_DIV1; //1-8 tim4_icInit.TIM_ICFilter = 0x0; TIM_ICInit(TIM4, &tim4_icInit);/* Enable the CC2 Interrupt Request */
TIM_ITConfig(TIM4, TIM_IT_CC1, ENABLE);/* TIM enable counter */
TIM_Cmd(TIM4, ENABLE);while (1)
{ rpm4 = TIM_GetCounter(TIM4); itstatus = TIM4->SR; }}void timer4_isr(void)
{ if (TIM_GetITStatus(TIM4, TIM_IT_CC1) == SET) { TIM_ClearITPendingBit(TIM4, TIM_IT_CC1); rpm4 = TIM_GetCounter(TIM4); }TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
}#input-capture