AD7746 Capacitance-to-digital converter driver

I2C Capacitance-to-digital converter with temperature and voltage sensors. The devices has two main channels: capacitance channel and voltage / temperature channel. More...

Detailed Description

I2C Capacitance-to-digital converter with temperature and voltage sensors. The devices has two main channels: capacitance channel and voltage / temperature channel.

The capacitance channel can measure from two different inputs (CIN1 and CIN2), selected using ad7746_set_cap_ch_input.

The voltage / temperature channel can measure from five different sources: Voltage from VIN pins, internal VCC, internal temperature sensor and external temperature sensor (see datasheet for proper setup). The mode of this channel can be set using ad7746_set_vt_ch_mode or will directly be set when trying to read from a specific source which is not the currently selected one. This mode change may lead to data not being available right away (in which case the reading function will return AD7746_NODATA error code).

Note
Constantly switching between modes in the voltage / temperature channel may lead to invalid data, for what it seems to be a device limitation.

This driver provides [S]ensor [A]ctuator [U]ber [L]ayer capabilities.

Files

file  ad7746_internal.h
 Internal definitions for AD7746 capacitance sensor.
 
file  ad7746_params.h
 Default configuration for AD7746 capaticance-to-digital converter.
 
file  ad7746.h
 AD7746 Capacitance-to-digital converter with temperature sensor driver.
 

Data Structures

struct  ad7746_params
 AD7746 params. More...
 
struct  ad7746
 AD7746 device descriptor. More...
 

Macros

#define AD7746_ZERO_SCALE_CODE   (0x800000LL)
 0 fF capacitance code
 
#define AD7746_INTERNAL_VREF   (1170)
 Interval voltage reference expressed in mV.
 
#define AD7746_DAC_MAX   (0x7F)
 Maximum value that can be configured into the DACs.
 

Typedefs

typedef struct ad7746_params ad7746_params_t
 AD7746 params.
 
typedef struct ad7746 ad7746_t
 AD7746 device descriptor.
 

Enumerations

enum  { AD7746_READ_CAP_CH = 0, AD7746_READ_VT_CH = 1 }
 Channel numbers for reading. More...
 
enum  { AD7746_OK = 0, AD7746_NOI2C = -1, AD7746_NODEV = -2, AD7746_NODATA = -3 }
 Named return values. More...
 
enum  ad7746_vt_sample_rate_t { AD7746_VT_SR_498 = 0, AD7746_VT_SR_312 = 1, AD7746_VT_SR_161 = 2, AD7746_VT_SR_082 = 3 }
 Voltage / Temperature channel sample rates. More...
 
enum  ad7746_vt_mode_t {
  AD7746_VT_MD_DIS = -1, AD7746_VT_MD_TEMP = 0, AD7746_VT_MD_ETEMP = 1, AD7746_VT_MD_VDD = 2,
  AD7746_VT_MD_VIN = 3
}
 Voltage / Temperature channel modes. More...
 
enum  ad7746_cap_input_t { AD7746_CAP_IN_1 = 0, AD7746_CAP_IN_2 }
 Capacitance channel input. More...
 
enum  ad7746_cap_sample_rate_t {
  AD7746_CAP_SR_909 = 0, AD7746_CAP_SR_838 = 1, AD7746_CAP_SR_500 = 2, AD7746_CAP_SR_263 = 3,
  AD7746_CAP_SR_161 = 4, AD7746_CAP_SR_130 = 5, AD7746_CAP_SR_109 = 6, AD7746_CAP_SR_091 = 7
}
 Capacitive channel sample rate. More...
 
enum  ad7746_exc_config_t { AD7746_EXC_A = 0x06, AD7746_EXC_B = 0x09, AD7746_EXC_AB = 0x0A }
 Excitation signal output configuration. More...
 

Functions

int ad7746_init (ad7746_t *dev, const ad7746_params_t *params)
 Initializes an AD7746 device. More...
 
int ad7746_read_capacitance_1 (ad7746_t *dev, int *value)
 Reads the capacitance from the input 1 (CIN1). More...
 
int ad7746_read_capacitance_2 (ad7746_t *dev, int *value)
 Reads the capacitance from the input 2 (CIN2). More...
 
int ad7746_read_voltage_in (ad7746_t *dev, int *value)
 Reads the voltage from the external voltage input (VIN). More...
 
int ad7746_read_voltage_vdd (ad7746_t *dev, int *value)
 Reads the voltage from the VDD pin. More...
 
int ad7746_read_temperature_int (ad7746_t *dev, int *value)
 Reads the temperature from the internal sensor. More...
 
int ad7746_read_temperature_ext (ad7746_t *dev, int *value)
 Reads the temperature from the external sensor (see datasheet). More...
 
int ad7746_set_cap_ch_input (const ad7746_t *dev, ad7746_cap_input_t input)
 Sets the current input for the capacitive measurement.If not configured manually, the driver sets the correct mode within the dedicated read function. More...
 
int ad7746_set_vt_ch_mode (ad7746_t *dev, ad7746_vt_mode_t mode)
 Sets the mode for the voltage / temperature channel and updates the descriptor with the new configuration. More...
 
int ad7746_set_vt_sr (const ad7746_t *dev, ad7746_vt_sample_rate_t sr)
 Sets the sample rate for the voltage / temperature channel. More...
 
int ad7746_set_cap_sr (const ad7746_t *dev, ad7746_cap_sample_rate_t sr)
 Sets the sample rate for the capacitance channel. More...
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Channel numbers for reading.

Enumerator
AD7746_READ_CAP_CH 

read capacitive channel

AD7746_READ_VT_CH 

read voltage / temperature channel

Definition at line 72 of file ad7746.h.

◆ anonymous enum

anonymous enum

Named return values.

Enumerator
AD7746_OK 

everything was fine

AD7746_NOI2C 

I2C communication failed.

AD7746_NODEV 

no AD7746 device found on the bus

AD7746_NODATA 

no data available

Definition at line 80 of file ad7746.h.

◆ ad7746_cap_input_t

Capacitance channel input.

Enumerator
AD7746_CAP_IN_1 

CIN1 input.

AD7746_CAP_IN_2 

CIN2 input.

Definition at line 111 of file ad7746.h.

◆ ad7746_cap_sample_rate_t

Capacitive channel sample rate.

Enumerator
AD7746_CAP_SR_909 

90.9 Hz

AD7746_CAP_SR_838 

83.8 Hz

AD7746_CAP_SR_500 

50.0 Hz

AD7746_CAP_SR_263 

26.3 Hz

AD7746_CAP_SR_161 

16.1 Hz

AD7746_CAP_SR_130 

13.0 Hz

AD7746_CAP_SR_109 

10.9 Hz

AD7746_CAP_SR_091 

9.1 Hz

Definition at line 119 of file ad7746.h.

◆ ad7746_exc_config_t

Excitation signal output configuration.

Enumerator
AD7746_EXC_A 

enable only exc A output

AD7746_EXC_B 

enable only exc B output

AD7746_EXC_AB 

enable exc A and B outputs

Definition at line 133 of file ad7746.h.

◆ ad7746_vt_mode_t

Voltage / Temperature channel modes.

Enumerator
AD7746_VT_MD_DIS 

channel disabled

AD7746_VT_MD_TEMP 

internal temperature sensor

AD7746_VT_MD_ETEMP 

external temperature sensor (see datasheet)

AD7746_VT_MD_VDD 

Vdd voltage monitor.

AD7746_VT_MD_VIN 

external voltage input (Vin)

Definition at line 100 of file ad7746.h.

◆ ad7746_vt_sample_rate_t

Voltage / Temperature channel sample rates.

Enumerator
AD7746_VT_SR_498 

49.8 Hz

AD7746_VT_SR_312 

31.2 Hz

AD7746_VT_SR_161 

16.1 Hz

AD7746_VT_SR_082 

8.2 Hz

Definition at line 90 of file ad7746.h.

Function Documentation

◆ ad7746_init()

int ad7746_init ( ad7746_t dev,
const ad7746_params_t params 
)

Initializes an AD7746 device.

Parameters
[in,out]devdevice descriptor
[in]paramsdevice configuration
Returns
AD7746_OK on success
AD7746_NODEV if no device is found on the bus
AD7746_NOI2C if other error occurs

◆ ad7746_read_capacitance_1()

int ad7746_read_capacitance_1 ( ad7746_t dev,
int *  value 
)

Reads the capacitance from the input 1 (CIN1).

Returns the value in fF.

Note
If the currently selected input does not match AD7746_CAP_IN_1 it will be changed to it. This may cause data not to be available right away. The time until new data is available will depend on the sample rate of the channel.
Parameters
[in,out]devdevice descriptor
[out]valueread value in fF
Returns
AD7746_OK on success
AD7746_NODATA if there is no data available in the channel
AD7746_I2C if other error occurs

◆ ad7746_read_capacitance_2()

int ad7746_read_capacitance_2 ( ad7746_t dev,
int *  value 
)

Reads the capacitance from the input 2 (CIN2).

Returns the value in fF.

Note
If the currently selected input does not match AD7746_CAP_IN_2 it will be changed to it. This may cause data not to be available right away. The time until new data is available will depend on the sample rate of the channel.
Parameters
[in,out]devdevice descriptor
[out]valueread value in fF
Returns
AD7746_OK on success
AD7746_NODATA if there is no data available in the channel
AD7746_I2C if other error occurs

◆ ad7746_read_temperature_ext()

int ad7746_read_temperature_ext ( ad7746_t dev,
int *  value 
)

Reads the temperature from the external sensor (see datasheet).

Note
If the current mode of the voltage / temperature channel does not match AD7746_VT_MD_ETEMP it will be changed to this mode, causing data not to be available right away. The time until new data is available will depend on the sample rate of the channel.
Parameters
[in,out]devdevice descriptor
[out]valueread value in celsius
Returns
AD7746_OK on success
AD7746_NODATA if there is no data available in the channel
AD7746_I2C if other error occurs

◆ ad7746_read_temperature_int()

int ad7746_read_temperature_int ( ad7746_t dev,
int *  value 
)

Reads the temperature from the internal sensor.

Note
If the current mode of the voltage / temperature channel does not match AD7746_VT_MD_TEMP it will be changed to this mode, causing data not to be available right away. The time until new data is available will depend on the sample rate of the channel.
Parameters
[in,out]devdevice descriptor
[out]valueread value in celsius
Returns
AD7746_OK on success
AD7746_NODATA if there is no data available in the channel
AD7746_I2C if other error occurs

◆ ad7746_read_voltage_in()

int ad7746_read_voltage_in ( ad7746_t dev,
int *  value 
)

Reads the voltage from the external voltage input (VIN).

Returns the value in mV.

Note
If the current mode of the voltage / temperature channel does not match AD7746_VT_MD_VIN it will be changed to this mode, causing data not to be available right away. The time until new data is available will depend on the sample rate of the channel.
Parameters
[in,out]devdevice descriptor
[out]valueread value in mV
Returns
AD7746_OK on success
AD7746_NODATA if there is no data available in the channel
AD7746_I2C if other error occurs

◆ ad7746_read_voltage_vdd()

int ad7746_read_voltage_vdd ( ad7746_t dev,
int *  value 
)

Reads the voltage from the VDD pin.

Returns the value in mV.

Note
If the current mode of the voltage / temperature channel does not match AD7746_VT_MD_VDD it will be changed to this mode, causing data not to be available right away. The time until new data is available will depend on the sample rate of the channel.
Parameters
[in,out]devdevice descriptor
[out]valueread value in mV
Returns
AD7746_OK on success
AD7746_NODATA if there is no data available in the channel
AD7746_I2C if other error occurs

◆ ad7746_set_cap_ch_input()

int ad7746_set_cap_ch_input ( const ad7746_t dev,
ad7746_cap_input_t  input 
)

Sets the current input for the capacitive measurement.If not configured manually, the driver sets the correct mode within the dedicated read function.

Parameters
[in]devdevice descriptor
[in]inputselected input - 0 for CIN1, 1 for CIN2
Returns
AD7746_OK on success
AD7746_NOI2C on error

◆ ad7746_set_cap_sr()

int ad7746_set_cap_sr ( const ad7746_t dev,
ad7746_cap_sample_rate_t  sr 
)

Sets the sample rate for the capacitance channel.

Parameters
[in]devdevice descriptor
[in]srsample rate
Returns
AD7746_OK on success
AD7746_NOI2C on error

◆ ad7746_set_vt_ch_mode()

int ad7746_set_vt_ch_mode ( ad7746_t dev,
ad7746_vt_mode_t  mode 
)

Sets the mode for the voltage / temperature channel and updates the descriptor with the new configuration.

If not configured manually, the driver sets the correct mode within the dedicated read function.

Parameters
[in,out]devdevice descriptor
[in]modemode to which the channel has to be set
Returns
AD7746_OK on success
AD7746_NOI2C on error

◆ ad7746_set_vt_sr()

int ad7746_set_vt_sr ( const ad7746_t dev,
ad7746_vt_sample_rate_t  sr 
)

Sets the sample rate for the voltage / temperature channel.

Parameters
[in]devdevice descriptor
[in]srsample rate
Returns
AD7746_OK on success
AD7746_NOI2C on error