Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Per Westermark
02/18/09 10:28
Read: 1496 times
Sweden


 
Msg Score: +1
 +1 Good Answer/Helpful
#162555 - Timer ticks
Responding to: Erik Malund's previous message
Or use C, but initialize a timer to tick every ms (or any other suitable tick frequency that gives a suitable resolution) and let your C program wait the required number of timer ticks.

You may have an interrupt count the ticks (and possibly also set a time-out flag), or you may look directly at timer registers. Just note that your 8-bit processor looks at one byte at a time, and that care should be used if looking at a two-byte register that gets incremented (by interrupt or 16-bit counting in a timer) asynchronously. You may catch one byte and then get a timer overflow before you look at the second byte, in which case you get an invalid result.

Assembler delays are best for short delays. An interrupt with timeout-flag allows your program to spend time doing other things while waiting for the flag to be set. With interrupts, you may also sleep your processor while it waits, to reduce the power consumption. Always think green (Intel most definitely don't) - especially if you may need to power the device from batteries.

List of 5 messages in thread
TopicAuthorDate
Delay loop in C Programming      Harrison Cheung      02/18/09 09:54      
   you can't        Erik Malund      02/18/09 09:59      
      Timer ticks        Per Westermark      02/18/09 10:28      
      It's IMPOSSIBLE - but here's how...      Andy Neil      02/18/09 10:30      
   You do not      Per Westermark      03/24/09 02:35      

Back to Subject List