This repository has been archived on 2024-09-22. You can view files and clone it, but cannot push or open issues or pull requests.
pbi-ide/help/BasicStampHelp/Content/LanguageTopics/Commands/POLLWAIT.htm

218 lines
13 KiB
HTML

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns:MadCap="http://www.madcapsoftware.com/Schemas/MadCap.xsd" MadCap:lastBlockDepth="6" MadCap:lastHeight="94" MadCap:lastWidth="853" MadCap:disableMasterStylesheet="true" MadCap:tocPath="" MadCap:InPreviewMode="false" MadCap:PreloadImages="false" MadCap:RuntimeFileType="Topic" MadCap:TargetType="WebHelp" lang="en-us" xml:lang="en-us" MadCap:PathToHelpSystem="../../../" MadCap:HelpSystemFileName="Default.xml" MadCap:SearchType="Stem">
<head><title>POLLWAIT</title>
<link href="../../SkinSupport/MadCap.css" rel="stylesheet" />
<link href="../../Resources/Stylesheets/BSE_Help.css" rel="stylesheet" />
<script src="../../SkinSupport/MadCapAll.js" type="text/javascript">
</script>
</head>
<body>
<h1 class="code">POLLWAIT</h1>
<div class="ImagePlusCaption">
<div class="Col2">
<p>
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" />
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="BS2pe icon" title="BS2pe icon" />
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" />
</p>
</div>
<p style="text-align: right;"><a href="../ExampleTopics/PollwaitEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLWAIT Example</a>
</p>
<p>&#160;</p>
</div>
<p class="clear">&#160;</p>
<p>&#160;</p>
<p class="PlainText">Syntax: <span class="keyword_in_text">POLLWAIT</span> <![CDATA[ ]]><i>Duration</i></p>
<h2>Function</h2>
<p>Pause program execution, in a low-power mode, in units of <i>Duration</i> until any
polled-input pin reaches the desired poll state.
</p>
<ul>
<li value="1"><b><i>Duration</i></b> is a variable/constant/expression (0 - 8) that
specifies the duration of the low-power state. The low-power duration is
2<sup style="font-style: italic;">Duration</sup> x 18 milliseconds. The table below indicates the low-power
duration for any given <i>Duration</i>. Using 8 as the <i>Duration</i> is a special
case; the BS2p, BS2pe, and BS2px will not go into low-power mode and will
respond quicker to polled inputs.</li>
</ul>
<h2>Quick Facts</h2>
<table width="100%" cellpadding="2" cellspacing="0" border="1">
<tr>
<td width="25%" align="center" bgcolor="#CFCFCF">&#160;</td>
<td width="25%" align="center" bgcolor="#CFCFCF">BS2p</td>
<td width="25%" align="center" bgcolor="#CFCFCF">BS2pe</td>
<td width="25%" align="center" bgcolor="#CFCFCF">BS2px</td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF">Current draw during <span class="keyword_in_text">POLLWAIT</span></td>
<td align="center">350 µA</td>
<td align="center">36 µA</td>
<td align="center">450 µA</td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF">Response time with <i>Duration</i><br />set
to 8</td>
<td align="center">Less than 160 µs</td>
<td align="center">Less than 250 µs</td>
<td align="center">Less than 100 µs</td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF">Special Notes</td>
<td align="left" colspan="3">
<ul>
<li value="1">Poll mode must be 2 or 4 and at least one polled-input must be set
to activate <span class="keyword_in_text">POLLWAIT</span><br></br>(<span class="keyword_in_text">POLLWAIT</span> will be ignored
otherwise).</li>
<li value="2">If both polled-wait and polled-run are active, the polled-run event
will occur immediately after the polled-wait detects an event.</li>
</ul>
</td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
<td align="center" colspan="3">
<p colspan="3" align="center"><a href="POLLIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLIN</a>, <a href="POLLMODE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLMODE</a>, <a href="POLLOUT.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLOUT</a>, <a href="POLLRUN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POLLRUN</a>, <a href="END.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">END</a>, <a href="NAP.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">NAP</a>, <a href="SLEEP.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SLEEP</a></p>
</td>
</tr>
</table>
<h2>Explanation</h2>
<p class="PlainText">The <span class="keyword_in_text">POLLWAIT</span> command is one of a family of unique "polling" commands on
the BS2p and BS2pe modules. The other commands in this family include <span class="keyword_in_text">POLLIN</span>,
<span class="keyword_in_text">POLLMODE</span>, <span class="keyword_in_text">POLLOUT</span> and <span class="keyword_in_text">POLLRUN</span>. The <span class="keyword_in_text">POLLWAIT</span> command
is used to pause program execution and go into a low-power state until any
polled-input pin reaches the desired poll state.</p>
<p class="PlainText">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.</p>
<p class="PlainText">The <span class="keyword_in_text">POLLWAIT</span> command is unique among the polling commands in that it
actually causes execution to halt, until a polled-input pin event occurs.
The <i>Duration</i> argument is similar to that of the <span class="keyword_in_text">NAP</span> 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 <span class="keyword_in_text">POLLIN</span> 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.</p>
<p class="PlainText">A <i>Duration</i> 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</p>
<center>
<table cellpadding="4" cellspacing="0" border="1">
<tr>
<td align="center" width="45" bgcolor="#CFCFCF"><i>Duration</i>
</td>
<td align="center" width="165" bgcolor="#CFCFCF">Length of Low-Power Mode</td>
</tr>
<tr>
<td align="center">0</td>
<td align="center">18 ms</td>
</tr>
<tr>
<td align="center">1</td>
<td align="center">36 ms</td>
</tr>
<tr>
<td align="center">2</td>
<td align="center">72 ms</td>
</tr>
<tr>
<td align="center">3</td>
<td align="center">144 ms</td>
</tr>
<tr>
<td align="center">4</td>
<td align="center">288 ms</td>
</tr>
<tr>
<td align="center">5</td>
<td align="center">576 ms</td>
</tr>
<tr>
<td align="center">6</td>
<td align="center">1152 ms (1.152 seconds)</td>
</tr>
<tr>
<td align="center">7</td>
<td align="center">2304 ms (2.304 seconds)</td>
</tr>
<tr>
<td align="center">8</td>
<td align="center">No power-down</td>
</tr>
</table>
</center>
<p>&#160;</p>
<p class="PlainText">The following is a simple example of the <span class="keyword_in_text">POLLWAIT</span> command.</p><pre class="BScode" xml:space="preserve">
Setup:
POLLIN 0, 0
POLLMODE 2
Main:
POLLWAIT 0
TOGGLE 1
GOTO Main
</pre>
<p class="PlainText">In this example, the <span class="keyword_in_text">POLLIN</span> command sets I/O pin 0 to be a polled-input
pin looking for a low (0) state. The Main routine immediately runs a <span class="keyword_in_text">POLLWAIT</span>command and specifies a <i>Duration</i> 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. </p>
<p class="PlainText">If low-power mode is not required, change the <span class="keyword_in_text">POLLWAIT</span> command in the
example above to "<span class="code_in_text">POLLWAIT 8</span>" 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 <span class="keyword_in_text">TOGGLE</span> command to execute in a much shorter amount of time after
a polled-input event occurs.</p>
<p class="PlainText">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.</p>
<p class="PlainText">During execution of power conserving commands (<span class="keyword_in_text">END</span>, <span class="keyword_in_text">NAP</span>, <span class="keyword_in_text">POLLWAIT</span>, and <span class="keyword_in_text">SLEEP</span>), 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.</p>
<p class="PlainText">If you plan to use <span class="keyword_in_text">END</span>, <span class="keyword_in_text">NAP</span>, <span class="keyword_in_text">POLLWAIT</span>, or <span class="keyword_in_text">SLEEP</span> 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. </p>
<div class="Col2">
<div class="MasterFoot">
<p MadCap:conditions="BSEconditions.BSEWebHelp (Primary)-INCLUDE"><a href="../../HomeTopics/HomePage.htm">Go to Welcome page</a>
</p>
</div>
</div>
<div class="Col2">
<div class="MasterFoot">
<p style="text-align: right;"><span class="ContactInfoProjectName">BASIC Stamp Help</span> <![CDATA[ ]]><span class="ContactInfoVersion#">Version 2.5.4</span> <![CDATA[ ]]></p>
<p style="text-align: right;">Copyright ©&#160;<span class="ContactInfoCompanyName">Parallax Inc.</span></p>
<p style="text-align: right;"><span class="SystemShortDate">8/8/2012</span>
</p>
</div>
</div>
<script type="text/javascript">/* <![CDATA[ */
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-285614-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
/* ]]> */</script>
<script type="text/javascript" src="../../SkinSupport/MadCapBodyEnd.js">
</script>
</body>
</html>