Strictly necessary cookies are on by default and cannot be turned off. Functional, Performance and Tracking/targeting/sharing cookies can be turned on below based on your preferences (this banner will remain available for you to accept cookies). You may change your cookie settings by deleting cookies from your browser. Then this banner will appear again. You can learn more details about cookies HERE.
Strictly necessary (always on)
Functional, Performance and Tracking/targeting/sharing (default off)
In your design as the timer clock is at 1MHz, the timer count is going to overflow and restart from initial count. For 4KHz input clock this can happen upto 250 times. When we capture the old and new value before and after overflow, the measurement of old-new can be a spurious value. I am suspecting this to cause the issue.
I'm not sure about your answer : at 1Mhz, the period of the timer clock is 1µs. At 4kHz, the period of the input signal is 250µs. The timer count will decrease by 250. When it overflows, the calculated value should be correct.
To see if the error comes from the overflow, I changed th number of bits of the timer to 32. The overflow will occur every 4295 s (more than on hour), but I still get the same spurious results .