summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ADS1115_WE.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/ADS1115_WE.cpp b/src/ADS1115_WE.cpp
index dc3098b..b7f3918 100644
--- a/src/ADS1115_WE.cpp
+++ b/src/ADS1115_WE.cpp
@@ -37,6 +37,8 @@ bool ADS1115_WE::init(){
}
writeRegister(ADS1115_CONFIG_REG, ADS1115_REG_RESET_VAL);
setVoltageRange_mV(ADS1115_RANGE_2048);
+ writeRegister(ADS1115_LO_THRESH_REG, 0x8000);
+ writeRegister(ADS1115_HI_THRESH_REG, 0x7FFF);
return 1;
}
@@ -88,6 +90,7 @@ void ADS1115_WE::setMeasureMode(ADS1115_MEASURE_MODE mode){
}
void ADS1115_WE::setVoltageRange_mV(ADS1115_RANGE range){
+ uint16_t currentVoltageRange = voltageRange;
switch(range){
case ADS1115_RANGE_6144:
@@ -115,19 +118,20 @@ void ADS1115_WE::setVoltageRange_mV(ADS1115_RANGE range){
uint16_t currentAlertPinMode = currentConfReg & 3;
uint16_t currentCompMode = (currentConfReg>>4) & 1;
+ currentConfReg &= ~(0x0E00);
+ currentConfReg |= range;
+ writeRegister(ADS1115_CONFIG_REG, currentConfReg);
+
if ((currentRange != range) && (currentAlertPinMode != ADS1115_DISABLE_ALERT)){
int16_t alertLimit = readRegister(ADS1115_HI_THRESH_REG);
- alertLimit = (alertLimit/currentRange) * range;
+ alertLimit = alertLimit * (currentVoltageRange * 1.0 / voltageRange);
writeRegister(ADS1115_HI_THRESH_REG, alertLimit);
alertLimit = readRegister(ADS1115_LO_THRESH_REG);
- alertLimit = (alertLimit/currentRange) * range;
+ alertLimit = alertLimit * (currentVoltageRange * 1.0 / voltageRange);
writeRegister(ADS1115_LO_THRESH_REG, alertLimit);
}
- currentConfReg &= ~(0x0E00);
- currentConfReg |= range;
- writeRegister(ADS1115_CONFIG_REG, currentConfReg);
}
void ADS1115_WE::setCompareChannels(ADS1115_MUX mux){