Positron Compiler Documentation

Pot

Source: Positron8 Compiler User Manual, PDF page 178

To I/O Pin 5-50k

0.1uF

Syntax

Variable = Pot Pin, Scale

Overview

Read a potentiometer, thermistor, photocell, or other variable resistance.

Parameters

Variable is a user defined variable. Pin is a Port.Pin constant that specifies the I/O pin to use. Scale is a constant, variable, or expression, used to scale the instruction's internal 16-bit result. 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.

Example

Device = 18F25K40
                                  ' Select the device to compile for
Declare Xtal = 16 ' Tell the compiler the device will be operating at 16MHz
Declare Hserial_Baud = 9600 ' Set the Baud rate for HRsoutLn
Dim MyByte as Byte
Do
  MyByte = Pot PORTB.0, 100  ' Read potentiometer on pin 0 of PORTB.
  HRsoutLn Dec MyByte, " "  ' Display the potentiometer reading
Loop
                             ' Repeat the process.

Notes

Internally, the Pot instruction calculates a 16-bit value, which is scaled down to an 8-bit value. The amount by which the internal value must be scaled varies with the size of the resistor being used.

The pin specified by Pot must be connected to one side of a resistor, whose other side is connected through a capacitor to ground. A resistance measurement is taken by timing how long it takes to discharge the capacitor through the resistor.

The value of scale must be determined by experimentation, however, this is easily accomplished as follows: -

Set the device under measure, the pot in this instance, to maximum resistance and read it with scale set to 255. The value returned in Var1 can now be used as scale: -

MyByte = Pot PORTB.0, 255

See also : ADin, RCin.