On Thu, Nov 08, 2001 at 12:06:39PM -0000, questuk wrote: > Hi, > > I wish to put a PIC into sleep mode then have it wake up every 10 seconds to check a port for activity, I know how to get PIC into sleep mode. > > I believe you can wake it using the PIC's clock (I have a 4Mhz xtal that runs the PIC) using TMR x and prescaler? > > Thanks Gary I'll be blunt: it can be done! ;-) And to exactly 10 second intervals! OK now's here's how: One of the reasons that SLEEP mode works so will is that the oscillator for the PIC is turned off. So with two exceptions, there is no clock available. So let's look at these execptions. Exception 1 is the watch dog timer. It has two issues. First is that since it's driven by an RC oscillator, it isn't very precise. Secondly I don't think that even with the prescaler that you can get a 10 second timeout. Exception 2 is Timer 1 on chips that have timer 1. timer 1 can be driven by an external oscillator that continues to run even in sleep. So if you configure timer 1 with interrupts on and an external crystal, it'll drop the chip out of SLEEP upon the overflow interrupt. The only problem is that that only low frequency crystal available is the 32.768 Khz crystal which will overflow every two seconds. However with the prescaler this delay can be extended to 16 seconds. Which is long enough. So this is what you do: - Get a chip with timer 1. If you're using a 16F84 part, upgrade to 16F628. - Attach a 32.768 Khz crystal to the timer 1 oscillator pins. - Configure timer 1 for external oscillator and max prescale. - Enable the timer 1 interrupt. - Load timer 1 so that it'll time out after 10 seconds. The value for this is left as an exercise for the student. ;-) - Go to SLEEP. And voila! you'll wake up exactly 10 seconds after you go to sleep. Thanks for the opportunity to explain. I started this post thinking that the task couldn't be done. But after thinking it through, the above is how you do it. BAJ -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads