Browse Source

Filament Runout Sensor Feature

With this change a mechanical or optical switch may be used to check the
availability of the filament and when the filament runs out an M600
(filament change) command is issued. This is only done while printing
with an SD card.

This feature was requested several times (issue #679), but the requests
were not accepted since it was believed that this situation should be
handled at host side. However during an SD print the control is totally
on firmware and I think that during an SD print it should be handled by
the firmware.

The original code was posted at reprap forum
(http://forums.reprap.org/read.php?1,297350) by Lazymonk. I have only
corrected some bugs of the code and improved it by adding definitions to
the configuration.h in order to make it more standardized.
Mehmet Sutas 10 years ago
parent
commit
cfc6a3a87a
4 changed files with 54 additions and 0 deletions
  1. 9
    0
      Marlin/Configuration.h
  2. 4
    0
      Marlin/Marlin.h
  3. 36
    0
      Marlin/Marlin_main.cpp
  4. 5
    0
      Marlin/pins_RAMPS_13.h

+ 9
- 0
Marlin/Configuration.h View File

375
 #define Y_MAX_LENGTH (Y_MAX_POS - Y_MIN_POS)
375
 #define Y_MAX_LENGTH (Y_MAX_POS - Y_MIN_POS)
376
 #define Z_MAX_LENGTH (Z_MAX_POS - Z_MIN_POS)
376
 #define Z_MAX_LENGTH (Z_MAX_POS - Z_MIN_POS)
377
 
377
 
378
+//===========================================================================
379
+//============================= Filament Runout Sensor ======================
380
+//===========================================================================
381
+//#define FILAMENT_RUNOUT_SENSOR // Uncomment for defining a filament runout sensor such as a mechanical or opto endstop to check the existence of filament
382
+                                 // In RAMPS uses servo pin 2. Can be changed in pins file. For other boards pin definition should be made.
383
+                                 // It is assumed that when logic high = filament available
384
+                                 //                    when logic  low = filament ran out
385
+//const bool FIL_RUNOUT_INVERTING = true;  // Should be uncommented and true or false should assigned
386
+//#define ENDSTOPPULLUP_FIL_RUNOUT // Uncomment to use internal pullup for filament runout pins if the sensor is defined.
378
 
387
 
379
 //===========================================================================
388
 //===========================================================================
380
 //============================= Bed Auto Leveling ===========================
389
 //============================= Bed Auto Leveling ===========================

+ 4
- 0
Marlin/Marlin.h View File

199
 void kill();
199
 void kill();
200
 void Stop();
200
 void Stop();
201
 
201
 
202
+#ifdef FILAMENT_RUNOUT_SENSOR
203
+void filrunout();
204
+#endif
205
+
202
 bool IsStopped();
206
 bool IsStopped();
203
 
207
 
204
 bool enquecommand(const char *cmd); //put a single ASCII command at the end of the current buffer or return false when it is full
208
 bool enquecommand(const char *cmd); //put a single ASCII command at the end of the current buffer or return false when it is full

+ 36
- 0
Marlin/Marlin_main.cpp View File

366
   int meas_delay_cm = MEASUREMENT_DELAY_CM;  //distance delay setting
366
   int meas_delay_cm = MEASUREMENT_DELAY_CM;  //distance delay setting
367
 #endif
367
 #endif
368
 
368
 
369
+#ifdef FILAMENT_RUNOUT_SENSOR
370
+   static bool filrunoutEnqued = false;
371
+#endif
372
+
369
 const char errormagic[] PROGMEM = "Error:";
373
 const char errormagic[] PROGMEM = "Error:";
370
 const char echomagic[] PROGMEM = "echo:";
374
 const char echomagic[] PROGMEM = "echo:";
371
 
375
 
525
   #endif
529
   #endif
526
 }
530
 }
527
 
531
 
532
+void setup_filrunoutpin()
533
+{
534
+#if defined(FILRUNOUT_PIN) && FILRUNOUT_PIN > -1
535
+   pinMode(FILRUNOUT_PIN,INPUT);
536
+   #if defined(ENDSTOPPULLUP_FIL_RUNOUT)
537
+      WRITE(FILLRUNOUT_PIN,HIGH);
538
+   #endif
539
+#endif
540
+}
541
+
528
 // Set home pin
542
 // Set home pin
529
 void setup_homepin(void)
543
 void setup_homepin(void)
530
 {
544
 {
601
 void setup()
615
 void setup()
602
 {
616
 {
603
   setup_killpin();
617
   setup_killpin();
618
+  setup_filrunoutpin();
604
   setup_powerhold();
619
   setup_powerhold();
605
   MYSERIAL.begin(BAUDRATE);
620
   MYSERIAL.begin(BAUDRATE);
606
   SERIAL_PROTOCOLLNPGM("start");
621
   SERIAL_PROTOCOLLNPGM("start");
4091
       plan_buffer_line(lastpos[X_AXIS], lastpos[Y_AXIS], lastpos[Z_AXIS], target[E_AXIS], fr60, active_extruder); //move z back
4106
       plan_buffer_line(lastpos[X_AXIS], lastpos[Y_AXIS], lastpos[Z_AXIS], target[E_AXIS], fr60, active_extruder); //move z back
4092
       plan_buffer_line(lastpos[X_AXIS], lastpos[Y_AXIS], lastpos[Z_AXIS], lastpos[E_AXIS], fr60, active_extruder); //final untretract
4107
       plan_buffer_line(lastpos[X_AXIS], lastpos[Y_AXIS], lastpos[Z_AXIS], lastpos[E_AXIS], fr60, active_extruder); //final untretract
4093
     #endif        
4108
     #endif        
4109
+
4110
+    #ifdef FILAMENT_RUNOUT_SENSOR
4111
+      filrunoutEnqued = false;
4112
+    #endif
4113
+    
4094
   }
4114
   }
4095
 
4115
 
4096
 #endif // FILAMENTCHANGEENABLE
4116
 #endif // FILAMENTCHANGEENABLE
5230
    const int KILL_DELAY = 10000;
5250
    const int KILL_DELAY = 10000;
5231
 #endif
5251
 #endif
5232
 
5252
 
5253
+#if defined(FILRUNOUT_PIN) && FILRUNOUT_PIN > -1
5254
+    if(card.sdprinting) {
5255
+      if(!(READ(FILRUNOUT_PIN))^FIL_RUNOUT_INVERTING)
5256
+      filrunout();        }
5257
+#endif
5258
+
5233
 #if defined(HOME_PIN) && HOME_PIN > -1
5259
 #if defined(HOME_PIN) && HOME_PIN > -1
5234
    static int homeDebounceCount = 0;   // poor man's debouncing count
5260
    static int homeDebounceCount = 0;   // poor man's debouncing count
5235
    const int HOME_DEBOUNCE_DELAY = 10000;
5261
    const int HOME_DEBOUNCE_DELAY = 10000;
5378
   while(1) { /* Intentionally left empty */ } // Wait for reset
5404
   while(1) { /* Intentionally left empty */ } // Wait for reset
5379
 }
5405
 }
5380
 
5406
 
5407
+#ifdef FILAMENT_RUNOUT_SENSOR
5408
+   void filrunout()
5409
+   {
5410
+      if filrunoutEnqued == false {
5411
+         filrunoutEnqued = true;
5412
+         enquecommand("M600");
5413
+      }
5414
+   }
5415
+#endif
5416
+
5381
 void Stop()
5417
 void Stop()
5382
 {
5418
 {
5383
   disable_heater();
5419
   disable_heater();

+ 5
- 0
Marlin/pins_RAMPS_13.h View File

61
   #define FILWIDTH_PIN        5
61
   #define FILWIDTH_PIN        5
62
 #endif
62
 #endif
63
 
63
 
64
+#if defined(FILAMENT_RUNOUT_SENSOR)
65
+  // define digital pin 4 for the filament runout sensor. Use the RAMPS 1.4 digital input 4 on the servos connector
66
+  #define FILRUNOUT_PIN        4
67
+#endif
68
+
64
 #if MB(RAMPS_13_EFB) || MB(RAMPS_13_EFF)
69
 #if MB(RAMPS_13_EFB) || MB(RAMPS_13_EFF)
65
   #define FAN_PIN            9 // (Sprinter config)
70
   #define FAN_PIN            9 // (Sprinter config)
66
   #if MB(RAMPS_13_EFF)
71
   #if MB(RAMPS_13_EFF)

Loading…
Cancel
Save