NAP

BS1 icon BS2 icon BS2e icon BS2sx icon BS2p icon BS2pe icon BS2px icon

NAP Example

 

 

 

Syntax: NAP Duration

Function

Enter sleep mode for a short time. Power consumption is reduced as indicated in the table below assuming no loads are being driven.

* Note: expressions are not allowed as arguments on the BS1.

Quick Facts

  BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px
Current Draw during Run 1 mA 3 mA 25 mA 60 mA 40 mA 15 mA 55 mA
Current Draw during NAP 25 µA 50 µA 200 µA 500 µA 350 µA 36 µA 450 µA
Related Commands

END, SLEEP

END, SLEEP, POLLWAIT

Accuracy of NAP -50 to 100% (±10% @ 75°F with stable power supply)

Explanation

NAP uses the same shutdown/startup mechanism as SLEEP, with one big difference. During SLEEP, the BASIC Stamp automatically compensates for variations in the speed of the watchdog timer oscillator that serves as its alarm clock. As a result, longer SLEEP intervals are accurate to approximately ±1 percent.

Duration Length of NAP
0 18 ms
1 36 ms
2 72 ms
3 144 ms
4 288 ms
5 576 ms
6 1152 ms (1.152 seconds)
7 2304 ms (2.304 seconds)

 

NAP intervals are directly controlled by the watchdog timer without compensation. Variations in temperature, supply voltage, and manufacturing tolerance of the BASIC Stamp's interpreter chip can cause the actual timing to vary by as much as -50, +100 percent (i.e., a Duration of 0, NAP can range from 9 to 36 ms). At room temperature with a fresh battery or other stable power supply, variations in the length of a NAP will be less than ±10 percent.

One great use for NAP is in a battery-powered application where at least some small amount of time is spent doing nothing. For example, you may have a program that loops endlessly, performing some task, and pausing for approximately 100 ms each time through the loop. You could replace your PAUSE 100 with NAP 3, as long as the timing of the 100 ms pause was not critical. The NAP 3 would effectively pause your program for about 144 milliseconds and, at the same time, would place the BASIC Stamp in low-power mode, which would extend your battery life.

During execution of power conserving commands (END, NAP, POLLWAIT, and SLEEP), current will occasionally be interrupted on I/O pins for about 18 ms durations (60 µs on the BS2pe). The reason is that the watchdog-timer reset that awakens the BASIC Stamp during these commands also causes all of the pins to switch to input mode for approximately 18 ms (60 µs on the BS2pe). When the interpreter firmware regains control of the processor, it restores the I/O direction dictated by your program.

If you plan to use END, NAP, POLLWAIT, or SLEEP in your programs, make sure that your loads can tolerate these power outages. The simplest solution is often to connect resistors high or low (to +5V or ground) as appropriate to ensure a continuing supply of current during the reset.

The example program can be used to demonstrate the effects of the NAP reset with an LED and resistor.

Go to PBASIC Language home page

Open Getting Started with Stamps in Class

Open Connection Troubleshooting

BASIC Stamp Help Version 2.5.4

Copyright © Parallax Inc.

8/21/2013