no-OS
ad7156.h
Go to the documentation of this file.
1 /***************************************************************************/
33 #ifndef __AD7156_H__
34 #define __AD7156_H__
35 
36 /******************************************************************************/
37 /***************************** Include Files **********************************/
38 /******************************************************************************/
39 #include <stdint.h>
40 #include "no_os_i2c.h"
41 
42 /******************************************************************************/
43 /*************************** AD7156 Definitions *******************************/
44 /******************************************************************************/
46 #define AD7156_ADDRESS 0x48
47 
49 #define AD7156_REG_STATUS 0x00
50 #define AD7156_REG_CH1_DATA_H 0x01
51 #define AD7156_REG_CH1_DATA_L 0x02
52 #define AD7156_REG_CH2_DATA_H 0x03
53 #define AD7156_REG_CH2_DATA_L 0x04
54 #define AD7156_REG_CH1_AVG_H 0x05
55 #define AD7156_REG_CH1_AVG_L 0x06
56 #define AD7156_REG_CH2_AVG_H 0x07
57 #define AD7156_REG_CH2_AVG_L 0x08
58 #define AD7156_REG_CH1_SENS_THRSH_H 0x09
59 #define AD7156_REG_CH1_TMO_THRSH_L 0x0A
60 #define AD7156_REG_CH1_SETUP 0x0B
61 #define AD7156_REG_CH2_SENS_THRSH_H 0x0C
62 #define AD7156_REG_CH2_TMO_THRSH_L 0x0D
63 #define AD7156_REG_CH2_SETUP 0x0E
64 #define AD7156_REG_CONFIG 0x0F
65 #define AD7156_REG_PWR_DWN_TMR 0x10
66 #define AD7156_REG_CH1_CAPDAC 0x11
67 #define AD7156_REG_CH2_CAPDAC 0x12
68 #define AD7156_REG_SERIAL_N3 0x13
69 #define AD7156_REG_SERIAL_N2 0x14
70 #define AD7156_REG_SERIAL_N1 0x15
71 #define AD7156_REG_SERIAL_N0 0x16
72 #define AD7156_REG_CHIP_ID 0x17
73 
75 #define AD7156_STATUS_PWR_DWN (1 << 7)
76 #define AD7156_STATUS_DAC_STEP2 (1 << 6)
77 #define AD7156_STATUS_OUT2 (1 << 5)
78 #define AD7156_STATUS_DAC_STEP1 (1 << 4)
79 #define AD7156_STATUS_OUT1 (1 << 3)
80 #define AD7156_STATUS_C1_C2 (1 << 2)
81 #define AD7156_STATUS_RDY2 (1 << 1)
82 #define AD7156_STATUS_RDY1 (1 << 0)
83 
85 #define AD7156_CH1_SETUP_RANGE(x) (((x) & 0x3) << 6)
86 #define AD7156_CH1_SETUP_HYST1 (1 << 4)
87 #define AD7156_CH1_SETUP_THR1(x) ((x) & 0xF)
88 
90 #define AD7156_CH2_SETUP_RANGE(x) (((x) & 0x3) << 6)
91 #define AD7156_CH2_SETUP_HYST2 (1 << 4)
92 #define AD7156_CH2_SETUP_THR2(x) ((x) & 0xF)
93 
95 #define AD7156_CDC_RANGE_2_PF 0
96 #define AD7156_CDC_RANGE_0_5_PF 1
97 #define AD7156_CDC_RANGE_1_PF 2
98 #define AD7156_CDC_RANGE_4_PF 3
99 
101 #define AD7156_CONFIG_THR_FIXED (1 << 7)
102 #define AD7156_CONFIG_THR_MD(x) (((x) & 0x3) << 5)
103 #define AD7156_CONFIG_EN_CH1 (1 << 4)
104 #define AD7156_CONFIG_EN_CH2 (1 << 3)
105 #define AD7156_CONFIG_MD(x) ((x) & 0x7)
106 
108 #define AD7156_ADAPTIVE_THRESHOLD 0
109 #define AD7156_FIXED_THRESHOLD 1
110 
112 #define AD7156_THR_MODE_NEGATIVE 0
113 #define AD7156_THR_MODE_POSITIVE 1
114 #define AD7156_THR_MODE_IN_WINDOW 2
115 #define AD7156_THR_MODE_OU_WINDOW 3
116 
118 #define AD7156_CONV_MODE_IDLE 0
119 #define AD7156_CONV_MODE_CONT_CONV 1
120 #define AD7156_CONV_MODE_SINGLE_CONV 2
121 #define AD7156_CONV_MODE_PWR_DWN 3
122 
124 #define AD7156_PWR_DWN_TMR_TIMEOUT(x) (((x) & 0x3F) | (1 << 6))
125 
127 #define AD7156_CH1_CAPDAC_DAC_EN1 (1 << 7)
128 #define AD7156_CH1_CAPDAC_DAC_AUTO1 (1 << 6)
129 #define AD7156_CH1_CAPDAC_DAC_VAL1(x) ((x) & 0x3F)
130 
132 #define AD7156_CH2_CAPDAC_DAC_EN2 (1 << 7)
133 #define AD7156_CH2_CAPDAC_DAC_AUTO2 (1 << 6)
134 #define AD7156_CH2_CAPDAC_DAC_VAL2(x) ((x) & 0x3F)
135 
137 #define AD7156_DEFAULT_ID 0x88
138 
140 #define AD7156_RESET_CMD 0xBF
141 
143 #define AD7156_CHANNEL1 1
144 #define AD7156_CHANNEL2 2
145 
146 /******************************************************************************/
147 /*************************** Types Declarations *******************************/
148 /******************************************************************************/
149 
150 struct ad7156_dev {
151  /* I2C */
153  /* Device Settings */
154  float ad7156_channel1_range;
156 };
157 
158 struct ad7156_init_param {
159  /* I2C */
161  /* Device Settings */
163  float ad7156_channel2_range;
164 };
165 
166 /******************************************************************************/
167 /************************ Functions Declarations ******************************/
168 /******************************************************************************/
169 
171 void ad7156_get_register_value(struct ad7156_dev *dev,
172  uint8_t* p_read_data,
173  uint8_t register_address,
174  uint8_t bytes_number);
175 
177 void ad7156_set_register_value(struct ad7156_dev *dev,
178  uint16_t register_value,
179  uint8_t register_address,
180  uint8_t bytes_number);
183 int8_t ad7156_init(struct ad7156_dev **device,
185 
187 int32_t ad7156_remove(struct ad7156_dev *dev);
188 
190 void ad7156_reset(struct ad7156_dev *dev);
191 
193 void ad7156_set_power_mode(struct ad7156_dev *dev,
194  uint8_t pwr_mode);
195 
197 void ad7156_channel_state(struct ad7156_dev *dev,
198  uint8_t channel,
199  uint8_t enable_conv);
200 
202 void ad7156_set_range(struct ad7156_dev *dev,
203  uint32_t channel,
204  uint8_t range);
205 
207 float ad7156_get_range(struct ad7156_dev *dev,
208  uint32_t channel);
209 
211 void ad7156_set_threshold_mode(struct ad7156_dev *dev,
212  uint8_t thr_mode,
213  uint8_t thr_fixed);
214 
216 void ad7156_set_threshold(struct ad7156_dev *dev,
217  uint8_t channel,
218  float p_fthr);
219 
222 void ad7156_set_sensitivity(struct ad7156_dev *dev,
223  uint8_t channel,
224  float p_fsensitivity);
225 
227 uint16_t ad7156_read_channel_data(struct ad7156_dev *dev,
228  uint8_t channel);
229 
232 uint16_t ad7156_wait_read_channel_data(struct ad7156_dev *dev,
233  uint8_t channel);
234 
238  uint8_t channel);
239 
243  uint8_t channel);
244 
245 #endif /* __AD7156_H__ */
AD7156_CONFIG_THR_FIXED
#define AD7156_CONFIG_THR_FIXED
Definition: ad7156.h:105
no_os_alloc.h
AD7156_REG_CHIP_ID
#define AD7156_REG_CHIP_ID
Definition: ad7156.h:72
AD7156_CDC_RANGE_0_5_PF
#define AD7156_CDC_RANGE_0_5_PF
Definition: ad7156.h:100
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).
Definition: ad7156.c:503
no_os_i2c_write
int32_t no_os_i2c_write(struct no_os_i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
I2C Write data to slave device.
Definition: no_os_i2c.c:159
no_os_i2c_init
int32_t no_os_i2c_init(struct no_os_i2c_desc **desc, const struct no_os_i2c_init_param *param)
Initialize the I2C communication peripheral.
Definition: no_os_i2c.c:52
ad7156_reset
void ad7156_reset(struct ad7156_dev *dev)
Resets the device.
Definition: ad7156.c:154
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.
Definition: ad7156.c:242
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.
Definition: ad7156.c:55
ad7156_set_power_mode
void ad7156_set_power_mode(struct ad7156_dev *dev, uint8_t pwr_mode)
Sets the converter mode of operation.
Definition: ad7156.c:174
AD7156_REG_CONFIG
#define AD7156_REG_CONFIG
Definition: ad7156.h:64
no_os_i2c_remove
int32_t no_os_i2c_remove(struct no_os_i2c_desc *desc)
Free the resources allocated by no_os_i2c_init().
Definition: no_os_i2c.c:113
ad7156_dev::ad7156_channel1_range
float ad7156_channel1_range
Definition: ad7156.h:166
AD7156_REG_CH1_DATA_H
#define AD7156_REG_CH1_DATA_H
Definition: ad7156.h:50
device
Definition: ad9361_util.h:69
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.
Definition: ad7156.c:333
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...
Definition: ad7156.c:402
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.
Definition: ad7156.c:74
AD7156_REG_CH1_SETUP
#define AD7156_REG_CH1_SETUP
Definition: ad7156.h:60
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.
Definition: ad7156.c:462
AD7156_CONFIG_THR_MD
#define AD7156_CONFIG_THR_MD(x)
Definition: ad7156.h:106
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.
Definition: ad7156.c:366
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.
Definition: ad7156.c:101
ad7156.h
Header file of AD7156 Driver.
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.
Definition: ad7156.c:333
ad7156_remove
int32_t ad7156_remove(struct ad7156_dev *dev)
Free the resources allocated by ad7156_init().
Definition: ad7156.c:136
AD7156_REG_CH2_DATA_H
#define AD7156_REG_CH2_DATA_H
Definition: ad7156.h:52
AD7156_CONFIG_EN_CH2
#define AD7156_CONFIG_EN_CH2
Definition: ad7156.h:108
AD7156_REG_CH2_SETUP
#define AD7156_REG_CH2_SETUP
Definition: ad7156.h:63
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.
Definition: ad7156.c:205
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.
Definition: ad7156.c:462
ad7156_dev::i2c_desc
struct no_os_i2c_desc * i2c_desc
Definition: ad7156.h:164
AD7156_REG_CH2_SENS_THRSH_H
#define AD7156_REG_CH2_SENS_THRSH_H
Definition: ad7156.h:61
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).
Definition: ad7156.c:503
AD7156_CONFIG_MD
#define AD7156_CONFIG_MD(x)
Definition: ad7156.h:109
ad7156_dev
Definition: ad7156.h:162
AD7156_REG_CH1_SENS_THRSH_H
#define AD7156_REG_CH1_SENS_THRSH_H
Definition: ad7156.h:58
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.
Definition: ad7156.c:281
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.
Definition: ad7156.c:205
ad7156_dev::ad7156_channel2_range
float ad7156_channel2_range
Definition: ad7156.h:167
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.
Definition: ad7156.c:431
no_os_i2c_desc
Structure holding I2C address descriptor.
Definition: no_os_i2c.h:101
ad7156_set_power_mode
void ad7156_set_power_mode(struct ad7156_dev *dev, uint8_t pwr_mode)
Sets the converter mode of operation.
Definition: ad7156.c:174
AD7156_CDC_RANGE_1_PF
#define AD7156_CDC_RANGE_1_PF
Definition: ad7156.h:101
no_os_i2c_read
int32_t no_os_i2c_read(struct no_os_i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
I2C Read data from slave device.
Definition: no_os_i2c.c:190
AD7156_CH1_SETUP_RANGE
#define AD7156_CH1_SETUP_RANGE(x)
Definition: ad7156.h:85
no_os_malloc
void * no_os_malloc(size_t size)
Allocate memory and return a pointer to it.
Definition: chibios_alloc.c:43
ad7156_init_param::i2c_init
struct no_os_i2c_init_param i2c_init
Definition: ad7156.h:172
no_os_i2c.h
Header file of I2C Interface.
ad7156_init_param::ad7156_channel1_range
float ad7156_channel1_range
Definition: ad7156.h:174
ad7156_init_param::ad7156_channel2_range
float ad7156_channel2_range
Definition: ad7156.h:175
AD7156_STATUS_RDY1
#define AD7156_STATUS_RDY1
Definition: ad7156.h:82
AD7156_CDC_RANGE_4_PF
#define AD7156_CDC_RANGE_4_PF
Definition: ad7156.h:102
no_os_free
void no_os_free(void *ptr)
Deallocate memory previously allocated by a call to no_os_calloc or no_os_malloc.
Definition: chibios_alloc.c:69
ad7156_init_param
Definition: ad7156.h:170
ad7156_remove
int32_t ad7156_remove(struct ad7156_dev *dev)
Free the resources allocated by ad7156_init().
Definition: ad7156.c:136
AD7156_RESET_CMD
#define AD7156_RESET_CMD
Definition: ad7156.h:152
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.
Definition: ad7156.c:281
AD7156_CDC_RANGE_2_PF
#define AD7156_CDC_RANGE_2_PF
Definition: ad7156.h:99
no_os_i2c_init_param
Structure holding the parameters for I2C initialization.
Definition: no_os_i2c.h:64
AD7156_REG_STATUS
#define AD7156_REG_STATUS
Definition: ad7156.h:49
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:113
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.
Definition: ad7156.c:431
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.
Definition: ad7156.c:242
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 pic...
Definition: ad7156.c:534
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.
Definition: ad7156.c:74
AD7156_CONFIG_EN_CH1
#define AD7156_CONFIG_EN_CH1
Definition: ad7156.h:107
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.
Definition: ad7156.c:366
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.
Definition: ad7156.c:101
AD7156_DEFAULT_ID
#define AD7156_DEFAULT_ID
Definition: ad7156.h:149
ad7156_reset
void ad7156_reset(struct ad7156_dev *dev)
Resets the device.
Definition: ad7156.c:154
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...
Definition: ad7156.c:402
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 pic...
Definition: ad7156.c:534
AD7156_STATUS_RDY2
#define AD7156_STATUS_RDY2
Definition: ad7156.h:81
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.
Definition: ad7156.c:55