From dad2f630c9bc25a6849ae8dbf65f612a3f647806 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <github@thinkyhead.com>
Date: Wed, 12 Sep 2018 04:27:57 -0500
Subject: [PATCH] Fix raw_filwidth_value error

---
 Marlin/temperature.cpp | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp
index cf28f6d8ba..665e5b5ec9 100644
--- a/Marlin/temperature.cpp
+++ b/Marlin/temperature.cpp
@@ -1743,6 +1743,10 @@ void Temperature::set_current_temp_raw() {
   }
 #endif // PINS_DEBUGGING
 
+#if ENABLED(FILAMENT_WIDTH_SENSOR)
+  uint32_t raw_filwidth_value; // = 0
+#endif
+
 void Temperature::readings_ready() {
   // Update the raw values if they've been read. Else we could be updating them during reading.
   if (!temp_meas_ready) set_current_temp_raw();
@@ -1883,10 +1887,6 @@ void Temperature::isr() {
     ISR_STATICS(BED);
   #endif
 
-  #if ENABLED(FILAMENT_WIDTH_SENSOR)
-    static unsigned long raw_filwidth_value = 0;
-  #endif
-
   #if DISABLED(SLOW_PWM_HEATERS)
     constexpr uint8_t pwm_mask =
       #if ENABLED(SOFT_PWM_DITHER)
@@ -2241,8 +2241,8 @@ void Temperature::isr() {
         if (!HAL_ADC_READY())
           next_sensor_state = adc_sensor_state; // redo this state
         else if (HAL_READ_ADC() > 102) { // Make sure ADC is reading > 0.5 volts, otherwise don't read.
-          raw_filwidth_value -= (raw_filwidth_value >> 7); // Subtract 1/128th of the raw_filwidth_value
-          raw_filwidth_value += ((unsigned long)HAL_READ_ADC() << 7); // Add new ADC reading, scaled by 128
+          raw_filwidth_value -= raw_filwidth_value >> 7; // Subtract 1/128th of the raw_filwidth_value
+          raw_filwidth_value += uint32_t(HAL_READ_ADC()) << 7; // Add new ADC reading, scaled by 128
         }
       break;
     #endif