Syntax: POT Pin, Scale, Variable
Read a 5 kΩ to 50 kΩ potentiometer, thermistor, photocell, or other variable resistance.
Note: See RCTIME for all BS2 models.
POT 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.
POT 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. POT 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:
Charge time: 5 x (50 x 103) x (0.1 x 10-6) = 25 x 10-3
The full charge time (5 TC) is 25 x 10-3 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 POT function.
After the capacitor is charged the I/O pin to an input mode and POTstarts 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.
The 16-bit reading is multiplied by (Scale ÷ 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.
BASIC Stamp Help Version 2.5.4
Copyright © Parallax Inc.