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/SLEEP.htm

211 lines
13 KiB
HTML
Raw Normal View History

<?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>SLEEP</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">SLEEP</h1>
<div class="ImagePlusCaption">
<div class="Col2">
<p>
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" />
<img src="../../graphics/pgm_icon2.gif" border="0" alt="BS2 icon" title="BS2 icon" />
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="BS2e icon" title="BS2e icon" />
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="BS2sx icon" title="BS2sx icon" />
<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/SleepEx.htm" target="" title="" alt="" class="MCXref_0">SLEEP Example</a>
</p>
<p>&#160;</p>
</div>
<p class="clear">&#160;</p>
<p>&#160;</p>
<p class="PlainText">Syntax: <span class="keyword_in_text">SLEEP</span> <![CDATA[ ]]><i>Duration</i></p>
<h2>Function</h2>
<p class="PlainText">Put the BASIC Stamp into low-power mode for a specified period of time.
</p>
<ul>
<li value="1"><b><i>Duration</i></b> is a variable/constant/expression* (1 - 65535) that
specifies the duration of sleep. The unit of time for <i>Duration</i> is one
second, though the BASIC Stamp rounds up to the nearest multiple of 2.3
seconds. </li>
</ul>
<p class="PlainText">*<img src="../../graphics/bs1note.gif" style="vertical-align: super;" /> Note: expressions are not allowed as arguments on the BS1.</p>
<h2>Quick Facts</h2>
<table cellpadding="4" cellspacing="0" border="1" style="caption-side: top;width: 100%;">
<col />
<col />
<col />
<col />
<col />
<col />
<col />
<col />
<tr align="center" bgcolor="#CFCFCF">
<td width="16%">&#160;</td>
<td width="12%">BS1</td>
<td width="12%">BS2</td>
<td width="12%">BS2e</td>
<td width="12%">BS2sx</td>
<td width="12%">BS2p</td>
<td width="12%">BS2pe</td>
<td width="12%">BS2px</td>
</tr>
<tr align="center">
<td bgcolor="#CFCFCF">Current Draw<br></br>during Run</td>
<td>1 mA</td>
<td>3 mA</td>
<td>25 mA</td>
<td>60 mA</td>
<td>40 mA</td>
<td>15 mA</td>
<td>55 mA</td>
</tr>
<tr align="center">
<td bgcolor="#CFCFCF">Current Draw<br></br>during <span class="keyword_in_text">SLEEP</span></td>
<td>25 µA</td>
<td>50 µA</td>
<td>200 µA</td>
<td>500 µA</td>
<td>350 µA</td>
<td>36 µA</td>
<td>450 µA</td>
</tr>
<TR ALIGN="center">
<TD BGCOLOR="#CFCFCF">Related Commands</TD>
<TD COLSPAN="4"><a href="END.htm" target="" title="" alt="" class="MCXref_0">END</a> , <a href="NAP.htm" target="" title="" alt="" class="MCXref_0">NAP</a></TD>
<TD COLSPAN="3"><a href="END.htm" target="" title="" alt="" class="MCXref_0">END</a>, <a href="NAP.htm" target="" title="" alt="" class="MCXref_0">NAP</a>, <a href="POLLWAIT.htm" target="" title="" alt="" class="MCXref_0">POLLWAIT</a></TD>
</TR>
<tr align="center">
<td bgcolor="#CFCFCF">Accuracy of <span class="keyword_in_text">SLEEP</span></td>
<td colspan="8">±1% @ 75°F with stable power supply</td>
</tr>
</table>
<h2>Explanation</h2>
<p class="PlainText"><span class="keyword_in_text">SLEEP</span> allows the BASIC Stamp to turn itself off, then turn back on after
a programmed duration. The length of <span class="keyword_in_text">SLEEP</span> can range from 2.3 seconds
to slightly over 18 hours. Power consumption is reduced to the amount described
in the table above, assuming no loads are being driven. </p>
<h3><a name="Sleep"></a>Sleep Units vs Sleep Resolution</h3>
<p class="PlainText">The units for <b style="font-style: italic;">Duration</b> are 1 second, but the resolution of the
<span class="keyword_in_text">SLEEP</span> instruction is 2.304 seconds. <span class="keyword_in_text">SLEEP</span> rounds the specified
number of seconds up to the nearest multiple of 2.304. Because of this, <b style="font-style: italic;">Duration</b> values below 10 are not very accurate.</p>
<table cellpadding="4" cellspacing="0" border="1" style="caption-side: top;width: 100%;">
<col style="width: 279px;" />
<col />
<col />
<col />
<col />
<col />
<col />
<col />
<col />
<col />
<col />
<tbody>
<tr align="center" bgcolor="#CFCFCF">
<td>When the <i>Duration</i> value is...</td>
<td style="text-align: center;">1</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">3</td>
<td style="text-align: center;">4</td>
<td style="text-align: center;">5</td>
<td style="text-align: center;">6</td>
<td style="text-align: center;">7</td>
<td style="text-align: center;">8</td>
<td style="text-align: center;">9</td>
<td style="text-align: center;">10</td>
</tr>
<tr>
<td bgcolor="#CFCFCF">Sleep time (in seconds) is approximately...</td>
<td style="text-align: center;">2.304</td>
<td style="text-align: center;">2.304</td>
<td style="text-align: center;">4.608</td>
<td style="text-align: center;">4.608</td>
<td style="text-align: center;">6.912</td>
<td style="text-align: center;">6.912</td>
<td style="text-align: center;">9.216</td>
<td style="text-align: center;">9.216</td>
<td style="text-align: center;">9.216</td>
<td style="text-align: center;">11.52</td>
</tr>
</tbody>
</table>
<p>&#160;</p>
<p class="PlainText">To estimate the actual sleeping period for any <i>Duration</i> value, use this equation:</p>
<p class="PlainText">
<img src="../../GeneratedImages/Equations/Equation1.png" style="width: 197px;height: 16px;" title="Equation for Sleep period" alt="Ceiling of Duration units divided by 2.304, result multiplied by 2.304" class="MCEquation mcReset" />
</p>
<p class="PlainText">The open-bottom square brackets indicate the <i>ceiling function</i>, which essentially means "round up the quantity inside to the next integer."</p>
<p class="PlainText">For example, <span class="code_in_text">SLEEP 1</span> sleeps for 2.304 seconds:</p>
<p>
<img src="../../GeneratedImages/Equations/Equation2.png" style="width: 159px;height: 110px;" class="MCEquation mcReset" />
</p>
<p class="PlainText">And, <span class="code_in_text">SLEEP&#160;10 </span>sleeps for approximately 11.52 seconds:</p>
<p>&#160;</p>
<p>
<img src="../../GeneratedImages/Equations/Equation3.png" style="width: 169px;height: 110px;" class="MCEquation mcReset" />
</p>
<h3>The Watchdog Timer Improves Sleep Accuracy Automatically</h3>
<p class="PlainText">Pins retain their previous I/O directions during <span class="keyword_in_text">SLEEP</span>. However, outputs
are interrupted every 2.3 seconds during <span class="keyword_in_text">SLEEP</span> due to the way the chip keeps
time. The alarm clock that wakes the BASIC Stamp up is called the watchdog timer.
The watchdog is a resistor/capacitor oscillator built into the interpreter chip.
During <span class="keyword_in_text">SLEEP</span>, the chip periodically wakes up and adjusts a counter to
determine how long it has been asleep. If it isn't time to wake up, the chip "hits
the snooze bar" and goes back to sleep. </p>
<p class="PlainText">To ensure accuracy of <span class="keyword_in_text">SLEEP</span> intervals, the BASIC Stamp periodically
compares the watchdog timer to the more-accurate resonator time base. It calculates
a correction factor that it uses during <span class="keyword_in_text">SLEEP</span>. As a result, longer
<span class="keyword_in_text">SLEEP</span> intervals are accurate to approximately ±1 percent.</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>
<p class="PlainText">The <a href="../ExampleTopics/SleepEx.htm" target="" title="" alt="" class="MCXref_0">SLEEP Example</a> can be used to demonstrate the
effects of this reset with an LED and resistor.</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>