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 {cpu-family} 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.

Available ADC pins

On the ConnectCore 8X system-on-module:

The ConnectCore 8X provides two types of ADC interfaces - {cpu-family} CPU ADCs and Micro Controller Assist (MCA) ADCs.

  • Six {cpu-family} pads can be configured as ADC channels (multiplexed with other functionality):

    • ADC_IN0

    • ADC_IN1

    • ADC_IN2

    • ADC_IN3

    • ADC_IN4

    • ADC_IN5

  • Nine MCA pads can be configured as ADC channels:

    • MCA_IO1

    • MCA_IO2

    • MCA_IO3

    • MCA_IO4

    • MCA_IO5

    • MCA_IO6

    • MCA_IO7

    • MCA_IO8

    • MCA_IO14

On the ConnectCore 8X SBC Pro:

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

    • MCA_IO7 (MCA ADC channel 7)

    • MCA_IO8 (MCA ADC channel 8)

    • MCA_IO14 (MCA ADC channel 14)

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

    • ADC_IN0 ({cpu-family} ADC channel 0)

    • ADC_IN1 ({cpu-family} ADC channel 1)

    • ADC_IN2 ({cpu-family} ADC channel 2)

    • ADC_IN3 ({cpu-family} ADC channel 3)

    • ADC_IN4 ({cpu-family} ADC channel 4)

    • ADC_IN5 ({cpu-family} ADC channel 5)

Formula

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

\$V_(READ) = (V_(IN) * 4095) / V_(REF)\$

where:

  • VREAD is the digital value read

  • VIN is the analog input voltage

  • VREF is the ADC voltage reference

Voltage reference

  • For the {cpu-family} ADC channels, the reference voltage is taken from the input pad ADC_VREFH, which should never be above 1.8 V.

    Digi recommends using ConnectCore 8X LGA output VDD_ADC_1V8 as the voltage reference.
  • 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 {cpu-family} ADC channels correspond to their pad number: ADC_IN0 is channel 0, ADC_IN1 is channel 1, and so on.

  • The indexes of MCA ADC channels correspond to 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. See MCA I/O pads for a list of all available MCA IOs and their capabilities.

Kernel configuration

You can manage the ADC drivers through the following kernel configuration options:

  • IMX8QXP ADC driver (CONFIG_IMX8QXP_ADC)

  • Digi ConnectCore SOMs Micro Controller Assist ADC (CONFIG_MCA_ADC)

These options are enabled as built-in on the default ConnectCore 8X kernel configuration file.

Kernel drivers

Device tree bindings and customization

The {cpu-family} ADC device tree binding is documented at Documentation/devicetree/bindings/iio/adc/imx8qxp-adc.txt.

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

  • The IOMUX (only for {cpu-family} ADC channels)

{cpu-family} ADC interface

{cpu-family} device tree
	adc0: adc@5a880000 {
		compatible = "fsl,imx8qxp-adc";
		reg = <0x0 0x5a880000 0x0 0x10000>;
		interrupts = <GIC_SPI 240 IRQ_TYPE_LEVEL_HIGH>;
		interrupt-parent = <&gic>;
		clocks = <&clk IMX8QXP_ADC0_CLK>,
			 <&clk IMX8QXP_ADC0_IPG_CLK>;
		clock-names = "per", "ipg";
		assigned-clocks = <&clk IMX8QXP_ADC0_CLK>;
		assigned-clock-rates = <24000000>;
		power-domains = <&pd_dma_adc0>;
		status = "disabled";
	};

IOMUX configuration

You must configure the pads that are to be used as {cpu-family} ADCs. This is not needed for MCA ADC channels. See Pin multiplexing (IOMUX).

{cpu-family} pads should only have one IOMUX configuration. Remove other configurations for those pads, like GPIO, when configuring them as ADCs.

The following external pads are configured as ADCs on the default device tree:

  • On the ConnectCore 8X SBC Pro expansion connector:

    Pad Signal ADC channel

    D13

    ADC_IN0

    0

Example: enable ADC channel 4 on ConnectCore 8X SBC Pro

For example, ADC channel 4 is available on the ConnectCore 8X SBC Pro expansion connector, which corresponds to pad ADC_IN4 of the CPU. In order to enable it, you must:

  • Configure the IOMUX of pad ADC_IN4 to work as ADC.

  • Remove any other ADC_IN4 IOMUX configuration from any active driver pinctrl group.

  • Add channel 4 to digi,adc-ch-list property on the ADC node.

  • Enable the ADC node.

ConnectCore 8X SBC Pro device tree
&adc0 {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_adc0>;
	digi,adc-ch-list = <0 4>;
	status = "okay";
};

&iomuxc {
	[...]

	/* Uncomment the pads you wish to use as ADCs */
	pinctrl_adc0: adc0grp {
		fsl,pins = <
			/* ADC_IN0 */
			SC_P_ADC_IN0_ADMA_ADC_IN0		0xc0000060
	//		/* ADC_IN1 */
	//		SC_P_ADC_IN1_ADMA_ADC_IN1		0xc0000060
	//		/* M40_UART_RX */
	//		SC_P_ADC_IN2_ADMA_ADC_IN2		0xc0000060
	//		/* M40_UART_TX */
	//		SC_P_ADC_IN3_ADMA_ADC_IN3		0xc0000060
			/* ADC_IN4 */
			SC_P_ADC_IN4_ADMA_ADC_IN4		0xc0000060
	//		/* ADC_IN5 */
	//		SC_P_ADC_IN5_ADMA_ADC_IN5		0xc0000060
		>;
	};
};

ConnectCore 8X MCA ADC interface

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

Example: enable MCA ADC channels 7 and 8 on ConnectCore 8X SBC Pro

For example, MCA ADC channels 7 and 8 are available on the ConnectCore 8X SBC Pro expansion connector. To enable them, you must:

  • Add channels 7 and 8 to digi,adc-ch-list property on the ADC node.

  • Enable the mca_adc node.

For accurate measurement conversion, you must measure the input voltage MCA_VCC and pass it to the kernel via property digi,adc-vref.

ConnectCore 8X SBC Pro device tree
&mca_adc {
	digi,adc-ch-list = <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 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 (adc0 for {cpu-family} and mca_adc for MCA).

  • Enable the channel indexes you want to enable by using digi,adc-ch-list (for both {cpu-family} and MCA ADC channels).

  • For {cpu-family} ADC channels, configure the IOMUX of the pins to operate just as ADCs and configure the pad settings.

  • 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 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
5a880000.adc
# cat /sys/bus/iio/devices/iio\:device1/name
mca-cc8x-adc

In this example, device0 corresponds to the {cpu-family} ADC and device1 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
37

The returned value is a decimal number with the result of the conversion. In the example for the {cpu-family} ADC:

\$V_(READ) = (V_(IN) * 4095) / V_(REF) -> V_(IN) = (V_(READ) * V_(REF)) / 4095 -> V_(IN) = (37 * 1.8) / 4095 = 0.016 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.439453125

\$V_(IN) = V_(READ) * "<in_voltage_scale>" = 37 * 0.439453125 = 16.259 mV = 0.016 V\$

Sample application

An example application called apix-adc-example is included in the dey-examples-digiapix recipe (part of dey-examples package) of meta-digi layer. This application shows how to access the ADCs using Digi APIx library on the ConnectCore 8X platform.

Go to GitHub to see the application instructions and source code.

See ADC API for more information about the ADC APIx.