Positron Compiler Documentation

Pot

Positron16 · Revision 1.1.3.5 · PDF page 196

Assignment Variable = Pot Pin, Scale

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

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. Assignment Variable is a user defined variable.

Device = 24HJ128GP502           ' Select the device to compile for
Declare Xtal = 16

Dim Var1 as Byte
Do                              ' Create a loop
  Var1 = Pot PORTB.0, 100      ' Read potentiometer on pin 0 of PORTB.
  Print Dec Var1, " "         ' Display the potentiometer reading
Loop                           ' Do it forever

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

Original diagram or table from Positron16, PDF page 196
Original figure / layout · PDF page 196
Text in this figure or table

To I/O Pin 5-50k

0.1uF

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: -

Var1 = Pot PORTB.0, 255

See also : ADin, RCin.

View original PDF page 196Open page in PDFOriginal PDF page 196