Shop OBEX P1 Docs P2 Docs Learn Events
NAP vs. SLEEP — Parallax Forums

NAP vs. SLEEP

EscamoteurEscamoteur Posts: 12
edited 2008-02-07 21:55 in BASIC Stamp
Hi,

is there any advantage of using NAP instead of sleep? I know it's not as accurate as SLEEP, but is there also an advantage?

Best

Thomas

Comments

  • Tracy AllenTracy Allen Posts: 6,666
    edited 2008-02-07 17:01
    The granularity of NAP is 8 values up to 2 seconds ((0.015 , 0.030, 0.060, 0.125, 0.25, 0.5, 1.0, 2.0 seconds)) and then SLEEP takes over with a granularity of about 2 seconds, up to about 18 hours. Long SLEEP intervals are fairly accurate, because the Stamp calibrates them against the resonator.

    Sometimes a program only needs a short NAP, to save power while waiting for something to happen. It is nowhere near as precise as PAUSE, but sometimes that doesn't matter.

    On the multislot Stamps, the BS2pe in partilar, there is also the POLLWAIT command, which is essentially a NAP command that waits for a change on an external pin. I find that very useful.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • NoBo780NoBo780 Posts: 94
    edited 2008-02-07 21:27
    I have been wondering how to use the SLEEP function for a while. How do you set up the syntax for that, as in, what is the formula for that command? Also when the BS2 is 'asleep', can it be woken up from an outside source (e.g. another micro), or will it just continue to sleep until the time specified is up?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Giggly Googley!
  • Mike GreenMike Green Posts: 23,101
    edited 2008-02-07 21:33
    Look in the manual for the exact syntax and definition. The time is specified in seconds. The Stamp will continue to sleep until the time specified is up. If you want to check for some outside signal, the way to do it is to NAP or SLEEP for a short period of time, then check the external signal. If the signal is not there, then go back and NAP or SLEEP again.
  • EscamoteurEscamoteur Posts: 12
    edited 2008-02-07 21:43
    @Tracy: Thanks for clarification. I didn't realize that SLEEP start from 2s on.

    Best

    Thomas
  • NoBo780NoBo780 Posts: 94
    edited 2008-02-07 21:55
    Ok. Thanks for the quick reply.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Giggly Googley!
Sign In or Register to comment.