On Mon, May 09, 2005 at 12:01:54PM +1200, Jinx wrote: > > > Any pointers to good tutorials / examples about using a non-system > > > clock for a 1 second delay would be extremely welcome. > > If you're going to use a 32768 xtal on TMR1 - > > 32768/4 = 8192Hz incrementation rate (DS30487B, Section 7.1) > > Therefore, re-load TMR1 with 0x0000-0x2000 = 0xe000 (= > - d8192) or just re-load TMR1H with 0xe0, as TMR1L has > already gone through 0x00. When TMR1 counts up from 0xe000 > to pass through 0x0000 you can either have it generate an interrupt > (by enabling TMR1IE) or poll TMR1IF to see if it's set. In either > case, clear TMR1IF and reload. This is a very simple background > 1 second timer. You don't need to do anything other than note that > TMR1 has gone through 0x0000 (and of course re-load it before > TMR1L gets to 0x00 again). Using binary counting like this means > you don't have to worry about reload jitter that can happen when > loading the timer low byte with non-zero values Are you sure there is no jitter if you reset the upper byte only? BTW I just checked my sunrise/sunset calendar program. It actually uses the 1:8 prescale and rollover for a 19 bit count (512k). So it ticks every 16 seconds. With a 1:1 prescale it rolls over every 2 seconds. > You can work out the maths if you're using a different xtal as the > main oscillator and using another timer and/or pre-scalers > > I'd go along with Byron about using mains cycles as the primary > timing source (RA4/T0CKI - RB0/INT - RB6/T1CKI). Note > though that mains frequency varies slightly during the day due to > demand and you should look at the daily (ie a 24h period) count > for accurate timing. IOW, the number of mains cycles coming in > between 7am and 7pm is more than likely going to be be less > (frequency would be 49.xx or 59.xx Hz) than the period 7pm to > 7am (frequency will be catch-up 50.xx or 60.xx Hz) But it remains accurate over the long term. You'll get 216000 ticks in a 24 hour period though the interval between them changes. BAJ -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist