|Top Previous Next|
Allows measuring input voltage with the integrated analog-to-digital converter (ADC).
Up to eight pins on the WebCell, pins A0 - A7, can be designated as analog inputs. The analog voltage level applied to one of these pins can be converted to a digital value on demand. The analog level is converted relative to a voltage reference, which can come from the WebCell or be externally applied via the Aref pin.
The conversion is performed using the convert function, giving the pin number (0 - 7) as an argument. The result of the conversion is an integer proportional to the analog value. The minimum value is zero and the maximum value is given by the constant max, which corresponds to an analog value equal to (or greater than) the voltage reference. Thus the actual voltage on the pin can be computed as follows:
V = Vref * Cell.ADC.convert(n) / Cell.ADC.max;
where n is the pin and Vref has been assigned the actual reference voltage.
To designate pins as analog inputs, use the enable property. Each bit of the property value corresponds to a pin of Port A; if the bit is set to 1, then that port pin is an analog input.
To select the reference voltage, use the reference property. If an external voltage reference is used, it should be in the range 1.0V - 2.6V. If the voltage reference is not very accurate, it can be measured against an internal reference using the calibrate function.