2018-06-19 09:42 PM
2018-06-19 10:25 PM
It would be good before sharing a large source code to express how the timer is being configured, the source code main bluprints would help tuning to the specific issue.
If here the timer is overflowing and the measured period between two falling edge (for example) is less than a timer period, just directly substract the 2 input captures regardless of their value. However the values shall be typed to be the same as the timer input captures. If the timer is 16 bit unsigned, so shall be the global variables tied to them.
Example: first capture is 0xF000, second is 0x1000, then period is (u16) 0x1000 - (u16) 0xF000 = 0x2000
Can't tell if this is the exact issue, just quick browsing the code. My two quick cents...
2018-06-20 12:30 AM
Thank you for replying. Tim 2 has been set in input capture mode. It has no prescaler and counts to 0xFFFF. I am taking inputs from Channel 2,3 and 4 of TIM2. TIM21 has been configured in basic mode, has a prescaler of 32000, and it counts upto 999. It is used to give us a an interrupt every second so that we can periodically print the display. Both timers have a 32MHz Clock source and both are 16-bit counters.