![]() |
no-OS
|
Implementation of AD5933 Driver. More...
#include <stdlib.h>#include <math.h>#include <errno.h>#include "no_os_alloc.h"#include "no_os_util.h"#include "no_os_delay.h"#include "ad5933.h"Macros | |
| #define | DIV_EPSILON 1e-12 |
Functions | |
| int | ad5933_init (struct ad5933_dev **device, struct ad5933_init_param *init_param) |
| Initializes the communication peripheral and the initial Values for AD5933 Board. | |
| int | ad5933_setup (struct ad5933_dev *dev) |
| Sets up the AD5933 device with the current configuration values. | |
| int | ad5933_remove (struct ad5933_dev *dev) |
| Free the resources allocated by ad5933_init(). | |
| int | ad5933_reg_write (struct ad5933_dev *dev, uint8_t reg, uint8_t val) |
| Write a single byte into a register. | |
| int | ad5933_reg_read (struct ad5933_dev *dev, uint8_t reg, uint8_t *val) |
| Read a single byte from a register. | |
| int | ad5933_set_register_value (struct ad5933_dev *dev, uint8_t register_address, uint32_t register_value, uint8_t bytes_number) |
| Write a multi-byte value into a register. | |
| int | ad5933_get_register_value (struct ad5933_dev *dev, uint32_t *data, uint8_t register_address, uint8_t bytes_number) |
| Reads a multi-byte value from a register. | |
| int | ad5933_reset (struct ad5933_dev *dev) |
| Resets the device. | |
| int | ad5933_set_system_clk (struct ad5933_dev *dev, enum ad5933_clock_source clk_source, uint32_t ext_clk_freq) |
| Selects the source of the system clock. | |
| int | ad5933_set_range_and_gain (struct ad5933_dev *dev, enum ad5933_output_range range, enum ad5933_pga_gain gain) |
| Selects the range and gain of the device. | |
| int | ad5933_set_range (struct ad5933_dev *dev, enum ad5933_output_range range) |
| Selects the output excitation range of the device. | |
| int | ad5933_set_gain (struct ad5933_dev *dev, enum ad5933_pga_gain gain) |
| Selects the PGA gain of the device. | |
| int | ad5933_get_temperature (struct ad5933_dev *dev, float *temperature) |
| Reads the temperature from the part and returns the data in degrees Celsius. | |
| int | ad5933_config_sweep (struct ad5933_dev *dev, double start_freq, double inc_freq, uint16_t num_increments) |
| Configures the sweep parameters: Start frequency, Frequency increment and Number of increments. | |
| int | ad5933_get_data (struct ad5933_dev *dev, uint8_t freq_function, int16_t *real, int16_t *imag) |
| Reads the real and imaginary value from register after requesting a frequency function. | |
| int | ad5933_calculate_gain_factor (struct ad5933_dev *dev, double *gain_factor, double calibration_impedance, enum meas_mode measurement_mode) |
| Reads the real and the imaginary data and calculates the Gain Factor. | |
| int | ad5933_calculate_impedance (struct ad5933_dev *dev, double gain_factor, double *impedance, enum meas_mode measurement_mode) |
| Reads the real and the imaginary data and calculates the Impedance. | |
| int | ad5933_set_settling_time (struct ad5933_dev *dev, uint16_t number_cycles) |
| Selects the number of settling cycles of the device. | |
| int | ad5933_wait_status (struct ad5933_dev *dev, uint8_t mask, uint8_t *status_out) |
| Polls the status register until (status & mask) is set or timeout. | |
| int | ad5933_get_raw_temperature (struct ad5933_dev *dev, int32_t *temperature) |
| Reads the raw temperature from the part. | |
| int | ad5933_get_magnitude (struct ad5933_dev *dev, double *magnitude) |
| Reads the real and imaginary data and calculates the DFT magnitude. | |
| int | ad5933_get_phase (struct ad5933_dev *dev, double system_phase, double *phase_rad) |
| Reads the data and calculates the impedance phase in radians. The system phase captured at calibration is subtracted to yield the phase due to the impedance alone. | |
| int | ad5933_initialize_sweep (struct ad5933_dev *dev) |
| Initializes the sweep sequence documented in the datasheet. Unknown impedance is connected to the output and the start frequency is applied. The device is now ready to start the sweep. | |
| int | ad5933_init_start_freq (struct ad5933_dev *dev) |
| Enables the DDS to output the programmed start frequency for an indefinite time. | |
| int | ad5933_start_sweep (struct ad5933_dev *dev) |
| ADC starts measuring after the programmed number of settling time cycles has elapsed. | |
| int | ad5933_increment_freq (struct ad5933_dev *dev) |
| Step to the next frequency point in the sweep. | |
| int | ad5933_repeat_freq (struct ad5933_dev *dev) |
| Repeat the current frequency point measurement. | |
| int | ad5933_power_down (struct ad5933_dev *dev) |
| Default state on power-up of the AD5933 is power-down mode. | |
| int | ad5933_standby (struct ad5933_dev *dev) |
| Powers up the part for general operation. | |
| uint32_t | ad5933_convert_freq_to_reg (struct ad5933_dev *dev, double frequency) |
| Converts a frequency value to the corresponding register binary value. | |
| int | ad5933_get_current_data (struct ad5933_dev *dev, int16_t *real, int16_t *imag) |
| Reads the real and imaginary value from register. | |
| int | ad5933_sweep_done (struct ad5933_dev *dev, int32_t *done) |
| Check if a frequency sweep has completed. | |
Variables | |
| const int32_t | pow_2_27 = 134217728ul |
Implementation of AD5933 Driver.
Copyright 2012(c) Analog Devices, Inc.
SPDX-License-Identifier: BSD-3-Clause
| #define DIV_EPSILON 1e-12 |
| int ad5933_calculate_gain_factor | ( | struct ad5933_dev * | dev, |
| double * | gain_factor, | ||
| double | calibration_impedance, | ||
| enum meas_mode | measurement_mode ) |
Reads the real and the imaginary data and calculates the Gain Factor.
| dev | - The device structure. |
| gain_factor | - The gain factor pointer. |
| calibration_impedance | - The calibration impedance value. |
| measurement_mode | - 2-wire (default) or 4-wire. |
| int ad5933_calculate_impedance | ( | struct ad5933_dev * | dev, |
| double | gain_factor, | ||
| double * | impedance, | ||
| enum meas_mode | measurement_mode ) |
Reads the real and the imaginary data and calculates the Impedance.
| dev | - The device structure. |
| gain_factor | - The gain factor. |
| impedance | - Pointer to the Impedance in ohms. |
| measurement_mode | - 2-wire (default) or 4-wire. |
| int ad5933_config_sweep | ( | struct ad5933_dev * | dev, |
| double | start_freq, | ||
| double | inc_freq, | ||
| uint16_t | num_increments ) |
Configures the sweep parameters: Start frequency, Frequency increment and Number of increments.
| dev | - The device structure. |
| start_freq | - Start frequency in Hz; |
| inc_freq | - Frequency increment in Hz; |
| num_increments | - Number of increments. Maximum value is 511(0x1FF). |
| uint32_t ad5933_convert_freq_to_reg | ( | struct ad5933_dev * | dev, |
| double | frequency ) |
Converts a frequency value to the corresponding register binary value.
| dev | - The device structure. |
| frequency | - The frequency value in Hz. |
| int ad5933_get_current_data | ( | struct ad5933_dev * | dev, |
| int16_t * | real, | ||
| int16_t * | imag ) |
Reads the real and imaginary value from register.
The caller must have waited for the point to become valid.
| dev | - The device structure. |
| real | - Pointer to the signed 16-bit real component. |
| imag | - Pointer to the signed 16-bit imaginary component. |
| int ad5933_get_data | ( | struct ad5933_dev * | dev, |
| uint8_t | freq_function, | ||
| int16_t * | real, | ||
| int16_t * | imag ) |
Reads the real and imaginary value from register after requesting a frequency function.
| dev | - The device structure. |
| freq_function | - Frequency function. |
| real | - Pointer to real data |
| imag | - Pointer to imaginary data |
| int ad5933_get_magnitude | ( | struct ad5933_dev * | dev, |
| double * | magnitude ) |
Reads the real and imaginary data and calculates the DFT magnitude.
| dev | - The device structure. |
| magnitude | - Pointer to the DFT magnitude sqrt(real^2 + imag^2). |
| int ad5933_get_phase | ( | struct ad5933_dev * | dev, |
| double | system_phase, | ||
| double * | phase_rad ) |
Reads the data and calculates the impedance phase in radians. The system phase captured at calibration is subtracted to yield the phase due to the impedance alone.
| dev | - The device structure. |
| system_phase | - The system phase captured at calibration in radians. |
| phase_rad | - Pointer to the impedance phase in radians. |
| int ad5933_get_raw_temperature | ( | struct ad5933_dev * | dev, |
| int32_t * | temperature ) |
Reads the raw temperature from the part.
The temperature sensor returns a 14-bit two's-complement code (13 data bits plus a sign bit); the caller converts to degrees Celsius by dividing by 32.
| dev | - The device structure. |
| temperature | - Pointer to the sign-extended raw temperature code. |
| int ad5933_get_register_value | ( | struct ad5933_dev * | dev, |
| uint32_t * | data, | ||
| uint8_t | register_address, | ||
| uint8_t | bytes_number ) |
Reads a multi-byte value from a register.
| dev | - The device structure. |
| data | - Pointer to the read register value. |
| register_address | - Address of the register. |
| bytes_number | - Number of bytes. |
| int ad5933_get_temperature | ( | struct ad5933_dev * | dev, |
| float * | temperature ) |
Reads the temperature from the part and returns the data in degrees Celsius.
| dev | - The device structure. |
| temperature | - Pointer to the temperature value in degrees Celsius. |
| int ad5933_increment_freq | ( | struct ad5933_dev * | dev | ) |
Step to the next frequency point in the sweep.
| dev | - The device structure. |
| int ad5933_init | ( | struct ad5933_dev ** | device, |
| struct ad5933_init_param * | init_param ) |
Initializes the communication peripheral and the initial Values for AD5933 Board.
| device | - The device structure. |
| init_param | - The structure that contains the device initial parameters. |
| int ad5933_init_start_freq | ( | struct ad5933_dev * | dev | ) |
Enables the DDS to output the programmed start frequency for an indefinite time.
| dev | - The device structure. |
| int ad5933_initialize_sweep | ( | struct ad5933_dev * | dev | ) |
Initializes the sweep sequence documented in the datasheet. Unknown impedance is connected to the output and the start frequency is applied. The device is now ready to start the sweep.
| dev | - The device structure. |
| int ad5933_power_down | ( | struct ad5933_dev * | dev | ) |
Default state on power-up of the AD5933 is power-down mode.
| dev | - The device structure. |
| int ad5933_reg_read | ( | struct ad5933_dev * | dev, |
| uint8_t | reg, | ||
| uint8_t * | val ) |
Read a single byte from a register.
| dev | - The device structure. |
| reg | - Address of the register. |
| val | - Pointer to the read byte. |
| int ad5933_reg_write | ( | struct ad5933_dev * | dev, |
| uint8_t | reg, | ||
| uint8_t | val ) |
Write a single byte into a register.
| dev | - The device structure. |
| reg | - Address of the register. |
| val | - Byte value to write. |
| int ad5933_remove | ( | struct ad5933_dev * | dev | ) |
Free the resources allocated by ad5933_init().
| dev | - The device structure. |
| int ad5933_repeat_freq | ( | struct ad5933_dev * | dev | ) |
Repeat the current frequency point measurement.
| dev | - The device structure. |
| int ad5933_reset | ( | struct ad5933_dev * | dev | ) |
Resets the device.
| dev | - The device structure. |
| int ad5933_set_gain | ( | struct ad5933_dev * | dev, |
| enum ad5933_pga_gain | gain ) |
Selects the PGA gain of the device.
| dev | - The device structure. |
| gain | - Gain option. |
| int ad5933_set_range | ( | struct ad5933_dev * | dev, |
| enum ad5933_output_range | range ) |
Selects the output excitation range of the device.
| dev | - The device structure. |
| range | - Range option (see enum ad5933_output_range). |
| int ad5933_set_range_and_gain | ( | struct ad5933_dev * | dev, |
| enum ad5933_output_range | range, | ||
| enum ad5933_pga_gain | gain ) |
Selects the range and gain of the device.
| dev | - The device structure. |
| range | - Range option. Example: AD5933_RANGE_2000mVpp AD5933_RANGE_200mVpp AD5933_RANGE_400mVpp AD5933_RANGE_1000mVpp |
| gain | - Gain option. Example: AD5933_GAIN_X5 AD5933_GAIN_X1 |
| int ad5933_set_register_value | ( | struct ad5933_dev * | dev, |
| uint8_t | register_address, | ||
| uint32_t | register_value, | ||
| uint8_t | bytes_number ) |
Write a multi-byte value into a register.
| dev | - The device structure. |
| register_address | - Address of the register. |
| register_value | - Data value to write. |
| bytes_number | - Number of bytes |
| int ad5933_set_settling_time | ( | struct ad5933_dev * | dev, |
| uint16_t | number_cycles ) |
Selects the number of settling cycles of the device.
| dev | - The device structure. |
| number_cycles | - 9-bit number of cycles to wait before triggering ADC, multiplier is inferred based on the number of cycles. |
| int ad5933_set_system_clk | ( | struct ad5933_dev * | dev, |
| enum ad5933_clock_source | clk_source, | ||
| uint32_t | ext_clk_freq ) |
Selects the source of the system clock.
| dev | - The device structure. |
| clk_source | - Selects the source of the system clock. Example: AD5933_CONTROL_INT_SYSCLK AD5933_CONTROL_EXT_SYSCLK |
| ext_clk_freq | - Frequency value of the external clock, if used. |
| int ad5933_setup | ( | struct ad5933_dev * | dev | ) |
Sets up the AD5933 device with the current configuration values.
| dev | - The device structure. |
| int ad5933_standby | ( | struct ad5933_dev * | dev | ) |
Powers up the part for general operation.
| dev | - The device structure. |
| int ad5933_start_sweep | ( | struct ad5933_dev * | dev | ) |
ADC starts measuring after the programmed number of settling time cycles has elapsed.
| dev | - The device structure. |
| int ad5933_sweep_done | ( | struct ad5933_dev * | dev, |
| int32_t * | done ) |
Check if a frequency sweep has completed.
Reads the STATUS register and extracts the SWEEP_DONE bit to indicate whether the AD5933 has finished the current frequency sweep.
| dev | The device structure. |
| done | Pointer to integer that will be non-zero if sweep done, 0 otherwise. |
| int ad5933_wait_status | ( | struct ad5933_dev * | dev, |
| uint8_t | mask, | ||
| uint8_t * | status_out ) |
Polls the status register until (status & mask) is set or timeout.
| dev | - The device structure. |
| mask | - Status bits to wait for. |
| status_out | - Optional pointer to receive the last status read. |
| const int32_t pow_2_27 = 134217728ul |