no-OS
Loading...
Searching...
No Matches
ad7156.h File Reference

Header file of AD7156 Driver. More...

#include <stdint.h>
#include "no_os_i2c.h"
Include dependency graph for ad7156.h:

Classes

struct  ad7156_dev
 
struct  ad7156_init_param
 

Macros

#define AD7156_ADDRESS   0x48
 
#define AD7156_REG_STATUS   0x00
 
#define AD7156_REG_CH1_DATA_H   0x01
 
#define AD7156_REG_CH1_DATA_L   0x02
 
#define AD7156_REG_CH2_DATA_H   0x03
 
#define AD7156_REG_CH2_DATA_L   0x04
 
#define AD7156_REG_CH1_AVG_H   0x05
 
#define AD7156_REG_CH1_AVG_L   0x06
 
#define AD7156_REG_CH2_AVG_H   0x07
 
#define AD7156_REG_CH2_AVG_L   0x08
 
#define AD7156_REG_CH1_SENS_THRSH_H   0x09
 
#define AD7156_REG_CH1_TMO_THRSH_L   0x0A
 
#define AD7156_REG_CH1_SETUP   0x0B
 
#define AD7156_REG_CH2_SENS_THRSH_H   0x0C
 
#define AD7156_REG_CH2_TMO_THRSH_L   0x0D
 
#define AD7156_REG_CH2_SETUP   0x0E
 
#define AD7156_REG_CONFIG   0x0F
 
#define AD7156_REG_PWR_DWN_TMR   0x10
 
#define AD7156_REG_CH1_CAPDAC   0x11
 
#define AD7156_REG_CH2_CAPDAC   0x12
 
#define AD7156_REG_SERIAL_N3   0x13
 
#define AD7156_REG_SERIAL_N2   0x14
 
#define AD7156_REG_SERIAL_N1   0x15
 
#define AD7156_REG_SERIAL_N0   0x16
 
#define AD7156_REG_CHIP_ID   0x17
 
#define AD7156_STATUS_PWR_DWN   (1 << 7)
 
#define AD7156_STATUS_DAC_STEP2   (1 << 6)
 
#define AD7156_STATUS_OUT2   (1 << 5)
 
#define AD7156_STATUS_DAC_STEP1   (1 << 4)
 
#define AD7156_STATUS_OUT1   (1 << 3)
 
#define AD7156_STATUS_C1_C2   (1 << 2)
 
#define AD7156_STATUS_RDY2   (1 << 1)
 
#define AD7156_STATUS_RDY1   (1 << 0)
 
#define AD7156_CH1_SETUP_RANGE(x)
 
#define AD7156_CH1_SETUP_HYST1   (1 << 4)
 
#define AD7156_CH1_SETUP_THR1(x)
 
#define AD7156_CH2_SETUP_RANGE(x)
 
#define AD7156_CH2_SETUP_HYST2   (1 << 4)
 
#define AD7156_CH2_SETUP_THR2(x)
 
#define AD7156_CDC_RANGE_2_PF   0
 
#define AD7156_CDC_RANGE_0_5_PF   1
 
#define AD7156_CDC_RANGE_1_PF   2
 
#define AD7156_CDC_RANGE_4_PF   3
 
#define AD7156_CONFIG_THR_FIXED   (1 << 7)
 
#define AD7156_CONFIG_THR_MD(x)
 
#define AD7156_CONFIG_EN_CH1   (1 << 4)
 
#define AD7156_CONFIG_EN_CH2   (1 << 3)
 
#define AD7156_CONFIG_MD(x)
 
#define AD7156_ADAPTIVE_THRESHOLD   0
 
#define AD7156_FIXED_THRESHOLD   1
 
#define AD7156_THR_MODE_NEGATIVE   0
 
#define AD7156_THR_MODE_POSITIVE   1
 
#define AD7156_THR_MODE_IN_WINDOW   2
 
#define AD7156_THR_MODE_OU_WINDOW   3
 
#define AD7156_CONV_MODE_IDLE   0
 
#define AD7156_CONV_MODE_CONT_CONV   1
 
#define AD7156_CONV_MODE_SINGLE_CONV   2
 
#define AD7156_CONV_MODE_PWR_DWN   3
 
#define AD7156_PWR_DWN_TMR_TIMEOUT(x)
 
#define AD7156_CH1_CAPDAC_DAC_EN1   (1 << 7)
 
#define AD7156_CH1_CAPDAC_DAC_AUTO1   (1 << 6)
 
#define AD7156_CH1_CAPDAC_DAC_VAL1(x)
 
#define AD7156_CH2_CAPDAC_DAC_EN2   (1 << 7)
 
#define AD7156_CH2_CAPDAC_DAC_AUTO2   (1 << 6)
 
#define AD7156_CH2_CAPDAC_DAC_VAL2(x)
 
#define AD7156_DEFAULT_ID   0x88
 
#define AD7156_RESET_CMD   0xBF
 
#define AD7156_CHANNEL1   1
 
#define AD7156_CHANNEL2   2
 

Functions

void ad7156_get_register_value (struct ad7156_dev *dev, uint8_t *p_read_data, uint8_t register_address, uint8_t bytes_number)
 Performs a burst read of a specified number of registers.
 
void ad7156_set_register_value (struct ad7156_dev *dev, uint16_t register_value, uint8_t register_address, uint8_t bytes_number)
 Writes data into one or two registers.
 
int8_t ad7156_init (struct ad7156_dev **device, struct ad7156_init_param init_param)
 Initializes the communication peripheral and the initial Values for AD7156 Board.
 
int32_t ad7156_remove (struct ad7156_dev *dev)
 Free the resources allocated by ad7156_init().
 
void ad7156_reset (struct ad7156_dev *dev)
 Resets the device.
 
void ad7156_set_power_mode (struct ad7156_dev *dev, uint8_t pwr_mode)
 Sets the converter mode of operation.
 
void ad7156_channel_state (struct ad7156_dev *dev, uint8_t channel, uint8_t enable_conv)
 Enables or disables conversion on the selected channel.
 
void ad7156_set_range (struct ad7156_dev *dev, uint32_t channel, uint8_t range)
 Sets the input range of the specified channel.
 
float ad7156_get_range (struct ad7156_dev *dev, uint32_t channel)
 Reads the range bits from the device and returns the range in pF.
 
void ad7156_set_threshold_mode (struct ad7156_dev *dev, uint8_t thr_mode, uint8_t thr_fixed)
 Selects the threshold mode of operation.
 
void ad7156_set_threshold (struct ad7156_dev *dev, uint8_t channel, float p_fthr)
 Writes to the threshold register when threshold fixed mode is enabled.
 
void ad7156_set_sensitivity (struct ad7156_dev *dev, uint8_t channel, float p_fsensitivity)
 Writes a value(pF) to the sensitivity register. This functions should be used when adaptive threshold mode is selected.
 
uint16_t ad7156_read_channel_data (struct ad7156_dev *dev, uint8_t channel)
 Reads a 12-bit sample from the selected channel.
 
uint16_t ad7156_wait_read_channel_data (struct ad7156_dev *dev, uint8_t channel)
 Waits for a finished CDC conversion and reads a 12-bit sample from the selected channel.
 
float ad7156_read_channel_capacitance (struct ad7156_dev *dev, uint8_t channel)
 Reads a sample the selected channel and converts the data to picofarads(pF).
 
float ad7156_wait_read_channel_capacitance (struct ad7156_dev *dev, uint8_t channel)
 Waits for a finished CDC conversion the selected channel, reads a sample and converts the data to picofarads(pF).
 

Detailed Description

Header file of AD7156 Driver.

Author
DNechita(Dan.N.nosp@m.echi.nosp@m.ta@an.nosp@m.alog.nosp@m..com)

Copyright 2013(c) Analog Devices, Inc.

SPDX-License-Identifier: BSD-3-Clause

Macro Definition Documentation

◆ AD7156_ADAPTIVE_THRESHOLD

#define AD7156_ADAPTIVE_THRESHOLD   0

◆ AD7156_ADDRESS

#define AD7156_ADDRESS   0x48

< AD7156 slave address AD7156 registers

◆ AD7156_CDC_RANGE_0_5_PF

#define AD7156_CDC_RANGE_0_5_PF   1

◆ AD7156_CDC_RANGE_1_PF

#define AD7156_CDC_RANGE_1_PF   2

◆ AD7156_CDC_RANGE_2_PF

#define AD7156_CDC_RANGE_2_PF   0

◆ AD7156_CDC_RANGE_4_PF

#define AD7156_CDC_RANGE_4_PF   3

AD7156_REG_CONFIG definition

◆ AD7156_CH1_CAPDAC_DAC_AUTO1

#define AD7156_CH1_CAPDAC_DAC_AUTO1   (1 << 6)

◆ AD7156_CH1_CAPDAC_DAC_EN1

#define AD7156_CH1_CAPDAC_DAC_EN1   (1 << 7)

◆ AD7156_CH1_CAPDAC_DAC_VAL1

#define AD7156_CH1_CAPDAC_DAC_VAL1 ( x)
Value:
((x) & 0x3F)

AD7156_REG_CH2_CAPDAC

◆ AD7156_CH1_SETUP_HYST1

#define AD7156_CH1_SETUP_HYST1   (1 << 4)

◆ AD7156_CH1_SETUP_RANGE

#define AD7156_CH1_SETUP_RANGE ( x)
Value:
(((x) & 0x3) << 6)

◆ AD7156_CH1_SETUP_THR1

#define AD7156_CH1_SETUP_THR1 ( x)
Value:
((x) & 0xF)

AD7156_REG_CH2_SETUP definition

◆ AD7156_CH2_CAPDAC_DAC_AUTO2

#define AD7156_CH2_CAPDAC_DAC_AUTO2   (1 << 6)

◆ AD7156_CH2_CAPDAC_DAC_EN2

#define AD7156_CH2_CAPDAC_DAC_EN2   (1 << 7)

◆ AD7156_CH2_CAPDAC_DAC_VAL2

#define AD7156_CH2_CAPDAC_DAC_VAL2 ( x)
Value:
((x) & 0x3F)

Chip identification code

◆ AD7156_CH2_SETUP_HYST2

#define AD7156_CH2_SETUP_HYST2   (1 << 4)

◆ AD7156_CH2_SETUP_RANGE

#define AD7156_CH2_SETUP_RANGE ( x)
Value:
(((x) & 0x3) << 6)

◆ AD7156_CH2_SETUP_THR2

#define AD7156_CH2_SETUP_THR2 ( x)

◆ AD7156_CHANNEL1

#define AD7156_CHANNEL1   1

◆ AD7156_CHANNEL2

#define AD7156_CHANNEL2   2

◆ AD7156_CONFIG_EN_CH1

#define AD7156_CONFIG_EN_CH1   (1 << 4)

◆ AD7156_CONFIG_EN_CH2

#define AD7156_CONFIG_EN_CH2   (1 << 3)

◆ AD7156_CONFIG_MD

#define AD7156_CONFIG_MD ( x)
Value:
((x) & 0x7)

AD7156_CONFIG_THR_FIXED options

◆ AD7156_CONFIG_THR_FIXED

#define AD7156_CONFIG_THR_FIXED   (1 << 7)

◆ AD7156_CONFIG_THR_MD

#define AD7156_CONFIG_THR_MD ( x)
Value:
(((x) & 0x3) << 5)

◆ AD7156_CONV_MODE_CONT_CONV

#define AD7156_CONV_MODE_CONT_CONV   1

◆ AD7156_CONV_MODE_IDLE

#define AD7156_CONV_MODE_IDLE   0

◆ AD7156_CONV_MODE_PWR_DWN

#define AD7156_CONV_MODE_PWR_DWN   3

AD7156_REG_PWR_DWN_TMR definition

◆ AD7156_CONV_MODE_SINGLE_CONV

#define AD7156_CONV_MODE_SINGLE_CONV   2

◆ AD7156_DEFAULT_ID

#define AD7156_DEFAULT_ID   0x88

AD7156 Reset Command

◆ AD7156_FIXED_THRESHOLD

#define AD7156_FIXED_THRESHOLD   1

◆ AD7156_PWR_DWN_TMR_TIMEOUT

#define AD7156_PWR_DWN_TMR_TIMEOUT ( x)
Value:
(((x) & 0x3F) | (1 << 6))

AD7156_REG_CH1_CAPDAC

◆ AD7156_REG_CH1_AVG_H

#define AD7156_REG_CH1_AVG_H   0x05

◆ AD7156_REG_CH1_AVG_L

#define AD7156_REG_CH1_AVG_L   0x06

◆ AD7156_REG_CH1_CAPDAC

#define AD7156_REG_CH1_CAPDAC   0x11

◆ AD7156_REG_CH1_DATA_H

#define AD7156_REG_CH1_DATA_H   0x01

◆ AD7156_REG_CH1_DATA_L

#define AD7156_REG_CH1_DATA_L   0x02

◆ AD7156_REG_CH1_SENS_THRSH_H

#define AD7156_REG_CH1_SENS_THRSH_H   0x09

◆ AD7156_REG_CH1_SETUP

#define AD7156_REG_CH1_SETUP   0x0B

◆ AD7156_REG_CH1_TMO_THRSH_L

#define AD7156_REG_CH1_TMO_THRSH_L   0x0A

◆ AD7156_REG_CH2_AVG_H

#define AD7156_REG_CH2_AVG_H   0x07

◆ AD7156_REG_CH2_AVG_L

#define AD7156_REG_CH2_AVG_L   0x08

◆ AD7156_REG_CH2_CAPDAC

#define AD7156_REG_CH2_CAPDAC   0x12

◆ AD7156_REG_CH2_DATA_H

#define AD7156_REG_CH2_DATA_H   0x03

◆ AD7156_REG_CH2_DATA_L

#define AD7156_REG_CH2_DATA_L   0x04

◆ AD7156_REG_CH2_SENS_THRSH_H

#define AD7156_REG_CH2_SENS_THRSH_H   0x0C

◆ AD7156_REG_CH2_SETUP

#define AD7156_REG_CH2_SETUP   0x0E

◆ AD7156_REG_CH2_TMO_THRSH_L

#define AD7156_REG_CH2_TMO_THRSH_L   0x0D

◆ AD7156_REG_CHIP_ID

#define AD7156_REG_CHIP_ID   0x17

AD7156_REG_STATUS definition

◆ AD7156_REG_CONFIG

#define AD7156_REG_CONFIG   0x0F

◆ AD7156_REG_PWR_DWN_TMR

#define AD7156_REG_PWR_DWN_TMR   0x10

◆ AD7156_REG_SERIAL_N0

#define AD7156_REG_SERIAL_N0   0x16

◆ AD7156_REG_SERIAL_N1

#define AD7156_REG_SERIAL_N1   0x15

◆ AD7156_REG_SERIAL_N2

#define AD7156_REG_SERIAL_N2   0x14

◆ AD7156_REG_SERIAL_N3

#define AD7156_REG_SERIAL_N3   0x13

◆ AD7156_REG_STATUS

#define AD7156_REG_STATUS   0x00

◆ AD7156_RESET_CMD

#define AD7156_RESET_CMD   0xBF

AD7156 Channels

◆ AD7156_STATUS_C1_C2

#define AD7156_STATUS_C1_C2   (1 << 2)

◆ AD7156_STATUS_DAC_STEP1

#define AD7156_STATUS_DAC_STEP1   (1 << 4)

◆ AD7156_STATUS_DAC_STEP2

#define AD7156_STATUS_DAC_STEP2   (1 << 6)

◆ AD7156_STATUS_OUT1

#define AD7156_STATUS_OUT1   (1 << 3)

◆ AD7156_STATUS_OUT2

#define AD7156_STATUS_OUT2   (1 << 5)

◆ AD7156_STATUS_PWR_DWN

#define AD7156_STATUS_PWR_DWN   (1 << 7)

◆ AD7156_STATUS_RDY1

#define AD7156_STATUS_RDY1   (1 << 0)

AD7156_REG_CH1_SETUP definition

◆ AD7156_STATUS_RDY2

#define AD7156_STATUS_RDY2   (1 << 1)

◆ AD7156_THR_MODE_IN_WINDOW

#define AD7156_THR_MODE_IN_WINDOW   2

◆ AD7156_THR_MODE_NEGATIVE

#define AD7156_THR_MODE_NEGATIVE   0

◆ AD7156_THR_MODE_OU_WINDOW

#define AD7156_THR_MODE_OU_WINDOW   3

◆ AD7156_THR_MODE_POSITIVE

#define AD7156_THR_MODE_POSITIVE   1

Function Documentation

◆ ad7156_channel_state()

void ad7156_channel_state ( struct ad7156_dev * dev,
uint8_t channel,
uint8_t enable_conv )

Enables or disables conversion on the selected channel.

Sets the input range of the specified channel.

Parameters
dev- The device structure.
channel- Channel option. Example: AD7156_CHANNEL1 AD7156_CHANNEL2
enable_conv- The state of channel activity. Example: 0 - disable conversion on selected channel. 1 - enable conversion on selected channel.

◆ ad7156_get_range()

float ad7156_get_range ( struct ad7156_dev * dev,
uint32_t channel )

Reads the range bits from the device and returns the range in pF.

Selects the threshold mode of operation.

Parameters
dev- The device structure.
channel- Channel option. Example: AD7156_CHANNEL1 AD7156_CHANNEL2
Returns
The capacitive input range(pF).

◆ ad7156_get_register_value()

void ad7156_get_register_value ( struct ad7156_dev * dev,
uint8_t * p_read_data,
uint8_t register_address,
uint8_t bytes_number )

Performs a burst read of a specified number of registers.

Writes data into one or two registers..

Parameters
dev- The device structure.
p_read_data- The read values are stored in this buffer.
register_address- The start address of the burst read.
bytes_number- Number of bytes to read.

◆ ad7156_init()

int8_t ad7156_init ( struct ad7156_dev ** device,
struct ad7156_init_param init_param )

Initializes the communication peripheral and the initial Values for AD7156 Board.

Parameters
device- The device structure.
init_param- The structure that contains the device initial parameters.
Returns
ret - The result of the initialization procedure. Example: -1 - I2C peripheral was not initialized or the device is not present. 0 - I2C peripheral was initialized and the device is present.

◆ ad7156_read_channel_capacitance()

float ad7156_read_channel_capacitance ( struct ad7156_dev * dev,
uint8_t channel )

Reads a sample the selected channel and converts the data to picofarads(pF).

Waits for a finished CDC conversion the selected channel, reads a sample and converts the data to picofarads(pF).

Parameters
dev- The device structure.
channel- Channel option. Example: AD7156_CHANNEL1 AD7156_CHANNEL2
Returns
Conversion result form the selected channel as picofarads(pF).

◆ ad7156_read_channel_data()

uint16_t ad7156_read_channel_data ( struct ad7156_dev * dev,
uint8_t channel )

Reads a 12-bit sample from the selected channel.

Waits for a finished CDC conversion and reads a 12-bit sample from the selected channel.

Parameters
dev- The device structure.
channel- Channel option. Example: AD7156_CHANNEL1 AD7156_CHANNEL2
Returns
Conversion result form the selected channel.

◆ ad7156_remove()

int32_t ad7156_remove ( struct ad7156_dev * dev)

Free the resources allocated by ad7156_init().

Free the resources allocated by ad7156_init(). Resets the device.

Parameters
dev- The device structure.
Returns
ret - The result of the remove procedure.

◆ ad7156_reset()

void ad7156_reset ( struct ad7156_dev * dev)

Resets the device.

Sets the converter mode of operation.

Parameters
dev- The device structure.

◆ ad7156_set_power_mode()

void ad7156_set_power_mode ( struct ad7156_dev * dev,
uint8_t pwr_mode )

Sets the converter mode of operation.

Enables or disables conversion on the selected channel.

Parameters
dev- The device structure.
pwr_mode- Mode of operation option. Example: AD7156_CONV_MODE_IDLE - Idle AD7156_CONV_MODE_CONT_CONV - Continuous conversion AD7156_CONV_MODE_SINGLE_CONV - Single conversion AD7156_CONV_MODE_PWR_DWN - Power-down

◆ ad7156_set_range()

void ad7156_set_range ( struct ad7156_dev * dev,
uint32_t channel,
uint8_t range )

Sets the input range of the specified channel.

Reads the range bits from the device and returns the range in pF.

Parameters
dev- The device structure.
channel- Channel option. Example: AD7156_CHANNEL1 AD7156_CHANNEL2
range- Input range option. Example: AD7156_CDC_RANGE_2_PF - 2pF input range. AD7156_CDC_RANGE_0_5_PF - 0.5pF input range. AD7156_CDC_RANGE_1_PF - 1pF input range. AD7156_CDC_RANGE_4_PF - 4pF input range.

◆ ad7156_set_register_value()

void ad7156_set_register_value ( struct ad7156_dev * dev,
uint16_t register_value,
uint8_t register_address,
uint8_t bytes_number )

Writes data into one or two registers.

Initializes the communication peripheral and checks if the device is present.

Parameters
dev- The device structure.
register_value- Data value to write.
register_address- Address of the register.
bytes_number- Number of bytes. Accepted values: 0 - 1.

◆ ad7156_set_sensitivity()

void ad7156_set_sensitivity ( struct ad7156_dev * dev,
uint8_t channel,
float p_fsensitivity )

Writes a value(pF) to the sensitivity register. This functions should be used when adaptive threshold mode is selected.

Reads a 12-bit sample from the selected channel

Parameters
dev- The device structure.
channel- Channel option. Example: AD7156_CHANNEL1 AD7156_CHANNEL2
p_fsensitivity- The sensitivity value in picofarads(pF).

◆ ad7156_set_threshold()

void ad7156_set_threshold ( struct ad7156_dev * dev,
uint8_t channel,
float p_fthr )

Writes to the threshold register when threshold fixed mode is enabled.

Writes a value(pF) to the sensitivity register. This functions should be used when adaptive threshold mode is selected.

Parameters
dev- The device structure.
channel- Channel option. Example: AD7156_CHANNEL1 AD7156_CHANNEL2
p_fthr- The threshold value in picofarads(pF). The value must not be out of the selected input range.

◆ ad7156_set_threshold_mode()

void ad7156_set_threshold_mode ( struct ad7156_dev * dev,
uint8_t thr_mode,
uint8_t thr_fixed )

Selects the threshold mode of operation.

Writes to the threshold register when threshold fixed mode is enabled.

Parameters
dev- The device structure.
thr_mode- Output comparator mode. Example: AD7156_THR_MODE_NEGATIVE AD7156_THR_MODE_POSITIVE AD7156_THR_MODE_IN_WINDOW AD7156_THR_MODE_OU_WINDOW
thr_fixed- Selects the threshold mode. Example: AD7156_ADAPTIVE_THRESHOLD AD7156_FIXED_THRESHOLD

◆ ad7156_wait_read_channel_capacitance()

float ad7156_wait_read_channel_capacitance ( struct ad7156_dev * dev,
uint8_t channel )

Waits for a finished CDC conversion the selected channel, reads a sample and converts the data to picofarads(pF).

Parameters
dev- The device structure.
channel- Channel option. Example: AD7156_CHANNEL1 AD7156_CHANNEL2
Returns
Conversion result form the selected channel as picofarads(pF).

◆ ad7156_wait_read_channel_data()

uint16_t ad7156_wait_read_channel_data ( struct ad7156_dev * dev,
uint8_t channel )

Waits for a finished CDC conversion and reads a 12-bit sample from the selected channel.

Reads a sample the selected channel and converts the data to picofarads(pF).

Parameters
dev- The device structure.
channel- Channel option. Example: AD7156_CHANNEL1 AD7156_CHANNEL2
Returns
Conversion result form the selected channel.