cancel
Showing results for 
Search instead for 
Did you mean: 

32bit input capture (AN2592) inaccuracy

Apnote "Achieving 32-bit timer resolution with software expansion" (AN2592) mentions that it is possibleto create 32bit input capture with only one 16bit timer. Combine interrupt from update event to count timer overflows and regular 16bit input capture to 32bit value.

Appnote does not deal with race condition between read out capture value and update event. In case that capture event takes place few cycles before or after update event, program detects that both flags are raised and must find out what happened first.

I recommend add procedure how to manage mentioned race condition because suggested solution is useless without it.

Section 3.2 Interrupt processing sounds wrong. Says that if both IRQs (Capture and update event) are called simultaneously then program should always service update event first. That leads to wrong results in cases when capture takes place short time before update event...

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

In the event that the IC an UPDATE events happen during the same IRQ call, the IC value will either be at the top end of the range if the IC event happened first, or at the bottom end of the range if the UPDATE event was first. With that information, you can solve the mystery of which to handle first.

IC > 32768 --> IC event was first

IC < 32768 --> UPDATE was first

You need to handle the timer in a timely fashion in order for this scheme to work at all in the first place.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

1 REPLY 1
TDK
Guru

In the event that the IC an UPDATE events happen during the same IRQ call, the IC value will either be at the top end of the range if the IC event happened first, or at the bottom end of the range if the UPDATE event was first. With that information, you can solve the mystery of which to handle first.

IC > 32768 --> IC event was first

IC < 32768 --> UPDATE was first

You need to handle the timer in a timely fashion in order for this scheme to work at all in the first place.

If you feel a post has answered your question, please click "Accept as Solution".