An Analog-to-Digital Converter (ADC) is a device that translates an analog voltage to a digital value that a microprocessor can understand.

The ConnectCore 8X provides two types of ADC interfaces:

  • The i.MX8QXP CPU ADCs

  • The Micro Controller Assist (MCA) ADCs

Both ADC controllers are 12-bit resolution, right justified, unsigned format. The MCA ADC channels are suitable for low-frequency sampling (under 10 Hz). For higher frequency sampling, Digi recommends you use the CPU ADC channels. The ADC drivers only support "one-shot" mode. Continuous capture mode is not currently supported.

The CPU ADCs are not yet supported.

Available ADC pins

On the ConnectCore 8X system-on-module there are:

  • 11 MCA pads that can be configured as ADC channels:

    • MCA_IO1

    • MCA_IO2

    • MCA_IO3

    • MCA_IO4

    • MCA_IO5

    • MCA_IO6

    • MCA_IO7

    • MCA_IO8

    • MCA_IO11

    • MCA_IO12

    • MCA_IO14

MCA_IO11 and MCA_IO12 are only ADC capable in SOMv1.

On the ConnectCore 8X SBC Express:

  • The following ADC channels are accessible on the Raspberry Pi expansion connector J11:

    • MCA_IO3 (MCA ADC channel 3)

    • MCA_IO4 (MCA ADC channel 4)

    • MCA_IO5 (MCA ADC channel 5)

    • MCA_IO6 (MCA ADC channel 6)

    • MCA_IO7 (MCA ADC channel 7)

    • MCA_IO8 (MCA ADC channel 8)

  • The following ADC channels are accessible on the Raspberry Pi expansion connector J17 (not assembled connector):

    • MCA_IO1 (MCA ADC channel 1)

    • MCA_IO2 (MCA ADC channel 2)

On the ConnectCore 8X SBC Pro:

  • The following ADC channels are accessible on the expansion connector J20:

    • MCA_IO5 (MCA ADC channel 5)

    • MCA_IO6 (MCA ADC channel 6)

    • MCA_IO7 (MCA ADC channel 7)

    • MCA_IO8 (MCA ADC channel 8)

    • MCA_IO14 (MCA ADC channel 14)

Formula

The value read on the ADC inputs responds to the formula:

VREAD = VIN * 4095 / VREF

where:

  • VREAD is the digital value read

  • VIN is the analog input voltage

  • VREF is the ADC voltage reference

Voltage reference

The result of the ADC conversion for a given input voltage is inversely proportional to the reference voltage (VREF) of the ADC.

  • For the MCA ADCs the reference voltage is configurable through one of the following device tree properties:

    • digi,adc-vref = <value_in_mV>: This device tree entry makes MCA ADCs use MCA_VCC as reference voltage. This is an input voltage for the ConnectCore 8X so you must configure it to the voltage value for your board.

    • digi,internal-vref: This boolean device tree entry makes MCA ADCs use a steady temperature-compensated 1.2 V as reference voltage.

      • Pad MCA_VREF_OUT will output the 1.2 V to be used as a voltage reference for external peripherals.

      • The value in digi,adc-vref property will be ignored

ADC channel mapping

  • The indexes of MCA ADC channels correspond with their MCA IO number: MCA_IO1 is channel 1, MCA_IO2 is channel 2, and so on.

Not all MCA IO pins are ADC-capable.

Kernel configuration

You can manage the MCA ADC driver support through the following kernel configuration option:

  • Digi ConnectCore 8X Micro Controller Assist ADC (CONFIG_MCA_CC8X_ADC)

This option is enabled as built-in on the default ConnectCore 8X kernel configuration file.

Kernel driver

The ADC drivers are located at:

File Description

drivers/iio/adc/mca-cc8x-adc.c

ConnectCore 8X MCA ADC driver

drivers/iio/adc/mca-common-adc.c

Common code for MCA and I/O expander ADC driver

Device tree bindings and customization

The MCA ADC device tree binding is documented at Documentation/devicetree/bindings/iio/adc/digi,mca-adc.txt.

The device tree must contain entries for:

  • The ADC interface

  • The enabled channels

ConnectCore 8X MCA ADC interface

ConnectCore 8X device tree
	mca_cc8x: mca@63 {
		mca_adc: adc {
			compatible = "digi,mca-cc8x-adc";
		};
	};

MCA-enabled ADC channels and voltage reference

This example describes how to enable MCA ADC channels 1 to 8 (corresponding to pads MCA_IO1 to MCA_IO8) by using property digi,adc-ch-list to specify the channels you want to enable.

For accurate measurements conversion, the input voltage VCC_MCA must be measured and passed to the kernel via property digi,adc-vref.

ConnectCore 8X SBC Express device tree
&mca_adc {
	digi,adc-ch-list = <1 2 3 4 5 6 7 8>;
	digi,adc-vref = <3000000>;
};

Customize the ADCs for your platform

Follow these steps to configure ADC channels on your custom design:

  • Identify the pins that you want configured as ADC and verify that they are ADC-capable.

  • In the device tree of your platform, create or uncomment the nodes for the ADC interfaces you plan to use (mca_adc for MCA).

  • Enable the channels indexes that you want to enable by using digi,adc-ch-list (for MCA ADC channels).

  • Compile the device tree and install it in your platform.

Using the ADCs

The ADC drivers are designed as standard Industrial I/O (IIO) device drivers that can be accessed from the sysfs or from user applications.

Sysfs access

When enabled, the ADC drivers will create the corresponding device entries in the IIO sysfs directory (/sys/bus/iio/devices). To determine which entry corresponds to which driver, read the name descriptor with:

Reading an ADC name through the sysfs
~# cat /sys/bus/iio/devices/iio\:device0/name
mca-cc8x-adc

In this example, device0 corresponds to the MCA ADC.

The driver creates a file entry named in_voltageX_raw for each ADC channel, where X corresponds to the channel number. Read the input value of a channel with:

Reading an ADC through the sysfs
~# cat /sys/bus/iio/devices/iio\:device0/in_voltage1_raw
768

The returned value is a decimal number with the result of the conversion. In the example:

VREAD = VIN * 4095 / VREF → VIN = VREAD * VREF / 4095 → VIN = 768 * 3 / 4095 = 0.563 V

To help with the calculation you can simply multiply the read value by the value contained in the in_voltage_scale descriptor:

Reading voltage scale through the sysfs
~# cat /sys/bus/iio/devices/iio\:device0/in_voltage_scale
0.732421875

VIN = VREAD * Scale = 768 * 0.732421875 = 0.563 V

Sample application

An example application called adc_sample is included in the dey-examples package of meta-digi layer. This application shows how to access the ADCs on the ConnectCore 8X platform.

To learn the syntax of the application run:

Sample application
~# adc_sample --help