Welcome! Log In Create A New Profile

Advanced

Temperature Management during M600 Working

Posted by toolmailbox 
Temperature Management during M600 Working
August 28, 2016 10:29PM
Hello, everyone! I am new about 3D printer and arduino.
These days, I am debugging my 3D printer. Although some problems are solved, however, this one (temperature management during M600 working) gives me a headache.

The hardware I used are mega2560+ramp1.4 without LCD
In my code, I change some code in M600 function, that is, I add some alarm function. So, when filament runs out, 3D printer will alarm until pressing endstop. But if the pause time is long, the temperature management will go crazy. Last time, I tested this function and paused for 10mins which resulted in a burn.
Is there someone can help me? Thank you!

=============================================================================================================================================

inline void gcode_M600() {
if (degHotend(active_extruder) < extrude_min_temp) {
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM(MSG_TOO_COLD_FOR_M600);
return;
}

//********************** store the normal temperature******************************

if (code_seen('S))
{
float temp_for_normal = code_value();
}

//*************************** set temperature for M600 pausing *****************************

if (code_seen('S'))
float temp_before_pause = code_value(); // get the temperature before pausing
float temp_during_pause = 35.0;
setTargetHotend(tem_during_pause, target_extruder); // set temperature value as target temperature during M600 works

//*******************************************************************************************************

float lastpos[NUM_AXIS], fr60 = feedrate / 60;

for (int i = 0; i < NUM_AXIS; i++)
lastpos = destination = current_position;

#if ENABLED(DELTA)
#define RUNPLAN calculate_delta(destination);
plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], destination[E_AXIS], fr60, active_extruder);
#else
#define RUNPLAN line_to_destination();
#endif

//retract by E
if (code_seen('E')) destination[E_AXIS] += code_value();
#ifdef FILAMENTCHANGE_FIRSTRETRACT
else destination[E_AXIS] += FILAMENTCHANGE_FIRSTRETRACT;
#endif

RUNPLAN;

//lift Z
if (code_seen('Z')) destination[Z_AXIS] += code_value();
#ifdef FILAMENTCHANGE_ZADD
else destination[Z_AXIS] += FILAMENTCHANGE_ZADD;
#endif

RUNPLAN;

//move xy
if (code_seen('X')) destination[X_AXIS] = code_value();
#ifdef FILAMENTCHANGE_XPOS
else destination[X_AXIS] = FILAMENTCHANGE_XPOS;
#endif

if (code_seen('Y')) destination[Y_AXIS] = code_value();
#ifdef FILAMENTCHANGE_YPOS
else destination[Y_AXIS] = FILAMENTCHANGE_YPOS;
#endif

RUNPLAN;

if (code_seen('L')) destination[E_AXIS] += code_value();
#ifdef FILAMENTCHANGE_FINALRETRACT
else destination[E_AXIS] += FILAMENTCHANGE_FINALRETRACT;
#endif

RUNPLAN;

//finish moves
st_synchronize();
//disable extruder steppers so filament can be removed
disable_e0();
disable_e1();
disable_e2();
disable_e3();
//delay(5000);

//*************************************************************

const long delaytime_h_a = 5000; // pause time =3 mins=180000 // wait time for triggering alarm sound
const long delaytime_alarm = 10000;
unsigned long starttime_endstop, endtime_endstop, starttime_alarm, endtime_alarm;

if (READ(FILRUNOUT_PIN) ^ FIL_RUNOUT_INVERTING){
starttime_endstop = millis(); // get the start time
for(;winking smiley{

// These 3 lines commands are used to keep the hearter working and updating data in lcd
manage_heater();
manage_inactivity();
lcd_update();

// add filament runout function here is to estimate small error of pressing filament endstop resulting from careless-------this function will be finished later
if(READ(FILRUNOUT_PIN)==LOW){
// PREVENT_DANGEROUS_EXTRUDE,
noTone(ALARMSPEAKER_PIN);
break;
}
endtime_endstop =millis();
if(endtime_endstop - starttime_endstop < delaytime_h_a){
alarm_function(20,10);
}
else{
alarm_function(10,7);
}
}
}

//************************************* temperature control II ********************************* //0801

float temp_after_pause = temp_before_pause;
for(;winking smiley
{
setTargetHotend(temp_after_pause, target_extruder); // set target temperature as the previous value
if (abs(temp_after_pause - degHotend(target_extruder)) < 3)
brak;
}

//********************************** temperature reset to the normal ***************************

for(;winking smiley
{
gcode_M109;
idle();
if (fbs(current_temperature[0] - temp_for_normal) <= 3)
break;
}

//*************************************************************************************************

delay(1000);// delay 2s

#ifdef FILAMENT_LCD_DISPLAY
LCD_ALERTMESSAGEPGM(MSG_FILAMENTCHANGE);
millis_t next_tick = 0;
while (!lcd_clicked()) {
#if DISABLED(AUTO_FILAMENT_CHANGE)
millis_t ms = millis();
if (ms >= next_tick) {
lcd_quick_feedback();
next_tick = ms + 2500; // feedback every 2.5s while waiting
}
manage_heater();s
manage_inactivity(true);
lcd_update();
#else
// SERIAL_ERRORLNPGM(MSG_FILRUNTS);
current_position[E_AXIS] += AUTO_FILAMENT_CHANGE_LENGTH;
destination[E_AXIS] = current_position[E_AXIS];
line_to_destination(AUTO_FILAMENT_CHANGE_FEEDRATE);
st_synchronize();
#endif
} // while(!lcd_clicked)
#else
current_position[E_AXIS] += AUTO_FILAMENT_CHANGE_LENGTH;
destination[E_AXIS] = current_position[E_AXIS];
line_to_destination(AUTO_FILAMENT_CHANGE_FEEDRATE);
st_synchronize();
#endif

lcd_quick_feedback(); // click sound feedback

#if ENABLED(AUTO_FILAMENT_CHANGE)
current_position[E_AXIS] = 0;
st_synchronize();
#endif

//return to normal
// if (code_seen('L')) destination[E_AXIS] -= code_value();
// #ifdef FILAMENTCHANGE_FINALRETRACT
// else destination[E_AXIS] -= FILAMENTCHANGE_FINALRETRACT;
// #endif

// current_position[E_AXIS] = destination[E_AXIS]; //the long retract of L is compensated by manual filament feeding
// plan_set_e_position(current_position[E_AXIS]);

// RUNPLAN; //should do nothing

lcd_reset_alert_level();

#if ENABLED(DELTA)
// Move XYZ to starting position, then E
calculate_delta(lastpos);
plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], destination[E_AXIS], fr60, active_extruder);
plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], lastpos[E_AXIS], fr60, active_extruder);
#else
// Move XY to starting position, then Z, then E
destination[X_AXIS] = lastpos[X_AXIS];
destination[Y_AXIS] = lastpos[Y_AXIS];
line_to_destination();
destination[Z_AXIS] = lastpos[Z_AXIS];
line_to_destination();
//destination[E_AXIS] = lastpos[E_AXIS];
//line_to_destination();

#endif

#if ENABLED(FILAMENT_RUNOUT_SENSOR)
filrunoutEnqueued = false; //initial value is "false"
#endif

}

#endif // FILAMENTCHANGEENABLE
Sorry, only registered users may post in this forum.

Click here to login