ADC Object

Top  Previous  Next

Allows measuring input voltage with the integrated analog-to-digital converter (ADC).

Description

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.

Constants

calValue

Gets the internal calibration voltage for the ADC.

max

Gets the maximum value returned by the convert function.

ref1V

Gets the constant used to select the 1.0V internal voltage reference.

refA0

Gets the constant used to select the A0 pin as the voltage reference.

refExt

Gets the constant used to select the Aref pin as the voltage reference.

refVccScaled

Gets the constant used to select Vcc / 1.6 as the voltage reference.

Static Functions

calibrate

Gets a calibration value for the ADC voltage reference.

convert

Converts an analog input to a digital value.

Static Properties

enable

Gets or sets which pins of Port A are analog inputs.

reference

Gets or sets the source for the ADC voltage reference.