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.
pull/1/head
Mehmet Sutas 10 years ago
parent
commit
cfc6a3a87a
  1. 9
      Marlin/Configuration.h
  2. 4
      Marlin/Marlin.h
  3. 36
      Marlin/Marlin_main.cpp
  4. 5
      Marlin/pins_RAMPS_13.h

9
Marlin/Configuration.h

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

4
Marlin/Marlin.h

@ -199,6 +199,10 @@ void prepare_move();
void kill(); void kill();
void Stop(); void Stop();
#ifdef FILAMENT_RUNOUT_SENSOR
void filrunout();
#endif
bool IsStopped(); bool IsStopped();
bool enquecommand(const char *cmd); //put a single ASCII command at the end of the current buffer or return false when it is full 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
Marlin/Marlin_main.cpp

@ -366,6 +366,10 @@ bool cancel_heatup = false;
int meas_delay_cm = MEASUREMENT_DELAY_CM; //distance delay setting int meas_delay_cm = MEASUREMENT_DELAY_CM; //distance delay setting
#endif #endif
#ifdef FILAMENT_RUNOUT_SENSOR
static bool filrunoutEnqued = false;
#endif
const char errormagic[] PROGMEM = "Error:"; const char errormagic[] PROGMEM = "Error:";
const char echomagic[] PROGMEM = "echo:"; const char echomagic[] PROGMEM = "echo:";
@ -525,6 +529,16 @@ void setup_killpin()
#endif #endif
} }
void setup_filrunoutpin()
{
#if defined(FILRUNOUT_PIN) && FILRUNOUT_PIN > -1
pinMode(FILRUNOUT_PIN,INPUT);
#if defined(ENDSTOPPULLUP_FIL_RUNOUT)
WRITE(FILLRUNOUT_PIN,HIGH);
#endif
#endif
}
// Set home pin // Set home pin
void setup_homepin(void) void setup_homepin(void)
{ {
@ -601,6 +615,7 @@ void servo_init()
void setup() void setup()
{ {
setup_killpin(); setup_killpin();
setup_filrunoutpin();
setup_powerhold(); setup_powerhold();
MYSERIAL.begin(BAUDRATE); MYSERIAL.begin(BAUDRATE);
SERIAL_PROTOCOLLNPGM("start"); SERIAL_PROTOCOLLNPGM("start");
@ -4091,6 +4106,11 @@ inline void gcode_M503() {
plan_buffer_line(lastpos[X_AXIS], lastpos[Y_AXIS], lastpos[Z_AXIS], target[E_AXIS], fr60, active_extruder); //move z back plan_buffer_line(lastpos[X_AXIS], lastpos[Y_AXIS], lastpos[Z_AXIS], target[E_AXIS], fr60, active_extruder); //move z back
plan_buffer_line(lastpos[X_AXIS], lastpos[Y_AXIS], lastpos[Z_AXIS], lastpos[E_AXIS], fr60, active_extruder); //final untretract plan_buffer_line(lastpos[X_AXIS], lastpos[Y_AXIS], lastpos[Z_AXIS], lastpos[E_AXIS], fr60, active_extruder); //final untretract
#endif #endif
#ifdef FILAMENT_RUNOUT_SENSOR
filrunoutEnqued = false;
#endif
} }
#endif // FILAMENTCHANGEENABLE #endif // FILAMENTCHANGEENABLE
@ -5230,6 +5250,12 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) //default argument s
const int KILL_DELAY = 10000; const int KILL_DELAY = 10000;
#endif #endif
#if defined(FILRUNOUT_PIN) && FILRUNOUT_PIN > -1
if(card.sdprinting) {
if(!(READ(FILRUNOUT_PIN))^FIL_RUNOUT_INVERTING)
filrunout(); }
#endif
#if defined(HOME_PIN) && HOME_PIN > -1 #if defined(HOME_PIN) && HOME_PIN > -1
static int homeDebounceCount = 0; // poor man's debouncing count static int homeDebounceCount = 0; // poor man's debouncing count
const int HOME_DEBOUNCE_DELAY = 10000; const int HOME_DEBOUNCE_DELAY = 10000;
@ -5378,6 +5404,16 @@ void kill()
while(1) { /* Intentionally left empty */ } // Wait for reset while(1) { /* Intentionally left empty */ } // Wait for reset
} }
#ifdef FILAMENT_RUNOUT_SENSOR
void filrunout()
{
if filrunoutEnqued == false {
filrunoutEnqued = true;
enquecommand("M600");
}
}
#endif
void Stop() void Stop()
{ {
disable_heater(); disable_heater();

5
Marlin/pins_RAMPS_13.h

@ -61,6 +61,11 @@
#define FILWIDTH_PIN 5 #define FILWIDTH_PIN 5
#endif #endif
#if defined(FILAMENT_RUNOUT_SENSOR)
// define digital pin 4 for the filament runout sensor. Use the RAMPS 1.4 digital input 4 on the servos connector
#define FILRUNOUT_PIN 4
#endif
#if MB(RAMPS_13_EFB) || MB(RAMPS_13_EFF) #if MB(RAMPS_13_EFB) || MB(RAMPS_13_EFF)
#define FAN_PIN 9 // (Sprinter config) #define FAN_PIN 9 // (Sprinter config)
#if MB(RAMPS_13_EFF) #if MB(RAMPS_13_EFF)

Loading…
Cancel
Save