An Analog-to-Digital Converter (ADC) is a device that translates an analog voltage to a digital value that a microprocessor can understand.

The MCA ADC controllers are 12-bit resolution, right justified, unsigned format. The MCA ADC channels are suitable for low-frequency sampling (under 10 Hz).

Available ADC pins

On the ConnectCore 8M Nano system-on-module:

  • Five MCA pads can be configured as ADC channels:

    • MCA_IO1

    • MCA_IO2

    • MCA_IO3

    • MCA_IO4

    • MCA_IO14

On the ConnectCore 8M Nano Development Kit:

  • The following ADC channels are accessible on the XBee Cellular socket J39-J40:

    • MCA_IO1 (MCA ADC channel 1)

    • MCA_IO2 (MCA ADC channel 2)

    • MCA_IO3 (MCA ADC channel 3)

    • MCA_IO4 (MCA ADC channel 4)

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 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 Nano 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 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:

  • Digi ConnectCore SOMs Micro Controller Assist ADC (CONFIG_MCA_ADC)

These options are enabled as built-in on the default ConnectCore 8M Nano kernel configuration file.

Kernel drivers

Device tree bindings and customization

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

ConnectCore 8M Nano MCA ADC interface

ConnectCore 8M Nano device tree
	mca_cc8m: mca@63 {
		mca_adc: adc {
			compatible = "digi,mca-cc8m-adc";
		};
	};

Example: enable MCA ADC channels 1, 2, 3 and 4 on ConnectCore 8M Nano Development Kit

For example, MCA ADC channels 1, 2, 3 and 4 are available on the ConnectCore 8M Nano Development Kit XBee Cellular socket. To enable them, you must:

  • Disable the mca_uart2 node on the device tree.

  • Add channels 1, 2, 3 and 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.

ConnectCore 8M Nano Development Kit device tree
//&mca_uart {
//	status = "okay";

	/* UART connected to XBee cellular socket */
//	mca_uart2: serial@0x940 {
//		iopins-names = "rx", "tx", "cts", "rts";
//		iopins = <2 1 3 4>;
//	};
//};

&mca_adc {
	digi,adc-ch-list = <1 2 3 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 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 (mca_adc for MCA).

  • Enable the channel indexes you want to enable by using digi,adc-ch-list.

  • 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:

Reading an ADC name through the sysfs
# cat /sys/bus/iio/devices/iio\:device0/name
mca-cc8m-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_voltage1_raw
37

The returned value is a decimal number with the result of the conversion. In the example for the {cpu-family} 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:

Reading voltage scale through the sysfs
# 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 meta-digi layer. This application shows how to access the ADCs using Digi APIx library on the ConnectCore 8M Nano platform.

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

See ADC API for more information about the ADC APIx.