|
|
|
|
Spockie-Tech
Site Admin
Joined: 31 May 2004
Posts: 3160
Location: Melbourne, Australia
|
Ive not implemented this on the AVR, but In general, if you want to time events without serious hold-ups, you setup a free-running rollover timer with a "terminal count "end of count" interrupt, AND and an external-input interrupt.
Then you just need a few registers to keep track of "what value the timer was at when event started" and read the timer again (+rollover counts) on event end. Do some math, and you get the elapsed time.
Things to watch for with this tech are nested interrupts and subsequent delays - you want to have your "tick/rollover interrupt handling routine as quick as possible, or your external event might occur while you're dealing with the rollover routine, causing delayed processing and timing jitter.
of course you need to be careful with your variables, stack, state machine processing flags and so on, since multiple interrupt levels can get confusing for new players.
Thats why I mentioned that an RTOS might be a better option if you want to get going quickly, although they do suck up some computrons that could go towards user-app if hardware is limited.
Debugging interrupt assembly code sucks too. _________________ Great minds discuss ideas. Average minds discuss events. Small minds discuss people
|
Mon Sep 13, 2010 12:32 am |
|
|
|
|
|
|
|
|
|
|