In SX Microcontrollers, SX/B Compiler and SX-Key Tool, PJMonty wrote: Paul, I would use the interrupt to create a clock of some sort. I have done this in other projects where the interrupt fires at regular intervals, and the interrupt handler updates a counter. When the counter reaches some logical value (e.g. the # of interrupts = .1 second), then it updates another counter that the rest of the code can use. The main code sits in a loop and polls the .1 second counter (or 1 second counter, or whatever time interval you choose) and when enough time has gone by, it jumps to a subroutine that handles something it has to do. This way, your main code creates a collection of time durations (x amount of time between temperature polls, y amount of time between fan adjustments, etc), and the main polling code simply keeps track of the amount of time that has elapsed and whether it has crossed the threshold for one of the events. If so, it jumps to the appropriate sub-routine. If not, then it keeps polling. The advantage to this approach is that when you think of another feature to add, all you do is create another timer threshold variable and add it to the collection you keep comparing against the time. It also lets you easily fine tune the granularity of events so that if you discover a certain event needs to happen more often, you just change a single constant in your code, re-assemble or compile, and then start the project running again. If you create a series of delays, then everything becomes dependent on everything else. If you decide to have some event happen more often, shortening that one delay means that all the delays that come after it need to be adjusted to keep the total time constant. Delays are a serial process, meaning that until one completes, the next can't start. By using a constant timer and polling that, you are in essence creating a mini multi-tasker. [list]Thanks, PeterM[/list] ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=119854#m119856 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)