2026-05-27 3:44 PM
Hi all.
I'm currently have the encoders from a motor connected to a timer block and I'm simply measuring the period for one of the pulses to determine the frequency.
On the first rising edge of the pulse, I set the counter (CNT register) to 0 and then enable the counter overflow interrupt enable flat.
On the next rising edge, I capture the counter value and add this to the amount of overflows which have happen.
All is well and I can confirmed the period is exactly as I expect as I've measuring this using my logic analyser (saleae logic analyzed)
However the problem:
I'm printing out the period of the motor encoder timings over the USB serial port and I'm logging the readings to a CSV file. I've capturing around 10k samples using different PWM values. I'm plotting the results, where the x axis is the time which a period was captured and the y axis is the time of the motor encoder period (usually around 1.2ms period, assuming 100% PWM)
However, I noticed out of the 10k+ samples, I come across peaks in my data, where the periods are around 1.2ms and all of a sudden I might get a peak, where the period is around 10ms! My logic analyser shows none of the pulses are never 10ms.
I've dumped the registers for every motor encover capture and I noticed when the massive peak occurs, there are around 5-7 overflows which have happened between when I reset the counter to zero and on the next rising edge.
My code is simply polling the interrupt registers and I've confirmed the same issue happens even if I decode my pulses using interrupt handlers.
I'll post my code tomorrow and some screenshot to fully explain the situation but I cannot figure why in some cases, I get these multiple overflows?
It's as if there could be a situation where I have a rising edge from the motor encoder which allows me to set the CNT register to 0 and for some reason, I'm missing a load of rising edges (voltage too low) and then I get a valid pulse. However my logic analyser doesn't show any pulses being missed.