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:
-
The i.MX6UL CPU ADCs (mapped to GPIO1_IO00 to GPIO1_IO09 pads)
-
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 are recommended. The ADC drivers only support "one-shot" mode. Continuous capture mode is not currently supported.
Available ADC pins
On the ConnectCore 6UL:
-
10 CPU pads (GPIO1_IO00..GPIO1_IO09) that can be configured as ADC channels (multiplexed with other functionality).
-
Five MCA pads that can be configured as ADC channels:
-
MCA_IO0
-
MCA_IO1
-
MCA_IO3
-
MCA_IO4
-
MCA_IO5
-
On the ConnectCore 6UL SBC Express:
-
GPIO1_IO04 (i.MX6UL ADC channel 4) is accessible on the expansion connector and optionally (requires a 0-ohm resistor) on Grove connector J12.
-
MCA_IO0 (MCA ADC channel 0) is accessible on Grove connector J12.
-
MCA_IO4 (MCA ADC channel 4) is accessible on the expansion connector and on Grove connector J11.
On the ConnectCore 6UL SBC Pro:
-
The following ADC channels are accessible on the GPIO expansion connector:
-
EXP_GPIO_1 (i.MX6UL ADC channel 5)
-
EXP_GPIO_2 (i.MX6UL ADC channel 3)
-
EXP_GPIO_3 (i.MX6UL ADC channel 2)
-
MCA_IO1 (MCA ADC channel 1)
-
MCA_IO3 (MCA ADC channel 3)
-
IOEXP_IO3 (I/O Expander ADC channel 3)
-
IOEXP_IO4 (I/O Expander ADC channel 4)
-
IOEXP_IO5 (I/O Expander ADC channel 5)
-
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 i.MX6UL ADC channels the reference voltage is the output of PMIC regulator vdda_adc_3v3, which is configured by default to 3.3V.
-
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 6UL 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_IO2/EXT_VREF will output the 1.2 V to be used as a voltage reference for external peripherals.
-
A 100 nF capacitor must be placed between MCA_IO2/EXT_VREF line and GND so that the reference works properly.
-
The value in digi,adc-vref property will be ignored
-
-
-
For the I/O expander ADC channels on the ConnectCore 6UL SBC Pro the reference voltage is the 3V3_IOEXP line, which is connected to a 3.3V regulator.
ADC channel mapping
-
The i.MX6UL ADC channels are available on the pads GPIO1_IO00 to GPIO1_IO09, which correspond to the ADC channels 0 to 9.
-
The indexes of MCA ADC channels correspond with their MCA IO number: MCA_IO0 is channel 0, MCA_IO4 is channel 4, and so on.
Not all MCA IO pins are ADC-capable. |
-
The indexes of I/O expander ADC channels on ConnectCore 6UL SBC Pro correspond to their IO number: IOEXP_IO3 is channel 3, IOEXP_IO4 is channel 4, and so on.
Not all I/O expander pins are ADC-capable. |
Kernel configuration
You can manage the i.MX6UL ADC driver support through the following kernel configuration option:
-
Freescale vf610 ADC driver (CONFIG_VF610_ADC)
You can manage the MCA ADC driver support through the following kernel configuration option:
-
Digi ConnectCore 6UL Micro Controller Assist ADC (CONFIG_MCA_CC6UL_ADC)
You can manage the I/O Expander ADC driver support through the following kernel configuration option:
-
Digi IO Expander (CONFIG_MFD_MCA_IOEXP)
These options are enabled as built-in on the default ConnectCore 6UL kernel configuration file.
Kernel driver
The ADC drivers are located at:
File | Description |
---|---|
i.MX6UL ADC driver |
|
ConnectCore 6UL MCA ADC driver |
|
Digi I/O expander ADC driver |
|
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:
-
The ADC interface
-
The enabled channels
-
The IOMUX (only for i.MX6UL ADC channels)
i.MX6UL ADC interface
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
mca_cc6ul: mca@7e {
mca_adc: adc {
compatible = "digi,mca-cc6ul-adc";
};
};
I/O expander ADC interface (ConnectCore 6UL SBC Pro only)
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:
-
Identify the pins that you want configured as ADC and verify that they are ADC-capable (either MCA or i.MX6UL).
-
In the device tree of your platform, create or uncomment the nodes for the ADC interfaces you plan to use (mca_adc for MCA and adc1 for i.MX6UL).
-
Enable the channels indexes that you want to enable by using the adc-ch-list property (for i.MX6UL ADC channels) or digi,adc-ch-list (for MCA ADC channels).
-
For i.MX6UL ADC channels, configure the iomux of the pins to operate as ADC 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 (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:
~# 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:
~# 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.
To learn the syntax of the application run:
~# 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/.