Roadrunner technical documentation Buy

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

Related products

RoadRunner D2

Info Doc Buy

  • CPU Microchip SAMA5D27
  • Cortex A5 @ 500 MHz
  • Very low power consumption:
    396mW in full speed mode
    198mW at Linux prompt
    17mW in standby mode
    10mW in suspend to RAM mode
  • Armhf architecture
  • DDR3L RAM 256 MB
  • QuadSPI 0/16/64/128MB
  • Size: 40x30 mm
  • Plug-in module
  • 200 pins 0.4 mm pitch
  • TFT parallel interface
  • Boot from internal Quad SPI or external uSD/eMMC
  • Linux Kernel 5.15 LTS
  • Debian, Buildroot and Yocto
  • Open source drivers
H10

Info Doc Buy

  • Single Board Computer based on RoadRunner Linux SOM (Included)
  • Classic "Credit Card" form factor
  • Two USB Host 2.0 ports (one configurable as USB client on the USB-C connector)
  • One 10/100 Mbit/s Lan port
  • Two AcmeSensor ports
  • Double placements for 2.54mm pitch 20x2 pinstrips (not soldered) for GPIOS, SPI, I2C, Serial etc ports
  • Credit Card footprint

Info Buy

  • All the circuitries you need to test the RoadRunner SOM
  • USB host, USB device, Ethernet port, MicroSD socket
  • Test points for power consumption measurements
  • All the Roadrunner signals exposed on 2.54mm pitch pins
  • On-board supercap for RTC and backup memory circuit

Home page Roadrunner technical documentation Buy