Timer Input randomly skips interrupt.
I'm sertanly missing something.
I have a board with STM32F103 that control fan via PWM and have to check it's speed with Fan's TACH out. TACH out is consistent PWM signal with duty cicle 50% and frequency 80 Hz.
Chip is running with 64MHz clock, APB1 is 32 MHz. TIM 2 prescaler is 32, clock division 4, input prescaler and filter I've checked with a lot different combinations.
TIM_TimeBaseInitStruct.TIM_Prescaler = 32;
TIM_TimeBaseInitStruct.TIM_Period = 200;
TIM_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV4;
TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseInitStruct);
TIM_ICInitStruct.TIM_Channel = TIM_Channel_2;
TIM_ICInitStruct.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM_ICInitStruct.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM_ICInitStruct.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM_ICInitStruct.TIM_ICFilter = 0b1011;
TIM_ICInit(TIM2, &TIM_ICInitStruct);
TIM_ITConfig(TIM2, TIM_IT_CC2, ENABLE);
NVIC_EnableIRQ(TIM2_IRQn);
TIM_Cmd(TIM2, ENABLE);Interrupt is simple as possible: im not counting value for now (math from SPL examle I used to were giving me inconsistent results), now I'm just reading it. When I measure the difference between two interrupts I'm getting consecutive results like this: 47 21 95 90 156 65405 95 65363 159 144 22 48 etc.
So, I fire output PIN on every interrupt for debug purpose with oscilloscope.
void TIM2_IRQHandler()
{
GPIO_SetBits(GPIOB, PIN_LED_OUT);
if(TIM_GetITStatus(TIM2, TIM_FLAG_CC2) != RESET)
{
TIM_ClearFlag(TIM2, TIM_FLAG_CC2);
value = TIM_GetCapture2(TIM2);
}
GPIO_ResetBits(GPIOB, PIN_LED_OUT);
}But the picture I get looks like this:
Looks like at random interruptions are not fired.
I've tried different channels, different filter settings, different timer scale settings, even different voltage levels. I can't change MCU clock speed.
I suspect that explanation to that is simple, i'm just missing or don't understand something.
Hope for your help stm gurus.
