You are here: Digi Embedded Yocto > System development > Linux v4.1 Board Support Package > Devices and interfaces > Analog-to-digital converter (ADC)

Analog-to-Digital Converter (ADC)

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 6UL provides two types of ADC interfaces:

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 are recommended. The ADC drivers only support "one-shot" mode. Continuous capture mode is not currently supported.

Available ADC pins

On the ConnectCore 6UL there are:

On the ConnectCore 6UL SBC Express:

On the ConnectCore 6UL SBC Pro:

Formula

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

VREAD = VIN * 4095 / VREF

where:

Voltage reference

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

CAUTION! MCA_VCC is an input voltage for the ConnectCore 6UL so the user must configure this reference voltage via the device tree (property digi,adc-vref) for accurate conversion of measurements using the MCA ADC channels.

ADC channel mapping

CAUTION! Not all MCA IO pins are ADC-capable.

CAUTION! Not all I/O expander pins are ADC-capable.

Kernel configuration

You can manage the i.MX6 ADC driver support through the following kernel configuration option:

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

You can manage the I/O Expander ADC driver support through the following kernel configuration option:

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

Platform driver mapping

The ADC drivers are located at:

File

Description

drivers/iio/adc/vf610_adc.c

i.MX6UL ADC driver

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

ConnectCore 6UL MCA ADC driver

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

Digi I/O expander 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 i.MX6UL ADC device tree binding is documented at Documentation/devicetree/bindings/iio/adc/vf610-adc.txt.

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

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

The device tree must contain entries for:

i.MX6UL ADC interface

Common i.MX6UL device tree 
            adc1: adc@02198000 {
                compatible = "fsl,imx6ul-adc", "fsl,vf610-adc";
                reg = <0x02198000 0x4000>;
                interrupts = <GIC_SPI 100 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&clks IMX6UL_CLK_ADC1>;
                num-channels = <2>;
                clock-names = "adc";
                status = "disabled";
            };

ConnectCore 6UL MCA ADC interface

Common ConnectCore 6UL device tree 
    mca_cc6ul: mca@7e {
        mca_adc: adc {
            compatible = "digi,mca-cc6ul-adc";
        };
    };

I/O expander ADC interface (ConnectCore 6UL SBC Pro only)

Common ConnectCore 6UL device tree 
    mca_ioexp: mca_io@6e {
        mca_ioexp_adc: adc {
            compatible = "digi,mca-ioexp-adc";
            digi,adc-vref = <3300000>;
        };
    };

i.MX6UL enabled ADC channels and IOMUX configuration

This example describes how to enable i.MX6UL ADC channel 4 (corresponding to pad GPIO1_IO04) by using property adc-ch-list to specify the channels you want to enable.

The i.MX6UL pads must have the IOMUX configuration to properly behave as ADC (this is not needed for MCA ADC channels).

&adc1 {
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_adc1>;
    adc-ch-list = <4>;
    status = "okay";
};
 
&iomuxc {
    imx6ul-ccimx6ul {
        /* Uncomment specific pins of the ADC channels enabled in 'adc-ch-list' */
        pinctrl_adc1: adc1grp {
            fsl,pins = <
                /* GPIO1_4/ADC1_IN4 (pin 7 of the expansion header) */
                MX6UL_PAD_GPIO1_IO04__GPIO1_IO04        0xb0
            >;
        };
    };
};

MCA-enabled ADC channels and voltage reference

This example describes how to enable MCA ADC channels 0 and 4 (corresponding to pads MCA_IO0 and MCA_IO4) by using property digi,adc-ch-list to specify the channels you want to enable.

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

&mca_adc {
    digi,adc-ch-list = <0 4>;
    digi,adc-vref = <3000000>;
};

Customize the ADCs for your platform

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

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 (MCA and i.MX6UL) 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:

~# cat /sys/bus/iio/devices/iio\:device0/name
mca-cc6ul-adc
~# cat /sys/bus/iio/devices/iio\:device1/name
2198000.adc

In this example, device0 corresponds to the MCA ADC and device1 corresponds to the i.MX6UL 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_voltage0_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 an ADC 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 6UL platform (both i.MX6UL and MCA ADCs).

To learn the syntax of the application run:

Sample application 
~# adc_sample --help

Find the source code of the application under ${DEY_INSTALL_DIR}/sources/meta-digi/meta-digi-dey/dey-examples/files/adc_sample/.

 

© 2017 Digi International Inc. All rights reserved.
Analog-to-Digital Converter (ADC) updated on 10 July 2017 11:24:29 AM