Wiki

This version (05 Jan 2021 16:28) was approved by Ioana Chelaru.The Previously approved version (27 Apr 2016 10:30) is available.Diff

AD7746 IIO Capacitance to Digital Converter Linux Driver

Supported Devices

Reference Circuits

Evaluation Boards

Description

This is a Linux industrial I/O (IIO) subsystem driver, targeting single and multi channel serial interface Capacitance to Digital Converters. 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 IIO for more information.

Source Code

Status

Source Mainlined?
git git

Files

Declaring I2C devices

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: Documentation/i2c/instantiating-devices.rst

21 Oct 2010 16:10

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
AD7745 ad7745
AD7746 ad7746
AD7747 ad7747
static struct i2c_board_info __initdata board_i2c_board_info[] = {
#if defined(CONFIG_AD7746) || defined(CONFIG_AD7746_MODULE)
	{
		I2C_BOARD_INFO("ad7746", 0x48),
	},
#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);

Adding Linux driver support

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

The driver depends on CONFIG_I2C

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

			    [--snip--]

				*** Analog to digital converters ***
			    <*>   Analog Devices AD7745, AD7746 AD7747 capacitive sensor driver

			    [--snip--]

Hardware configuration

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.

02 Mar 2011 15:16

This specifies any shell prompt running on the target

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

root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0> ls -l
-r--r--r--    1 root     root          4096 Jan  1 11:17 dev
-rw-r--r--    1 root     root          4096 Jan  1 11:17 in_capacitance-capacitance_calibbias
-rw-r--r--    1 root     root          4096 Jan  1 11:17 in_capacitance-capacitance_scale
-rw-r--r--    1 root     root          4096 Jan  1 11:17 in_capacitance0-capacitance2_calibscale
-rw-r--r--    1 root     root          4096 Jan  1 11:17 in_capacitance0-capacitance2_offset
-r--r--r--    1 root     root          4096 Jan  1 11:17 in_capacitance0-capacitance2_raw
--w-------    1 root     root          4096 Jan  1 11:17 in_capacitance0_calibbias_calibration
-rw-r--r--    1 root     root          4096 Jan  1 11:17 in_capacitance0_calibscale
--w-------    1 root     root          4096 Jan  1 11:17 in_capacitance0_calibscale_calibration
-rw-r--r--    1 root     root          4096 Jan  1 11:19 in_capacitance0_offset
-r--r--r--    1 root     root          4096 Jan  1 11:17 in_capacitance0_raw
-rw-r--r--    1 root     root          4096 Jan  1 11:17 in_capacitance1-capacitance3_calibscale
-rw-r--r--    1 root     root          4096 Jan  1 11:17 in_capacitance1-capacitance3_offset
-r--r--r--    1 root     root          4096 Jan  1 11:17 in_capacitance1-capacitance3_raw
--w-------    1 root     root          4096 Jan  1 11:17 in_capacitance1_calibbias_calibration
-rw-r--r--    1 root     root          4096 Jan  1 11:17 in_capacitance1_calibscale
--w-------    1 root     root          4096 Jan  1 11:17 in_capacitance1_calibscale_calibration
-rw-r--r--    1 root     root          4096 Jan  1 11:17 in_capacitance1_offset
-r--r--r--    1 root     root          4096 Jan  1 11:17 in_capacitance1_raw
-rw-r--r--    1 root     root          4096 Jan  1 11:17 in_capacitance_calibbias
-rw-r--r--    1 root     root          4096 Jan  1 11:17 in_capacitance_sampling_frequency
-r--r--r--    1 root     root          4096 Jan  1 11:17 in_capacitance_sampling_frequency_available
-rw-r--r--    1 root     root          4096 Jan  1 11:17 in_capacitance_scale
-r--r--r--    1 root     root          4096 Jan  1 11:17 in_temp0_input
-r--r--r--    1 root     root          4096 Jan  1 11:17 in_temp1_input
--w-------    1 root     root          4096 Jan  1 11:17 in_voltage0_calibscale_calibration
-r--r--r--    1 root     root          4096 Jan  1 11:17 in_voltage0_raw
-r--r--r--    1 root     root          4096 Jan  1 11:17 in_voltage1_supply_raw
-rw-r--r--    1 root     root          4096 Jan  1 11:17 in_voltage_sampling_frequency
-r--r--r--    1 root     root          4096 Jan  1 11:17 in_voltage_sampling_frequency_available
-rw-r--r--    1 root     root          4096 Jan  1 11:17 in_voltage_scale
-rw-r--r--    1 root     root          4096 Jan  1 11:17 in_voltage_supply_scale
-r--r--r--    1 root     root          4096 Jan  1 11:17 name
drwxr-xr-x    2 root     root             0 Jan  1 11:17 power
lrwxrwxrwx    1 root     root             0 Jan  1 11:17 subsystem -> ../../../../../../bus/iio
-rw-r--r--    1 root     root          4096 Jan  1 11:17 uevent

Show device name

This specifies any shell prompt running on the target

root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0> cat name
ad7746

Show available sampling frequencies / update rates

This specifies any shell prompt running on the target

root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0> cat in_capacitance_sampling_frequency_available
91 84 50 26 16 13 11 9

root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0> cat in_voltage_sampling_frequency_available
50 31 16 8
root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0>

Set sampling frequency / update rate

This specifies any shell prompt running on the target

root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0> cat in_capacitance_sampling_frequency
91
root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0> echo 50 > in_capacitance_sampling_frequency
root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0> cat in_capacitance_sampling_frequency
50
root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0>

Show scales for single and differential input channels

Lists all available scales for the input and input pairs:

ADC Input Channel name
CIN1(+) in_capacitance_scale
CIN2(+) in_capacitance_scale
CIN1(+) - CIN1(-) in_capacitance-capacitance_scale
CIN2(+) - CIN2(-) in_capacitance-capacitance_scale
VIN1 in_voltage_scale
VIN_VDD_MON in_voltage_supply_scale

This specifies any shell prompt running on the target

root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0> cat in_capacitance_scale
0.000000488

Show channel CIN1(+) measurement

Description:
Raw unscaled capacitance measurement on channel in_capacitance0_raw

ADC Input Channel name
CIN1(+) in_capacitance0_raw
CIN2(+) in_capacitance1_raw
CIN1(+) - CIN1(-) in_capacitance0-capacitance2_raw
CIN2(+) - CIN2(-) in_capacitance1-capacitance3_raw
VIN1 in_voltage0_raw
VIN_VDD_MON in_voltage1_supply_raw

This specifies any shell prompt running on the target

root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0> cat in_capacitance0_raw
14914

U = in_capacitance0_raw * in_capacitance_scale = 14914 * 0.000000488 = 0.007278032 pF

Show internal temperature measurement

Description:
Scaled temperature measurement on channel in_temp0_input. Results are in millidegrees Celsius.

ADC Input Channel Channel name
TEMP (internal sensor) in_temp0_input
TEMP (external sensor diode) in_temp1_input

This specifies any shell prompt running on the target

root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0> cat in_temp0_input
28756

T = in_temp0_input = 28756 = 28.756 °C

Set channel common mode offset (CAPDAC)

Description:
If known for a device, offset to be added to <type>[Y]_raw prior to scaling by <type>[Y]_scale in order to obtain value in the <type> units as specified in <type>[y]_raw documentation.

Input CAPDAC Channel name
CIN1(+) CAPDAC(+) in_capacitance0_offset
CIN2(+) CAPDAC(+) in_capacitance1_offset
CIN1(-) CAPDAC(-) in_capacitance1-capacitance3_offset
CIN2(-) CAPDAC(-) in_capacitance0-capacitance2_offset

The AD7745/AD7746 CDC full-scale input range is ±4.096 pF. The part can accept a higher capacitance on the input and the common-mode or offset (not-changing component) capacitance can be balanced by programmable on-chip CAPDACs.

Example 4pF Offset:
in_capacitance0_offset = Offset / in_capacitance_scale = 4pF / 0.000000488 = 8196721

This specifies any shell prompt running on the target

root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0> echo 8196721 > in_capacitance0_offset
root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0> cat in_capacitance0_offset
8127504

Perform channel gain calibration

Description:
Triggers gain calibration on channel in_capacitance0 or in_capacitance1

This specifies any shell prompt running on the target

root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0> echo 1 > in_capacitance1_calibscale_calibration
root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0> cat in_capacitance1_calibscale
1.000000

Set channel gain coefficient

Description:
Write gain coefficient for channel in_capacitance0 or in_capacitance1 Valid range is between 1.0 and 1.99999999.

This specifies any shell prompt running on the target

root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0> echo 1.5 > in_capacitance1_calibscale
root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0> cat in_capacitance1_calibscale
1.500000

Perform channel offset calibration

Description:
Triggers offset calibration on channel in_capacitance0 or in_capacitance1

This specifies any shell prompt running on the target

root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0> echo 1 > in_capacitance1_calibbias_calibration
root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0> cat in_capacitance_calibbias
0

More Information

resources/tools-software/linux-drivers/iio-cdc/ad7745.txt · Last modified: 05 Jan 2021 16:09 by Ioana Chelaru