summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWolfgang (Wolle) Ewald <wolfgang.ewald@wolles-elektronikkiste.de>2020-07-02 21:36:50 +0200
committerGitHub <noreply@github.com>2020-07-02 21:36:50 +0200
commit6adeb07209e7f6c4300653dbf3be1c40107e9b4c (patch)
tree3ae066be5a29749297491db2f31991a6f4818a55 /src
parentUpdate library.properties (diff)
downloadADS1115_WE-6adeb07209e7f6c4300653dbf3be1c40107e9b4c.tar
ADS1115_WE-6adeb07209e7f6c4300653dbf3be1c40107e9b4c.tar.gz
ADS1115_WE-6adeb07209e7f6c4300653dbf3be1c40107e9b4c.tar.bz2
ADS1115_WE-6adeb07209e7f6c4300653dbf3be1c40107e9b4c.tar.lz
ADS1115_WE-6adeb07209e7f6c4300653dbf3be1c40107e9b4c.tar.xz
ADS1115_WE-6adeb07209e7f6c4300653dbf3be1c40107e9b4c.tar.zst
ADS1115_WE-6adeb07209e7f6c4300653dbf3be1c40107e9b4c.zip
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){