Skip to content

Commit

Permalink
Fix issue #38
Browse files Browse the repository at this point in the history
The calculation of the "trim" value during calibration had an error with overflow which has been addressed
  • Loading branch information
SV-Zanshin authored and SV-Zanshin committed Jan 18, 2019
1 parent 0678a66 commit 518b476
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/MCP7940.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; // //
Expand All @@ -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); // //
Expand Down
1 change: 1 addition & 0 deletions src/MCP7940.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 **
Expand Down

0 comments on commit 518b476

Please sign in to comment.