Data Gator
Hardware and software documentation for the Data Gator project.
Loading...
Searching...
No Matches
OWMAdafruit_ADS1015.h
1// Modifications by SwitchDoc Labs - ADS1115 Delay increased
2/**************************************************************************/
20/**************************************************************************/
21#ifndef Adafruit_ADS1015_h
22#define Adafruit_ADS1015_h
23
24#if ARDUINO >= 100
25 #include "Arduino.h"
26#else
27 #include "WProgram.h"
28#endif
29
30#include <Wire.h>
31
32
33
34/*=========================================================================
35 I2C ADDRESS/BITS
36 -----------------------------------------------------------------------*/
37 #define ADS1015_ADDRESS (0x48) // 1001 000 (ADDR = GND)
38/*=========================================================================*/
39
40/*=========================================================================
41 CONVERSION DELAY (in mS)
42 -----------------------------------------------------------------------*/
43 #define ADS1015_CONVERSIONDELAY (1)
44 #define ADS1115_CONVERSIONDELAY (12) // 8
45/*=========================================================================*/
46
47/*=========================================================================
48 POINTER REGISTER
49 -----------------------------------------------------------------------*/
50 #define ADS1015_REG_POINTER_MASK (0x03)
51 #define ADS1015_REG_POINTER_CONVERT (0x00)
52 #define ADS1015_REG_POINTER_CONFIG (0x01)
53 #define ADS1015_REG_POINTER_LOWTHRESH (0x02)
54 #define ADS1015_REG_POINTER_HITHRESH (0x03)
55/*=========================================================================*/
56
57/*=========================================================================
58 CONFIG REGISTER
59 -----------------------------------------------------------------------*/
60 #define ADS1015_REG_CONFIG_OS_MASK (0x8000)
61 #define ADS1015_REG_CONFIG_OS_SINGLE (0x8000) // Write: Set to start a single-conversion
62 #define ADS1015_REG_CONFIG_OS_BUSY (0x0000) // Read: Bit = 0 when conversion is in progress
63 #define ADS1015_REG_CONFIG_OS_NOTBUSY (0x8000) // Read: Bit = 1 when device is not performing a conversion
64
65 #define ADS1015_REG_CONFIG_MUX_MASK (0x7000)
66 #define ADS1015_REG_CONFIG_MUX_DIFF_0_1 (0x0000) // Differential P = AIN0, N = AIN1 (default)
67 #define ADS1015_REG_CONFIG_MUX_DIFF_0_3 (0x1000) // Differential P = AIN0, N = AIN3
68 #define ADS1015_REG_CONFIG_MUX_DIFF_1_3 (0x2000) // Differential P = AIN1, N = AIN3
69 #define ADS1015_REG_CONFIG_MUX_DIFF_2_3 (0x3000) // Differential P = AIN2, N = AIN3
70 #define ADS1015_REG_CONFIG_MUX_SINGLE_0 (0x4000) // Single-ended AIN0
71 #define ADS1015_REG_CONFIG_MUX_SINGLE_1 (0x5000) // Single-ended AIN1
72 #define ADS1015_REG_CONFIG_MUX_SINGLE_2 (0x6000) // Single-ended AIN2
73 #define ADS1015_REG_CONFIG_MUX_SINGLE_3 (0x7000) // Single-ended AIN3
74
75 #define ADS1015_REG_CONFIG_PGA_MASK (0x0E00)
76 #define ADS1015_REG_CONFIG_PGA_6_144V (0x0000) // +/-6.144V range = Gain 2/3
77 #define ADS1015_REG_CONFIG_PGA_4_096V (0x0200) // +/-4.096V range = Gain 1
78 #define ADS1015_REG_CONFIG_PGA_2_048V (0x0400) // +/-2.048V range = Gain 2 (default)
79 #define ADS1015_REG_CONFIG_PGA_1_024V (0x0600) // +/-1.024V range = Gain 4
80 #define ADS1015_REG_CONFIG_PGA_0_512V (0x0800) // +/-0.512V range = Gain 8
81 #define ADS1015_REG_CONFIG_PGA_0_256V (0x0A00) // +/-0.256V range = Gain 16
82
83 #define ADS1015_REG_CONFIG_MODE_MASK (0x0100)
84 #define ADS1015_REG_CONFIG_MODE_CONTIN (0x0000) // Continuous conversion mode
85 #define ADS1015_REG_CONFIG_MODE_SINGLE (0x0100) // Power-down single-shot mode (default)
86
87 #define ADS1015_REG_CONFIG_DR_MASK (0x00E0)
88 #define ADS1015_REG_CONFIG_DR_128SPS (0x0000) // 128 samples per second
89 #define ADS1015_REG_CONFIG_DR_250SPS (0x0020) // 250 samples per second
90 #define ADS1015_REG_CONFIG_DR_490SPS (0x0040) // 490 samples per second
91 #define ADS1015_REG_CONFIG_DR_920SPS (0x0060) // 920 samples per second
92 #define ADS1015_REG_CONFIG_DR_1600SPS (0x0080) // 1600 samples per second (default)
93 #define ADS1015_REG_CONFIG_DR_2400SPS (0x00A0) // 2400 samples per second
94 #define ADS1015_REG_CONFIG_DR_3300SPS (0x00C0) // 3300 samples per second
95
96 #define ADS1015_REG_CONFIG_CMODE_MASK (0x0010)
97 #define ADS1015_REG_CONFIG_CMODE_TRAD (0x0000) // Traditional comparator with hysteresis (default)
98 #define ADS1015_REG_CONFIG_CMODE_WINDOW (0x0010) // Window comparator
99
100 #define ADS1015_REG_CONFIG_CPOL_MASK (0x0008)
101 #define ADS1015_REG_CONFIG_CPOL_ACTVLOW (0x0000) // ALERT/RDY pin is low when active (default)
102 #define ADS1015_REG_CONFIG_CPOL_ACTVHI (0x0008) // ALERT/RDY pin is high when active
103
104 #define ADS1015_REG_CONFIG_CLAT_MASK (0x0004) // Determines if ALERT/RDY pin latches once asserted
105 #define ADS1015_REG_CONFIG_CLAT_NONLAT (0x0000) // Non-latching comparator (default)
106 #define ADS1015_REG_CONFIG_CLAT_LATCH (0x0004) // Latching comparator
107
108 #define ADS1015_REG_CONFIG_CQUE_MASK (0x0003)
109 #define ADS1015_REG_CONFIG_CQUE_1CONV (0x0000) // Assert ALERT/RDY after one conversions
110 #define ADS1015_REG_CONFIG_CQUE_2CONV (0x0001) // Assert ALERT/RDY after two conversions
111 #define ADS1015_REG_CONFIG_CQUE_4CONV (0x0002) // Assert ALERT/RDY after four conversions
112 #define ADS1015_REG_CONFIG_CQUE_NONE (0x0003) // Disable the comparator and put ALERT/RDY in high state (default)
113/*=========================================================================*/
114
115typedef enum
116{
117 GAIN_TWOTHIRDS = ADS1015_REG_CONFIG_PGA_6_144V,
118 GAIN_ONE = ADS1015_REG_CONFIG_PGA_4_096V,
119 GAIN_TWO = ADS1015_REG_CONFIG_PGA_2_048V,
120 GAIN_FOUR = ADS1015_REG_CONFIG_PGA_1_024V,
121 GAIN_EIGHT = ADS1015_REG_CONFIG_PGA_0_512V,
122 GAIN_SIXTEEN = ADS1015_REG_CONFIG_PGA_0_256V
123} adsGain_t;
124
126{
127protected:
128 // Instance-specific properties
129 uint8_t m_i2cAddress;
130 uint8_t m_conversionDelay;
131 uint8_t m_bitShift;
132 adsGain_t m_gain;
133
134 public:
135 Adafruit_ADS1015(uint8_t i2cAddress = ADS1015_ADDRESS);
136 void begin(void);
142 void setGain(adsGain_t gain);
143 adsGain_t getGain(void);
144
145 private:
146};
147
148// Derive from ADS1105 & override construction to set properties
150{
151 public:
152 Adafruit_ADS1115(uint8_t i2cAddress = ADS1015_ADDRESS);
153
154 private:
155};
156
157
158#endif
Definition OWMAdafruit_ADS1015.h:126
int16_t readADC_Differential_2_3(void)
Reads the conversion results, measuring the voltage difference between the P (AIN2) and N (AIN3) inpu...
Definition OWMAdafruit_ADS1015.cpp:249
void setGain(adsGain_t gain)
Sets the gain and input voltage range.
Definition OWMAdafruit_ADS1015.cpp:121
uint16_t readADC_SingleEnded(uint8_t channel)
Gets a single-ended ADC reading from the specified channel.
Definition OWMAdafruit_ADS1015.cpp:141
int16_t readADC_Differential_0_1(void)
Reads the conversion results, measuring the voltage difference between the P (AIN0) and N (AIN1) inpu...
Definition OWMAdafruit_ADS1015.cpp:198
adsGain_t getGain(void)
Gets a gain and input voltage range.
Definition OWMAdafruit_ADS1015.cpp:131
void begin(void)
Sets up the HW (reads coefficients values, etc.)
Definition OWMAdafruit_ADS1015.cpp:112
int16_t getLastConversionResults()
In order to clear the comparator, we need to read the conversion results. This function reads the las...
Definition OWMAdafruit_ADS1015.cpp:347
void startComparator_SingleEnded(uint8_t channel, int16_t threshold)
Sets up the comparator to operate in basic mode, causing the ALERT/RDY pin to assert (go from high to...
Definition OWMAdafruit_ADS1015.cpp:301
Definition OWMAdafruit_ADS1015.h:150
int reset_count
number of resets retrieved for NVS
Definition scheduler.hpp:31