David Williams wrote: > > Hello, > > I've got to set a pin every 24 hours plus or minus 10 minutes. I need the > timer to work while I'm doing a bunch of other things (I guess this means > I've got to use interrupts). Anyway, anyone have any ideas how to set up > a 24 hour count? C code is preferred. > > Thanks, > Dave It remembers me about a device I did long ago, when 60Hz AC was not available (to synch the unit), and no RTC chip available at that time, so we needed to track time basically by software, *with* several interrupts sharing the same microprocessor, it was a Z80. We had two ideas, the first one was to implement a top priority interrupt (NMI - Non Maskable Interrupt) each second, so it would be our 3600 counts per hour. The idea was simple and nice, if some of the secondary interrupts were not also top priorities... :) The second idea (that worked), had the processor main routine just counting Z80 processing cycles. It just counted certain number or instructions per second. We accounted how many processing cycles were used in each one of the 6 possible interrupts. At the end of each one, the routine just subtracted its particular cycles quantity from the main timer decrementing counters. It means that the main routine always decremented its counters to zero at the right time. There was a tricky thing; Each interrupt routine should take care of possible missing "seconds counter" update. This situation only happens if an interrupt was being handled during the time when the "non interrupted main clock routine" should reach its counters to zero and update the seconds counter, but it was not done because the interrupt routine. Then we changed this job to the main timer routine. If the decrementing counters were negative, the routine immediately updated the "seconds counter" and calculated the misplaced negative value for a new (smaller) reload, so the next seconds update would be right on time. Of course, at that time we had no software to take care of how many machine cycles each routine would take, so we needed to do it manually. Many pages of paper and lots of handwriting later, we got the right code. Ahh, by the way, we had no assembler compiler either, it was everything done by hand... can you imagine how long it takes to write a 1000 bytes of code? 2708 was the Eprom chip, programmed by hand in a byte by byte fashion, first to a couple of 2114 (1k sram) and then the continuous programming cycles... :) It took 3 weeks to do what we can do today in just 5 minutes or less. Wagner