world leader in high performance signal processing
This version (05 Sep 2012 13:25) was approved by mhennerich.The Previously approved version (08 Nov 2011 16:58) is available.Diff

AD7152 IIO Capacitance to Digital Converter Linux Driver

Supported Devices

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.

AD7152

Couldn't find description in http://www.analog.com/AD7152

AD7153

Couldn't find description in http://www.analog.com/AD7153

Source Code

Status

Source Mainlined?
git git

Files

Function File
driver drivers/staging/iio/cdc/ad7152.c

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

21 Oct 2010 16:10 · Michael Hennerich

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
AD7152 ad7152
AD7153 ad7153
static struct i2c_board_info __initdata board_i2c_board_info[] = {
#if defined(CONFIG_AD7152) || defined(CONFIG_AD7152_MODULE)
	{
		I2C_BOARD_INFO("ad7152", 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 ring
			    -*-   Enable triggered sampling support

			    [--snip--]

				*** Analog to digital converters ***
			    <*>   Analog Devices AD7152/3 capacitive sensor dr
iver

			    [--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 · Michael Hennerich

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
-rw-r--r--    1 root     root          4096 Jan  2 22:46 in_capacitance0-capacitance2_calibbias
-rw-r--r--    1 root     root          4096 Jan  2 22:46 in_capacitance0-capacitance2_calibscale
-r--r--r--    1 root     root          4096 Jan  2 22:46 in_capacitance0-capacitance2_raw
-rw-r--r--    1 root     root          4096 Jan  2 22:46 in_capacitance0-capacitance2_scale
-rw-r--r--    1 root     root          4096 Jan  2 22:46 in_capacitance0_calibbias
--w-------    1 root     root          4096 Jan  2 22:46 in_capacitance0_calibbias_calibration
-rw-r--r--    1 root     root          4096 Jan  2 22:46 in_capacitance0_calibscale
--w-------    1 root     root          4096 Jan  2 22:46 in_capacitance0_calibscale_calibration
-r--r--r--    1 root     root          4096 Jan  2 22:46 in_capacitance0_raw
-rw-r--r--    1 root     root          4096 Jan  2 22:46 in_capacitance0_scale
-rw-r--r--    1 root     root          4096 Jan  2 22:46 in_capacitance1-capacitance3_calibbias
-rw-r--r--    1 root     root          4096 Jan  2 22:46 in_capacitance1-capacitance3_calibscale
-r--r--r--    1 root     root          4096 Jan  2 22:46 in_capacitance1-capacitance3_raw
-rw-r--r--    1 root     root          4096 Jan  2 22:46 in_capacitance1-capacitance3_scale
-rw-r--r--    1 root     root          4096 Jan  2 22:46 in_capacitance1_calibbias
--w-------    1 root     root          4096 Jan  2 22:46 in_capacitance1_calibbias_calibration
-rw-r--r--    1 root     root          4096 Jan  2 22:46 in_capacitance1_calibscale
--w-------    1 root     root          4096 Jan  2 22:46 in_capacitance1_calibscale_calibration
-r--r--r--    1 root     root          4096 Jan  2 22:46 in_capacitance1_raw
-rw-r--r--    1 root     root          4096 Jan  2 22:46 in_capacitance1_scale
-r--r--r--    1 root     root          4096 Jan  2 22:46 in_capacitance_scale_available
-r--r--r--    1 root     root          4096 Jan  2 22:46 name
drwxr-xr-x    2 root     root             0 Jan  2 22:46 power
-rw-r--r--    1 root     root          4096 Jan  2 22:46 sampling_frequency
-r--r--r--    1 root     root          4096 Jan  2 22:46 sampling_frequency_available
lrwxrwxrwx    1 root     root             0 Jan  2 22:46 subsystem -> ../../../../../../bus/iio
-rw-r--r--    1 root     root          4096 Jan  2 22:46 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
ad7152

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 sampling_frequency_available
200 50 20 17

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 sampling_frequency
200
root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0> echo 50 > sampling_frequency
root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0> cat sampling_frequency
50
root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0>

Show available scales for single and differential input channels

Lists all available scales for the input and input pairs:

ADC Input Pair Channel name
CIN1(+) in_capacitance0_raw
CIN2(+) in_capacitance1_raw
CIN1(+) - CIN1(-) in_capacitance0-capacitance2_raw
CIN2(+) - CIN2(-) in_capacitance1-capacitance3_raw

Setting these directly influences the CDC input range, by altering the Input Range settings.

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_available
0.000061050 0.000030525 0.000015263 0.000007631

Set scale for input channels

Scale to be applied to in_capacitance0_raw, in_capacitance1_raw, in_capacitance0-capacitance2_raw and in_capacitance1-capacitance3_raw in order to obtain the measured capacitance in picofarads (pF). Allows the user to select one scale out of the available scales.

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_scale
0.000061050
root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0> echo 0.000030525 > in_capacitance0_scale
root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0> cat in_capacitance0_scale
0.000030525
root:/sys/devices/platform/i2c-bfin-twi.0/i2c-0/0-0048/iio:device0>

Show channel CIN1(+) measurement

Description:
Raw unscaled capacitance measurement on channel in_capacitance0_raw

ADC Input Pair Channel name
CIN1(+) in_capacitance0_raw
CIN2(+) in_capacitance1_raw
CIN1(+) - CIN1(-) in_capacitance0-capacitance2_raw
CIN2(+) - CIN2(-) in_capacitance1-capacitance3_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
-1

U = in_capacitance0_raw * in_capacitance0_scale = 23344 * 0.000030525 = 0.7126 pF

Show channel differential CIN2(+) - CIN2(-) measurement

Description:
Raw unscaled voltage measurement on channel in_capacitance1-capacitance3_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_capacitance1-capacitance3_raw
-16

U = in_capacitance1-capacitance3_raw * in_capacitance1-capacitance3_scale = -16 * 0.000030525 = -0.0004884 pF

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_capacitance1_calibbias
12101

More Information