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

141 lines
8.3 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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>COUNT</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">COUNT</h1>
<div class="ImagePlusCaption">
<div class="Col2">
<p>
<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/CountEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">COUNT Example</a>
</p>
<p>&#160;</p>
</div>
<p class="clear">&#160;</p>
<p>&#160;</p>
<p>Syntax: <span class="keyword_in_text">COUNT</span> <![CDATA[ ]]><i>Pin</i>,<i> Duration</i>,<i> Variable</i></p>
<h2>Function</h2>
<p class="PlainText">Count the number of cycles (0-1-0 or 1-0-1) on the specified pin during the <i>Duration</i> time frame and store that number in <i>Variable</i>.
</p>
<ul>
<li value="1"><b><i>Pin</i></b> is a variable/constant/expression (0 15) that specifies
the I/O pin to use. This pin will be set to input mode.</li>
<li value="2"><b><i>Duration</i></b> is a variable/constant/expression (1 65535) specifying
the time during which to count. The unit of time for <i>Duration</i> is described
below.</li>
<li value="3"><b><i>Variable</i></b> is a variable (usually a Word) in which the count will
be stored.</li>
</ul>
<h2>Quick Facts<br /></h2>
<table width="100%" cellpadding="4" cellspacing="0" border="1">
<tr>
<td width="20%" align="center" bgcolor="#CFCFCF">&#160;</td>
<td width="16%" align="center" bgcolor="#CFCFCF">BS2 / BS2e</td>
<td width="16%" align="center" bgcolor="#CFCFCF">BS2sx</td>
<td width="16%" align="center" bgcolor="#CFCFCF">BS2p</td>
<td width="16%" align="center" bgcolor="#CFCFCF">BS2pe</td>
<td width="16%" align="center" bgcolor="#CFCFCF">BS2px</td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF">Units in <i>Duration</i></td>
<td align="center">1 ms</td>
<td align="center">400 µs</td>
<td align="center">287 µs</td>
<td align="center">720 µs</td>
<td align="center">287 µs</td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF"><i>Duration</i> range</td>
<td align="center">1 ms to 65.535 s</td>
<td align="center">400 µs to 26.214 s</td>
<td align="center">287 µs to 18.809 s</td>
<td align="center">720 µs to 47.180 s</td>
<td align="center">287 µs to 18.809 s</td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF">Minimum pulse width</td>
<td align="center">4.16 µs</td>
<td align="center">1.66 µs</td>
<td align="center">1.20 µs</td>
<td align="center">3.00 µs</td>
<td align="center">1.20 µs</td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF">Maximum frequency<br></br>(square wave)</td>
<td align="center">120,000 Hz</td>
<td align="center">300,000 Hz</td>
<td align="center">416,700 Hz</td>
<td align="center">166,667 Hz</td>
<td align="center">416,700 Hz</td>
</tr>
<tr>
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
<td align="center" colspan="5">
<p colspan="5" align="center"><a href="PULSIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">PULSIN</a>
</p>
</td>
</tr>
</table>
<h2>Explanation</h2>
<p class="PlainText">The <span class="keyword_in_text">COUNT</span> instruction makes the <i>Pin</i> an input, then for the specified
<i>duration</i>, counts cycles on that pin and stores the total in a variable. A
cycle is a change in state from 1 to 0 to 1, or from 0 to 1 to 0.</p>
<p class="PlainText">According to table above, <span class="keyword_in_text">COUNT</span> on the BS2 can respond to transitions
(pulse widths) as small as 4.16 microseconds (µs). A cycle consists of two transitions
(e.g., 0 to 1, then 1 to 0), so <span class="keyword_in_text">COUNT</span> (on the BS2) can respond to square
waves with periods as short as 8.32 µs; up to 120 kilohertz (kHz) in frequency.
For non-square waves (those whose high time and low time are unequal), the shorter
of the high and low times must be at least 4.16 µs in width (on the BS2). Refer
to the table for data on other BASIC Stamp modules.</p>
<p class="PlainText">If you use <span class="keyword_in_text">COUNT</span> on slowly changing analog waveforms like sine waves,
you may find that the value returned is higher than expected. This is because the
waveform may pass through the BASIC Stamps 1.4-volt logic threshold slowly enough
that noise causes false counts. You can fix this by passing the signal through
a Schmitt Trigger, like one of the inverters of a 74HCT14. Or, you may use the
BS2pxs built-in Schmitt-Trigger pin property; see
<a href="CONFIGPIN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">CONFIGPIN</a> for details. </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>