POT Pin,Scale,Var
Reads a potentiometer (or some other resistive device) on Pin. Pin
may be a constant, 0 - 15, or a variable that contains a number 0 - 15
(e.g. B0) or a pin name (e.g. PORTA.0).
The resistance is measured by timing the discharge of a capacitor
through the resistor (typically 5K to 50K). Scale is used to adjust for
varying RC constants. For larger RC constants, Scale should be set
low (a minimum value of one). For smaller RC constants, Scale should
be set to its maximum value (255). If Scale is set correctly, Var should
be zero near minimum resistance and 255 near maximum resistance.
Unfortunately, Scale must be determined experimentally. To do so, set
the device under measure to maximum resistance and read it with
Scale set to 127. Adjust Scale until the Pot command returns 254. If
255, decrease the scale. If 253 or lower, increase the scale. (Note:
This is similar to the process performed by the Alt-P option of the BS1
environment).
Use the following code to automate the process. Make sure that you set
the pot to maximum resistance.
B0 Var Byte
scale Var Byte
For scale = 1 To 255
POT 0,scale,B0
If (B0 > 253) Then calibrated
Next scale
Serout 2,0,["Increase R or C.",10,13]
Stop
calibrated:
Serout 2,0,["Scale= ",#scale,10,13]
Bookmarks