Aruna
aruna::driver::ADS101x Class Reference

#include <ADS101x.h>

Inheritance diagram for aruna::driver::ADS101x:
Collaboration diagram for aruna::driver::ADS101x:

Public Types

enum  MUX {
  MUX::DEFAULT = 0b000 << 12, MUX::AINp0_AINn1 = 0b000 << 12, MUX::AINp0_AINn3 = 0b001 << 12, MUX::AINp1_AINn3 = 0b010 << 12,
  MUX::AINp2_AINn3 = 0b011 << 12, MUX::AINp0_AINnGND = 0b100 << 12, MUX::AINp1_AINnGND = 0b101 << 12, MUX::AINp2_AINnGND = 0b110 << 12,
  MUX::AINp3_AINnGND = 0b111 << 12
}
 Input multiplexer configuration (ADS1015 only) These bits configure the input multiplexer. More...
 

Public Member Functions

err_t isConnected (uint8_t address)
 check if device is connected and functional More...
 
 ADS101x (MUX compare, I2C_master *i2c_bus, uint8_t address=default_address)
 ADS101x I²C 12 bit ADC with four channels. More...
 
- Public Member Functions inherited from aruna::driver::ADC
template<typename T >
err_t read_raw (T &raw)
 Read raw value from ADC, convert to voltage yourself. More...
 
template<typename T >
err_t read_voltage (T &mV)
 Read voltage level of input. More...
 
size_t get_resolution () const
 Get the resolution in bits of the ADC. More...
 
uint16_t get_reference () const
 Get the reference voltage in micro Voltage. More...
 
virtual int32_t raw_to_voltage (int32_t raw)
 Convert raw data to voltage. More...
 
template<typename T >
aruna::err_t read_raw (T &raw)
 
template<typename T >
aruna::err_t read_voltage (T &mV)
 

Private Types

enum  register_address_pointer { register_address_pointer::CONVERSION = 0b00, register_address_pointer::CONFIG = 0b01, register_address_pointer::LO_TRESH = 0b10, register_address_pointer::HI_TRESH = 0b11 }
 Pointer to the registers. More...
 
enum  reset_value { reset_value::CONVERSION = 0x0000, reset_value::CONFIG = 0x8583, reset_value::LO_THRESH = 0x8000, reset_value::HI_THRESH = 0x7FFF }
 write these values to the respected registers to reset them to their default value. More...
 
enum  OS { OS::W_NO_EFFECT = 0b0 << 15, OS::W_START_A_SINGLE_CONVERSION = 0b1 << 15, OS::R_DEVICE_IS_CURRENTLY_PERFORMING_A_CONVERSION = 0b0 << 15, OS::R_DEVICE_IS_NOT_CURRENTLY_PERFORMING_A_CONVERSION = 0b1 << 15 }
 Operational status or single-shot conversion start This bit determines the operational status of the device. More...
 
enum  PGA {
  PGA::DEFAULT = 0b010 << 9, PGA::FSR_6144mV = 0b000 << 9, PGA::FSR_4096mV = 0b001 << 9, PGA::FSR_2048mV = 0b010 << 9,
  PGA::FSR_1024mV = 0b011 << 9, PGA::FSR_0512mV = 0b100 << 9, PGA::FSR_0256mV = 0b101 << 9
}
 Programmable gain amplifier configuration These bits set the FSR of the programmable gain amplifier. More...
 
enum  MODE { MODE::DEFAULT = 0b1 << 8, MODE::CONTINUOUS_CONVERSION = 0b0 << 8, MODE::SINGLE_SHOT = 0b1 << 8 }
 Device operating mode This bit controls the operating mode. More...
 
enum  DR {
  DR::DEFAULT = 0b100 << 5, DR::SPS_128 = 0b000 << 5, DR::SPS_250 = 0b001 << 5, DR::SPS_490 = 0b010 << 5,
  DR::SPS_920 = 0b011 << 5, DR::SPS_1600 = 0b100 << 5, DR::SPS_2400 = 0b101 << 5, DR::SPS_3300 = 0b110 << 5
}
 Data rate These bits control the data rate setting. More...
 
enum  COMP_MODE { COMP_MODE::DEFAULT = 0b0 << 4, COMP_MODE::TRADITIONAL = 0b0 << 4, COMP_MODE::WINDOW = 0b1 << 4 }
 Comparator mode (ADS1014 and ADS1015 only) This bit configures the comparator operating mode. More...
 
enum  COMP_POL { COMP_POL::DEFAULT = 0b0 << 3, COMP_POL::ACTIVE_LOW = 0b0 << 3, COMP_POL::ACTIVE_HIGH = 0b1 << 3 }
 Comparator polarity (ADS1014 and ADS1015 only) This bit controls the polarity of the ALERT/RDY pin. More...
 
enum  COMP_LAT { COMP_LAT::DEFAULT = 0b0 << 2, COMP_LAT::NONLATCHING_COMPARATOR = 0b0 << 2, COMP_LAT::LATCHING_COMPARATOR = 0b1 << 2 }
 Latching comparator (ADS1014 and ADS1015 only) This bit controls whether the ALERT/RDY pin latches after being asserted or clears after conversions are within the margin of the upper and lower threshold values. More...
 
enum  COMP_QUEUE {
  COMP_QUEUE::DEFAULT = 0b11, COMP_QUEUE::ASSERT_AFTER_ONE_CONVERSION = 0b00, COMP_QUEUE::ASSERT_AFTER_TWO_CONVERSIONS = 0b01, COMP_QUEUE::ASSERT_AFTER_FOUR_CONVERSION = 0b10,
  COMP_QUEUE::DISABLE_COMPARATOR_AND_SET_ALERT_RDY_PIN_TO_HIGH_IMPEDANCE = 0b11
}
 Comparator queue and disable (ADS1014 and ADS1015 only) These bits perform two functions. More...
 

Private Member Functions

err_t _read (int32_t &raw) override
 Read analogue value and convert to 32bit signed resolution. More...
 

Private Attributes

const MUX compare
 
I2C_masteri2c_bus
 
uint8_t const i2c_address
 

Static Private Attributes

uint8_t static const default_address = 0b1001000
 

Additional Inherited Members

- Protected Member Functions inherited from aruna::driver::ADC
err_t set_resolution (size_t bits)
 Set resolution of ADC. More...
 
err_t set_reference (uint16_t mV)
 set reference voltage, used to convert raw data to voltage. More...
 

Detailed Description

Definition at line 13 of file ADS101x.h.

Member Enumeration Documentation

◆ COMP_LAT

Latching comparator (ADS1014 and ADS1015 only) This bit controls whether the ALERT/RDY pin latches after being asserted or clears after conversions are within the margin of the upper and lower threshold values.

This bit serves no function on the ADS1013.

Enumerator
DEFAULT 
NONLATCHING_COMPARATOR 
LATCHING_COMPARATOR 

Definition at line 148 of file ADS101x.h.

148  {
149  DEFAULT = 0b0 << 2,
150  NONLATCHING_COMPARATOR = 0b0 << 2,
151  LATCHING_COMPARATOR = 0b1 << 2,
152  };

◆ COMP_MODE

Comparator mode (ADS1014 and ADS1015 only) This bit configures the comparator operating mode.

This bit serves no function on the ADS1013.

Enumerator
DEFAULT 
TRADITIONAL 
WINDOW 

Definition at line 126 of file ADS101x.h.

126  {
127  DEFAULT = 0b0 << 4,
128  TRADITIONAL = 0b0 << 4,
129  WINDOW = 0b1 << 4,
130  };

◆ COMP_POL

Comparator polarity (ADS1014 and ADS1015 only) This bit controls the polarity of the ALERT/RDY pin.

This bit serves no function on the ADS1013.

Enumerator
DEFAULT 
ACTIVE_LOW 
ACTIVE_HIGH 

Definition at line 136 of file ADS101x.h.

136  {
137  DEFAULT = 0b0 << 3,
138  ACTIVE_LOW = 0b0 << 3,
139  ACTIVE_HIGH = 0b1 << 3,
140  };

◆ COMP_QUEUE

Comparator queue and disable (ADS1014 and ADS1015 only) These bits perform two functions.

When set to 11, the comparator is disabled and the ALERT/RDY pin is set to a high-impedance state. When set to any other value, the ALERT/RDY pin and the comparator function are enabled, and the set value determines the number of successive conversions exceeding the upper or lower threshold required before asserting the ALERT/RDY pin. These bits serve no function on the ADS1013.

Enumerator
DEFAULT 
ASSERT_AFTER_ONE_CONVERSION 
ASSERT_AFTER_TWO_CONVERSIONS 
ASSERT_AFTER_FOUR_CONVERSION 
DISABLE_COMPARATOR_AND_SET_ALERT_RDY_PIN_TO_HIGH_IMPEDANCE 

Definition at line 163 of file ADS101x.h.

163  {
164  DEFAULT = 0b11,
165  ASSERT_AFTER_ONE_CONVERSION = 0b00,
166  ASSERT_AFTER_TWO_CONVERSIONS = 0b01,
167  ASSERT_AFTER_FOUR_CONVERSION = 0b10,
168  DISABLE_COMPARATOR_AND_SET_ALERT_RDY_PIN_TO_HIGH_IMPEDANCE = 0b11,
169  };

◆ DR

enum aruna::driver::ADS101x::DR
strongprivate

Data rate These bits control the data rate setting.

Enumerator
DEFAULT 
SPS_128 
SPS_250 
SPS_490 
SPS_920 
SPS_1600 
SPS_2400 
SPS_3300 

Definition at line 111 of file ADS101x.h.

111  {
112  DEFAULT = 0b100 << 5,
113  SPS_128 = 0b000 << 5,
114  SPS_250 = 0b001 << 5,
115  SPS_490 = 0b010 << 5,
116  SPS_920 = 0b011 << 5,
117  SPS_1600 = 0b100 << 5,
118  SPS_2400 = 0b101 << 5,
119  SPS_3300 = 0b110 << 5,
120  };

◆ MODE

enum aruna::driver::ADS101x::MODE
strongprivate

Device operating mode This bit controls the operating mode.

Enumerator
DEFAULT 
CONTINUOUS_CONVERSION 
SINGLE_SHOT 

Definition at line 101 of file ADS101x.h.

101  {
102  DEFAULT = 0b1 << 8,
103  CONTINUOUS_CONVERSION = 0b0 << 8,
104  SINGLE_SHOT = 0b1 << 8,
105  };

◆ MUX

Input multiplexer configuration (ADS1015 only) These bits configure the input multiplexer.

These bits serve no function on the ADS1013 and ADS1014.

Enumerator
DEFAULT 
AINp0_AINn1 
AINp0_AINn3 
AINp1_AINn3 
AINp2_AINn3 
AINp0_AINnGND 
AINp1_AINnGND 
AINp2_AINnGND 
AINp3_AINnGND 

Definition at line 19 of file ADS101x.h.

19  {
20  DEFAULT = 0b000 << 12,
21  AINp0_AINn1 = 0b000 << 12,
22  AINp0_AINn3 = 0b001 << 12,
23  AINp1_AINn3 = 0b010 << 12,
24  AINp2_AINn3 = 0b011 << 12,
25  AINp0_AINnGND = 0b100 << 12,
26  AINp1_AINnGND = 0b101 << 12,
27  AINp2_AINnGND = 0b110 << 12,
28  AINp3_AINnGND = 0b111 << 12,
29  };

◆ OS

enum aruna::driver::ADS101x::OS
strongprivate

Operational status or single-shot conversion start This bit determines the operational status of the device.

OS can only be written when in power-down state and has no effect when a conversion is ongoing.

Enumerator
W_NO_EFFECT 
W_START_A_SINGLE_CONVERSION 
R_DEVICE_IS_CURRENTLY_PERFORMING_A_CONVERSION 
R_DEVICE_IS_NOT_CURRENTLY_PERFORMING_A_CONVERSION 

Definition at line 75 of file ADS101x.h.

75  {
76  W_NO_EFFECT = 0b0 << 15,
77  W_START_A_SINGLE_CONVERSION = 0b1 << 15,
78  R_DEVICE_IS_CURRENTLY_PERFORMING_A_CONVERSION = 0b0 << 15,
79  R_DEVICE_IS_NOT_CURRENTLY_PERFORMING_A_CONVERSION = 0b1 << 15,
80  };

◆ PGA

enum aruna::driver::ADS101x::PGA
strongprivate

Programmable gain amplifier configuration These bits set the FSR of the programmable gain amplifier.

These bits serve no function on the ADS1013.

Enumerator
DEFAULT 
FSR_6144mV 
FSR_4096mV 
FSR_2048mV 
FSR_1024mV 
FSR_0512mV 
FSR_0256mV 

Definition at line 87 of file ADS101x.h.

87  {
88  DEFAULT = 0b010 << 9,
89  FSR_6144mV = 0b000 << 9,
90  FSR_4096mV = 0b001 << 9,
91  FSR_2048mV = 0b010 << 9,
92  FSR_1024mV = 0b011 << 9,
93  FSR_0512mV = 0b100 << 9,
94  FSR_0256mV = 0b101 << 9,
95  };

◆ register_address_pointer

Pointer to the registers.

Enumerator
CONVERSION 
CONFIG 
LO_TRESH 
HI_TRESH 

Definition at line 53 of file ADS101x.h.

53  {
54  CONVERSION = 0b00,
55  CONFIG = 0b01,
56  LO_TRESH = 0b10,
57  HI_TRESH = 0b11,
58  };

◆ reset_value

write these values to the respected registers to reset them to their default value.

Enumerator
CONVERSION 
CONFIG 
LO_THRESH 
HI_THRESH 

Definition at line 63 of file ADS101x.h.

63  {
64  CONVERSION = 0x0000,
65  CONFIG = 0x8583,
66  LO_THRESH = 0x8000,
67  HI_THRESH = 0x7FFF,
68  };

Constructor & Destructor Documentation

◆ ADS101x()

ADS101x::ADS101x ( ADS101x::MUX  compare,
I2C_master i2c_bus,
uint8_t  address = default_address 
)

ADS101x I²C 12 bit ADC with four channels.

Parameters
compareselect pin and comparison
i2c_busI²C Bus for communication
addressoptional I²C address, will use default address if not omitted.

Definition at line 53 of file ADS101x.cpp.

53  : compare(compare), i2c_bus(i2c_bus),
54  i2c_address(address) {
55  set_reference(3300);
56  set_resolution(12);
57 
58 }
uint8_t const i2c_address
Definition: ADS101x.h:173
err_t set_reference(uint16_t mV)
set reference voltage, used to convert raw data to voltage.
Definition: ADC.cpp:18
err_t set_resolution(size_t bits)
Set resolution of ADC.
Definition: ADC.cpp:13
I2C_master * i2c_bus
Definition: ADS101x.h:172
Here is the call graph for this function:

Member Function Documentation

◆ _read()

err_t ADS101x::_read ( int32_t &  raw)
overrideprivatevirtual

Read analogue value and convert to 32bit signed resolution.

Parameters
rawstore result here
Returns
error code

Implements aruna::driver::ADC.

Definition at line 12 of file ADS101x.cpp.

12  {
13  err_t err = err_t::OK;
14  int16_t conversion = 0;
15  uint16_t config = (int) ADS101x::OS::W_START_A_SINGLE_CONVERSION |
16  (int) compare |
17  (int) ADS101x::PGA::DEFAULT |
19  (int) ADS101x::DR::DEFAULT |
24 
25  uint8_t data[2];
26  uint8_t config_array[2]={ static_cast<uint8_t>(config & 0xff), static_cast<uint8_t>(config >> 8) };
27 // write config
28  err = i2c_bus->write(i2c_address, (uint8_t) register_address_pointer::CONFIG, config_array, 2);
29  if ((bool) err)
30  return err;
31 // set Conversion register to read and read conversion register
33 // printf("read: 0x%X%X\n", data[0], data[1]);
34  conversion = (int16_t) (data[0] << 8 | (data[1] & 0xFF));
35  conversion = conversion >> 4;
36 // TODO use function from Actuator.h
37 // raw = ((conversion * (4096 - 0)) / 2047) + 0;
38 
39  double input, inputLow, inputHigh, outputHigh, outputLow;
40  input = conversion;
41  inputLow = -2048;
42  inputHigh = 2047;
43  outputHigh = INT32_MAX;
44  outputLow = INT32_MIN;
45 // TODO make convert_range function and replace Actuator::convert_range with this
46 // TODO range converting should be done by the ADC parent.
47 // https://gamedev.stackexchange.com/questions/33441/how-to-convert-a-number-from-one-min-max-set-to-another-min-max-set
48  raw = ((input - inputLow) / (inputHigh - inputLow)) * (outputHigh - outputLow) + outputLow;
49  return err;
50 }
err_t read(uint8_t address, uint8_t reg, uint8_t *buffer, size_t buffer_size)
Read data from I²C slave.
Definition: I2C_master.cpp:7
uint8_t const i2c_address
Definition: ADS101x.h:173
err_t write(uint8_t address, uint8_t reg, uint8_t *data, size_t data_size)
Write data to the I²C bus.
Definition: I2C_master.cpp:15
I2C_master * i2c_bus
Definition: ADS101x.h:172
Here is the call graph for this function:

◆ isConnected()

err_t aruna::driver::ADS101x::isConnected ( uint8_t  address)

check if device is connected and functional

Parameters
address,I²Caddress
Returns
err_t::OK if OK.

Member Data Documentation

◆ compare

const MUX aruna::driver::ADS101x::compare
private

Definition at line 171 of file ADS101x.h.

◆ default_address

uint8_t static const aruna::driver::ADS101x::default_address = 0b1001000
staticprivate

Definition at line 48 of file ADS101x.h.

◆ i2c_address

uint8_t const aruna::driver::ADS101x::i2c_address
private

Definition at line 173 of file ADS101x.h.

◆ i2c_bus

I2C_master* aruna::driver::ADS101x::i2c_bus
private

Definition at line 172 of file ADS101x.h.


The documentation for this class was generated from the following files: