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