AD5933

AD5933 IIO Impedance Converter and Network Analyzer.

Supported Devices

Evaluation Boards

Reference Circuits

Description

This is a Linux industrial I/O (Linux Industrial I/O Subsystem) subsystem driver, targeting Impedance Converters and Network Analyzers. 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

Hardware configuration

https://wiki.analog.com/_media/resources/tools-software/linux-drivers/iio-impedance-analyzer/ad5933_eval_lr.jpg

Adding Linux driver support

Kernel configuration

Configure kernel with make menuconfig (alternatively use make xconfig or make qconfig)

Note

The driver depends on CONFIG_I2C

Linux Kernel Configuration
    Device Drivers  --->
        [*] Staging drivers  --->
            <*>     Industrial I/O support --->
                --- Industrial I/O support
                -*-   Enable buffer support within IIO
                -*-   Enable triggered sampling support

                [--snip--]

                *** Network Analyzer, Impedance Converters ***
                <*>   Analog Devices AD5933, AD5934 driver

                [--snip--]

Platform-data configuration

Example platform device initialization

The driver obtains its supply voltage from a regulator named vdd and uses that voltage to determine the excitation ranges. Register the actual board supply through the regulator framework and provide a clock lookup named mclk when using an external master clock. The ad5933_platform_data structure is not consumed by this driver.

AD5933 can use its internal oscillator when no usable external clock is provided. AD5934 requires an external master clock: its board configuration must provide the actual MCLK source. The driver’s AD5933 internal-clock fallback does not make an AD5934 board usable without that source.

The registration fragment below assumes the board has already registered these regulator and clock resources; it does not define board-specific supply voltages or clock rates.

Unlike PCI or USB devices, I2C devices are not enumerated at the hardware level. Instead, the software must know which devices are connected on each I2C bus segment, and what address these devices are using. For this reason, the kernel code must instantiate I2C devices explicitly. There are different ways to achieve this, depending on the context and requirements. However the most common method is to declare the I2C devices by bus number.

This method is appropriate when the I2C bus is a system bus, as in many embedded systems, wherein each I2C bus has a number which is known in advance. It is thus possible to pre-declare the I2C devices that inhabit this bus. This is done with an array of struct i2c_board_info, which is registered by calling i2c_register_board_info().

So, to enable such a driver one need only edit the board support file by adding an appropriate entry to i2c_board_info.

For more information see: How to instantiate I2C devices

Depending on the converter IC used, you may need to set the I2C_BOARD_INFO name accordingly, matching your part name.

ADI part number

I2C_BOARD_INFO Name

AD5933

ad5933

AD5934

ad5934

static struct i2c_board_info __initdata board_i2c_board_info[] = {
#if defined(CONFIG_AD5933) || defined(CONFIG_AD5933_MODULE)
    {
        I2C_BOARD_INFO("ad5933", 0x0D),
    },
#endif
};
static int __init board_init(void)
{
    [--snip--]

    i2c_register_board_info(0, board_i2c_board_info,
                ARRAY_SIZE(board_i2c_board_info));
    [--snip--]

    return 0;
}
arch_initcall(board_init);

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.

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:deviceX> ls -l
drwxr-xr-x    4 root     root             0 Jan  1 21:48 buffer
-rw-r--r--    1 root     root          4096 Jan  1 21:48 in_voltage0_scale
-r--r--r--    1 root     root          4096 Jan  1 21:48 in_voltage0_scale_available
-r--r--r--    1 root     root          4096 Jan  1 21:48 name
-rw-r--r--    1 root     root          4096 Jan  1 21:48 out_altvoltage0_frequency_increment
-rw-r--r--    1 root     root          4096 Jan  1 21:48 out_altvoltage0_frequency_points
-rw-r--r--    1 root     root          4096 Jan  1 21:48 out_altvoltage0_frequency_start
-rw-r--r--    1 root     root          4096 Jan  1 21:48 out_altvoltage0_raw
-r--r--r--    1 root     root          4096 Jan  1 21:48 out_altvoltage0_scale_available
-rw-r--r--    1 root     root          4096 Jan  1 21:48 out_altvoltage0_settling_cycles
drwxr-xr-x    2 root     root             0 Jan  1 21:48 power
lrwxrwxrwx    1 root     root             0 Jan  1 21:48 subsystem -> ../../../o
-r--r--r--    1 root     root          4096 Jan  1 21:48 in_temp_raw
-rw-r--r--    1 root     root          4096 Jan  1 21:48 uevent

Use out_altvoltage0_raw to select or read the excitation range in mV. out_altvoltage0_scale_available lists the supported values, which depend on the actual supply voltage.

Identify the device

root:/sys/bus/iio/devices/iio:deviceX> cat name
ad5933

Basic operation

Show available input scales

Description: /sys/bus/iio/devices/iio:deviceX/in_voltage0_scale_available List available input scales. Programmable gain amplifier (PGA) options.

root:/sys/bus/iio/devices/iio:deviceX> cat in_voltage0_scale_available
1 0.2

Set sweep start frequency

Description: /sys/bus/iio/devices/iio:deviceX/out_altvoltage0_frequency_start

Frequency sweep start frequency in Hz.

root:/sys/bus/iio/devices/iio:deviceX> echo 15000 > out_altvoltage0_frequency_start
root:/sys/bus/iio/devices/iio:deviceX> cat out_altvoltage0_frequency_start
14999

Set frequency increment

Description: /sys/bus/iio/devices/iio:deviceX/out_altvoltage0_frequency_increment Frequency increment in Hz (step size) between consecutive frequency points along the sweep.

root:/sys/bus/iio/devices/iio:deviceX> echo 200 > out_altvoltage0_frequency_increment

Set number of frequency points

Description: /sys/bus/iio/devices/iio:deviceX/out_altvoltage0_frequency_points Number of frequency points (steps) in the frequency sweep. This value, in conjunction with the out_altvoltage0_frequency_start and the out_altvoltage0_frequency_increment, determines the frequency sweep range for the sweep operation.

root:/sys/bus/iio/devices/iio:deviceX> echo 100 > out_altvoltage0_frequency_points
root:/sys/bus/iio/devices/iio:deviceX> cat out_altvoltage0_frequency_points
100

Set number of settling time cycles

Description: /sys/bus/iio/devices/iio:deviceX/out_altvoltage0_settling_cycles Number of output excitation cycles (settling time cycles) that are allowed to pass through the unknown impedance, after each frequency increment, and before the ADC is triggered to perform a conversion sequence of the response signal.

root:/sys/bus/iio/devices/iio:deviceX> echo 15 > out_altvoltage0_settling_cycles
root:/sys/bus/iio/devices/iio:deviceX> cat out_altvoltage0_settling_cycles
15

Show available output ranges

Description: /sys/bus/iio/devices/iio:deviceX/out_altvoltage0_scale_available List available output scales/ranges in millivolt.

root:/sys/bus/iio/devices/iio:deviceX> cat out_altvoltage0_scale_available
1980 970 383 198

Set output range

Description: /sys/bus/iio/devices/iio:deviceX/out_altvoltage0_raw Sets output scale/range in millivolt.

root:/sys/bus/iio/devices/iio:deviceX> echo 1980 > out_altvoltage0_raw
root:/sys/bus/iio/devices/iio:deviceX> cat out_altvoltage0_raw
1980

Set input scale

Recalibrate the impedance gain factor whenever the PGA gain, output excitation voltage, or external current-to-voltage gain resistor changes. A calibration taken with previous settings must not be reused for the new settings. Ensure that the receive signal remains within the linear ADC range.

Description: /sys/bus/iio/devices/iio:deviceX/in_voltage0_scale Sets input scale. Controls programmable gain amplifier (PGA).

root:/sys/bus/iio/devices/iio:deviceX> echo 0.2 > in_voltage0_scale
root:/sys/bus/iio/devices/iio:deviceX> cat in_voltage0_scale
0.2

Show internal temperature

The temperature channel is unindexed and exposes in_temp_raw and in_temp_scale. Calculate temperature in millidegrees Celsius as raw multiplied by scale. The on-chip sensor’s measurement range is −40°C to +125°C.

Run these commands in the device’s sysfs directory:

raw=$(cat in_temp_raw)
scale=$(cat in_temp_scale)
awk -v raw="$raw" -v scale="$scale" 'BEGIN { print raw * scale }'

Buffer management

root:/sys/bus/iio/devices/iio:deviceX/buffer> ls
enable              length
root:/sys/bus/iio/devices/iio:deviceX/buffer>

The Industrial I/O subsystem supports buffered data acquisition. Buffer implementation and capabilities depend on the driver. Devices with buffer support expose each buffer at /sys/bus/iio/devices/iio:deviceX/bufferY, where Y is the buffer index, starting at 0. The first buffer is additionally exposed through the legacy buffer directory, which contains its buffer-control attributes. Its scan configuration is exposed through the legacy scan_elements directory, while multi-buffer systems expose the scan attributes in the corresponding bufferY directory. Read samples from the device character node /dev/iio:deviceX; the selected buffer is determined by the active buffer configuration.

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.

watermark

A single positive integer specifying the maximum number of scan elements to wait for. Poll will block until the watermark is reached. Blocking read will wait until the minimum between the requested read amount or the low water mark is available. Non-blocking read will retrieve the available samples from the buffer even if there are less samples then watermark level. This allows the application to block on poll with a timeout and read the available samples after the timeout expires and thus have a maximum delay guarantee.

data_available

A read-only value indicating the bytes of data available in the buffer. In the case of an output buffer, this indicates the amount of empty space available to write data to. In the case of an input buffer, this indicates the amount of data available for reading.

length_align_bytes

Using the high-speed interface. DMA buffers may have an alignment requirement for the buffer length. Newer versions of the kernel will report the alignment requirements associated with a device through the length_align_bytes property.

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:deviceX/scan_elements> ls
in_voltage_imag_en     in_voltage_imag_type   in_voltage_real_index
in_voltage_imag_index  in_voltage_real_en     in_voltage_real_type

The real and imaginary scan channels are unindexed.

in_voltageX_en / in_voltageX-voltageY_en / in_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 / in_timestamp_type:

Describes the scan element’s representation in the buffer. The format is [be|le]:[s|u]bits/storagebits[Xrepeat]>>shift. The prefix gives byte order; s or u specifies signed (two’s complement) or unsigned data. bits is the number of meaningful bits and storagebits is the storage width. The optional repeat count describes repeated elements. After interpreting byte order, shift the storage value right by shift and mask it to bits; signed values also require sign extension. For example, be:u12/16>>1 describes an unsigned 12-bit value in big-endian 16-bit storage, shifted right by one bit. Account for alignment padding when combining enabled elements into a complete scan.

in_voltageX_index / in_voltageX-voltageY_index / in_timestamp_index:

A nonnegative integer specifying the ordering 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.

root:/sys/bus/iio/devices/iio:deviceX/scan_elements> grep ""
in_voltage_imag_en:    1
in_voltage_imag_index: 1
in_voltage_imag_type:  s16/16>>0
in_voltage_real_en:    1
in_voltage_real_index: 0
in_voltage_real_type:  s16/16>>0

Buffer Example

> cd /sys/bus/iio/devices/iio:device0
> echo 10000 > out_altvoltage0_frequency_start
> echo 100 > out_altvoltage0_frequency_increment
> echo 100 > out_altvoltage0_frequency_points
> echo 512 > buffer/length
> echo 1 > buffer/enable

Data interpretation

index

datum

type

0

Real Sample f0

signed short 16-bit

1

Imag Sample f0

signed short 16-bit

[fn * 2]

Real Sample fn

signed short 16-bit

[fn * 2] + 1

Imag Sample fn

signed short 16-bit

The buffer contains signed real/imaginary DFT output codes, not impedance in ohms. Apply application-specific gain/phase calibration to derive impedance; the driver does not perform that conversion.

root:> hexdump -d /dev/iio:device0
0000000   09451   //01627//   09541   01663   09622   01697   09708   01734
0000010   09799   01757   09889   01791   09985   01820   10079   01856
0000020   10172   01887   10264   01922   10357   01962   10451   02005
0000030   10543   02044   10628   02082   10714   02123   10798   02153
0000040   10889   02188   10983   02230   11069   02268   11157   02302
0000050   11246   02339   11335   02381   11429   02423   11514   02461
0000060   11603   02500   11688   02539   11782   02573   11871   02618
0000070   11955   02659   12045   02703   12135   02743   12221   02787
0000080   12307   02828   12393   02877   12481   02910   12567   02951
0000090   12659   02991   12750   03034   12840   03080   12927   03130
00000a0   13010   03173   13102   03220   13185   03268   13271   03313
00000b0   13356   03358   13443   03401   13525   03445   13612   03491
00000c0   13700   03536   13791   03584   13875   03630   13958   03684
00000d0   14047   03729   14135   03785   14216   03834   14302   03879
00000e0   14383   03930   14469   03982   14555   04028   14634   04084
00000f0   14722   04131   14805   04183   14890   04231   14972   04291
0000100   15052   04340   15136   04389   15216   04445   15301   04495
0000110   15377   04549   15455   04604   15526   04651   15595   04703
0000120   15661   04758   15731   04809   15782   04856   15836   04905
0000130   15885   04943   15939   04990   15993   05043   16035   05083
0000140   16077   05131   16118   05174   16165   05223   16198   05265
0000150   16241   05311   16275   05351   16300   05389   16336   05438
0000160   16373   05482   16405   05522   16441   05559   16470   05603
0000170   16498   05644   16534   05690   16554   05742   16577   05780
0000180   16601   05827   16621   05874   16640   05904   16668   05943
0000190   16686   05983
0000194

More Information