This article explains how to use the built-in 4-channel @ 10 bit A/D converter lines
The A/D converter input lines are available on the following pins:
| Signal | Description | CORE9G25 |
|---|---|---|
| 3.3V | 3.3 volt power line | W24 |
| AVDD | Clean 3.24V out for A/D circuitry | |
| VREF | A/D voltage reference input | W19 |
| AGND | Analog GND | |
| AD0 | Analog input 0 | W20 |
| AD1 | Analog input 1 | W21 |
| AD2 | Analog input 2 | W22 |
| AD3 | Analog input 3 | W23 |
| GND | Digital GND | W1 |
Test the Module
Loading the module should have created a sysfs directory in /sys/bus/iio/devices/iio:deviceN, N being between 0 and 255. It is most likely to be 0, but you can be sure by looking into the name file in that directory.
root@at91sam9g20ek:~# ls -l /sys/bus/iio/devices/iio\:device0/ drwxr-xr-x 2 root root 0 Mar 10 02:24 buffer -r--r--r-- 1 root root 4096 Mar 10 02:24 dev -r--r--r-- 1 root root 4096 Mar 10 02:24 in_voltage0_raw -r--r--r-- 1 root root 4096 Mar 10 02:24 in_voltage1_raw -r--r--r-- 1 root root 4096 Mar 10 02:24 in_voltage2_raw -r--r--r-- 1 root root 4096 Mar 10 02:24 in_voltage3_raw -rw-r--r-- 1 root root 4096 Mar 10 02:24 in_voltage_scale -r--r--r-- 1 root root 4096 Mar 10 02:24 name drwxr-xr-x 2 root root 0 Mar 10 02:24 power drwxr-xr-x 2 root root 0 Mar 10 02:24 scan_elements lrwxrwxrwx 1 root root 0 Mar 10 02:24 subsystem -> ../../../../bus/iio drwxr-xr-x 2 root root 0 Mar 10 02:24 trigger -rw-r--r-- 1 root root 4096 Mar 10 02:24 uevent
If you have devtmpfs, it will also have created an iio:deviceN file under /dev.
Software Triggers
Software triggers are an ADC operating mode where the software starts the conversion.
This feature is exposed by IIO through the following files:
in_voltageX_raw: raw value of the channel X of the ADCin_voltage_scale: value you have to multiply in_voltageX_raw with to have a value in microvolts
Reading into in_voltageX_raw will perform a software trigger on the ADC, then block until the conversion is completed, and finally return the value of this conversion.
Please note that conversions are done one channel at a time.
Here is the output on the AT91SAM9 console that shows an ADC measure when a 3V DC power supply is connected between analog ground AGND and ADC input 0 AD0 pins:
root@at91sam9g20ek:~# cat /sys/bus/iio/devices/iio\:device0/in_voltage0_raw 948 root@at91sam9g20ek:~# cat /sys/bus/iio/devices/iio\:device0/in_voltage_scale 3222.000000
We can calculate the result: 948 x 3222 = 3.0V
More Details, Reading the A/D converter lines:


