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 8M Mini provides two types of ADC interfaces:
-
The i.MX8M Mini 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 8M Mini system-on-module:
The ConnectCore 8M Mini provides two types of ADC interfaces - i.MX8M Mini CPU ADCs and Micro Controller Assist (MCA) ADCs.
-
Six i.MX8M Mini 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 8M Mini Development Kit:
-
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 (i.MX8M Mini ADC channel 0)
-
ADC_IN1 (i.MX8M Mini ADC channel 1)
-
ADC_IN2 (i.MX8M Mini ADC channel 2)
-
ADC_IN3 (i.MX8M Mini ADC channel 3)
-
ADC_IN4 (i.MX8M Mini ADC channel 4)
-
ADC_IN5 (i.MX8M Mini 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.MX8M Mini 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 8M Mini 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 8M Mini 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.MX8M Mini 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 8M Mini kernel configuration file.
Kernel drivers
-
i.MX8M Mini ADC driver:
drivers/iio/adc/imx8qxp_adc.c
-
ConnectCore 8M Mini MCA ADC driver:
drivers/iio/adc/mca-adc.c
Device tree bindings and customization
The i.MX8M Mini 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.MX8M Mini ADC channels)
i.MX8M Mini ADC interface
adc0: adc@5a880000 {
compatible = "fsl,imx8qxp-adc";
reg = <0x5a880000 0x10000>;
interrupts = <GIC_SPI 240 IRQ_TYPE_LEVEL_HIGH>;
interrupt-parent = <&gic>;
clocks = <&adc0_lpcg 0>,
<&adc0_lpcg 1>;
clock-names = "per", "ipg";
assigned-clocks = <&clk IMX_SC_R_ADC_0 IMX_SC_PM_CLK_PER>;
assigned-clock-rates = <24000000>;
power-domains = <&pd IMX_SC_R_ADC_0>;
status = "disabled";
};
IOMUX configuration
You must configure the pads that are to be used as i.MX8M Mini ADCs. This is not needed for MCA ADC channels. See Pin multiplexing (IOMUX).
i.MX8M Mini 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 8M Mini Development Kit expansion connector:
Pad Signal ADC channel D13
ADC_IN0
0
Example: enable ADC channel 4 on ConnectCore 8M Mini Development Kit
For example, ADC channel 4 is available on the ConnectCore 8M Mini Development Kit 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.
&adc0 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_adc0>;
digi,adc-ch-list = <0 4>;
status = "okay";
};
&adc0 {
vref-supply = <®_1v8_adc_vref>;
digi,max-channel = <5>;
};
&iomuxc {
[...]
/* Uncomment the pads you wish to use as ADCs */
pinctrl_adc0: adc0grp {
fsl,pins = <
/* ADC_IN0 */
{cpu-prefix-ucase}_ADC_IN0_ADMA_ADC_IN0 0xc0000060
// /* ADC_IN1 */
// {cpu-prefix-ucase}_ADC_IN1_ADMA_ADC_IN1 0xc0000060
// /* M40_UART_RX */
// {cpu-prefix-ucase}_ADC_IN2_ADMA_ADC_IN2 0xc0000060
// /* M40_UART_TX */
// {cpu-prefix-ucase}_ADC_IN3_ADMA_ADC_IN3 0xc0000060
// /* ADC_IN4 */
// {cpu-prefix-ucase}_ADC_IN4_ADMA_ADC_IN4 0xc0000060
// /* ADC_IN5 */
// {cpu-prefix-ucase}_ADC_IN5_ADMA_ADC_IN5 0xc0000060
>;
};
};
ConnectCore 8M Mini MCA ADC interface
mca_cc8m: mca@63 {
mca_adc: adc {
compatible = "digi,mca-adc";
digi,adc-vref = <3000000>;
};
};
Example: enable MCA ADC channels 7 and 8 on ConnectCore 8M Mini Development Kit
For example, MCA ADC channels 7 and 8 are available on the ConnectCore 8M Mini Development Kit 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
.
&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 i.MX8M Mini andmca_adc
for MCA). -
Enable the channel indexes you want to enable by using
digi,adc-ch-list
(for both i.MX8M Mini and MCA ADC channels). -
For i.MX8M Mini 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:
# cat /sys/bus/iio/devices/iio\:device0/name
5a880000.adc
# cat /sys/bus/iio/devices/iio\:device1/name
mca-som-adc
In this example, device0
corresponds to the i.MX8M Mini 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:
# 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 i.MX8M Mini 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:
# 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 the meta-digi layer.
This application shows how to access the ADCs using Digi APIx library on the ConnectCore 8M Mini platform.
Go to GitHub to see the application instructions and source code.
See ADC API for more information about the ADC APIx.