| ??? 11/14/03 18:43 Read: times |
#58705 - RE: More Delay Information Responding to: ???'s previous message |
First, set up a timer for auto reloading at a frequency high enough to give you good resolution; in its interrupt service routine, simply increment Now, a 16 bit unsigned variable; don't worry about rollover.
In your non-interrupt code, you want a pair of procedures, e.g. void DelayStart(DelayObjectT * Object, u16 Duration); and bool DelayExpired(DelayObjectT *); You will likely also want to define a symbol e.g. DelayGranularity, that expresses the amount of time that corresponds to the timer interrupt rate, e.g. 1000 microsec / tick for a 1 KHz interrupt rate. DelayObjectT is simply a 16 bit unsigned. In -Start(), momentarily disable the timer interrupt, then: *Object = Now + Duration;, then reenable the interrupt. In DelayExpired(), get a sample of Now (again, disable interrupts during this access), and figure out whether or not the delay interval has occurred yet, then return True or False. You may also want to have DelayAdjust (Object, Duration), that simply adds Duration to *Object. In your LED code, start the timer, then periodically poll it to see if it has expired. The higher your polling rate, relative to your delay interval, the less jitter you'll have. There are several ways in which this delay service can be polished. For example, you can add DelayDriver() that runs in the main loop and looks for changes in Now; when it sees a change, it goes through a list of delay objects, and, for those that have expired, calls a user supplied function. In this design, DelayObjectT is bigger, holding data needed to support the queueing and the callback mechanisms. Bon appetit! |
| Topic | Author | Date |
| More Delay Information | 01/01/70 00:00 | |
| Timer Operation | 01/01/70 00:00 | |
| RE: More Delay Information | 01/01/70 00:00 | |
| RE: More Delay Information | 01/01/70 00:00 | |
| RE: More Delay Information | 01/01/70 00:00 | |
RE: More Delay Information | 01/01/70 00:00 |



