AD7124Library
1.0.3
Arduino library for the AD7124 ADC
|
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... | |
int Ad7124Chip::begin | ( | int | slave_select | ) |
Initializes the AD7124.
slave_select | The Slave Chip Select Id to be passed to the SPI calls |
int Ad7124Chip::channelConfig | ( | uint8_t | ch | ) |
Returns the setup number used by the channel.
ch | channel number 0 to 15 |
int Ad7124Chip::currentChannel | ( | ) |
Returns the last sampling channel.
int Ad7124Chip::enableChannel | ( | uint8_t | ch, |
bool | enable = true |
||
) |
Enable/Disable channel.
ch | channel number 0 to 15 |
enable | true for enabled |
long Ad7124Chip::getData | ( | ) |
Returns the last sample.
long Ad7124Chip::getRegister | ( | Ad7124::RegisterId | id | ) |
Reads the value of the specified register.
id | register identifier |
int Ad7124Chip::internalCalibration | ( | uint8_t | ch | ) |
Proceed to Internal zero-scale and full-scale calibration.
ch | channel number |
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.
ch | channel number |
int Ad7124Chip::reset | ( | ) |
Resets the device.
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.
mode | Control the mode of operation for ADC |
power_mode | Power mode |
ref_en | Internal 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_sel | select the clock source for the ADC |
int Ad7124Chip::setChannel | ( | uint8_t | ch, |
uint8_t | cfg, | ||
Ad7124::InputSel | ainp, | ||
Ad7124::InputSel | ainm, | ||
bool | enable = false |
||
) |
Setup channel.
ch | channel number 0 to 15 |
cfg | Setup select. These bits identify which of the eight setups are used to configure the ADC for this channel. |
ainp | Positive analog input AINP input select. |
ainm | Negative analog input AINM input select. |
enable | Channel enable bit. Setting this bit enables the device channel for the conversion sequence. |
int Ad7124Chip::setConfig | ( | uint8_t | cfg, |
Ad7124::RefSel | ref, | ||
Ad7124::PgaSel | pga, | ||
bool | bipolar, | ||
Ad7124::BurnoutCurrent | burnout = Ad7124::BurnoutOff |
||
) |
Sets a setup.
cfg | Setup select. |
ref | Reference source select bits. |
pga | Gain select bits. |
bipolar | Polarity select bit. When this bit is set, bipolar operation is selected. When this bit is cleared, unipolar operation is selected. |
burnout | These bits select the magnitude of the sensor burnout detect current source. |
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.
cfg | Setup select. |
filter | Filter type |
postfilter | Post filter type |
fs | Filter 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. |
rej60 | When 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. |
single | Single 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. |
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.
cfg | Setup select. |
value | gain |
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.
cfg | Setup select. |
value | offset |
int Ad7124Chip::setMode | ( | Ad7124::OperatingMode | mode | ) |
Control the mode of operation for ADC.
mode | mode of operation |
int Ad7124Chip::setRegister | ( | Ad7124::RegisterId | id, |
long | value | ||
) |
Writes the value of the specified register.
id | register identifier |
value | 8 to 24 bits register value |
|
inline |
set IO timeout in milliseconds
int Ad7124Chip::startSingleConversion | ( | uint8_t | ch | ) |
Start conversion in single mode.
ch | channel number |
int Ad7124Chip::status | ( | ) |
Returns the status register.
|
inline |
return IO timeout in milliseconds (default is 1000ms)
|
static |
Converts sample to voltage.
value | sample |
gain | gain |
vref | full scale voltage |
bipolar |
int Ad7124Chip::waitEndOfConversion | ( | uint32_t | timeout_ms | ) |
Waits until a new conversion result is available.
timeout_ms | timeout delay |