From d152a892aa5703f6606377c040dd1d9c3a45186b Mon Sep 17 00:00:00 2001 From: JoAnn Manges Date: Wed, 18 Nov 2020 01:07:56 -0500 Subject: [PATCH 1/6] Fix MAX31865 to show RTD resistance values --- Marlin/src/module/temperature.cpp | 16 ++++++++++++---- Marlin/src/module/temperature.h | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index 167b35cc2bac..110e5412794e 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -2204,6 +2204,7 @@ void Temperature::disable_all_heaters() { #define MAX6675_SPEED_BITS 3 // (_BV(SPR1)) // clock ÷ 64 #elif HAS_MAX31865 static uint16_t max6675_temp = 2000; // From datasheet 16 bits D15-D0 + static uint16_t max31865_resistance = 2000; #define MAX6675_ERROR_MASK 1 // D0 Bit not used #define MAX6675_DISCARD_BITS 1 // Data is in D15-D1 #define MAX6675_SPEED_BITS 3 // (_BV(SPR1)) // clock ÷ 64 @@ -2248,10 +2249,7 @@ void Temperature::disable_all_heaters() { #if HAS_MAX31865 Adafruit_MAX31865 &maxref = MAX6675_SEL(max31865_0, max31865_1); - max6675_temp = int(maxref.temperature( - MAX6675_SEL(MAX31865_SENSOR_OHMS_0, MAX31865_SENSOR_OHMS_1), - MAX6675_SEL(MAX31865_CALIBRATION_OHMS_0, MAX31865_CALIBRATION_OHMS_1) - )); + max31865_resistance = convert_rtd_resistance(maxref.readRTD(), MAX6675_SEL(MAX31865_CALIBRATION_OHMS_0, MAX31865_CALIBRATION_OHMS_1)); #endif // @@ -2325,6 +2323,9 @@ void Temperature::disable_all_heaters() { if (max6675_temp & 0x00002000) max6675_temp |= 0xFFFFC000; // Support negative temperature #endif + // return the RTD resistance for MAX31865 for display in SHOW_TEMP_ADC_VALUES + if (HAS_MAX31865) max6675_temp = max31865_resistance; + MAX6675_TEMP(hindex) = max6675_temp; return int(max6675_temp); @@ -2332,6 +2333,13 @@ void Temperature::disable_all_heaters() { #endif // HAS_MAX6675 +/** + * Calculate MAX31865 Resistance value + */ +uint16_t Temperature::convert_rtd_resistance(const float rtd, const int16_t refResistor){ + return (uint16_t) (rtd / 32768.00 * refResistor); +} + /** * Update raw temperatures */ diff --git a/Marlin/src/module/temperature.h b/Marlin/src/module/temperature.h index edaa1c53843a..6ea443e68bb9 100644 --- a/Marlin/src/module/temperature.h +++ b/Marlin/src/module/temperature.h @@ -806,6 +806,7 @@ class Temperature { private: static void update_raw_temperatures(); static void updateTemperaturesFromRawValues(); + static uint16_t convert_rtd_resistance(const float rtd, const int16_t refResistor); #define HAS_MAX6675 EITHER(HEATER_0_USES_MAX6675, HEATER_1_USES_MAX6675) #if HAS_MAX6675 From 4d99ca6694ddc60c54e9fbd4a28135c7995e427f Mon Sep 17 00:00:00 2001 From: JoAnn Manges Date: Wed, 18 Nov 2020 02:56:55 -0500 Subject: [PATCH 2/6] Took out the call statement made 1 line calc. --- Marlin/src/module/temperature.cpp | 9 +-------- Marlin/src/module/temperature.h | 1 - 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index 110e5412794e..46a0aa7280c4 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -2249,7 +2249,7 @@ void Temperature::disable_all_heaters() { #if HAS_MAX31865 Adafruit_MAX31865 &maxref = MAX6675_SEL(max31865_0, max31865_1); - max31865_resistance = convert_rtd_resistance(maxref.readRTD(), MAX6675_SEL(MAX31865_CALIBRATION_OHMS_0, MAX31865_CALIBRATION_OHMS_1)); + max31865_resistance = maxref.readRTD() / 32768.00 * MAX6675_SEL(MAX31865_CALIBRATION_OHMS_0, MAX31865_CALIBRATION_OHMS_1); #endif // @@ -2333,13 +2333,6 @@ void Temperature::disable_all_heaters() { #endif // HAS_MAX6675 -/** - * Calculate MAX31865 Resistance value - */ -uint16_t Temperature::convert_rtd_resistance(const float rtd, const int16_t refResistor){ - return (uint16_t) (rtd / 32768.00 * refResistor); -} - /** * Update raw temperatures */ diff --git a/Marlin/src/module/temperature.h b/Marlin/src/module/temperature.h index 6ea443e68bb9..edaa1c53843a 100644 --- a/Marlin/src/module/temperature.h +++ b/Marlin/src/module/temperature.h @@ -806,7 +806,6 @@ class Temperature { private: static void update_raw_temperatures(); static void updateTemperaturesFromRawValues(); - static uint16_t convert_rtd_resistance(const float rtd, const int16_t refResistor); #define HAS_MAX6675 EITHER(HEATER_0_USES_MAX6675, HEATER_1_USES_MAX6675) #if HAS_MAX6675 From 6d877d0e0a59d3219eaea1d4563b40e913a091f3 Mon Sep 17 00:00:00 2001 From: JoAnn Manges Date: Wed, 18 Nov 2020 03:12:38 -0500 Subject: [PATCH 3/6] fix error --- Marlin/src/module/temperature.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index 46a0aa7280c4..0a120a03eafc 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -2324,7 +2324,9 @@ void Temperature::disable_all_heaters() { #endif // return the RTD resistance for MAX31865 for display in SHOW_TEMP_ADC_VALUES - if (HAS_MAX31865) max6675_temp = max31865_resistance; + #if HAS_MAX31865 + max6675_temp = max31865_resistance; + #endif MAX6675_TEMP(hindex) = max6675_temp; From f97d42ab0e5429b863e49f678ddee510a7d22789 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 18 Nov 2020 23:01:40 -0600 Subject: [PATCH 4/6] Update temperature.cpp --- Marlin/src/module/temperature.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index 0a120a03eafc..b4f01c78b340 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -2204,7 +2204,7 @@ void Temperature::disable_all_heaters() { #define MAX6675_SPEED_BITS 3 // (_BV(SPR1)) // clock ÷ 64 #elif HAS_MAX31865 static uint16_t max6675_temp = 2000; // From datasheet 16 bits D15-D0 - static uint16_t max31865_resistance = 2000; + static uint16_t max31865_ohms = 2000; #define MAX6675_ERROR_MASK 1 // D0 Bit not used #define MAX6675_DISCARD_BITS 1 // Data is in D15-D1 #define MAX6675_SPEED_BITS 3 // (_BV(SPR1)) // clock ÷ 64 @@ -2249,7 +2249,7 @@ void Temperature::disable_all_heaters() { #if HAS_MAX31865 Adafruit_MAX31865 &maxref = MAX6675_SEL(max31865_0, max31865_1); - max31865_resistance = maxref.readRTD() / 32768.00 * MAX6675_SEL(MAX31865_CALIBRATION_OHMS_0, MAX31865_CALIBRATION_OHMS_1); + max31865_ohms = maxref.readRTD() / 32768.0f * MAX6675_SEL(MAX31865_CALIBRATION_OHMS_0, MAX31865_CALIBRATION_OHMS_1); #endif // @@ -2323,10 +2323,8 @@ void Temperature::disable_all_heaters() { if (max6675_temp & 0x00002000) max6675_temp |= 0xFFFFC000; // Support negative temperature #endif - // return the RTD resistance for MAX31865 for display in SHOW_TEMP_ADC_VALUES - #if HAS_MAX31865 - max6675_temp = max31865_resistance; - #endif + // Return the RTD resistance for MAX31865 for display in SHOW_TEMP_ADC_VALUES + TERN_(HAS_MAX31865, max6675_temp = max31865_ohms); MAX6675_TEMP(hindex) = max6675_temp; From 2beb040453d627e70ed92db94ee030daba5f2eae Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 18 Nov 2020 23:05:41 -0600 Subject: [PATCH 5/6] Update temperature.cpp --- Marlin/src/module/temperature.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index b4f01c78b340..d12658f14103 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -2204,7 +2204,6 @@ void Temperature::disable_all_heaters() { #define MAX6675_SPEED_BITS 3 // (_BV(SPR1)) // clock ÷ 64 #elif HAS_MAX31865 static uint16_t max6675_temp = 2000; // From datasheet 16 bits D15-D0 - static uint16_t max31865_ohms = 2000; #define MAX6675_ERROR_MASK 1 // D0 Bit not used #define MAX6675_DISCARD_BITS 1 // Data is in D15-D1 #define MAX6675_SPEED_BITS 3 // (_BV(SPR1)) // clock ÷ 64 @@ -2249,7 +2248,7 @@ void Temperature::disable_all_heaters() { #if HAS_MAX31865 Adafruit_MAX31865 &maxref = MAX6675_SEL(max31865_0, max31865_1); - max31865_ohms = maxref.readRTD() / 32768.0f * MAX6675_SEL(MAX31865_CALIBRATION_OHMS_0, MAX31865_CALIBRATION_OHMS_1); + const uint16_t max31865_ohms = maxref.readRTD() / 32768.0f * MAX6675_SEL(MAX31865_CALIBRATION_OHMS_0, MAX31865_CALIBRATION_OHMS_1); #endif // From f8581539cfbdc3b625b433e366f2f265b3ca1997 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 18 Nov 2020 23:10:01 -0600 Subject: [PATCH 6/6] int maths --- Marlin/src/module/temperature.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index d12658f14103..19de70b31c52 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -2248,7 +2248,7 @@ void Temperature::disable_all_heaters() { #if HAS_MAX31865 Adafruit_MAX31865 &maxref = MAX6675_SEL(max31865_0, max31865_1); - const uint16_t max31865_ohms = maxref.readRTD() / 32768.0f * MAX6675_SEL(MAX31865_CALIBRATION_OHMS_0, MAX31865_CALIBRATION_OHMS_1); + const uint16_t max31865_ohms = (uint32_t(maxref.readRTD()) * MAX6675_SEL(MAX31865_CALIBRATION_OHMS_0, MAX31865_CALIBRATION_OHMS_1)) >> 16; #endif //