POLLWAIT

BS2p icon BS2pe icon BS2px icon

POLLWAIT Example

 

 

 

Syntax: POLLWAIT Duration

Function

Pause program execution, in a low-power mode, in units of Duration until any polled-input pin reaches the desired poll state.

Quick Facts

  BS2p BS2pe BS2px
Current draw during POLLWAIT 350 µA 36 µA 450 µA
Response time with Duration
set to 8
Less than 160 µs Less than 250 µs Less than 100 µs
Special Notes
  • Poll mode must be 2 or 4 and at least one polled-input must be set to activate POLLWAIT

    (POLLWAIT will be ignored otherwise).
  • If both polled-wait and polled-run are active, the polled-run event will occur immediately after the polled-wait detects an event.
Related Commands

POLLIN, POLLMODE, POLLOUT, POLLRUN, END, NAP, SLEEP

Explanation

The POLLWAIT command is one of a family of unique "polling" commands on the BS2p and BS2pe modules. The other commands in this family include POLLIN, POLLMODE, POLLOUT and POLLRUN. The POLLWAIT command is used to pause program execution and go into a low-power state until any polled-input pin reaches the desired poll state.

The "polling" commands allow the BASIC Stamp to respond to certain I/O pin events at a faster rate than what is normally possible through manual PBASIC programming. The term "poll" comes from the fact that the BASIC Stamp's interpreter periodically checks the state of the designated polled-input pins. It "polls" these pins after the end of each PBASIC instruction and before it reads the next PBASIC instruction from the user program; giving the appearance that it is polling "in the background". This feature should not be confused with the concept of interrupts, as the BASIC Stamp does not support true interrupts.

The POLLWAIT command is unique among the polling commands in that it actually causes execution to halt, until a polled-input pin event occurs. The Duration argument is similar to that of the NAP command; using the values 0 to 7 specifies the duration of the low-power period. After the low-power period is over, the BASIC Stamp polls the polled-input pins and determines if any meet the desired poll state. If no polled-input is in the desired state (as set by POLLIN command) the BASIC Stamp goes back into low-power mode, again, for the same duration as before. If any polled-input is in the desired state, however, the BASIC Stamp will continue execution with the next line of code.

A Duration of 8 makes the BASIC Stamp pause execution in normal running mode (not low-power mode) until a polled-input event occurs. The response time is indicated in the table below. Since the response time is so fast, this feature can be used to synchronize a portion of PBASIC code to an incoming pulse

Duration Length of Low-Power Mode
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)
8 No power-down

 

The following is a simple example of the POLLWAIT command.

Setup:
  POLLIN 0, 0
  POLLMODE 2

Main:
  POLLWAIT 0
  TOGGLE 1
  GOTO Main

In this example, the POLLIN command sets I/O pin 0 to be a polled-input pin looking for a low (0) state. The Main routine immediately runs a POLLWAITcommand and specifies a Duration of 0 (with results in a low-power state of 18 ms). This means that every 18 milliseconds, the BASIC Stamp wakes-up and checks I/O pin 0 for a low. If I/O pin 0 is high, it goes back to sleep for another 18 milliseconds. If I/O pin 0 is low, it runs the next line of code, which toggles the state of I/O pin 1. Then the loop starts all over again.

If low-power mode is not required, change the POLLWAIT command in the example above to "POLLWAIT 8" instead. This will have the effect of keeping the BASIC Stamp in normal running mode (i.e., no low-power glitches) and will also cause the TOGGLE command to execute in a much shorter amount of time after a polled-input event occurs.

Note: Due to the nature of low-power mode, I/O pin 1 may occasionally toggle between high and low even if I/O pin 0 stays low. This is an artifact of power conserving commands, described below.

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.

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