STM32 timer misses count in Input Capture mode
Hi everyone. I am using STM32F303RE and STM32L011 nucleo boards as a part of my experiment. I used STM32F303RE to generate PWM signal (in Interrupt mode) for 1MHz.
Clock Source - PLLCLK (8Mhz * 9 = 72 MHz).
Timer Period = 71
PWM pulse = 35 (for 50% duty cycle)
I used picoscope to measure the frequency. You can see the image below.
Now, i set up the STM32L011 in input capture mode (interrupt mode) to capture this 1 MHz signal. It has 32MHz clock source. The input signal is divided by 8 ( sConfigIC.ICPrescaler = TIM_ICPSC_DIV8;)
In Interrupt mode, i used CCR register to get the captures done. I read it through UART in serial plot.
As you can see, the timer misses a count. I don't know the problem behind this but this always happens. The timer always misses a count. I tested with different signals but got the same result. Even tried PWM with STM32L011 and captured in another controller, but the result is the same.
Here is the capture_flag_function that i use to get the values
void capture_flag_function (void)
{ switch(capture_flag) { case 1: compare_value = htim2.Instance->CCR1; break; case 2: capture_new = htim2.Instance->CCR1; CAPTURE_sm = BUFF_FULL; break; default: break; } }by comparing compare_value and capture_new, i obtain the count value.
if(capture_new > compare_value)
count_new = capture_new - compare_value; if(capture_new < compare_value) count_new = 65536 - compare_value + capture_new;Does anyone have an idea of the problem I am facing? Or can you give me suggestions if I am doing something wrong. Thank you.
#count #stm32f303 #stm32-timer-counter #timer-interrupts #frequency-detection #stm32l0-timer #stm32f303-timer Note: this post was migrated and contained many threaded conversations, some content may be missing.