AD7124Library  1.0.3
Arduino library for the AD7124 ADC
Ad7124Chip Class Reference

ADC device. More...

#include <ad7124.h>

Public Member Functions

int begin (int slave_select)
 Initializes the AD7124. More...
 
int channelConfig (uint8_t ch)
 Returns the setup number used by the channel. More...
 
int currentChannel ()
 Returns the last sampling channel. More...
 
int enableChannel (uint8_t ch, bool enable=true)
 Enable/Disable channel. More...
 
long getData ()
 Returns the last sample. More...
 
long getRegister (Ad7124::RegisterId id)
 Reads the value of the specified register. More...
 
int internalCalibration (uint8_t ch)
 Proceed to Internal zero-scale and full-scale calibration. More...
 
long read (uint8_t ch)
 Sampling a channel The channel is enabled in single mode, then the conversion is started and the value of the sample is returned. More...
 
int reset ()
 Resets the device. More...
 
int setAdcControl (Ad7124::OperatingMode mode, Ad7124::PowerMode power_mode, bool ref_en=true, Ad7124::ClkSel clk_sel=Ad7124::InternalClk)
 Sets the ADC Control register. More...
 
int setChannel (uint8_t ch, uint8_t cfg, Ad7124::InputSel ainp, Ad7124::InputSel ainm, bool enable=false)
 Setup channel. More...
 
int setConfig (uint8_t cfg, Ad7124::RefSel ref, Ad7124::PgaSel pga, bool bipolar, Ad7124::BurnoutCurrent burnout=Ad7124::BurnoutOff)
 Sets a setup. More...
 
int setConfigFilter (uint8_t cfg, Ad7124::FilterType filter, Ad7124::PostFilterType postfilter, uint16_t fs, bool rej60, bool single)
 Sets the filter type and output word rate for a setup. More...
 
int setConfigGain (uint8_t cfg, uint32_t value)
 Set gain for a setup The gain registers are 24-bit registers and hold the full-scale calibration coefficient for the ADC. The AD7124 is factory calibrated to a gain of 1. The gain register contains this factory generated value on power-on and after a reset. More...
 
int setConfigOffset (uint8_t cfg, uint32_t value)
 Set offset for a setup The offset registers are 24-bit registers and hold the offset calibration coefficient for the ADC and its power-on reset value is 0x800000. More...
 
int setMode (Ad7124::OperatingMode mode)
 Control the mode of operation for ADC. More...
 
int setRegister (Ad7124::RegisterId id, long value)
 Writes the value of the specified register. More...
 
void setTimeout (uint32_t ms)
 set IO timeout in milliseconds More...
 
int startSingleConversion (uint8_t ch)
 Start conversion in single mode. More...
 
int status ()
 Returns the status register. More...
 
uint32_t timeout () const
 return IO timeout in milliseconds (default is 1000ms) More...
 
int waitEndOfConversion (uint32_t timeout_ms)
 Waits until a new conversion result is available. More...
 

Static Public Member Functions

static double toVoltage (long value, int gain, double vref, bool bipolar=true)
 Converts sample to voltage. More...
 

Detailed Description

ADC device.

Definition at line 186 of file ad7124.h.

Member Function Documentation

int Ad7124Chip::begin ( int  slave_select)

Initializes the AD7124.

Parameters
slave_selectThe Slave Chip Select Id to be passed to the SPI calls
Returns
0 for success or negative error code
int Ad7124Chip::channelConfig ( uint8_t  ch)

Returns the setup number used by the channel.

Parameters
chchannel number 0 to 15
Returns
setup number (0 to 7), or negative error code
int Ad7124Chip::currentChannel ( )

Returns the last sampling channel.

Returns
channel or negative error code
int Ad7124Chip::enableChannel ( uint8_t  ch,
bool  enable = true 
)

Enable/Disable channel.

Parameters
chchannel number 0 to 15
enabletrue for enabled
Returns
0 for success or negative error code
long Ad7124Chip::getData ( )

Returns the last sample.

Returns
sample or negative error code
long Ad7124Chip::getRegister ( Ad7124::RegisterId  id)

Reads the value of the specified register.

Parameters
idregister identifier
Returns
8 to 24 bits register value, negative for error.
int Ad7124Chip::internalCalibration ( uint8_t  ch)

Proceed to Internal zero-scale and full-scale calibration.

Parameters
chchannel number
Returns
0 for success or negative error code
long Ad7124Chip::read ( uint8_t  ch)

Sampling a channel The channel is enabled in single mode, then the conversion is started and the value of the sample is returned.

Parameters
chchannel number
Returns
sample or negative error code
int Ad7124Chip::reset ( )

Resets the device.

Returns
Returns true for success, AD7124_TIMEOUT for timeout
int Ad7124Chip::setAdcControl ( Ad7124::OperatingMode  mode,
Ad7124::PowerMode  power_mode,
bool  ref_en = true,
Ad7124::ClkSel  clk_sel = Ad7124::InternalClk 
)

Sets the ADC Control register.

Parameters
modeControl the mode of operation for ADC
power_modePower mode
ref_enInternal reference voltage enable. When this bit is set, the internal reference is enabled and available at the REFOUT pin. When this bit is cleared, the internal reference is disabled.
clk_selselect the clock source for the ADC
Returns
0 for success or negative error code
int Ad7124Chip::setChannel ( uint8_t  ch,
uint8_t  cfg,
Ad7124::InputSel  ainp,
Ad7124::InputSel  ainm,
bool  enable = false 
)

Setup channel.

Parameters
chchannel number 0 to 15
cfgSetup select. These bits identify which of the eight setups are used to configure the ADC for this channel.
ainpPositive analog input AINP input select.
ainmNegative analog input AINM input select.
enableChannel enable bit. Setting this bit enables the device channel for the conversion sequence.
Returns
0 for success or negative error code
int Ad7124Chip::setConfig ( uint8_t  cfg,
Ad7124::RefSel  ref,
Ad7124::PgaSel  pga,
bool  bipolar,
Ad7124::BurnoutCurrent  burnout = Ad7124::BurnoutOff 
)

Sets a setup.

Parameters
cfgSetup select.
refReference source select bits.
pgaGain select bits.
bipolarPolarity select bit. When this bit is set, bipolar operation is selected. When this bit is cleared, unipolar operation is selected.
burnoutThese bits select the magnitude of the sensor burnout detect current source.
Returns
0 for success or negative error code
int Ad7124Chip::setConfigFilter ( uint8_t  cfg,
Ad7124::FilterType  filter,
Ad7124::PostFilterType  postfilter,
uint16_t  fs,
bool  rej60,
bool  single 
)

Sets the filter type and output word rate for a setup.

Parameters
cfgSetup select.
filterFilter type
postfilterPost filter type
fsFilter output data rate select bits. These bits set the output data rate of the sinc 3 and sinc 4 filters as well as the fast settling filters. In addition, they affect the position of the first notch of the filter and the cutoff frequency. In association with the gain selection, they also determine the output noise and, therefore, the effective resolution of the device (see noise tables). FS can have a value from 1 to 2047.
rej60When this bit is set, a first order notch is placed at 60 Hz when the first notch of the sinc filter is at 50 Hz. This allows simultaneous 50 Hz and 60 Hz rejection.
singleSingle cycle conversion enable bit. When this bit is set, the AD7124 settles in one conversion cycle so that it functions as a zero latency ADC. This bit has no effect when multiple analog input channels are enabled or when the single conversion mode is selected. When the fast filters are used, this bit has no effect.
Returns
0 for success or negative error code
int Ad7124Chip::setConfigGain ( uint8_t  cfg,
uint32_t  value 
)

Set gain for a setup The gain registers are 24-bit registers and hold the full-scale calibration coefficient for the ADC. The AD7124 is factory calibrated to a gain of 1. The gain register contains this factory generated value on power-on and after a reset.

Parameters
cfgSetup select.
valuegain
Returns
0 for success or negative error code
int Ad7124Chip::setConfigOffset ( uint8_t  cfg,
uint32_t  value 
)

Set offset for a setup The offset registers are 24-bit registers and hold the offset calibration coefficient for the ADC and its power-on reset value is 0x800000.

Parameters
cfgSetup select.
valueoffset
Returns
0 for success or negative error code
int Ad7124Chip::setMode ( Ad7124::OperatingMode  mode)

Control the mode of operation for ADC.

Parameters
modemode of operation
Returns
0 for success or negative error code
int Ad7124Chip::setRegister ( Ad7124::RegisterId  id,
long  value 
)

Writes the value of the specified register.

Parameters
idregister identifier
value8 to 24 bits register value
Returns
0, negative for error.
void Ad7124Chip::setTimeout ( uint32_t  ms)
inline

set IO timeout in milliseconds

int Ad7124Chip::startSingleConversion ( uint8_t  ch)

Start conversion in single mode.

Parameters
chchannel number
Returns
0 for success or negative error code
int Ad7124Chip::status ( )

Returns the status register.

uint32_t Ad7124Chip::timeout ( ) const
inline

return IO timeout in milliseconds (default is 1000ms)

static double Ad7124Chip::toVoltage ( long  value,
int  gain,
double  vref,
bool  bipolar = true 
)
static

Converts sample to voltage.

Parameters
valuesample
gaingain
vreffull scale voltage
bipolar
Returns
voltage
int Ad7124Chip::waitEndOfConversion ( uint32_t  timeout_ms)

Waits until a new conversion result is available.

Parameters
timeout_mstimeout delay
Returns
0 for success or negative error code