Roadrunner technical documentation Buy on-line

How to use the ADC lines

This article illustrates how to use the ADC lines on Roadrunner board

Tested on Linux Kernel: 4.19.78

Pinout of ADC lines

Up to 12 ADC lines are available on the RoadRunner SOM:

Signal Description Line
3.3V 3.3 volt power line
AVDD Clean 3.24V out for A/D circuitry
VREF A/D voltage reference input
AGND Analog GND
AD0 Analog input 0 PD19
AD1 Analog input 1 PD20
AD2 Analog input 2 PD21
AD3 Analog input 3 PD22
AD4 Analog input 4 PD23
AD5 Analog input 5 PD24
AD6 Analog input 6 PD25
AD7 Analog input 7 PD26
AD8 Analog input 8 PD27
AD9 Analog input 9 PD28
AD10 Analog input 10 PD29
AD11 Analog input 11 PD30
GND Digital GND

Enable the Linux Kernel ADC modules

To enable the ADC Linux driver and the IIO user space interface inside make menuconfig:

Device Drivers  ---> 
    <*> Industrial I/O support  ---> 
        <*> Enable software IIO device support 
        <*> Enable software triggers support
        Analog to digital converters  --->
            <*> Atmel AT91 ADC
            <*> Atmel AT91 SAMA5D2 ADC      

Follow this article to compile the Linux Kernel, enable the right drivers and use the right device tree definitions.

Configure the device tree

Edit the device tree source at arch/arm/boot/dts/at91-sama5d2_roadrunner.dts of your board adding these lines:

Insert this definition to enable the driver:

vddin_3v3: fixed-regulator-vddin_3v3 {
    compatible = "regulator-fixed";

    regulator-name = "VDDIN_3V3";
    regulator-min-microvolt = <3300000>;
    regulator-max-microvolt = <3300000>;
    regulator-always-on;
    regulator-boot-on;
    status = "okay";
};

vddana: fixed-regulator-vddana {
    compatible = "regulator-fixed";

    regulator-name = "VDDANA";
    regulator-min-microvolt = <3300000>;
    regulator-max-microvolt = <3300000>;
    regulator-always-on;
    regulator-boot-on;
    vin-supply = <&vddin_3v3>;
    status = "okay";
};

advref: fixed-regulator-advref {
    compatible = "regulator-fixed";

    regulator-name = "advref";
    regulator-min-microvolt = <3300000>;
    regulator-max-microvolt = <3300000>;
    regulator-always-on;
    regulator-boot-on;
    vin-supply = <&vddana>;
    status = "okay";
};

adc: adc@fc030000 {
    vddana-supply = <&vddana>; 
    vref-supply =  <&vddana>; 
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_adc_default>;
    status = "okay";
};

Insert this definition to select the pin to use:

pinctrl_adc_default: adc_default {
    pinmux = <PIN_PD19__GPIO>,
            <PIN_PD20__GPIO>,
            <PIN_PD21__GPIO>,
            <PIN_PD22__GPIO>,
            <PIN_PD23__GPIO>,
            <PIN_PD24__GPIO>,
            <PIN_PD25__GPIO>,
            <PIN_PD26__GPIO>,
            <PIN_PD27__GPIO>,
            <PIN_PD28__GPIO>,
            <PIN_PD29__GPIO>,
            <PIN_PD30__GPIO>;
    bias-disable;
};

Generate the at91-sama5d2_roadrunner.dtb:

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- at91-sama5d2_roadrunner.dtb

Rename it in acme-roadrunner.dtb and save it inside boot partition.

Use the ADC from command line

cat /sys/bus/iio/devices/iio\:device0/in_voltage0_raw
cat /sys/bus/iio/devices/iio\:device0/in_voltage1_raw
...
cat /sys/bus/iio/devices/iio\:device0/in_voltage11_raw

More in-depth examples are available from Microchip at:

Python example

Without using mpio library:

import time

def get_adc(id):
    with open("/sys/bus/iio/devices/iio:device0/in_voltage%d_raw" % id) as f:
        value=int(f.read())
        return value

while True:
    print "ADC value: %d" % get_adc(0)
    time.sleep(1)

Using mpio library:

from mpio import ADC
import time

while True:
    adc = ADC(0)
    print "ADC value: %d" % adc.value(0)
    time.sleep(1)

Links

Sergio Tanzilli
System designer, webmaster and Acme Systems co-founder
Personal email: tanzilli@acmesystems.it
Webpages: https://www.acmesystems.it - https://www.tanzolab.it
Github repositories: https://github.com/tanzilli and https://github.com/acmesystems
Telegram group dedicated to the Acme Systems boards: https://t.me/acmesystemssrl

Roadrunner technical documentation Buy on-line

Bruna Mandolino