@@ -69,7 +69,7 @@ boolean SFE_ADS122C04::begin(uint8_t deviceAddress, TwoWire &wirePort)
69
69
}
70
70
71
71
// Configure the chip for the selected wire mode
72
- boolean SFE_ADS122C04::configureADCmode (uint8_t wire_mode)
72
+ boolean SFE_ADS122C04::configureADCmode (uint8_t wire_mode, uint8_t rate )
73
73
{
74
74
ADS122C04_initParam initParams; // Storage for the chip parameters
75
75
@@ -78,7 +78,7 @@ boolean SFE_ADS122C04::configureADCmode(uint8_t wire_mode)
78
78
initParams.inputMux = ADS122C04_MUX_AIN1_AIN0; // Route AIN1 to AINP and AIN0 to AINN
79
79
initParams.gainLevel = ADS122C04_GAIN_8; // Set the gain to 8
80
80
initParams.pgaBypass = ADS122C04_PGA_ENABLED; // The PGA must be enabled for gains >= 8
81
- initParams.dataRate = ADS122C04_DATA_RATE_20SPS ; // Set the data rate (samples per second) to 20
81
+ initParams.dataRate = rate ; // Set the data rate (samples per second). Defaults to 20
82
82
initParams.opMode = ADS122C04_OP_MODE_NORMAL; // Disable turbo mode
83
83
initParams.convMode = ADS122C04_CONVERSION_MODE_SINGLE_SHOT; // Use single shot mode
84
84
initParams.selectVref = ADS122C04_VREF_EXT_REF_PINS; // Use the external REF pins
@@ -96,7 +96,7 @@ boolean SFE_ADS122C04::configureADCmode(uint8_t wire_mode)
96
96
initParams.inputMux = ADS122C04_MUX_AIN1_AIN0; // Route AIN1 to AINP and AIN0 to AINN
97
97
initParams.gainLevel = ADS122C04_GAIN_4; // Set the gain to 4
98
98
initParams.pgaBypass = ADS122C04_PGA_ENABLED; // Enable the PGA
99
- initParams.dataRate = ADS122C04_DATA_RATE_20SPS ; // Set the data rate (samples per second) to 20
99
+ initParams.dataRate = rate ; // Set the data rate (samples per second). Defaults to 20
100
100
initParams.opMode = ADS122C04_OP_MODE_NORMAL; // Disable turbo mode
101
101
initParams.convMode = ADS122C04_CONVERSION_MODE_SINGLE_SHOT; // Use single shot mode
102
102
initParams.selectVref = ADS122C04_VREF_EXT_REF_PINS; // Use the external REF pins
@@ -114,7 +114,7 @@ boolean SFE_ADS122C04::configureADCmode(uint8_t wire_mode)
114
114
initParams.inputMux = ADS122C04_MUX_AIN1_AIN0; // Route AIN1 to AINP and AIN0 to AINN
115
115
initParams.gainLevel = ADS122C04_GAIN_8; // Set the gain to 8
116
116
initParams.pgaBypass = ADS122C04_PGA_ENABLED; // The PGA must be enabled for gains >= 8
117
- initParams.dataRate = ADS122C04_DATA_RATE_20SPS ; // Set the data rate (samples per second) to 20
117
+ initParams.dataRate = rate ; // Set the data rate (samples per second). Defaults to 20
118
118
initParams.opMode = ADS122C04_OP_MODE_NORMAL; // Disable turbo mode
119
119
initParams.convMode = ADS122C04_CONVERSION_MODE_SINGLE_SHOT; // Use single shot mode
120
120
initParams.selectVref = ADS122C04_VREF_EXT_REF_PINS; // Use the external REF pins
@@ -132,7 +132,7 @@ boolean SFE_ADS122C04::configureADCmode(uint8_t wire_mode)
132
132
initParams.inputMux = ADS122C04_MUX_AIN1_AIN0; // Route AIN1 to AINP and AIN0 to AINN
133
133
initParams.gainLevel = ADS122C04_GAIN_4; // Set the gain to 4
134
134
initParams.pgaBypass = ADS122C04_PGA_ENABLED; // Enable the PGA
135
- initParams.dataRate = ADS122C04_DATA_RATE_20SPS ; // Set the data rate (samples per second) to 20
135
+ initParams.dataRate = rate ; // Set the data rate (samples per second). Defaults to 20
136
136
initParams.opMode = ADS122C04_OP_MODE_NORMAL; // Disable turbo mode
137
137
initParams.convMode = ADS122C04_CONVERSION_MODE_SINGLE_SHOT; // Use single shot mode
138
138
initParams.selectVref = ADS122C04_VREF_EXT_REF_PINS; // Use the external REF pins
@@ -150,7 +150,7 @@ boolean SFE_ADS122C04::configureADCmode(uint8_t wire_mode)
150
150
initParams.inputMux = ADS122C04_MUX_AIN1_AIN0; // Route AIN1 to AINP and AIN0 to AINN
151
151
initParams.gainLevel = ADS122C04_GAIN_8; // Set the gain to 8
152
152
initParams.pgaBypass = ADS122C04_PGA_ENABLED; // The PGA must be enabled for gains >= 8
153
- initParams.dataRate = ADS122C04_DATA_RATE_20SPS ; // Set the data rate (samples per second) to 20
153
+ initParams.dataRate = rate ; // Set the data rate (samples per second). Defaults to 20
154
154
initParams.opMode = ADS122C04_OP_MODE_NORMAL; // Disable turbo mode
155
155
initParams.convMode = ADS122C04_CONVERSION_MODE_SINGLE_SHOT; // Use single shot mode
156
156
initParams.selectVref = ADS122C04_VREF_EXT_REF_PINS; // Use the external REF pins
@@ -168,7 +168,7 @@ boolean SFE_ADS122C04::configureADCmode(uint8_t wire_mode)
168
168
initParams.inputMux = ADS122C04_MUX_AIN1_AIN0; // Route AIN1 to AINP and AIN0 to AINN
169
169
initParams.gainLevel = ADS122C04_GAIN_4; // Set the gain to 4
170
170
initParams.pgaBypass = ADS122C04_PGA_ENABLED; // Enable the PGA
171
- initParams.dataRate = ADS122C04_DATA_RATE_20SPS ; // Set the data rate (samples per second) to 20
171
+ initParams.dataRate = rate ; // Set the data rate (samples per second). Defaults to 20
172
172
initParams.opMode = ADS122C04_OP_MODE_NORMAL; // Disable turbo mode
173
173
initParams.convMode = ADS122C04_CONVERSION_MODE_SINGLE_SHOT; // Use single shot mode
174
174
initParams.selectVref = ADS122C04_VREF_EXT_REF_PINS; // Use the external REF pins
@@ -186,7 +186,7 @@ boolean SFE_ADS122C04::configureADCmode(uint8_t wire_mode)
186
186
initParams.inputMux = ADS122C04_MUX_AIN1_AIN0; // Route AIN1 to AINP and AIN0 to AINN
187
187
initParams.gainLevel = ADS122C04_GAIN_1; // Set the gain to 1
188
188
initParams.pgaBypass = ADS122C04_PGA_DISABLED;
189
- initParams.dataRate = ADS122C04_DATA_RATE_20SPS ; // Set the data rate (samples per second) to 20
189
+ initParams.dataRate = rate ; // Set the data rate (samples per second). Defaults to 20
190
190
initParams.opMode = ADS122C04_OP_MODE_NORMAL; // Disable turbo mode
191
191
initParams.convMode = ADS122C04_CONVERSION_MODE_SINGLE_SHOT; // Use single shot mode
192
192
initParams.selectVref = ADS122C04_VREF_INTERNAL; // Use the internal 2.048V reference
@@ -204,7 +204,7 @@ boolean SFE_ADS122C04::configureADCmode(uint8_t wire_mode)
204
204
initParams.inputMux = ADS122C04_MUX_AIN1_AIN0; // Route AIN1 to AINP and AIN0 to AINN
205
205
initParams.gainLevel = ADS122C04_GAIN_1; // Set the gain to 1
206
206
initParams.pgaBypass = ADS122C04_PGA_DISABLED;
207
- initParams.dataRate = ADS122C04_DATA_RATE_20SPS ; // Set the data rate (samples per second) to 20
207
+ initParams.dataRate = rate ; // Set the data rate (samples per second). Defaults to 20
208
208
initParams.opMode = ADS122C04_OP_MODE_NORMAL; // Disable turbo mode
209
209
initParams.convMode = ADS122C04_CONVERSION_MODE_SINGLE_SHOT; // Use single shot mode
210
210
initParams.selectVref = ADS122C04_VREF_INTERNAL; // Use the internal 2.048V reference
@@ -373,16 +373,17 @@ float SFE_ADS122C04::readPT100Fahrenheit(void) // Read the temperature in Fahren
373
373
374
374
// Read the raw signed 24-bit ADC value as int32_t
375
375
// The result needs to be multiplied by VREF / GAIN to convert to Volts
376
- int32_t SFE_ADS122C04::readRawVoltage (void )
376
+ int32_t SFE_ADS122C04::readRawVoltage (uint8_t rate )
377
377
{
378
378
raw_voltage_union raw_v; // union to convert uint32_t to int32_t
379
379
unsigned long start_time = millis (); // Record the start time so we can timeout
380
380
boolean drdy = false ; // DRDY (1 == new data is ready)
381
381
uint8_t previousWireMode = _wireMode; // Record the previous wire mode so we can restore it
382
+ uint8_t previousRate = ADS122C04_Reg.reg1 .bit .DR ; // Record the previous rate so we can restore it
382
383
383
384
// Configure the ADS122C04 for raw mode
384
385
// Disable the IDAC, use the internal 2.048V reference and set the gain to 1
385
- if ((configureADCmode (ADS122C04_RAW_MODE)) == false )
386
+ if ((configureADCmode (ADS122C04_RAW_MODE, rate )) == false )
386
387
{
387
388
if (_printDebug == true )
388
389
{
@@ -408,7 +409,7 @@ int32_t SFE_ADS122C04::readRawVoltage(void)
408
409
{
409
410
_debugPort->println (F (" readRawVoltage: checkDataReady timed out" ));
410
411
}
411
- configureADCmode (previousWireMode); // Attempt to restore the previous wire mode
412
+ configureADCmode (previousWireMode, previousRate ); // Attempt to restore the previous wire mode
412
413
return (0 );
413
414
}
414
415
@@ -419,12 +420,12 @@ int32_t SFE_ADS122C04::readRawVoltage(void)
419
420
{
420
421
_debugPort->println (F (" readRawVoltage: ADS122C04_getConversionData failed" ));
421
422
}
422
- configureADCmode (previousWireMode); // Attempt to restore the previous wire mode
423
+ configureADCmode (previousWireMode, previousRate ); // Attempt to restore the previous wire mode
423
424
return (0 );
424
425
}
425
426
426
427
// Restore the previous wire mode
427
- if ((configureADCmode (previousWireMode)) == false )
428
+ if ((configureADCmode (previousWireMode, previousRate )) == false )
428
429
{
429
430
if (_printDebug == true )
430
431
{
@@ -463,18 +464,19 @@ uint32_t SFE_ADS122C04::readADC(void)
463
464
}
464
465
465
466
// Read the internal temperature
466
- float SFE_ADS122C04::readInternalTemperature (void )
467
+ float SFE_ADS122C04::readInternalTemperature (uint8_t rate )
467
468
{
468
469
internal_temperature_union int_temp; // union to convert uint16_t to int16_t
469
470
uint32_t raw_temp; // The raw temperature from the ADC
470
471
unsigned long start_time = millis (); // Record the start time so we can timeout
471
472
boolean drdy = false ; // DRDY (1 == new data is ready)
472
473
float ret_val = 0.0 ; // The return value
473
474
uint8_t previousWireMode = _wireMode; // Record the previous wire mode so we can restore it
475
+ uint8_t previousRate = ADS122C04_Reg.reg1 .bit .DR ; // Record the previous rate so we can restore it
474
476
475
477
// Enable the internal temperature sensor
476
478
// Reading the ADC value will return the temperature
477
- if ((configureADCmode (ADS122C04_TEMPERATURE_MODE)) == false )
479
+ if ((configureADCmode (ADS122C04_TEMPERATURE_MODE, rate )) == false )
478
480
{
479
481
if (_printDebug == true )
480
482
{
@@ -500,7 +502,7 @@ float SFE_ADS122C04::readInternalTemperature(void)
500
502
{
501
503
_debugPort->println (F (" readInternalTemperature: checkDataReady timed out" ));
502
504
}
503
- configureADCmode (previousWireMode); // Attempt to restore the previous wire mode
505
+ configureADCmode (previousWireMode, previousRate ); // Attempt to restore the previous wire mode
504
506
return (ret_val);
505
507
}
506
508
@@ -511,12 +513,12 @@ float SFE_ADS122C04::readInternalTemperature(void)
511
513
{
512
514
_debugPort->println (F (" readInternalTemperature: ADS122C04_getConversionData failed" ));
513
515
}
514
- configureADCmode (previousWireMode); // Attempt to restore the previous wire mode
516
+ configureADCmode (previousWireMode, previousRate ); // Attempt to restore the previous wire mode
515
517
return (ret_val);
516
518
}
517
519
518
520
// Restore the previous wire mode
519
- if ((configureADCmode (previousWireMode)) == false )
521
+ if ((configureADCmode (previousWireMode, previousRate )) == false )
520
522
{
521
523
if (_printDebug == true )
522
524
{
0 commit comments