From 518b47683023ccc2df591a3c6bfaba25890ff7bf Mon Sep 17 00:00:00 2001 From: SV-Zanshin Date: Fri, 18 Jan 2019 08:21:10 +0000 Subject: [PATCH] Fix issue #38 The calculation of the "trim" value during calibration had an error with overflow which has been addressed --- src/MCP7940.cpp | 10 +++++----- src/MCP7940.h | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/MCP7940.cpp b/src/MCP7940.cpp index 9104b50..94db5c4 100644 --- a/src/MCP7940.cpp +++ b/src/MCP7940.cpp @@ -494,7 +494,7 @@ int8_t MCP7940_Class::calibrate(const DateTime& dt) { // return calibrate((const int8_t)trim); // // } // of method calibrate() //----------------------------------// int8_t MCP7940_Class::calibrate(const float fMeas) { // Calibrate according to frequency // - int8_t trim = getCalibrationTrim(); // Get the current trim // + int16_t trim = getCalibrationTrim(); // Get the current trim // uint32_t fIdeal = getSQWSpeed(); // read the current SQW Speed code // switch (fIdeal) { // set variable to real SQW speed // case 0: fIdeal = 1; // // @@ -509,10 +509,10 @@ int8_t MCP7940_Class::calibrate(const float fMeas) { // case 4: fIdeal = 64; // // } // of switch SQWSpeed value // // trim += ((fMeas-(float)fIdeal) * (32768.0/fIdeal) * 60.0) / 2.0; // Use formula from datasheet // - if (trim > 130) { // Force number ppm to be in range // - trim = 130; // // - } else if (trim < -130) { // check for low out-of-bounds too // - trim = -130; // // + if (trim > 127) { // Force number ppm to be in range // + trim = 127; // // + } else if (trim < -128) { // check for low out-of-bounds too // + trim = -128; // // } // of if-then-else trim out of range // // trim = calibrate(trim); // Set the new trim value // return(trim); // // diff --git a/src/MCP7940.h b/src/MCP7940.h index d2c20ca..b2bbccb 100644 --- a/src/MCP7940.h +++ b/src/MCP7940.h @@ -24,6 +24,7 @@ ** ** ** Vers. Date Developer Github ID Comments ** ** ====== ========== =================== ======================================================================== ** +** 1.1.5 2019-01-18 INemesisI Issue #38 - Overflow on setting new TRIM value ** ** 1.1.4 2018-12-15 hexeguitar Issue #36 - Overflow on I2C_MODES datatype corrected ** ** 1.1.4 2018-12-15 huynh213 Issue #35 - MCP7940.adjust() function resets the PWRFAIL and VBATEN ** ** 1.1.3 2018-08-08 amgrays Issue #32 - invalid return on SetMFP corrected **