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 system-on-module provides two types of ADC interfaces:
-
The i.MX6UL 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 6UL system-on-module there are:
-
Ten i.MX6UL pads that can be configured as ADC channels (multiplexed with other functionality):
-
GPIO1_IO00
-
GPIO1_IO01
-
GPIO1_IO02
-
GPIO1_IO03
-
GPIO1_IO04
-
GPIO1_IO05
-
GPIO1_IO06
-
GPIO1_IO07
-
GPIO1_IO08
-
GPIO1_IO09
-
-
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:
-
The following ADC channels are accessible on the Raspberry Pi expansion connector J8:
-
GPIO1_IO04 (i.MX6UL ADC channel 4)
-
GPIO1_IO05 (i.MX6UL ADC channel 5)
-
MCA_IO0 (MCA ADC channel 0), requires a 0-ohm resistor
-
MCA_IO4 (MCA ADC channel 4)
-
-
The following ADC channels are accessible on Grove connector J11:
-
MCA_IO4 (MCA ADC channel 4)
-
-
The following ADC channels are accessible on Grove connector J12:
-
GPIO1_IO04 (i.MX6UL ADC channel 4), requires a 0-ohm resistor
-
MCA_IO0 (MCA ADC channel 0)
-
On the ConnectCore 6UL SBC Pro:
-
The following ADC channels are accessible on the GPIO expansion connector J30:
-
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)
-
-
The following ADC channels are accessible on the SPI expansion connector J34:
-
MCA_IO5 (MCA 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 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 indexes of i.MX6UL ADC channels correspond to their pad number: GPIO1_IO00 is channel 0, GPIO1_IO01 is channel 1, and so on.
-
The indexes of MCA ADC channels correspond to 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. See MCA I/O pads for a list of all available MCA IOs and their capabilities. -
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, MCA and I/O Expander ADC drivers support through the following kernel configuration options:
-
Freescale vf610 ADC driver (CONFIG_VF610_ADC)
-
Digi ConnectCore SOMs Micro Controller Assist ADC (CONFIG_MCA_ADC)
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 |
Device tree bindings and customization
The i.MX6UL ADC device tree binding is documented at Documentation/devicetree/bindings/iio/adc/vf610-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.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";
};
IOMUX configuration
You must configure the pads that are to be used as i.MX6UL ADCs as standard GPIOs (inputs). This is not needed for MCA or I/O expander ADC channels. See Pin multiplexing (IOMUX).
i.MX6UL pads should only have one IOMUX configuration. Remove other configurations for those pads, like PWM, when configuring them as ADCs. |
The following external pads are configured as ADCs on the default device tree:
-
On the ConnectCore 6UL SBC Express expansion connector:
Pad Signal ADC channel 7
ADC/GPIO1_4
4
-
On the ConnectCore 6UL SBC Pro GPIO connector:
Pad Signal ADC channel 13
EXP_GPIO_3
2
Example: enable ADC channel 3 on ConnectCore 6UL SBC Pro
For example, ADC channel 3 is available on the ConnectCore 6UL SBC Pro GPIO connector which corresponds to pad GPIO1_IO03 of the CPU. In order to enable it, you must:
-
Configure the IOMUX of pad GPIO1_IO03 to work as GPIO.
-
Remove any other GPIO1_IO03 IOMUX configuration from any active driver pinctrl group.
-
Add channel 3 to adc-ch-list property on the ADC node.
-
Enable the ADC node.
&adc1 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_adc1>;
adc-ch-list = <2 3>;
status = "okay";
};
&iomuxc {
imx6ul-ccimx6ul {
/* Uncomment specific pins of the ADC channels enabled in 'adc-ch-list' */
pinctrl_adc1: adc1grp {
fsl,pins = <
/*
* EXP_GPIO_1 -> GPIO1_5/ADC1_IN5, it also
* requires disabling 'pwm4'
*/
// MX6UL_PAD_GPIO1_IO05__GPIO1_IO05 0x1b0b0
/* EXP_GPIO_2 -> GPIO1_3/ADC1_IN3 */
MX6UL_PAD_GPIO1_IO03__GPIO1_IO03 0xb0
/* EXP_GPIO_3 -> GPIO1_2/ADC1_IN2 */
MX6UL_PAD_GPIO1_IO02__GPIO1_IO02 0xb0
>;
};
};
};
ConnectCore 6UL MCA ADC interface
mca_cc6ul: mca@7e {
mca_adc: adc {
compatible = "digi,mca-cc6ul-adc";
};
};
Example: enable MCA ADC channel 4 on ConnectCore 6UL SBC Express
For example, MCA ADC channel 4 is available on the ConnectCore 6UL SBC Express expansion connector. In order to enable it, you must:
-
Add channel 4 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.
&mca_adc {
digi,adc-ch-list = <0 4>;
digi,adc-vref = <3000000>;
};
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>;
};
};
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 (adc1 for i.MX6UL and mca_adc for MCA).
-
Enable the channel indexes 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 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 for the MCA ADC:
\$V_(READ) = (V_(IN) * 4095) / V_(REF) -> V_(IN) = (V_(READ) * V_(REF)) / 4095 -> V_(IN) = (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
\$V_(IN) = V_(READ) * "<in_voltage_scale>" = 768 * 0.732421875 = 562.5 mV = 0.563 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 6UL platform.
Go to GitHub to see the application instructions and source code.
See ADC API for more information about the ADC APIx.