AD74413R

AD74413R/AD74412R Quad-Channel, Software Configurable, Input and Output Circuit Linux Driver.

Supported Devices

Evaluation Boards

Source Code

Status

Source

Mainlined?

ADI tree

Yes

Files

Function

File

core driver

ad74413r.c

Documentation

adi,ad74413r.yaml

Example device tree

Function

File

dts

rpi-ad74413r-overlay.dts

Driver testing

When configured with channel 0 as voltage output, channel 1 as current output, channel 2 as voltage input and channel 3 as current input, the following structure is created under the corresponding IIO device.

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 Aug 17 09:56 buffer
-r--r--r-- 1 root root 4096 Aug 17 09:56 dev
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_current0_offset
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_current0_raw
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_current0_sampling_frequency
-r--r--r-- 1 root root 4096 Aug 17 09:56 in_current0_sampling_frequency_available
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_current0_scale
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_current3_offset
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_current3_raw
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_current3_sampling_frequency
-r--r--r-- 1 root root 4096 Aug 17 09:56 in_current3_sampling_frequency_available
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_current3_scale
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_voltage1_offset
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_voltage1_raw
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_voltage1_sampling_frequency
-r--r--r-- 1 root root 4096 Aug 17 09:56 in_voltage1_sampling_frequency_available
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_voltage1_scale
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_voltage2_offset
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_voltage2_raw
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_voltage2_sampling_frequency
-r--r--r-- 1 root root 4096 Aug 17 09:56 in_voltage2_sampling_frequency_available
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_voltage2_scale
-r--r--r-- 1 root root 4096 Aug 17 09:56 name
lrwxrwxrwx 1 root root    0 Aug 17 09:56 of_node -> ../../../../../../../../firmware/devicetree/base/soc/spi@7e204000/ad74413r@0
-rw-r--r-- 1 root root 4096 Aug 17 09:56 out_current1_raw
-rw-r--r-- 1 root root 4096 Aug 17 09:56 out_current1_scale
-rw-r--r-- 1 root root 4096 Aug 17 09:56 out_voltage0_raw
-rw-r--r-- 1 root root 4096 Aug 17 09:56 out_voltage0_scale
drwxr-xr-x 2 root root    0 Aug 17 09:56 power
drwxr-xr-x 2 root root    0 Aug 17 09:56 scan_elements
lrwxrwxrwx 1 root root    0 Aug 17 09:56 subsystem -> ../../../../../../../../bus/iio
drwxr-xr-x 2 root root    0 Aug 17 09:56 trigger
-rw-r--r-- 1 root root 4096 Aug 17 09:56 uevent

Identify the device

root:/sys/bus/iio/devices/iio:device0> cat name
ad74413r

Basic operation

Show raw measurement

Description: Raw measurement of current on channel 0.

root:/sys/bus/iio/devices/iio:device0> cat in_current0_raw
4608

Show scale

Description: Scale to be applied to the raw measurement of current on channel 0, together with in_current0_offset: current[mA] = (raw + offset) * scale.

root:/sys/bus/iio/devices/iio:device0> cat in_current0_scale
0.001525902

Set sampling frequency

Description: Show available sampling frequencies and select one for channel 0.

On AD74413R, 20 SPS enables 50 Hz/60 Hz rejection and 10 SPS also provides HART noise rejection. Selecting 1200 or 4800 SPS disables the 50 Hz/60 Hz rejection. Choose the rate for both bandwidth and interference rejection; use the model-specific sampling_frequency_available values.

root:/sys/bus/iio/devices/iio:device0> cat in_current0_sampling_frequency_available
10 20 1200 4800
root:/sys/bus/iio/devices/iio:device0> cat in_current0_sampling_frequency
20
root:/sys/bus/iio/devices/iio:device0> echo 4800 > in_current0_sampling_frequency
root:/sys/bus/iio/devices/iio:device0> cat in_current0_sampling_frequency
4800

These are AD74413R rates. AD74412R exposes only 20 Hz and 4800 Hz.

Buffer management

Description: The scan_elements directory contains interfaces for elements that will be captured for a single triggered sample set in the buffer

root:/sys/bus/iio/devices/iio:device0> cd scan_elements/
root:/sys/bus/iio/devices/iio:device0/scan_elements> ls -l
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_current0_en
-r--r--r-- 1 root root 4096 Aug 17 09:56 in_current0_index
-r--r--r-- 1 root root 4096 Aug 17 09:56 in_current0_type
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_current3_en
-r--r--r-- 1 root root 4096 Aug 17 09:56 in_current3_index
-r--r--r-- 1 root root 4096 Aug 17 09:56 in_current3_type
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_voltage1_en
-r--r--r-- 1 root root 4096 Aug 17 09:56 in_voltage1_index
-r--r--r-- 1 root root 4096 Aug 17 09:56 in_voltage1_type
-rw-r--r-- 1 root root 4096 Aug 17 09:56 in_voltage2_en
-r--r--r-- 1 root root 4096 Aug 17 09:56 in_voltage2_index
-r--r--r-- 1 root root 4096 Aug 17 09:56 in_voltage2_type

Before enabling the buffer, a few steps need to be completed.

  • For example, if we want to capture all input channels, we need to enable the scan elements:

root:/sys/bus/iio/devices/iio:device0/scan_elements> echo 1 > in_current0_en
root:/sys/bus/iio/devices/iio:device0/scan_elements> echo 1 > in_voltage1_en
root:/sys/bus/iio/devices/iio:device0/scan_elements> echo 1 > in_voltage2_en
root:/sys/bus/iio/devices/iio:device0/scan_elements> echo 1 > in_current3_en
root:/sys/bus/iio/devices/iio:device0/scan_elements> cd ../buffer/
root:/sys/bus/iio/devices/iio:device0/buffer> ls -l
-r--r--r-- 1 root root 4096 Aug 17 09:56 data_available
-rw-r--r-- 1 root root 4096 Aug 17 09:56 enable
-rw-r--r-- 1 root root 4096 Aug 17 09:56 length
-rw-r--r-- 1 root root 4096 Aug 17 09:56 watermark
  • Set the buffer length:

root:/sys/bus/iio/devices/iio:device0/buffer> echo 1024 > length
  • Set the watermak:

root:/sys/bus/iio/devices/iio:device0/buffer> echo 512 > watermark
  • Enable the buffer:

root:/sys/bus/iio/devices/iio:device0/buffer> echo 1 > enable
  • Read the samples as binary scan data. Each enabled ADC channel is stored as big-endian 32 bits, with 16 valid bits shifted by 8 (be:u16/32>>8); see scan_elements/*_index and *_type.

root:/sys/bus/iio/devices/iio:device0/buffer> cat /dev/iio:device0

More Information