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.

Available ADC pins

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

  • Six i.MX8QXP pads that can be configured as ADC channels (multiplexed with other functionality):

    • ADC_IN0

    • ADC_IN1

    • ADC_IN2

    • ADC_IN3

    • ADC_IN4

    • ADC_IN5

  • 9 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_IO14

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)

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

    • ADC_IN0 (i.MX8QXP ADC channel 0)

    • ADC_IN1 (i.MX8QXP ADC channel 1)

    • ADC_IN2 (i.MX8QXP ADC channel 2)

    • ADC_IN3 (i.MX8QXP ADC channel 3)

    • ADC_IN4 (i.MX8QXP ADC channel 4)

    • ADC_IN5 (i.MX8QXP 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 i.MX8QXP ADC channels, the reference voltage is taken from the input pad ADC_VREFH, which should never be above 1.8V.

    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 i.MX8QXP 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.

Kernel configuration

You can manage the i.MX8QXP and MCA ADC drivers support 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 driver

The ADC drivers are located at:

File Description

drivers/iio/adc/imx8qxp_adc.c

i.MX8QXP ADC driver

drivers/iio/adc/mca-adc.c

ConnectCore 8X MCA ADC driver

Device tree bindings and customization

The i.MX8QXP 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 i.MX8QXP ADC channels)

i.MX8QXP ADC interface

i.MX8QXP 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";
	};

ConnectCore 8X MCA ADC interface

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

i.MX8QXP enabled ADC channels and IOMUX configuration

This example describes how to enable i.MX8QXP ADC channel 4 by using property digi,adc-ch-list to specify the channels you want to enable.

The i.MX8QXP pads must have the IOMUX configuration to properly behave as ADC. This is not needed for MCA ADC channels.

i.MX8QXP pads should only have one IOMUX configuration. Remove other configurations for those pads, like GPIO, when configuring them as ADCs.
ConnectCore 8X SBC Pro device tree
&adc0 {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_adc0>;
	digi,adc-ch-list = <4>;
	status = "okay";
};

&iomuxc {
	/* Expansion Connector */
	pinctrl_expansion: expansiongrp {
		fsl,pins = <
			[...]

			/* Remove the pads you wish to use as ADCs */
			/* ADC_IN0 */
			SC_P_ADC_IN0_LSIO_GPIO1_IO10			0x06000020
			/* ADC_IN1 */
			SC_P_ADC_IN1_LSIO_GPIO1_IO09			0x06000020
			/* M40_UART_RX */
			SC_P_ADC_IN2_LSIO_GPIO1_IO12			0x06000020
			/* M40_UART_TX */
			SC_P_ADC_IN3_LSIO_GPIO1_IO11			0x06000020
	//		/* ADC_IN4 */
	//		SC_P_ADC_IN4_LSIO_GPIO1_IO14			0x06000020
			/* ADC_IN5 */
			SC_P_ADC_IN5_LSIO_GPIO1_IO13			0x06000020
		>;
	};

	/* 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
		>;
	};
};

MCA-enabled ADC channels and voltage reference

This example describes how to enable MCA ADC channels 5 to 8 by using property digi,adc-ch-list to specify the channels you want to enable.

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

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

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

  • For i.MX8QXP 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

You can access the ADC channels from your Android application. See ADC API for more information about the ADC APIx.

Sample application

The ADC Sample Application demonstrates the usage of the ADC API. In this example, you can select one of the ADC channels available in your ConnectCore 8X and configure the sample rate of that interface.

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