For a normal ( also called a Single Channel ) read use.

    var = ReadAD_port( ANX )

For a Differential Channel read use the following. Where ANpX is the positive port, and ANnY is the negative port.

    user_variable = ReadAD( ANpX , ANnY )

To obtain a byte value from an AD Channel use the following to force a 10 or 12 bit AD Channel to respond with a byte value.

    user_variable = ReadAD( ANpX , TRUE )

Command Availability:

When using ReadAD ( ANx ) the returned value is an 8 bit number [0- 255]. The user variable assigned by the function can be a byte, word, integer or long.

When using ReadAD ( ANpX , ANnY ) the returned value is an integer, as negative values can be returned.

When using ReadAD ( ANpX , TRUE ) the returned value is an integer, but you should treat as a byte.

ReadAD is a function that can be used to read the built-in analog to digital converter that many microcontroller chips include. port should be specified as AN0, AN1, AN2, etc., up to the number of analog inputs available on the chip that is in use. Those familiar with Atmel AVR microcontrollers can also refer to the ports as ADC0, ADC1, etc. Refer to the datasheet for the microcontroller chip to find the number of ports available. (Note: it’s perfectly acceptable to use ANx on AVR, or ADCx on the microcontroller)

Another function, ReadAD10, is similar to ReadAD. The only difference is that it returns a full value of the ADC either 8bits or 10 bits.

The constant AD_Delay controls is the acquisition delay. The default value is 20 us. This can be changed by adding the following constant.

    #define AD_Delay 2 10us

ADSpeed controls the source of the clock for the ADC module. It varies from one chip to another. InternalClock is a Microchip PIC microcontroller only option that will drive the ADC from an internal RC oscillator. The default value is 128.


    'default value
    #define ADSpeed MediumSpeed

    'pre-defined constants
    #define HighSpeed 255
    #define MediumSpeed 128
    #define LowSpeed 0

AD_VREF_DELAY controls the charging time for VRef capacitor on Atmel AVR microcontrollers only. This therefore controls the charge from internal VRef. ReadAD will not be accurate for internal reference without this.


This example reads the ADC port and writes the output to the EEPROM.

    #chip 16F819, 8
    #config osc = int

    'Set the input pin direction
    Dir PORTA.0 In

    'Loop to take readings until the EEPROM is full
    For CurrentAddress = 0 to 255

        'Take a reading and log it
        EPWrite CurrentAddress, ReadAD(AN0)

        'Wait 10 minutes before getting another reading
        Wait 10 min

See Also ReadAD10, ReadAD12