SLEEP vs. @ SLEEP vs. NAP
PBP's SLEEP command is designed to work with the Watch Dog Timer.
It sets the WDT prescaler to an appropriate divisor then internally does an @ SLEEP.
When it wakes-up it decrements a counter and if that counter is still greater than zero, it goes back to sleep.
The processor may have to go through several hundred or even thousands of sleep/wake cycles before execution of the program will resume. It all depends on the specified period.
If the WDT is disabled and you are relying on port change interrupts to wake the PIC it will take just as many of those interrupts before the program resumes execution.
If you are using ASM Interrupts, the ISR will be called on each wake-up. This also may happen several hundred times before the rest of the program can see what happened in the interrupt.
If you are using ON INTERRUPT, no interrupts will be serviced until after the complete SLEEP command has finished.<hr>
@ SLEEP in assembly language, simply puts the processor to sleep for 1 sleep/wake cycle. Program execution will resume immediately on the first wake-up. Or if interrupts are enabled, it will jump to the ISR first, then resume were it left off. Although if interrupts are enabled, you <strike>must have 2 NOP's</strike> should have 1 NOP after the @ SLEEP statement to allow the pipeline to load the ISR's first instruction.<hr>
PBP's NAP command operates much like @ SLEEP, except it changes the WDT prescaler according to the specified period (12F-16F only) before executing an @ SLEEP internally.
It only waits one sleep/wake cycle.
hth,
Bookmarks