AD7768-1
AD7768-1 IIO Low Power Sigma-Delta ADC Linux Driver.
Supported Devices
Evaluation Boards
Description
This is a Linux industrial I/O (Linux Industrial I/O Subsystem) subsystem driver, targeting single channel serial interface ADCs. 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? |
|
|---|---|---|
[No] |
Files
Function |
File |
|---|---|
driver |
Devicetree
Required devicetree properties:
compatible: Needs to be the name of the device. E.g.
ad7768-1reg: The chipselect number used for the device
spi-max-frequency: Maximum SPI clock frequency.
spi-cpol: Needs to be set for the correct SPI mode
spi-cpha: Needs to be set for the correct SPI mode
vref-supply: Phandle to the fixed regulator
clocks: Phandle to the clock signal source
interrupts: a list of interrupt specifiers
adc_vref: fixedregulator@0 {
compatible = "regulator-fixed";
regulator-name = "fixed-supply";
regulator-min-microvolt = <4096000>;
regulator-max-microvolt = <4096000>;
regulator-boot-on;
};
clocks {
ad7768_mclk: clock@0 {
#clock-cells = <0>;
compatible = "fixed-clock";
clock-frequency = <16384000>;
};
};
#address-cells = <1>;
#size-cells = <0>;
status = "okay";
ad7768@0 {
compatible = "ad7768-1";
reg = <0>;
spi-max-frequency = <16000000>;
spi-cpol;
spi-cpha;
#interrupt-cells = <2>;
interrupts = <25 0x2>;
interrupt-parent = <&gpio>;
vref-supply = <&adc_vref>;
clocks = <&ad7768_mclk>;
clock-names = "mclk";
};
Driver testing
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 Oct 12 22:15 buffer
-r--r--r-- 1 root root 4096 Oct 12 22:15 dev
-rw-r--r-- 1 root root 4096 Oct 12 22:15 in_voltage0_raw
-rw-r--r-- 1 root root 4096 Oct 12 22:15 in_voltage_filter_low_pass_3db_frequency
-r--r--r-- 1 root root 4096 Oct 12 22:15 in_voltage_filter_low_pass_3db_frequency_available
-rw-r--r-- 1 root root 4096 Oct 12 22:15 in_voltage_scale
-r--r--r-- 1 root root 4096 Oct 12 22:15 name
lrwxrwxrwx 1 root root 0 Oct 12 22:15 of_node -> ../../../../../../../../firmware/devicetree/base/soc/spi@7e204000/ad7768@0
drwxr-xr-x 2 root root 0 Oct 12 22:15 power
-rw-r--r-- 1 root root 4096 Oct 12 22:27 sampling_frequency
drwxr-xr-x 2 root root 0 Oct 12 22:15 scan_elements
lrwxrwxrwx 1 root root 0 Oct 12 22:15 subsystem -> ../../../../../../../../bus/iio
drwxr-xr-x 2 root root 0 Oct 12 22:15 trigger
-rw-r--r-- 1 root root 4096 Oct 12 22:15 uevent
Show device name
root:/sys/bus/iio/devices/iio:device0> cat name
ad7768-1
Show scale
Description: scale to be applied to in_voltage0_raw in order to obtain the measured voltage in millivolts.
root:/sys/bus/iio/devices/iio:device0> cat in_voltage_scale
0.000488281
Show channel 0 measurement
Description: Raw unscaled voltage measurement on channel 0
root:/sys/bus/iio/devices/iio:device0> cat in_voltage0_raw
2040915
U = in_voltage0_raw * in_voltage_scale = 2040915 * 0.000488281= 996.54 mV
Set sampling frequency / update rate
root:/sys/bus/iio/devices/iio:device0> cat sampling_frequency
32000
root:/sys/bus/iio/devices/iio:device0> echo 256000 > sampling_frequency
root:/sys/bus/iio/devices/iio:device0> cat sampling_frequency
256000
root:/sys/bus/iio/devices/iio:device0>
Show available bandwidths for the current set frequency
root:/sys/bus/iio/devices/iio:device0> cat sampling_frequency
256000
root:/sys/bus/iio/devices/iio:device0> cat in_voltage_filter_low_pass_3db_frequency_available
6528.000000, 8320.000000, 13760.000000
root:/sys/bus/iio/devices/iio:device0>
Change the bandwidth
root:/sys/bus/iio/devices/iio:device0> cat in_voltage_filter_low_pass_3db_frequency_available
6528.000000, 8320.000000, 13760.000000
root:/sys/bus/iio/devices/iio:device0> cat in_voltage_filter_low_pass_3db_frequency
6528.000000
root:/sys/bus/iio/devices/iio:device0> echo 13760 > in_voltage_filter_low_pass_3db_frequency
root:/sys/bus/iio/devices/iio:device0> cat in_voltage_filter_low_pass_3db_frequency
13760.000000
root:/sys/bus/iio/devices/iio:device0>
Trigger management
Note
This driver only supports it’s own default trigger source ad7768-1-dev0
root:/sys/bus/iio/devices/iio:device0> cat trigger/current_trigger
ad7768-1-dev0
Buffer management
root:/sys/bus/iio/devices/iio:device0/buffer> ls
enable length watermark
root:/sys/bus/iio/devices/iio:device0/buffer>
Every buffer implementation features a set of files:
length Get/set the number of sample sets that may be held by the buffer.
enable Enables/disables the buffer. This file should be written last, after length and selection of scan elements
scan_elements 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/scan_elements> ls
in_voltage0_en in_voltage0_index in_voltage0_type
root:/sys/bus/iio/devices/iio:device0/scan_elements>
in_voltageX_en / in_voltageX-voltageY_en / timestamp_en: Scan element control for triggered data capture. Writing 1 will enable the scan element, writing 0 will disable it
in_voltageX_type / in_voltageX-voltageY_type / timestamp_type: Description of the scan element data storage within the buffer and therefore in the form in which it is read from user-space. Form is [s|u]bits/storage-bits. s or u specifies if signed (2’s complement) or unsigned. bits is the number of bits of data and storage-bits is the space (after padding) that it occupies in the buffer. Note that some devices will have additional information in the unused bits so to get a clean value, the bits value must be used to mask the buffer output value appropriately. The storage-bits value also specifies the data alignment. So u12/16 will be a unsigned 12 bit integer stored in a 16 bit location aligned to a 16 bit boundary. For other storage combinations this attribute will be extended appropriately.
in_voltageX_index / in_voltageX-voltageY_index / timestamp_index: A single positive integer specifying the position of this scan element in the buffer. Note these are not dependent on what is enabled and may not be contiguous. Thus for user-space to establish the full layout these must be used in conjunction with all _en attributes to establish which channels are present, and the relevant _type attributes to establish the data storage format.
Low level register access via debugfs (direct_reg_access)
Some IIO drivers feature an optional debug facility, allowing users to read or write registers directly. Special care needs to be taken when using this feature, since you can modify registers on the back of the driver. Accessing debugfs requires root privileges.
In order to identify if the IIO device in question feature this option you first need to identify the IIO device number.
Therefore read the name attribute of each IIO device
root@analog:~# grep "" /sys/bus/iio/devices/iio\:device/name
ad7768-1
root@analog:~#
Change directory to /sys/kernel/debug/iio/iio:deviceX and check if the direct_reg_access file exists.
root@analog:~# cd /sys/kernel/debug/iio/iio\:device0/
root@analog:/sys/kernel/debug/iio/iio:device0# ls direct_reg_access
ls direct_reg_access
root@analog:/sys/kernel/debug/iio/iio:device0#
Reading
root@analog:/sys/kernel/debug/iio/iio:device0# echo 0x3 > direct_reg_access
root@analog:/sys/kernel/debug/iio/iio:device0# cat direct_reg_access
0x7
root@analog:/sys/kernel/debug/iio/iio:device0#
Writing
Write ADDRESS VALUE
root@analog:/sys/kernel/debug/iio/iio:device0# echo 0x15 0x2 > direct_reg_access
root@analog:/sys/kernel/debug/iio/iio:device0# cat direct_reg_access
0x2
root@analog:/sys/kernel/debug/iio/iio:device0#