no-OS
Functions
ad7193.c File Reference

Implementation of AD7193 Driver. More...

#include <stdlib.h>
#include "ad7193.h"
#include "no-os/error.h"
#include "no-os/delay.h"
Include dependency graph for ad7193.c:

Functions

int ad7193_init (struct ad7193_dev **device, struct ad7193_init_param init_param)
 Initializes the communication peripheral and the initial Values for AD7193 Board and resets the device. More...
 
int ad7193_remove (struct ad7193_dev *dev)
 Free the resources allocated by ad7193_init(). More...
 
int ad7193_set_register_value (struct ad7193_dev *dev, uint8_t reg_addr, uint32_t reg_val, uint8_t bytes_number)
 Writes data into a register. More...
 
int ad7193_get_register_value (struct ad7193_dev *dev, uint8_t reg_addr, uint8_t bytes_number, uint32_t *reg_data)
 Reads the value of a register. More...
 
int ad7193_set_masked_register_value (struct ad7193_dev *dev, uint8_t reg_addr, uint32_t mask, uint32_t reg_data, uint8_t bytes)
 Write masked data into device register. More...
 
int ad7193_reset (struct ad7193_dev *dev)
 Resets the device. More...
 
int ad7193_set_operating_mode (struct ad7193_dev *dev, enum ad7193_adc_modes opt_mode)
 Sets device into the specified operating mode. More...
 
int ad7193_wait_rdy_go_low (struct ad7193_dev *dev)
 Waits for RDY pin to go low. More...
 
int ad7193_channels_select (struct ad7193_dev *dev, uint16_t chn_mask)
 Selects the channels to be enabled. More...
 
int ad7193_calibrate (struct ad7193_dev *dev, uint8_t mode, uint8_t channel)
 Performs the given calibration to the specified channel. More...
 
int ad7193_config_input_mode (struct ad7193_dev *dev, uint8_t mode)
 Configures the input mode of the ADC. More...
 
int ad7193_buffer_select (struct ad7193_dev *dev, uint8_t buff_en)
 Enables or disables the buffer on the ADC input channels. More...
 
int ad7193_output_rate_select (struct ad7193_dev *dev, uint16_t out_rate_code)
 Selects the filter output data rate of the ADC. More...
 
int ad7193_clock_select (struct ad7193_dev *dev, enum ad7193_adc_clock clk_select)
 Selects the clock source of the ADC. More...
 
int ad7193_set_bridge_switch (struct ad7193_dev *dev, uint8_t bpdsw_select)
 Opens or closes the bridge power-down switch of the ADC. More...
 
int ad7193_range_setup (struct ad7193_dev *dev, uint8_t polarity, enum ad7193_adc_range range)
 Selects the polarity of the conversion and the ADC input range. More...
 
int ad7193_single_conversion (struct ad7193_dev *dev, uint32_t *reg_data)
 Returns the result of a single conversion. More...
 
int ad7193_continuous_read_avg (struct ad7193_dev *dev, uint8_t sample_number, uint32_t *samples_avg)
 Returns the average of several conversion results. More...
 
int ad7193_temperature_read (struct ad7193_dev *dev, float *temp)
 Read data from temperature sensor and converts it to Celsius degrees. More...
 
float ad7193_convert_to_volts (struct ad7193_dev *dev, uint32_t raw_data, float v_ref)
 Converts 24-bit raw data to milivolts. More...
 

Detailed Description

Implementation of AD7193 Driver.

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

Copyright 2012(c) Analog Devices, Inc.

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Function Documentation

◆ ad7193_buffer_select()

int ad7193_buffer_select ( struct ad7193_dev dev,
uint8_t  buff_en 
)

Enables or disables the buffer on the ADC input channels.

Parameters
dev- The device structure.
buff_en- Enable/disable option. Example: 0 - Buffer disabled 1 - Buffer Enabled
Returns
SUCCESS in case of success or negative error code.
Here is the caller graph for this function:

◆ ad7193_calibrate()

int ad7193_calibrate ( struct ad7193_dev dev,
uint8_t  mode,
uint8_t  channel 
)

Performs the given calibration to the specified channel.

Parameters
dev- The device structure.
mode- Calibration type.
channel- Channel to be calibrated.
Returns
SUCCESS in case of success or negative error code.

◆ ad7193_channels_select()

int ad7193_channels_select ( struct ad7193_dev dev,
uint16_t  chn_mask 
)

Selects the channels to be enabled.

Parameters
dev- The device structure.
chn_mask- Channel mask. Example: AD7193_CH_0 - AIN1(+) - AIN2(-); (Pseudo = 0) AD7193_CH_1 - AIN3(+) - AIN4(-); (Pseudo = 0) AD7193_TEMP - Temperature sensor AD7193_SHORT - AIN2(+) - AIN2(-); (Pseudo = 0)
Returns
SUCCESS in case of success or negative error code.
Here is the caller graph for this function:

◆ ad7193_clock_select()

int ad7193_clock_select ( struct ad7193_dev dev,
enum ad7193_adc_clock  clk_select 
)

Selects the clock source of the ADC.

Parameters
dev- The device structure.
clk_select- Clock source to be selected. Accepted values: AD7193_EXT_CRYSTAL_MCLK1_MCLK2 AD7193_EXT_CRYSTAL_MCLK2 AD7193_INT_CLK_4_92_MHZ_TRIST AD7193_INT_CLK_4_92_MHZ
Returns
SUCCESS in case of success or negative error code.
Here is the caller graph for this function:

◆ ad7193_config_input_mode()

int ad7193_config_input_mode ( struct ad7193_dev dev,
uint8_t  mode 
)

Configures the input mode of the ADC.

Parameters
dev- The device structure.
mode- Mode selection. Example: 0 - Differential Analog Inputs 1 - Pseudo Differential Analog Inputs
Returns
SUCCESS in case of success or negative error code.
Here is the caller graph for this function:

◆ ad7193_continuous_read_avg()

int ad7193_continuous_read_avg ( struct ad7193_dev dev,
uint8_t  sample_number,
uint32_t *  samples_avg 
)

Returns the average of several conversion results.

Parameters
dev- The device structure.
sample_number- the number of samples
samples_avg- Average of the samples read
Returns
SUCCESS in case of success or negative error code.

◆ ad7193_convert_to_volts()

float ad7193_convert_to_volts ( struct ad7193_dev dev,
uint32_t  raw_data,
float  v_ref 
)

Converts 24-bit raw data to milivolts.

Parameters
dev- The device structure.
raw_data- 24-bit data sample.
v_ref- The value of the voltage reference used by the device.
Returns
voltage - The result of the conversion expressed as volts.

◆ ad7193_get_register_value()

int ad7193_get_register_value ( struct ad7193_dev dev,
uint8_t  reg_addr,
uint8_t  bytes_number,
uint32_t *  reg_data 
)

Reads the value of a register.

Parameters
dev- The device structure.
reg_addr- Address of the register.
bytes_number- Number of bytes that will be read.
reg_data- Data read from the register.
Returns
SUCCESS in case of success or negative error code.
Here is the caller graph for this function:

◆ ad7193_init()

int ad7193_init ( struct ad7193_dev **  device,
struct ad7193_init_param  init_param 
)

Initializes the communication peripheral and the initial Values for AD7193 Board and resets the device.

Parameters
device- The device structure.
init_param- The structure that contains the device initial parameters.
Returns
SUCCESS in case of success or negative error code.

◆ ad7193_output_rate_select()

int ad7193_output_rate_select ( struct ad7193_dev dev,
uint16_t  out_rate_code 
)

Selects the filter output data rate of the ADC.

Parameters
dev- The device structure.
out_rate_code- Filter output data rate code.
Returns
SUCCESS in case of success or negative error code.
Here is the caller graph for this function:

◆ ad7193_range_setup()

int ad7193_range_setup ( struct ad7193_dev dev,
uint8_t  polarity,
enum ad7193_adc_range  range 
)

Selects the polarity of the conversion and the ADC input range.

Parameters
dev- The device structure.
polarity- Polarity select bit. Example: 0 - bipolar operation is selected. 1 - unipolar operation is selected.
range- Gain select bits. These bits are written by the user to select the ADC input range.
Returns
SUCCESS in case of success or negative error code.
Here is the caller graph for this function:

◆ ad7193_remove()

int ad7193_remove ( struct ad7193_dev dev)

Free the resources allocated by ad7193_init().

Parameters
dev- The device structure.
Returns
SUCCESS in case of success or negative error code.

◆ ad7193_reset()

int ad7193_reset ( struct ad7193_dev dev)

Resets the device.

Parameters
dev- The device structure.
Returns
SUCCESS in case of success or negative error code.
Here is the caller graph for this function:

◆ ad7193_set_bridge_switch()

int ad7193_set_bridge_switch ( struct ad7193_dev dev,
uint8_t  bpdsw_select 
)

Opens or closes the bridge power-down switch of the ADC.

Parameters
dev- The device structure.
bpdsw_select- Option to open or close bridge power-down switch. 0 - Switch Opened 1 - Switch Closed
Returns
SUCCESS in case of success or negative error code.
Here is the caller graph for this function:

◆ ad7193_set_masked_register_value()

int ad7193_set_masked_register_value ( struct ad7193_dev dev,
uint8_t  reg_addr,
uint32_t  mask,
uint32_t  reg_data,
uint8_t  bytes 
)

Write masked data into device register.

Parameters
dev- The device structure.
reg_addr- Address of the register.
mask- The mask.
reg_data- Register data to be written.
bytes- Number of bytes that will be read.
Returns
SUCCESS in case of success or negative error code.
Here is the caller graph for this function:

◆ ad7193_set_operating_mode()

int ad7193_set_operating_mode ( struct ad7193_dev dev,
enum ad7193_adc_modes  opt_mode 
)

Sets device into the specified operating mode.

Parameters
dev- The device structure.
opt_mode- Operating mode to be set. Accepted values: AD7193_MODE_CONT AD7193_MODE_SINGLE AD7193_MODE_IDLE AD7193_MODE_PWRDN AD7193_MODE_CAL_INT_ZERO AD7193_MODE_CAL_INT_FULL AD7193_MODE_CAL_SYS_ZERO AD7193_MODE_CAL_SYS_FULL
Returns
SUCCESS in case of success or negative error code.
Here is the caller graph for this function:

◆ ad7193_set_register_value()

int ad7193_set_register_value ( struct ad7193_dev dev,
uint8_t  reg_addr,
uint32_t  reg_val,
uint8_t  bytes_number 
)

Writes data into a register.

Parameters
dev- The device structure.
reg_addr- Address of the register.
reg_val- Data value to write.
bytes_number- Number of bytes to be written.
Returns
SUCCESS in case of success or negative error code.
Here is the caller graph for this function:

◆ ad7193_single_conversion()

int ad7193_single_conversion ( struct ad7193_dev dev,
uint32_t *  reg_data 
)

Returns the result of a single conversion.

Parameters
dev- The device structure.
reg_data- Buffer to store sampled register data
Returns
SUCCESS in case of success or negative error code.
Here is the caller graph for this function:

◆ ad7193_temperature_read()

int ad7193_temperature_read ( struct ad7193_dev dev,
float *  temp 
)

Read data from temperature sensor and converts it to Celsius degrees.

Parameters
dev- The device structure.
temp- Stores the temperature result.
Returns
SUCCESS in case of success or negative error code.

◆ ad7193_wait_rdy_go_low()

int ad7193_wait_rdy_go_low ( struct ad7193_dev dev)

Waits for RDY pin to go low.

Returns
SUCCESS in case of success or negative error code.
Here is the caller graph for this function: