How to use the ADC lines

This article illustrates how to use the ADC lines on the Acme Systems Linux boards based on Microchip SAMG2x, SAMA5D3x and SAMD2x CPUs

Step 1: Enable the Linux Kernel ADC modules

Follow this tutorial: Compile the Linux Kernel from sources to know how to cross compile the Linux Kernel and how to configure the drivers to enable inside it.

Enable the IIO user space interface and the Microchip/Atmel ADC device driver as shown below:

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      

Step 2: Configure the device tree

Edit the device tree source of your board adding these lines:

RoadRunner

Insert this definition to enable the driver:

adc: adc@fc030000 {
    compatible = "atmel,sama5d2-adc";
    vddana-supply = <&vdd_3v3_lp_reg>;
    vref-supply = <&vdd_3v3_lp_reg>;
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_adc_default>;
    status = "okay";

    vdd_3v3_lp_reg: REG_LDO2 {
        regulator-name = "VDD_3V3_LP";
        regulator-min-microvolt = <3300000>;
        regulator-max-microvolt = <3300000>;
        regulator-always-on;
    };
};

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>;
    bias-disable;
};

Acqua

Insert this definition to enable the driver and the pin to use (Acqua pinout):

adc0: adc@f8018000 {
    pinctrl-names = "default";
    pinctrl-0 = <
        &pinctrl_adc0_adtrg
        &pinctrl_adc0_ad0
        &pinctrl_adc0_ad1
        &pinctrl_adc0_ad2
        &pinctrl_adc0_ad3
        &pinctrl_adc0_ad4
        &pinctrl_adc0_ad5
        &pinctrl_adc0_ad6
        &pinctrl_adc0_ad7
        &pinctrl_adc0_ad8
        &pinctrl_adc0_ad9
        &pinctrl_adc0_ad10
        &pinctrl_adc0_ad11
        >;
    status = "okay";
};

Aria

pinctrl@fffff400 {
    adc0 {
        pinctrl_adc0_ad0: adc0_ad0 {
            atmel,pins = <AT91_PIOB 11 AT91_PERIPH_GPIO AT91_PINCTRL_NONE>;
        };
        pinctrl_adc0_ad1: adc0_ad1 {
            atmel,pins = <AT91_PIOB 12 AT91_PERIPH_GPIO AT91_PINCTRL_NONE>;
        };
        pinctrl_adc0_ad2: adc0_ad2 {
            atmel,pins = <AT91_PIOB 13 AT91_PERIPH_GPIO AT91_PINCTRL_NONE>;
        };
        pinctrl_adc0_ad3: adc0_ad3 {
            atmel,pins = <AT91_PIOB 14 AT91_PERIPH_GPIO AT91_PINCTRL_NONE>;
        };
    };
};

adc0: adc@f804c000 {
    status = "okay";
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_adc0_ad0 &pinctrl_adc0_ad1 &pinctrl_adc0_ad2 &pinctrl_adc0_ad3>;
    atmel,adc-channels-used = <0xf>;
    atmel,adc-num-channels = <4>;
    compatible = "atmel,at91sam9x5-adc";
    atmel,adc-startup-time = <40>;
    atmel,adc-status-register = <0x1c>;
    atmel,adc-trigger-register = <0x08>;
    atmel,adc-use-external;
    atmel,adc-vref = <3250>;
    atmel,adc-res = <8 10>;
    atmel,adc-res-names = "lowres", "highres";
    atmel,adc-use-res = "highres";
    trigger@0 {
        trigger-name = "continuous";
        trigger-value = <0x6>;
    };
};

Arietta

Use the Arietta G25 pinout to enable the ADC lines

Step 3: Check the system log

...

Step 4: Check that exist the device inside the /dev directory:

...

Step 5: Use the ADC from user space

Here is a simple hardware setup to quickly test the A/D lines:

It is a simple linear trimmer (1Kohm but any value is ok) with the central cursor wired to J4.34 (AD0) and the other terminals wired to J4.9 (GND) and J4.5 (3V3).

To read the cursor position in a range o 0 to 1023 type:

root@arietta:~# cat /sys/bus/iio/devices/iio\:device0/in_voltage0_raw
512 

A detailed description of the Atmel AT91 ADC driver used on the Kernel 3.xx is available on this page:

A/D converter lines

The Analog to Digital converter lines are located on the Acme Systems modules on the following pins:

| Signal | Description                        | RoadRunner  | Acqua        | Arietta     | Aria    | Terra   | Fox G20|
|--------|------------------------------------|-------------|--------------|-------------|---------|---------|--------|
| 3.3V   | 3.3 volt power line                |             |              | J4.5        |         | D14.1   | J6.1   |     
| AVDD   | Clean 3.24V out for A/D circuitry  |             |              |             |         | D14.2   | J6.33  |
| VREF   | A/D voltage reference input        |             | J1.50        |             | W19     | D14.3   | J6.34  |
| AGND   | Analog GND                         |             |              |             |         | D14.4   | J6.35  |
|  AD0   | Analog input 0                     | PD19        | PD20 - J1.40 | J4.34       | W20     | D14.5   | J6.30  |
|  AD1   | Analog input 1                     | PD20        | PD21 - J1.41 | J4.36       | W21     | D14.6   | J6.29  |
|  AD2   | Analog input 2                     | PD21        | PD22 - J1.42 | J4.38       | W22     | D14.7   | J6.28  |
|  AD3   | Analog input 3                     | PD22        | PD23 - J1.43 | J4.40       | W23     | D14.8   | J6.27  |
|  AD4   | Analog input 4                     | PD23        | PD24 - J1.44 |             |         |         |        |
|  AD5   | Analog input 5                     | PD24        | PD25 - J1.45 |             |         |         |        |
|  AD6   | Analog input 6                     | PD25        | PD26 - J1.46 |             |         |         |        |
|  AD7   | Analog input 7                     | PD26        | PD27 - J1.47 |             |         |         |        |
|  AD8   | Analog input 8                     | PD27        | PD28 - J1.48 |             |         |         |        |
|  AD9   | Analog input 9                     | PD28        | PD29 - J1.49 |             |         |         |        |
|  AD10  | Analog input 10                    | PD29        | PD30 - J2.2  |             |         |         |        |
|  AD11  | Analog input 11                    | PD30        | PD31 - J2.1  |             |         |         |        |
|  GND   | Digital GND                        |             | J2.4         | J4.9        |  W1     | D14.10  | J6.40  |

On Arietta and Aria the A/D resolution is 10 bits so using for example a Vfer or 3.3 volt the minimal resolution is about 3.2 mV.

On Arietta the VREF line is wired internally to the 3V3 volt so is not possible to change it.

By wiring the VREF pin to AVDD or VDD (max 3.3 volt) it's possible to read a max voltage of 3.24 volt with a resolution of 10 bit (1024 samples). In this way the max sample resolution we obtain is about 3.24V/1024 ~= 3mV.

On VREF no voltage higher than 3.3 Volt can be applied. If you need to read a higher signal use a schematic like this:

A module called DAISY-20 is available to use these lines in the range of 0 to 10 volts. Elsewhere use this schematic to test quickly the A/D lines:

Sergio Tanzilli
System designer, software developer and company co-founder
tanzilli@acmesystems.it
Webpages: https://www.acmesystems.it and http://www.tanzolab.it
Github repository: https://github.com/tanzilli and https://github.com/acmesystems