AD7124

AD7124 IIO Sigma-Delta ADC Linux Driver.

Supported Devices

This driver supports the

Evaluation Boards

Description

This is a Linux industrial I/O (Linux Industrial I/O Subsystem) subsystem driver for the AD7124-4 and AD7124-8 multiplexed sigma-delta ADCs. Voltage channels are configured from devicetree channel nodes. The industrial I/O subsystem provides a unified framework for drivers for many different types of converters and sensors using a number of different physical interfaces (i2c, spi, etc). See Linux Industrial I/O Subsystem for more information.

Source Code

Status

Source

Mainlined?

git

Yes

Files

Driver testing

Each and every IIO device, typically a hardware chip, has a device folder under /sys/bus/iio/devices/iio:deviceX. Where X is the IIO index of the device. Under every of these directory folders reside a set of files, depending on the characteristics and features of the hardware device in question. These files are consistently generalized and documented in the IIO ABI documentation. In order to determine which IIO deviceX corresponds to which hardware device, the user can read the name file /sys/bus/iio/devices/iio:deviceX/name. In case the sequence in which the iio device drivers are loaded/registered is constant, the numbering is constant and may be known in advance.

Tip

An example program which uses the interface can be found here:

root:/> cd /sys/bus/iio/devices/
root:/sys/bus/iio/devices> ls
iio:device0

root:/sys/bus/iio/devices> cd iio\:device0

root:/sys/bus/iio/devices/iio:device0> ls -l
drwxr-xr-x 2 root root    0 Jun 23 21:46 buffer
-r--r--r-- 1 root root 4096 Jun 23 21:46 dev
-rw-r--r-- 1 root root 4096 Jun 23 21:46 in_voltage0-voltage1_offset
-rw-r--r-- 1 root root 4096 Jun 23 21:46 in_voltage0-voltage1_raw
-rw-r--r-- 1 root root 4096 Jun 23 21:46 in_voltage0-voltage1_sampling_frequency
-rw-r--r-- 1 root root 4096 Jun 23 21:46 in_voltage0-voltage1_scale
-rw-r--r-- 1 root root 4096 Jun 23 21:46 in_voltage2-voltage3_offset
-rw-r--r-- 1 root root 4096 Jun 23 21:46 in_voltage2-voltage3_raw
-rw-r--r-- 1 root root 4096 Jun 23 21:46 in_voltage2-voltage3_sampling_frequency
-rw-r--r-- 1 root root 4096 Jun 23 21:46 in_voltage2-voltage3_scale
-rw-r--r-- 1 root root 4096 Jun 23 21:46 in_voltage4-voltage5_offset
-rw-r--r-- 1 root root 4096 Jun 23 21:46 in_voltage4-voltage5_raw
-rw-r--r-- 1 root root 4096 Jun 23 21:46 in_voltage4-voltage5_sampling_frequency
-rw-r--r-- 1 root root 4096 Jun 23 21:46 in_voltage4-voltage5_scale
-rw-r--r-- 1 root root 4096 Jun 23 21:46 in_voltage6-voltage7_offset
-rw-r--r-- 1 root root 4096 Jun 23 21:46 in_voltage6-voltage7_raw
-rw-r--r-- 1 root root 4096 Jun 23 21:46 in_voltage6-voltage7_sampling_frequency
-rw-r--r-- 1 root root 4096 Jun 23 21:46 in_voltage6-voltage7_scale
-r--r--r-- 1 root root 4096 Jun 23 21:46 name
lrwxrwxrwx 1 root root    0 Jun 23 21:46 of_node -> ../../../../../../../../firmware/devicetree/base/soc/spi@7e204000/ad7124-4@0
drwxr-xr-x 2 root root    0 Jun 23 21:46 power
drwxr-xr-x 2 root root    0 Jun 23 21:46 scan_elements
lrwxrwxrwx 1 root root    0 Jun 23 21:46 subsystem -> ../../../../../../../../bus/iio
drwxr-xr-x 2 root root    0 Jun 23 21:46 trigger
-rw-r--r-- 1 root root 4096 Jun 23 21:46 uevent

Identify the device

root:/sys/bus/iio/devices/iio:device0> cat name
ad7124-4

Basic operation

Show channel scale and offset

Description: Scales and offsets to be applied to in_voltagex_voltagey_raw in order to obdatin the measured voltage in millivolts

root:/sys/bus/iio/devices/iio:device0> cat in_voltage0-voltage1_scale
0.000149011
root:/sys/bus/iio/devices/iio:device0> cat in_voltage0-voltage1_offset
0
root:/sys/bus/iio/devices/iio:device0> cat in_voltage0-voltage1_raw
2679470

Description: Channel Ainp0-Ainm1 is configured as unipolar, with a gain of 1: U_mV = (raw + offset) × scale = (2679470 + 0) × 0.000149011 ≈ 399.27 mV.

root:/sys/bus/iio/devices/iio:device0> cat in_voltage2-voltage3_scale
0.000298023
root:/sys/bus/iio/devices/iio:device0> cat in_voltage2-voltage3_offset
-8388608
root:/sys/bus/iio/devices/iio:device0> cat in_voltage2-voltage3_raw
9716211

Description: Channel Ainp2-Ainm3 is configured as bipolar, with a gain of 1: U_mV = (raw + offset) × scale = (9716211 - 8388608) × 0.000298023 ≈ 395.66 mV.

Set sampling frequency

Description: The output data rate depends on the master clock frequency (fclk) which in turn determines the power mode:

  • The sampling frequency depends on the filter and clock: fCLK/(32 × N × FS), with N = 3 for sinc3, N = 4 for sinc4, additional averaging for sinc1 combinations, and FS clamped to 1..2047. Post filters have fixed rates. Read sampling_frequency back after writing it.

root:/sys/bus/iio/devices/iio:device0> cat in_voltage0-voltage1_sampling_frequency
10
root:/sys/bus/iio/devices/iio:device0> cat in_voltage2-voltage3_sampling_frequency
960
root:/sys/bus/iio/devices/iio:device0> echo 2400 > in_voltage0-voltage1_sampling_frequency
root:/sys/bus/iio/devices/iio:device0> cat in_voltage0-voltage1_sampling_frequency
2400
root:/sys/bus/iio/devices/iio:device0> echo 5000 > in_voltage2-voltage3_sampling_frequency
root:/sys/bus/iio/devices/iio:device0> cat in_voltage2-voltage3_sampling_frequency
4800

More Information