no-OS
ad5933.h
Go to the documentation of this file.
1 /***************************************************************************/
39 #ifndef __AD5933_H__
40 #define __AD5933_H__
41 
42 /******************************************************************************/
43 /***************************** Include Files **********************************/
44 /******************************************************************************/
45 #include <stdint.h>
46 #include "no_os_i2c.h"
47 
48 /******************************************************************************/
49 /************************** AD5933 Definitions ********************************/
50 /******************************************************************************/
51 
52 /* AD5933 Registers */
53 #define AD5933_REG_CONTROL_HB 0x80 // HB of the Control register
54 #define AD5933_REG_CONTROL_LB 0x81 // LB of the Control register
55 #define AD5933_REG_FREQ_START 0x82 // Start frequency
56 #define AD5933_REG_FREQ_INC 0x85 // Frequency increment
57 #define AD5933_REG_INC_NUM 0x88 // Number of increments
58 #define AD5933_REG_SETTLING_CYCLES 0x8A // Number of settling time cycles
59 #define AD5933_REG_STATUS 0x8F // Status
60 #define AD5933_REG_TEMP_DATA 0x92 // Temperature data
61 #define AD5933_REG_REAL_DATA 0x94 // Real data
62 #define AD5933_REG_IMAG_DATA 0x96 // Imaginary data
63 
64 /* AD5933_REG_CONTROL_HB Bits */
65 #define AD5933_CONTROL_FUNCTION(x) ((x) << 4)
66 #define AD5933_CONTROL_RANGE(x) ((x) << 1)
67 #define AD5933_CONTROL_PGA_GAIN(x) ((x) << 0)
68 
69 /* AD5933_REG_CONTROL_LB Bits */
70 #define AD5933_CONTROL_RESET (0x1 << 4)
71 #define AD5933_CONTROL_INT_SYSCLK (0x0 << 3)
72 #define AD5933_CONTROL_EXT_SYSCLK (0x1 << 3)
73 
74 /* AD5933_CONTROL_FUNCTION(x) options */
75 #define AD5933_FUNCTION_NOP 0x0
76 #define AD5933_FUNCTION_INIT_START_FREQ 0x1
77 #define AD5933_FUNCTION_START_SWEEP 0x2
78 #define AD5933_FUNCTION_INC_FREQ 0x3
79 #define AD5933_FUNCTION_REPEAT_FREQ 0x4
80 #define AD5933_FUNCTION_MEASURE_TEMP 0x9
81 #define AD5933_FUNCTION_POWER_DOWN 0xA
82 #define AD5933_FUNCTION_STANDBY 0xB
83 
84 /* AD5933_CONTROL_RANGE(x) options */
85 #define AD5933_RANGE_2000mVpp 0x0
86 #define AD5933_RANGE_200mVpp 0x1
87 #define AD5933_RANGE_400mVpp 0x2
88 #define AD5933_RANGE_1000mVpp 0x3
89 
90 /* AD5933_CONTROL_PGA_GAIN(x) options */
91 #define AD5933_GAIN_X5 0
92 #define AD5933_GAIN_X1 1
93 
94 /* AD5933 Default number of settling cycles */
95 #define AD5933_15_CYCLES 15
96 
97 /* AD5933 settling cycles mulitiplier */
98 #define AD5933_SETTLING_X1 0
99 #define AD5933_SETTLING_X2 1
100 #define AD5933_SETTLING_X4 3
101 
102 /* AD5933_REG_STATUS Bits */
103 #define AD5933_STAT_TEMP_VALID (0x1 << 0)
104 #define AD5933_STAT_DATA_VALID (0x1 << 1)
105 #define AD5933_STAT_SWEEP_DONE (0x1 << 2)
106 
107 /* AD5933 Address */
108 #define AD5933_ADDRESS 0x0D
109 
110 /* AD5933 Block Commands */
111 #define AD5933_BLOCK_WRITE 0xA0
112 #define AD5933_BLOCK_READ 0xA1
113 #define AD5933_ADDR_POINTER 0xB0
114 
115 /* AD5933 Specifications */
116 #define AD5933_INTERNAL_SYS_CLK 16000000ul // 16MHz
117 #define AD5933_MAX_INC_NUM 511 // Maximum increment number
118 
119 /******************************************************************************/
120 /*************************** Types Declarations *******************************/
121 /******************************************************************************/
122 
123 struct ad5933_dev {
124  /* I2C */
126  /* Device Settings */
127  uint32_t current_sys_clk;
129  uint8_t current_gain;
130  uint8_t current_range;
131 };
132 
134  /* I2C */
136  /* Device Settings */
137  uint32_t current_sys_clk;
139  uint8_t current_gain;
140  uint8_t current_range;
141 };
142 
143 /******************************************************************************/
144 /************************ Functions Declarations ******************************/
145 /******************************************************************************/
146 
148 int32_t ad5933_init(struct ad5933_dev **device,
150 
152 int32_t ad5933_remove(struct ad5933_dev *dev);
153 
155 void ad5933_set_register_value(struct ad5933_dev *dev,
156  uint8_t register_address,
157  uint32_t register_value,
158  uint8_t bytes_number);
159 
161 uint32_t ad5933_get_register_value(struct ad5933_dev *dev,
162  uint8_t register_address,
163  uint8_t bytes_number);
164 
166 void ad5933_reset(struct ad5933_dev *dev);
167 
169 void ad5933_set_system_clk(struct ad5933_dev *dev,
170  int8_t clk_source,
171  uint32_t ext_clk_freq);
172 
174 void ad5933_set_range_and_gain(struct ad5933_dev *dev,
175  int8_t range,
176  int8_t gain);
177 
179 float ad5933_get_temperature(struct ad5933_dev *dev);
180 
182 void ad5933_config_sweep(struct ad5933_dev *dev,
183  uint32_t start_freq,
184  uint32_t inc_freq,
185  uint16_t inc_num);
186 
188 void ad5933_start_sweep(struct ad5933_dev *dev);
189 
191 void ad5933_get_data(struct ad5933_dev *dev,
192  uint8_t freq_function,
193  short *imag_data,
194  short *real_data);
195 
197 double ad5933_calculate_gain_factor(struct ad5933_dev *dev,
198  uint32_t calibration_impedance,
199  uint8_t freq_function);
200 
202 double ad5933_calculate_impedance(struct ad5933_dev *dev,
203  double gain_factor,
204  uint8_t freq_function);
205 
207 void ad5933_set_settling_time(struct ad5933_dev *dev,
208  uint8_t mulitplier,
209  uint16_t number_cycles);
210 
211 #endif /* __AD5933_H__ */
AD5933_STAT_DATA_VALID
#define AD5933_STAT_DATA_VALID
Definition: ad5933.h:104
AD5933_REG_FREQ_INC
#define AD5933_REG_FREQ_INC
Definition: ad5933.h:56
AD5933_FUNCTION_START_SWEEP
#define AD5933_FUNCTION_START_SWEEP
Definition: ad5933.h:77
AD5933_ADDR_POINTER
#define AD5933_ADDR_POINTER
Definition: ad5933.h:113
AD5933_CONTROL_PGA_GAIN
#define AD5933_CONTROL_PGA_GAIN(x)
Definition: ad5933.h:67
AD5933_CONTROL_FUNCTION
#define AD5933_CONTROL_FUNCTION(x)
Definition: ad5933.h:65
ad5933_set_range_and_gain
void ad5933_set_range_and_gain(struct ad5933_dev *dev, int8_t range, int8_t gain)
Selects the range and gain of the device.
Definition: ad5933.c:227
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:85
AD5933_CONTROL_RESET
#define AD5933_CONTROL_RESET
Definition: ad5933.h:70
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:51
AD5933_REG_FREQ_START
#define AD5933_REG_FREQ_START
Definition: ad5933.h:55
ad5933_init_param::current_clock_source
uint8_t current_clock_source
Definition: ad5933.h:138
AD5933_CONTROL_RANGE
#define AD5933_CONTROL_RANGE(x)
Definition: ad5933.h:66
ad5933_remove
int32_t ad5933_remove(struct ad5933_dev *dev)
Free the resources allocated by ad5933_init().
Definition: ad5933.c:99
ad5933_get_register_value
uint32_t ad5933_get_register_value(struct ad5933_dev *dev, uint8_t register_address, uint8_t bytes_number)
Reads the value of a register.
Definition: ad5933.c:144
AD5933_SETTLING_X2
#define AD5933_SETTLING_X2
Definition: ad5933.h:99
ad5933_config_sweep
void ad5933_config_sweep(struct ad5933_dev *dev, uint32_t start_freq, uint32_t inc_freq, uint16_t inc_num)
Configures the sweep parameters: Start frequency, Frequency increment and Number of increments.
Definition: ad5933.c:291
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:70
ad5933_get_temperature
float ad5933_get_temperature(struct ad5933_dev *dev)
Reads the temperature from the part and returns the data in degrees Celsius.
Definition: ad5933.c:250
ad5933_set_register_value
void ad5933_set_register_value(struct ad5933_dev *dev, uint8_t register_address, uint32_t register_value, uint8_t bytes_number)
Writes data into a register.
Definition: ad5933.c:120
ad5933_dev::current_clock_source
uint8_t current_clock_source
Definition: ad5933.h:128
device
Definition: ad9361_util.h:75
AD5933_REG_INC_NUM
#define AD5933_REG_INC_NUM
Definition: ad5933.h:57
AD5933_CONTROL_EXT_SYSCLK
#define AD5933_CONTROL_EXT_SYSCLK
Definition: ad5933.h:72
ad5933_set_system_clk
void ad5933_set_system_clk(struct ad5933_dev *dev, int8_t clk_source, uint32_t ext_clk_freq)
Selects the source of the system clock.
Definition: ad5933.c:194
ad5933_reset
void ad5933_reset(struct ad5933_dev *dev)
Resets the device.
Definition: ad5933.c:175
ad5933_init
int32_t ad5933_init(struct ad5933_dev **device, struct ad5933_init_param init_param)
Initializes the communication peripheral and the initial Values for AD5933 Board.
Definition: ad5933.c:70
ad5933_set_system_clk
void ad5933_set_system_clk(struct ad5933_dev *dev, int8_t clk_source, uint32_t ext_clk_freq)
Selects the source of the system clock.
Definition: ad5933.c:194
AD5933_REG_SETTLING_CYCLES
#define AD5933_REG_SETTLING_CYCLES
Definition: ad5933.h:58
AD5933_REG_TEMP_DATA
#define AD5933_REG_TEMP_DATA
Definition: ad5933.h:60
AD5933_FUNCTION_STANDBY
#define AD5933_FUNCTION_STANDBY
Definition: ad5933.h:82
ad5933_set_register_value
void ad5933_set_register_value(struct ad5933_dev *dev, uint8_t register_address, uint32_t register_value, uint8_t bytes_number)
Writes data into a register.
Definition: ad5933.c:120
AD5933_MAX_INC_NUM
#define AD5933_MAX_INC_NUM
Definition: ad5933.h:117
ad5933_dev::current_sys_clk
uint32_t current_sys_clk
Definition: ad5933.h:127
AD5933_STAT_TEMP_VALID
#define AD5933_STAT_TEMP_VALID
Definition: ad5933.h:103
ad5933_set_settling_time
void ad5933_set_settling_time(struct ad5933_dev *dev, uint8_t mulitplier, uint16_t number_cycles)
Selects the number of settling cycles of the device.
Definition: ad5933.c:480
ad5933_dev
Definition: ad5933.h:123
AD5933_FUNCTION_NOP
#define AD5933_FUNCTION_NOP
Definition: ad5933.h:75
ad5933_start_sweep
void ad5933_start_sweep(struct ad5933_dev *dev)
Starts the sweep operation.
Definition: ad5933.c:337
ad5933_remove
int32_t ad5933_remove(struct ad5933_dev *dev)
Free the resources allocated by ad5933_init().
Definition: ad5933.c:99
ad5933_init_param::current_sys_clk
uint32_t current_sys_clk
Definition: ad5933.h:137
pow_2_27
const int32_t pow_2_27
Definition: ad5933.c:50
ad5933_dev::current_gain
uint8_t current_gain
Definition: ad5933.h:129
ad5933_get_register_value
uint32_t ad5933_get_register_value(struct ad5933_dev *dev, uint8_t register_address, uint8_t bytes_number)
Reads the value of a register.
Definition: ad5933.c:144
ad5933_calculate_gain_factor
double ad5933_calculate_gain_factor(struct ad5933_dev *dev, uint32_t calibration_impedance, uint8_t freq_function)
Reads the real and the imaginary data and calculates the Gain Factor.
Definition: ad5933.c:421
ad5933_config_sweep
void ad5933_config_sweep(struct ad5933_dev *dev, uint32_t start_freq, uint32_t inc_freq, uint16_t inc_num)
Configures the sweep parameters: Start frequency, Frequency increment and Number of increments.
Definition: ad5933.c:291
AD5933_REG_REAL_DATA
#define AD5933_REG_REAL_DATA
Definition: ad5933.h:61
AD5933_REG_IMAG_DATA
#define AD5933_REG_IMAG_DATA
Definition: ad5933.h:62
ad5933_set_settling_time
void ad5933_set_settling_time(struct ad5933_dev *dev, uint8_t multiplier, uint16_t number_cycles)
Selects the number of settling cycles of the device.
Definition: ad5933.c:480
ad5933_calculate_impedance
double ad5933_calculate_impedance(struct ad5933_dev *dev, double gain_factor, uint8_t freq_function)
Reads the real and the imaginary data and calculates the Impedance.
Definition: ad5933.c:449
ad5933_init_param::current_gain
uint8_t current_gain
Definition: ad5933.h:139
ad5933.h
Header file of AD5933 Driver.
no_os_i2c_desc
Structure holding I2C descriptor.
Definition: no_os_i2c.h:81
ad5933_dev::i2c_desc
struct no_os_i2c_desc * i2c_desc
Definition: ad5933.h:125
AD5933_SETTLING_X4
#define AD5933_SETTLING_X4
Definition: ad5933.h:100
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:104
no_os_i2c.h
Header file of I2C Interface.
AD5933_REG_CONTROL_HB
#define AD5933_REG_CONTROL_HB
Definition: ad5933.h:53
ad5933_init_param::current_range
uint8_t current_range
Definition: ad5933.h:140
ad5933_init
int32_t ad5933_init(struct ad5933_dev **device, struct ad5933_init_param init_param)
Initializes the communication peripheral and the initial Values for AD5933 Board.
Definition: ad5933.c:70
ad5933_init_param::i2c_init
struct no_os_i2c_init_param i2c_init
Definition: ad5933.h:135
ad5933_start_sweep
void ad5933_start_sweep(struct ad5933_dev *dev)
Starts the sweep operation.
Definition: ad5933.c:337
ad5933_get_data
void ad5933_get_data(struct ad5933_dev *dev, uint8_t freq_function, short *imag_data, short *real_data)
Reads the real and imaginary value from register.
Definition: ad5933.c:378
no_os_i2c_init_param
Structure holding the parameters for I2C initialization.
Definition: no_os_i2c.h:64
AD5933_FUNCTION_INIT_START_FREQ
#define AD5933_FUNCTION_INIT_START_FREQ
Definition: ad5933.h:76
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:96
ad5933_calculate_gain_factor
double ad5933_calculate_gain_factor(struct ad5933_dev *dev, uint32_t calibration_impedance, uint8_t freq_function)
Reads the real and the imaginary data and calculates the Gain Factor.
Definition: ad5933.c:421
AD5933_REG_CONTROL_LB
#define AD5933_REG_CONTROL_LB
Definition: ad5933.h:54
ad5933_get_temperature
float ad5933_get_temperature(struct ad5933_dev *dev)
Reads the temperature from the part and returns the data in degrees Celsius.
Definition: ad5933.c:250
ad5933_set_range_and_gain
void ad5933_set_range_and_gain(struct ad5933_dev *dev, int8_t range, int8_t gain)
Selects the range and gain of the device.
Definition: ad5933.c:227
ad5933_init_param
Definition: ad5933.h:133
AD5933_FUNCTION_MEASURE_TEMP
#define AD5933_FUNCTION_MEASURE_TEMP
Definition: ad5933.h:80
ad5933_reset
void ad5933_reset(struct ad5933_dev *dev)
Resets the device.
Definition: ad5933.c:175
AD5933_INTERNAL_SYS_CLK
#define AD5933_INTERNAL_SYS_CLK
Definition: ad5933.h:116
AD5933_SETTLING_X1
#define AD5933_SETTLING_X1
Definition: ad5933.h:98
ad5933_dev::current_range
uint8_t current_range
Definition: ad5933.h:130
ad5933_get_data
void ad5933_get_data(struct ad5933_dev *dev, uint8_t freq_function, short *imag_data, short *real_data)
Reads the real and imaginary value from register.
Definition: ad5933.c:378
AD5933_REG_STATUS
#define AD5933_REG_STATUS
Definition: ad5933.h:59
ad5933_calculate_impedance
double ad5933_calculate_impedance(struct ad5933_dev *dev, double gain_factor, uint8_t freq_function)
Reads the real and the imaginary data and calculates the Impedance.
Definition: ad5933.c:449