??? 08/07/06 18:01 Read: times |
#121800 - on the subject of timing Responding to: ???'s previous message |
there are two ways of timing a)a loop and b) using a timer.
a1) in asm a2) in C b1) to set a flag b2) to execute in the ISR a1) will be precise except any ISR activity will add to the timing. Also, the uC can do nothing while the loop runs. a2) will be very imprecise and any ISR activity will add to the timing. Also, the uC can do nothing while the loop runs. It can be used only in one case: I need a lot of delay, do not care how much, as long as it is a lot. One place where I gladly use a C 'delay' is in timeout loops. This is because these loops are never to time out except when something goes horribly wrong and thus can be set for some huge value to be 100 times the needed time and the likelyhood of a compiler revision changing that to 1 or less is minimal. b1) will be precise except any ISR activity coinciding with the timer interrupt will add to the timing. The uC can run other things while waiting. b2) will be precise except any ISR activity initiated before and coinciding with the timer interrupt will add to the timing (this can, if critical, be avoided by setting the timer interrupt to a higher priority). The uC can run other things while waiting. This method limits how much can be done at the 'time tick' since long ISRs are the bane of much. Erik more 'exotic flavors' exist e.g. using a PCA, but all are derivatives of the above. |