On Wed, 25 Oct 2006, David wrote: > Do you have any suggestions how I might implement what I need to do ? > > I need the INT2 to wake up and increment a counter and then go back to > sleep (this seems straight forward), > but I need to know when 1 minute has expired to send the accumulated count. > > As you mention, when the micro is put back to sleep, the watchdog will > be reset and I loose my 1 minute interval. You don't need to have the watchdog timer configured for a one minute interval; you can configure it with something shorter which reduces your error when you get interrupted. You haven't specified what your tolerance is on the one minute. If it needs to be even remotely accurate, the WDT isn't going to get you there; look at its specs in the data sheet. If you need accuracy, put a 32K crystal on timer 1 which you can configure to give you an interrupt every second. And if you wake up due to an INT2 interrupt in the middle of a second, it won't matter, since timer 1 isn't reset by sleeping. >> >> >>> In addition to requesting help regarding the entering and exit of sleep >>> mode, will the watchdog time fully timeout (ie. not be reset each time >>> the micro wakes for INT2) ? >>> >> >> The sleep instruction clears the WDT. Waking up will not. >> >> >>> I have set up the code shown below. The aim was to toggle a pin each >>> time the micro woke up so I can time the watchdog timeout. >>> What actually happens is the micro sleeps for 4-5 seconds then wakes up >>> and toggles the pin for several seconds at around 64ms >>> then sleeps for 4-5 seconds again. The watchdog timer postscaler is set >>> 1:1 at present. The micro is using internal 4MHz oscillator. >>> >> >> If your code wakes up from an interrupt, TO will be set, and the WDT >> will still be running. You won't get into your "if (!TO)" code, and >> the PIC will reset when the WDT times out. At that point, TO will be >> clear, and you'll get back into your "if (!TO)" code until you have >> another interrupt. >> >> >>> void init() >>> { >>> DP1203_init(1,10); >>> INTERRUPT_init(); >>> PulseCount = 0; >>> ADCON1 = 0xff; >>> OSCCON = 0x60; // 4MHz >>> IDLEN = false; >>> SCS0 = false; >>> SCS1 = false; >>> SWDTEN = true; >>> SLEEP(); >>> } >>> >>> void main(void) >>> { >>> init(); >>> for(;;) >>> { >>> if(!TO) >>> { >>> LATB3 = !LATB3; >>> //SetRFMode(RF_SW_TRANSMITTER); >>> //RFPORT.Buf[0] = hi_byte(PulseCount); >>> //RFPORT.Buf[0] = lo_byte(PulseCount); >>> //SendRFPacket(0x02,RFPORT.Buf); >>> //SetRFMode(RF_SW_TRANSMITTER); >>> IDLEN = false; >>> SCS0 = false; >>> SCS1 = false; >>> SWDTEN = true; >>> SLEEP(); >>> } >>> } >>> } >>> -- -- John W. Temples, III -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist