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

122 lines
7.9 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>POT</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">POT</h1>
<div class="ImagePlusCaption">
<div class="Col2">
<p>
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" /><span class="code_in_text"> {PBASIC&#160;1.0}</span>
</p>
</div>
<p style="text-align: right;"><a href="../ExampleTopics/PotEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">POT Example</a>
</p>
<p>&#160;</p>
</div>
<p class="clear">&#160;</p>
<p>&#160;</p>
<p class="PlainText">Syntax: <span class="keyword_in_text">POT</span> <![CDATA[ ]]><i>Pin</i>,<i> Scale</i>,<i> Variable</i></p>
<h2>Function</h2>
<p class="PlainText">Read a 5 kΩ to 50 kΩ potentiometer, thermistor, photocell, or other
variable resistance.</p>
<ul>
<li value="1"><b><i>Pin</i></b> is a variable/constant (0 - 7) that specifies the I/O pin
to use. This pin will be set to output mode initially, then to input mode. </li>
<li value="2"><b><i>Scale</i></b> is a variable/constant (0 - 255) used to scale the
command's internal 16-bit result. See Explanation below for steps to finding
the scale value to use for your circuit.</li>
<li value="3"><b><i>Variable</i></b> is a variable (usually a byte) where the final result
of the reading will be stored. Internally, the <span class="keyword_in_text">POT</span> command calculates
a 16-bit value, which is scaled down to an 8-bit value. </li>
</ul>
<p>Note: See <a href="RCTIME.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">RCTIME</a> for all BS2 models.</p>
<h2>Explanation</h2>
<p class="PlainText"><span class="keyword_in_text">POT</span> reads a variable resistance and returns a value (0 - 255) representing
the amount of time it took to discharge the capacitor through the resistance. Pin
must be connected to one side of the variable resistance, whose other side is
connected through a capacitor to ground, as shown below. </p>
<center>
<img src="../../graphics/pot_sch.gif" border="0">
</img>
</center>
<p>&#160;</p>
<p class="PlainText"><span class="keyword_in_text">POT</span> works by first setting the specified I/O pin to an output and setting
its state high. This step places +5 volts on one side of the capacitor and ground
(0 volts) on the other side, which charges the capacitor. <span class="keyword_in_text">POT</span> will hold the
pin high for 10 milliseconds to charge the capacitor. It is important to select
component values that will allow the capacitor to charge in this period. If, for
example, a 50 kΩ potentiometer is used with a 0.1 µF cap, the maximum
charge time would be:</p>
<p class="PlainText">Charge time: 5 x (50 x 10<sup>3</sup>) x (0.1 x 10<sup>-6</sup>)
= 25 x 10<sup>-3</sup></p>
<p class="PlainText">The full charge time (5 TC) is 25 x 10<sup>-3</sup> or 25 milliseconds.
Obviously, the capacitor would never fully charge when the potentiometer is
at its maximum position. In this case, changing the capacitor to 0.01 µF
reduces the charge time to 2.5 milliseconds; well within the range of the
<span class="keyword_in_text">POT</span> function.</p>
<p class="PlainText">After the capacitor is charged the I/O pin to an input mode and <span class="keyword_in_text">POT</span>starts its timer. Initially the I/O pin will see a high (1) that will eventually
drop to a low (0) when the capacitor discharges past the 1.4-volt threshold.
The timer stops once the low is seen. The value of the variable resistor affects
the time it takes to discharge the capacitor from 5 volts to approximately 1.4
volts.</p>
<p class="PlainText">The 16-bit reading is multiplied by (<i>Scale</i> ÷ 256), so a scale
value of 128 would reduce the range by approximately 50%, a scale of 64 would
reduce to 25%, and so on. The amount by which the internal value must be scaled
varies with the size of the resistor being used.</p>
<h3>Finding the best <i>Scale</i> value: </h3>
<ol type="1">
<li value="1">Build the circuit shown above and plug the BS1 into the PC. </li>
<li value="2">Select Run | POT Scaling.<br></br> A special calibration window appears, allowing you to find the best value.</li>
<li value="3">The window asks for the number of the I/O pin to which the variable resistor
is connected. Select the appropriate pin (0 - 7).</li>
<li value="4">The editor downloads a short program to the BS1 (this overwrites any program
already stored in the BS1).</li>
<li value="5">Two numbers will be displayed: scale and value. Adjust the resistor until
the smallest number is shown for scale (assuming you can adjust the resistor,
as with a potentiometer).</li>
<li value="6">Once you've found the smallest number for scale, you're done. This number
should be used for the <i>Scale</i> in the <span class="keyword_in_text">POT</span> command.</li>
<li value="7">Optionally, you can verify the scale number found above by selecting the
POT Value checkbox. This locks the scale and causes the BS1 to read the resistor
continuously. The window displays the value. If the scale is good, you should
be able to adjust the resistor, achieving a 0-255 reading for the value (or as
close as possible). To change the scale value and repeat this step, just
uncheck the box. Continue this process until you find the best scale.</li>
</ol>
<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>