ADS1118  1.0.0
Arduino library for Texas Instruments ADS1118 chip
ADS1118.h
1 #ifndef ADS1118_h
2 #define ADS1118_h
3 
4 #include "Arduino.h"
5 #include <SPI.h>
6 
12 union Config {
15  struct {
16  uint8_t reserved:1;
17  uint8_t noOperation:2;
18  uint8_t pullUp:1;
19  uint8_t sensorMode:1;
20  uint8_t rate:3;
21  uint8_t operatingMode:1;
22  uint8_t pga:3;
23  uint8_t mux:3;
24  uint8_t singleStart:1;
25  } bits;
26  uint16_t word;
27  struct {
28  uint8_t lsb;
29  uint8_t msb;
30  } byte;
31 };
32 
33 
38 class ADS1118 {
39  public:
40  ADS1118(uint8_t io_pin_cs);
41  void begin();
42  double getTemperature();
43  uint16_t getADCValue(uint8_t inputs);
44  double getMilliVolts(uint8_t inputs);
45  double getMilliVolts();
47  void setSampligRate(uint8_t samplingRate);
48  void setFullScaleRange(uint8_t fsr);
49  void setContinuousMode();
50  void setSingleShotMode();
51  void disablePullup();
52  void enablePullup();
53  void setInputSelected(uint8_t input);
54  //Input multiplexer configuration selection for bits "MUX"
55  //Differential inputs
56  const uint8_t DIFF_0_1 = 0b000;
57  const uint8_t DIFF_0_3 = 0b001;
58  const uint8_t DIFF_1_3 = 0b010;
59  const uint8_t DIFF_2_3 = 0b011;
60  //Single ended inputs
61  const uint8_t AIN_0 = 0b100;
62  const uint8_t AIN_1 = 0b101;
63  const uint8_t AIN_2 = 0b110;
64  const uint8_t AIN_3 = 0b111;
66 
67  //Bit constants
68  const uint16_t SCLK = 2000000;
69 
70  // Used by "SS" bit
71  const uint8_t START_NOW = 1;
72 
73  // Used by "TS_MODE" bit
74  const uint8_t ADC_MODE = 0;
75  const uint8_t TEMP_MODE = 1;
76 
77  // Used by "MODE" bit
78  const uint8_t CONTINUOUS = 0;
79  const uint8_t SINGLE_SHOT = 1;
80 
81  // Used by "PULL_UP_EN" bit
82  const uint8_t PULLUP = 1;
83  const uint8_t NO_PULLUP = 0;
84 
85  // Used by "NOP" bits
86  const uint8_t VALID_CFG = 0b01;
87  const uint8_t NO_VALID_CFG= 0b00;
88 
89  // Used by "Reserved" bit
90  const uint8_t RESERVED = 1;
91 
92  /*Full scale range (FSR) selection by "PGA" bits.
93  [Warning: this could increase the noise and the effective number of bits (ENOB). See tables above]*/
94  const uint8_t FSR_6144 = 0b000;
95  const uint8_t FSR_4096 = 0b001;
96  const uint8_t FSR_2048 = 0b010;
97  const uint8_t FSR_1024 = 0b011;
98  const uint8_t FSR_0512 = 0b100;
99  const uint8_t FSR_0256 = 0b111;
100 
101  /*Sampling rate selection by "DR" bits.
102  [Warning: this could increase the noise and the effective number of bits (ENOB). See tables above]*/
103  const uint8_t RATE_8SPS = 0b000;
104  const uint8_t RATE_16SPS = 0b001;
105  const uint8_t RATE_32SPS = 0b010;
106  const uint8_t RATE_64SPS = 0b011;
107  const uint8_t RATE_128SPS = 0b100;
108  const uint8_t RATE_250SPS = 0b101;
109  const uint8_t RATE_475SPS = 0b110;
110  const uint8_t RATE_860SPS = 0b111;
111 
112 private:
113  uint8_t lastSensorMode=3;
114  uint8_t cs;
115  const float pgaFSR[8] = {6.144, 4.096, 2.048, 1.024, 0.512, 0.256, 0.256, 0.256};
116  const uint8_t CONV_TIME[8]={125, 63, 32, 16, 8, 4, 3, 2};
117 
118 /*
119  Table 1. Noise in μVRMS (μVPP) at VDD = 3.3 V [1]
120  DATA RATE FSR (Full-Scale Range)
121  (SPS) ±6.144 V ±4.096 V ±2.048 V ±1.024 V ±0.512 V ±0.256 V
122  8 187.5 (187.5) 125 (125) 62.5 (62.5) 31.25 (31.25) 15.62 (15.62) 7.81 (7.81)
123  16 187.5 (187.5) 125 (125) 62.5 (62.5) 31.25 (31.25) 15.62 (15.62) 7.81 (7.81)
124  32 187.5 (187.5) 125 (125) 62.5 (62.5) 31.25 (31.25) 15.62 (15.62) 7.81 (7.81)
125  64 187.5 (187.5) 125 (125) 62.5 (62.5) 31.25 (31.25) 15.62 (15.62) 7.81 (7.81)
126  128 187.5 (187.5) 125 (125) 62.5 (62.5) 31.25 (31.25) 15.62 (15.62) 7.81 (12.35)
127  250 187.5 (252.09) 125 (148.28) 62.5 (84.03) 31.25 (39.54) 15.62 (16.06) 7.81 (18.53)
128  475 187.5 (266.92) 125 (227.38) 62.5 (79.08) 31.25 (56.84) 15.62 (32.13) 7.81 (25.95)
129  860 187.5 (430.06) 125 (266.93) 62.5 (118.63) 31.25 (64.26) 15.62 (40.78) 7.81 (35.83)
130 
131 
132  Table 2. ENOB from RMS Noise (Noise-Free Bits from Peak-to-Peak Noise) at VDD = 3.3 V
133  DATA RATE FSR (Full-Scale Range)
134  (SPS) ±6.144 V ±4.096 V ±2.048 V ±1.024 V ±0.512 V ±0.256 V
135  8 16 (16) 16 (16) 16 (16) 16 (16) 16 (16) 16 (16)
136  16 16 (16) 16 (16) 16 (16) 16 (16) 16 (16) 16 (16)
137  32 16 (16) 16 (16) 16 (16) 16 (16) 16 (16) 16 (16)
138  64 16 (16) 16 (16) 16 (16) 16 (16) 16 (16) 16 (16)
139  128 16 (16) 16 (16) 16 (16) 16 (16) 16 (16) 16 (15.33)
140  250 16 (15.57) 16 (15.75) 16 (15.57) 16 (15.66) 16 (15.96) 16 (14.75)
141  475 16 (15.49) 16 (15.13) 16 (15.66) 16 (15.13) 16 (14.95) 16 (14.26)
142  860 16 (14.8) 16 (14.9) 16 (15.07) 16 (14.95) 16 (14.61) 16 (13.8)
143 
144 
145  [1] Texas Instruments, "ADS1118 Ultrasmall, Low-Power, SPI™-Compatible, 16-Bit Analog-to-Digital
146  Converter with Internal Reference and Temperature Sensor", ADS1118 datasheet, SBAS457E [OCTOBER 2010–REVISED OCTOBER 2015].
147 
148  Note: This information is taken from http://www.ti.com
149  Copyright © 2010–2015, Texas Instruments Incorporated
150 */
151 
152 };
153 
154 #endif
const uint8_t AIN_3
Single ended input: Vin=A3.
Definition: ADS1118.h:64
const uint8_t FSR_6144
Range: ±6.144 v. LSB SIZE = 187.5μV.
Definition: ADS1118.h:94
const uint8_t VALID_CFG
Data will be written to Config register.
Definition: ADS1118.h:86
const uint8_t TEMP_MODE
Internal temperature sensor reading mode.
Definition: ADS1118.h:75
uint8_t mux
"MUX" bits
Definition: ADS1118.h:23
const uint8_t RATE_16SPS
16 samples/s, Tconv=62.5ms
Definition: ADS1118.h:104
uint8_t pga
"PGA" bits
Definition: ADS1118.h:22
const uint8_t FSR_0512
Range: ±0.512 v. LSB SIZE = 15.625μV.
Definition: ADS1118.h:98
const uint8_t DIFF_0_1
Differential input: Vin=A0-A1.
Definition: ADS1118.h:56
const uint8_t RATE_475SPS
475 samples/s, Tconv=2.105ms
Definition: ADS1118.h:109
const uint8_t AIN_0
Single ended input: Vin=A0.
Definition: ADS1118.h:61
const uint8_t RATE_128SPS
128 samples/s, Tconv=7.8125ms
Definition: ADS1118.h:107
uint8_t sensorMode
"TS_MODE" bit
Definition: ADS1118.h:19
const uint8_t NO_VALID_CFG
Data won&#39;t be written to Config register.
Definition: ADS1118.h:87
uint8_t lsb
Byte LSB.
Definition: ADS1118.h:28
void disablePullup()
Disabling the internal pull-up resistor of the DOUT pin.
Definition: ADS1118.cpp:226
const uint8_t AIN_1
Single ended input: Vin=A1.
Definition: ADS1118.h:62
uint8_t rate
"DR" bits
Definition: ADS1118.h:20
void begin()
This method initialize the SPI port and the config register.
Definition: ADS1118.cpp:77
const uint8_t DIFF_0_3
Differential input: Vin=A0-A3.
Definition: ADS1118.h:57
void setFullScaleRange(uint8_t fsr)
Setting the full scale range in the config register.
Definition: ADS1118.cpp:197
const uint8_t RATE_860SPS
860 samples/s, Tconv=1.163ms
Definition: ADS1118.h:110
const uint8_t FSR_4096
Range: ±4.096 v. LSB SIZE = 125μV.
Definition: ADS1118.h:95
const uint8_t RATE_8SPS
8 samples/s, Tconv=125ms
Definition: ADS1118.h:103
uint16_t word
Representation in word (16-bits) format.
Definition: ADS1118.h:26
const uint8_t NO_PULLUP
Internal pull-up resistor disabled.
Definition: ADS1118.h:83
const uint8_t ADC_MODE
External (inputs) voltage reading mode.
Definition: ADS1118.h:74
uint8_t noOperation
"NOP" bits
Definition: ADS1118.h:17
struct Config::@0 bits
Structure of the config register of the ADS1118. (See datasheet [1])
const uint8_t FSR_0256
Range: ±0.256 v. LSB SIZE = 7.8125μV.
Definition: ADS1118.h:99
const uint8_t FSR_2048
Range: ±2.048 v. LSB SIZE = 62.5μV ***DEFAULT.
Definition: ADS1118.h:96
void setSampligRate(uint8_t samplingRate)
Setting the sampling rate specified in the config register.
Definition: ADS1118.cpp:189
Definition: ADS1118.h:38
uint8_t reserved
"Reserved" bit
Definition: ADS1118.h:16
double getMilliVolts()
Getting the millivolts from the settled inputs.
Definition: ADS1118.cpp:140
Union configuration register.
Definition: ADS1118.h:13
void setInputSelected(uint8_t input)
Setting the inputs to be adquired in the config register.
Definition: ADS1118.cpp:205
void enablePullup()
Enabling the internal pull-up resistor of the DOUT pin.
Definition: ADS1118.cpp:233
const uint8_t RATE_250SPS
250 samples/s, Tconv=4ms
Definition: ADS1118.h:108
const uint8_t AIN_2
Single ended input: Vin=A2.
Definition: ADS1118.h:63
const uint8_t FSR_1024
Range: ±1.024 v. LSB SIZE = 31.25μV.
Definition: ADS1118.h:97
uint8_t operatingMode
"MODE" bit
Definition: ADS1118.h:21
void setSingleShotMode()
Setting to single shot adquisition and power down mode.
Definition: ADS1118.cpp:219
const uint8_t RATE_64SPS
64 samples/s, Tconv=15.625ms
Definition: ADS1118.h:106
const uint8_t PULLUP
Internal pull-up resistor enabled for DOUT ***DEFAULT.
Definition: ADS1118.h:82
const uint8_t SINGLE_SHOT
Single-shot conversion and power down mode.
Definition: ADS1118.h:79
struct Config::@1 byte
Representation in bytes (8-bits) format.
const uint16_t SCLK
ADS1118 SCLK frequency: 4000000 Hz Maximum for ADS1118.
Definition: ADS1118.h:68
uint8_t msb
Byte MSB.
Definition: ADS1118.h:29
void decodeConfigRegister(union Config configRegister)
Decoding a configRegister structure and then print it out to the Serial port.
Definition: ADS1118.cpp:241
void setContinuousMode()
Setting to continuous adquisition mode.
Definition: ADS1118.cpp:212
uint8_t pullUp
"PULL_UP_EN" bit
Definition: ADS1118.h:18
const uint8_t DIFF_1_3
Differential input: Vin=A1-A3.
Definition: ADS1118.h:58
union Config configRegister
Config register.
Definition: ADS1118.h:65
const uint8_t RESERVED
Its value is always 1, reserved.
Definition: ADS1118.h:90
const uint8_t DIFF_2_3
Differential input: Vin=A2-A3.
Definition: ADS1118.h:59
uint8_t singleStart
"SS" bit
Definition: ADS1118.h:24
const uint8_t START_NOW
Start of conversion in single-shot mode.
Definition: ADS1118.h:71
double getTemperature()
Getting the temperature in degrees celsius from the internal sensor of the ADS1118.
Definition: ADS1118.cpp:158
const uint8_t RATE_32SPS
32 samples/s, Tconv=31.25ms
Definition: ADS1118.h:105
uint16_t getADCValue(uint8_t inputs)
Getting a sample from the specified input.
Definition: ADS1118.cpp:91
ADS1118(uint8_t io_pin_cs)
Constructor.
Definition: ADS1118.cpp:70
const uint8_t CONTINUOUS
Continuous conversion mode.
Definition: ADS1118.h:78