Browse Source

Fix FILAMENT_WIDTH_SENSOR infinite loop issue

Addressing #6992 and #5851
Scott Lahteine 8 years ago
parent
commit
a9f8e518bf
5 changed files with 15 additions and 15 deletions
  1. 3
    3
      Marlin/Marlin.h
  2. 5
    5
      Marlin/Marlin_main.cpp
  3. 2
    2
      Marlin/planner.cpp
  4. 3
    3
      Marlin/temperature.cpp
  5. 2
    2
      Marlin/temperature.h

+ 3
- 3
Marlin/Marlin.h View File

@@ -370,9 +370,9 @@ extern float soft_endstop_min[XYZ], soft_endstop_max[XYZ];
370 370
   extern bool filament_sensor;         // Flag that filament sensor readings should control extrusion
371 371
   extern float filament_width_nominal, // Theoretical filament diameter i.e., 3.00 or 1.75
372 372
                filament_width_meas;    // Measured filament diameter
373
-  extern int8_t measurement_delay[];   // Ring buffer to delay measurement
374
-  extern int filwidth_delay_index[2];  // Ring buffer indexes. Used by planner, temperature, and main code
375
-  extern int meas_delay_cm;            // Delay distance
373
+  extern uint8_t meas_delay_cm,        // Delay distance
374
+                 measurement_delay[];  // Ring buffer to delay measurement
375
+  extern int8_t filwidth_delay_index[2]; // Ring buffer indexes. Used by planner, temperature, and main code
376 376
 #endif
377 377
 
378 378
 #if ENABLED(ADVANCED_PAUSE_FEATURE)

+ 5
- 5
Marlin/Marlin_main.cpp View File

@@ -630,9 +630,9 @@ float cartes[XYZ] = { 0 };
630 630
   bool filament_sensor = false;                                 // M405 turns on filament sensor control. M406 turns it off.
631 631
   float filament_width_nominal = DEFAULT_NOMINAL_FILAMENT_DIA,  // Nominal filament width. Change with M404.
632 632
         filament_width_meas = DEFAULT_MEASURED_FILAMENT_DIA;    // Measured filament diameter
633
-  int8_t measurement_delay[MAX_MEASUREMENT_DELAY + 1];          // Ring buffer to delayed measurement. Store extruder factor after subtracting 100
634
-  int filwidth_delay_index[2] = { 0, -1 };                      // Indexes into ring buffer
635
-  int meas_delay_cm = MEASUREMENT_DELAY_CM;                     // Distance delay setting
633
+  uint8_t meas_delay_cm = MEASUREMENT_DELAY_CM,                 // Distance delay setting
634
+          measurement_delay[MAX_MEASUREMENT_DELAY + 1];         // Ring buffer to delayed measurement. Store extruder factor after subtracting 100
635
+  int8_t filwidth_delay_index[2] = { 0, -1 };                   // Indexes into ring buffer
636 636
 #endif
637 637
 
638 638
 #if ENABLED(FILAMENT_RUNOUT_SENSOR)
@@ -8898,11 +8898,11 @@ inline void gcode_M400() { stepper.synchronize(); }
8898 8898
   inline void gcode_M405() {
8899 8899
     // This is technically a linear measurement, but since it's quantized to centimeters and is a different unit than
8900 8900
     // everything else, it uses parser.value_int() instead of parser.value_linear_units().
8901
-    if (parser.seen('D')) meas_delay_cm = parser.value_int();
8901
+    if (parser.seen('D')) meas_delay_cm = parser.value_byte();
8902 8902
     NOMORE(meas_delay_cm, MAX_MEASUREMENT_DELAY);
8903 8903
 
8904 8904
     if (filwidth_delay_index[1] == -1) { // Initialize the ring buffer if not done since startup
8905
-      const int temp_ratio = thermalManager.widthFil_to_size_ratio() - 100; // -100 to scale within a signed byte
8905
+      const uint8_t temp_ratio = thermalManager.widthFil_to_size_ratio() - 100; // -100 to scale within a signed byte
8906 8906
 
8907 8907
       for (uint8_t i = 0; i < COUNT(measurement_delay); ++i)
8908 8908
         measurement_delay[i] = temp_ratio;

+ 2
- 2
Marlin/planner.cpp View File

@@ -1103,12 +1103,12 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1103 1103
         while (filwidth_delay_dist >= MMD_MM) filwidth_delay_dist -= MMD_MM;
1104 1104
 
1105 1105
         // Convert into an index into the measurement array
1106
-        filwidth_delay_index[0] = (int)(filwidth_delay_dist * 0.1 + 0.0001);
1106
+        filwidth_delay_index[0] = int8_t(filwidth_delay_dist * 0.1);
1107 1107
 
1108 1108
         // If the index has changed (must have gone forward)...
1109 1109
         if (filwidth_delay_index[0] != filwidth_delay_index[1]) {
1110 1110
           filwidth_e_count = 0; // Reset the E movement counter
1111
-          const int8_t meas_sample = thermalManager.widthFil_to_size_ratio() - 100; // Subtract 100 to reduce magnitude - to store in a signed char
1111
+          const uint8_t meas_sample = thermalManager.widthFil_to_size_ratio() - 100; // Subtract 100 to reduce magnitude - to store in a signed char
1112 1112
           do {
1113 1113
             filwidth_delay_index[1] = (filwidth_delay_index[1] + 1) % MMD_CM; // The next unused slot
1114 1114
             measurement_delay[filwidth_delay_index[1]] = meas_sample;         // Store the measurement

+ 3
- 3
Marlin/temperature.cpp View File

@@ -180,7 +180,7 @@ int16_t Temperature::minttemp_raw[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_RAW_LO_TE
180 180
 #endif
181 181
 
182 182
 #if ENABLED(FILAMENT_WIDTH_SENSOR)
183
-  int16_t Temperature::meas_shift_index;  // Index of a delayed sample in buffer
183
+  int8_t Temperature::meas_shift_index;  // Index of a delayed sample in buffer
184 184
 #endif
185 185
 
186 186
 #if HAS_AUTO_FAN
@@ -196,7 +196,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS],
196 196
 #endif
197 197
 
198 198
 #if ENABLED(FILAMENT_WIDTH_SENSOR)
199
-  int Temperature::current_raw_filwidth = 0;  //Holds measured filament diameter - one extruder only
199
+  uint16_t Temperature::current_raw_filwidth = 0; // Measured filament diameter - one extruder only
200 200
 #endif
201 201
 
202 202
 #if ENABLED(PROBING_HEATERS_OFF)
@@ -957,7 +957,7 @@ void Temperature::updateTemperaturesFromRawValues() {
957 957
 
958 958
   // Convert raw Filament Width to millimeters
959 959
   float Temperature::analog2widthFil() {
960
-    return current_raw_filwidth / 16383.0 * 5.0;
960
+    return current_raw_filwidth * 5.0 * (1.0 / 16383.0);
961 961
     //return current_raw_filwidth;
962 962
   }
963 963
 

+ 2
- 2
Marlin/temperature.h View File

@@ -247,7 +247,7 @@ class Temperature {
247 247
     #endif
248 248
 
249 249
     #if ENABLED(FILAMENT_WIDTH_SENSOR)
250
-      static int16_t meas_shift_index;  // Index of a delayed sample in buffer
250
+      static int8_t meas_shift_index;  // Index of a delayed sample in buffer
251 251
     #endif
252 252
 
253 253
     #if HAS_AUTO_FAN
@@ -255,7 +255,7 @@ class Temperature {
255 255
     #endif
256 256
 
257 257
     #if ENABLED(FILAMENT_WIDTH_SENSOR)
258
-      static int current_raw_filwidth;  //Holds measured filament diameter - one extruder only
258
+      static uint16_t current_raw_filwidth; // Measured filament diameter - one extruder only
259 259
     #endif
260 260
 
261 261
     #if ENABLED(PROBING_HEATERS_OFF)

Loading…
Cancel
Save