From 469aa100974072bbec469608a84cd181b503f336 Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Fri, 29 Mar 2019 07:27:29 +0100 Subject: [PATCH 001/180] Enable MMU cutter. --- Firmware/variants/1_75mm_MK25-RAMBo10a-E3Dv6full.h | 2 +- Firmware/variants/1_75mm_MK25-RAMBo13a-E3Dv6full.h | 2 +- Firmware/variants/1_75mm_MK25S-RAMBo10a-E3Dv6full.h | 2 +- Firmware/variants/1_75mm_MK25S-RAMBo13a-E3Dv6full.h | 2 +- Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h | 2 +- Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Firmware/variants/1_75mm_MK25-RAMBo10a-E3Dv6full.h b/Firmware/variants/1_75mm_MK25-RAMBo10a-E3Dv6full.h index b5e9c1af0..cd6367422 100644 --- a/Firmware/variants/1_75mm_MK25-RAMBo10a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK25-RAMBo10a-E3Dv6full.h @@ -500,7 +500,7 @@ #define MMU_REQUIRED_FW_BUILDNR 132 #define MMU_FORCE_STEALTH_MODE #define MMU_DEBUG //print communication between MMU2 and printer on serial -//#define MMU_HAS_CUTTER +#define MMU_HAS_CUTTER #define MMU_IDLER_SENSOR_ATTEMPTS_NR 21 //max. number of attempts to load filament if first load failed; value for max bowden length and case when loading fails right at the beginning diff --git a/Firmware/variants/1_75mm_MK25-RAMBo13a-E3Dv6full.h b/Firmware/variants/1_75mm_MK25-RAMBo13a-E3Dv6full.h index 05b5e0923..4d76675ce 100644 --- a/Firmware/variants/1_75mm_MK25-RAMBo13a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK25-RAMBo13a-E3Dv6full.h @@ -501,7 +501,7 @@ #define MMU_REQUIRED_FW_BUILDNR 132 #define MMU_FORCE_STEALTH_MODE #define MMU_DEBUG //print communication between MMU2 and printer on serial -//#define MMU_HAS_CUTTER +#define MMU_HAS_CUTTER #define MMU_IDLER_SENSOR_ATTEMPTS_NR 21 //max. number of attempts to load filament if first load failed; value for max bowden length and case when loading fails right at the beginning diff --git a/Firmware/variants/1_75mm_MK25S-RAMBo10a-E3Dv6full.h b/Firmware/variants/1_75mm_MK25S-RAMBo10a-E3Dv6full.h index a1822970c..1c24d1a17 100644 --- a/Firmware/variants/1_75mm_MK25S-RAMBo10a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK25S-RAMBo10a-E3Dv6full.h @@ -500,7 +500,7 @@ #define MMU_REQUIRED_FW_BUILDNR 132 #define MMU_FORCE_STEALTH_MODE #define MMU_DEBUG //print communication between MMU2 and printer on serial -//#define MMU_HAS_CUTTER +#define MMU_HAS_CUTTER #define MMU_IDLER_SENSOR_ATTEMPTS_NR 21 //max. number of attempts to load filament if first load failed; value for max bowden length and case when loading fails right at the beginning diff --git a/Firmware/variants/1_75mm_MK25S-RAMBo13a-E3Dv6full.h b/Firmware/variants/1_75mm_MK25S-RAMBo13a-E3Dv6full.h index 92773807c..997929941 100644 --- a/Firmware/variants/1_75mm_MK25S-RAMBo13a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK25S-RAMBo13a-E3Dv6full.h @@ -501,7 +501,7 @@ #define MMU_REQUIRED_FW_BUILDNR 132 #define MMU_FORCE_STEALTH_MODE #define MMU_DEBUG //print communication between MMU2 and printer on serial -//#define MMU_HAS_CUTTER +#define MMU_HAS_CUTTER #define MMU_IDLER_SENSOR_ATTEMPTS_NR 21 //max. number of attempts to load filament if first load failed; value for max bowden length and case when loading fails right at the beginning diff --git a/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h b/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h index 4a1fe53cf..d5ff5dfa4 100644 --- a/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h @@ -626,7 +626,7 @@ #define MMU_REQUIRED_FW_BUILDNR 83 #define MMU_HWRESET #define MMU_DEBUG //print communication between MMU2 and printer on serial -//#define MMU_HAS_CUTTER +#define MMU_HAS_CUTTER #define MMU_IDLER_SENSOR_ATTEMPTS_NR 21 //max. number of attempts to load filament if first load failed; value for max bowden length and case when loading fails right at the beginning #endif //__CONFIGURATION_PRUSA_H diff --git a/Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h b/Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h index 1c0c6d28e..d0227fdf7 100644 --- a/Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h @@ -626,7 +626,7 @@ #define MMU_REQUIRED_FW_BUILDNR 83 #define MMU_HWRESET #define MMU_DEBUG //print communication between MMU2 and printer on serial -//#define MMU_HAS_CUTTER +#define MMU_HAS_CUTTER #define MMU_IDLER_SENSOR_ATTEMPTS_NR 21 //max. number of attempts to load filament if first load failed; value for max bowden length and case when loading fails right at the beginning #endif //__CONFIGURATION_PRUSA_H From eeea2725cba04a94c78bfd1cf58c7465087a6c25 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 17 Mar 2019 19:49:21 +0100 Subject: [PATCH 002/180] Partial LA15 support --- Firmware/ConfigurationStore.cpp | 4 +- Firmware/Configuration_adv.h | 51 +++++---------- Firmware/Marlin_main.cpp | 28 +++------ Firmware/planner.cpp | 107 ++++++++++++++++++++------------ Firmware/planner.h | 7 ++- 5 files changed, 99 insertions(+), 98 deletions(-) diff --git a/Firmware/ConfigurationStore.cpp b/Firmware/ConfigurationStore.cpp index f2df8fc6c..8ed2dd708 100644 --- a/Firmware/ConfigurationStore.cpp +++ b/Firmware/ConfigurationStore.cpp @@ -165,8 +165,8 @@ void Config_PrintSettings(uint8_t level) #endif if (level >= 10) { #ifdef LIN_ADVANCE - printf_P(PSTR("%SLinear advance settings:\n M900 K%.2f E/D = %.2f\n"), - echomagic, extruder_advance_k, advance_ed_ratio); + printf_P(PSTR("%SLinear advance settings:\n M900 K%.2f\n"), + echomagic, extruder_advance_K); #endif //LIN_ADVANCE } } diff --git a/Firmware/Configuration_adv.h b/Firmware/Configuration_adv.h index 951302877..d731e8633 100644 --- a/Firmware/Configuration_adv.h +++ b/Firmware/Configuration_adv.h @@ -276,43 +276,26 @@ #endif /** - * Implementation of linear pressure control - * - * Assumption: advance = k * (delta velocity) - * K=0 means advance disabled. - * See Marlin documentation for calibration instructions. - */ + * Linear Pressure Control v1.5 + * + * Assumption: advance [steps] = k * (delta velocity [steps/s]) + * K=0 means advance disabled. + * + * NOTE: K values for LIN_ADVANCE 1.5 differ from earlier versions! + * + * Set K around 0.22 for 3mm PLA Direct Drive with ~6.5cm between the drive gear and heatbreak. + * Larger K values will be needed for flexible filament and greater distances. + * If this algorithm produces a higher speed offset than the extruder can handle (compared to E jerk) + * print acceleration will be reduced during the affected moves to keep within the limit. + * + * See http://marlinfw.org/docs/features/lin_advance.html for full instructions. + * Mention @Sebastianv650 on GitHub to alert the author of any issues. + */ #define LIN_ADVANCE #ifdef LIN_ADVANCE - #define LIN_ADVANCE_K 0 //Try around 45 for PLA, around 25 for ABS. - - /** - * Some Slicers produce Gcode with randomly jumping extrusion widths occasionally. - * For example within a 0.4mm perimeter it may produce a single segment of 0.05mm width. - * While this is harmless for normal printing (the fluid nature of the filament will - * close this very, very tiny gap), it throws off the LIN_ADVANCE pressure adaption. - * - * For this case LIN_ADVANCE_E_D_RATIO can be used to set the extrusion:distance ratio - * to a fixed value. Note that using a fixed ratio will lead to wrong nozzle pressures - * if the slicer is using variable widths or layer heights within one print! - * - * This option sets the default E:D ratio at startup. Use `M900` to override this value. - * - * Example: `M900 W0.4 H0.2 D1.75`, where: - * - W is the extrusion width in mm - * - H is the layer height in mm - * - D is the filament diameter in mm - * - * Example: `M900 R0.0458` to set the ratio directly. - * - * Set to 0 to auto-detect the ratio based on given Gcode G1 print moves. - * - * Slic3r (including Prusa Slic3r) produces Gcode compatible with the automatic mode. - * Cura (as of this writing) may produce Gcode incompatible with the automatic mode. - */ -#define LIN_ADVANCE_E_D_RATIO 0 // The calculated ratio (or 0) according to the formula W * H / ((D / 2) ^ 2 * PI) - // Example: 0.4 * 0.2 / ((1.75 / 2) ^ 2 * PI) = 0.033260135 + #define LIN_ADVANCE_K 0 // Unit: mm compression per 1mm/s extruder speed + //#define LA_DEBUG // If enabled, this will generate debug information output over USB. #endif // Arc interpretation settings: diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index d37fbb38e..b9af28b7a 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -2073,35 +2073,23 @@ static float probe_pt(float x, float y, float z_before) { #ifdef LIN_ADVANCE /** - * M900: Set and/or Get advance K factor and WH/D ratio + * M900: Set and/or Get advance K factor * * K Set advance K factor - * R Set ratio directly (overrides WH/D) - * W H D Set ratio from WH/D */ inline void gcode_M900() { st_synchronize(); const float newK = code_seen('K') ? code_value_float() : -1; - if (newK >= 0) extruder_advance_k = newK; - - float newR = code_seen('R') ? code_value_float() : -1; - if (newR < 0) { - const float newD = code_seen('D') ? code_value_float() : -1, - newW = code_seen('W') ? code_value_float() : -1, - newH = code_seen('H') ? code_value_float() : -1; - if (newD >= 0 && newW >= 0 && newH >= 0) - newR = newD ? (newW * newH) / (sq(newD * 0.5) * M_PI) : 0; - } - if (newR >= 0) advance_ed_ratio = newR; - + if (newK >= 0 && newK < 10) + extruder_advance_K = newK; + else + SERIAL_ECHOLNPGM("K out of allowed range!"); + SERIAL_ECHO_START; SERIAL_ECHOPGM("Advance K="); - SERIAL_ECHOLN(extruder_advance_k); - SERIAL_ECHOPGM(" E/D="); - const float ratio = advance_ed_ratio; - if (ratio) SERIAL_ECHOLN(ratio); else SERIAL_ECHOLNPGM("Auto"); - } + SERIAL_ECHOLN(extruder_advance_K); +} #endif // LIN_ADVANCE bool check_commands() { diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index 4a8d6659a..43c9f10b7 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -126,8 +126,7 @@ float extrude_min_temp=EXTRUDE_MINTEMP; #endif #ifdef LIN_ADVANCE - float extruder_advance_k = LIN_ADVANCE_K, - advance_ed_ratio = LIN_ADVANCE_E_D_RATIO, + float extruder_advance_K = LIN_ADVANCE_K, position_float[NUM_AXIS] = { 0 }; #endif @@ -402,6 +401,13 @@ void planner_recalculate(const float &safe_final_speed) if ((prev->flag | current->flag) & BLOCK_FLAG_RECALCULATE) { // NOTE: Entry and exit factors always > 0 by all previous logic operations. calculate_trapezoid_for_block(prev, prev->entry_speed, current->entry_speed); + #ifdef LIN_ADVANCE + if (current->use_advance_lead) { + const float comp = current->e_D_ratio * extruder_advance_K * axis_steps_per_unit[E_AXIS]; + current->max_adv_steps = current->nominal_speed * comp; + current->final_adv_steps = next->entry_speed * comp; + } + #endif // Reset current only to ensure next trapezoid is computed. prev->flag &= ~BLOCK_FLAG_RECALCULATE; } @@ -415,6 +421,13 @@ void planner_recalculate(const float &safe_final_speed) // Last/newest block in buffer. Exit speed is set with safe_final_speed. Always recalculated. current = block_buffer + prev_block_index(block_buffer_head); calculate_trapezoid_for_block(current, current->entry_speed, safe_final_speed); + #ifdef LIN_ADVANCE + if (current->use_advance_lead) { + const float comp = current->e_D_ratio * extruder_advance_K * axis_steps_per_unit[E_AXIS]; + current->max_adv_steps = current->nominal_speed * comp; + current->final_adv_steps = safe_final_speed * comp; + } + #endif current->flag &= ~BLOCK_FLAG_RECALCULATE; // SERIAL_ECHOLNPGM("planner_recalculate - 4"); @@ -748,11 +761,6 @@ void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate #endif // ENABLE_MESH_BED_LEVELING target[E_AXIS] = lround(e*cs.axis_steps_per_unit[E_AXIS]); -#ifdef LIN_ADVANCE - const float mm_D_float = sqrt(sq(x - position_float[X_AXIS]) + sq(y - position_float[Y_AXIS])); - float de_float = e - position_float[E_AXIS]; -#endif - #ifdef PREVENT_DANGEROUS_EXTRUDE if(target[E_AXIS]!=position[E_AXIS]) { @@ -761,7 +769,6 @@ void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate position[E_AXIS]=target[E_AXIS]; //behave as if the move really took place, but ignore E part #ifdef LIN_ADVANCE position_float[E_AXIS] = e; - de_float = 0; #endif SERIAL_ECHO_START; SERIAL_ECHOLNRPGM(_n(" cold extrusion prevented"));////MSG_ERR_COLD_EXTRUDE_STOP @@ -773,7 +780,6 @@ void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate position[E_AXIS]=target[E_AXIS]; //behave as if the move really took place, but ignore E part #ifdef LIN_ADVANCE position_float[E_AXIS] = e; - de_float = 0; #endif SERIAL_ECHO_START; SERIAL_ECHOLNRPGM(_n(" too long extrusion prevented"));////MSG_ERR_LONG_EXTRUDE_STOP @@ -1001,10 +1007,50 @@ Having the real displacement of the head, we can calculate the total movement le if(block->steps_x.wide == 0 && block->steps_y.wide == 0 && block->steps_z.wide == 0) { block->acceleration_st = ceil(cs.retract_acceleration * steps_per_mm); // convert to: acceleration steps/sec^2 + #ifdef LIN_ADVANCE + block->use_advance_lead = false; + #endif } else { block->acceleration_st = ceil(cs.acceleration * steps_per_mm); // convert to: acceleration steps/sec^2 + + #ifdef LIN_ADVANCE + /** + * + * Use LIN_ADVANCE for blocks if all these are true: + * + * block->steps_e : This is a print move, because we checked for X, Y, Z steps before. + * + * extruder_advance_K : There is an advance factor set. + * + * delta_mm[E_AXIS] > 0 : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves) + */ + block->use_advance_lead = block->steps_e + && extruder_advance_K + && delta_mm[E_AXIS] > 0; + + if (block->use_advance_lead) { + block->e_D_ratio = (e - position_float[E_AXIS]) / + sqrt(sq(x - position_float[X_AXIS]) + + sq(y - position_float[Y_AXIS]) + + sq(z - position_float[Z_AXIS])); + + // Check for unusual high e_D ratio to detect if a retract move was combined with the last print move due to min. steps per segment. Never execute this with advance! + // This assumes no one will use a retract length of 0mm < retr_length < ~0.2mm and no one will print 100mm wide lines using 3mm filament or 35mm wide lines using 1.75mm filament. + if (block->e_D_ratio > 3.0) + block->use_advance_lead = false; + else { + const uint32_t max_accel_steps_per_s2 = max_jerk[E_AXIS] / (extruder_advance_K * block->e_D_ratio) * steps_per_mm; + #ifdef LA_DEBUG + if (block->acceleration_st > max_accel_steps_per_s2) + SERIAL_ECHOLNPGM("Acceleration limited."); + #endif + NOMORE(block->acceleration_st, max_accel_steps_per_s2); + } + } + #endif + // Limit acceleration per axis //FIXME Vojtech: One shall rather limit a projection of the acceleration vector instead of using the limit. if(((float)block->acceleration_st * (float)block->steps_x.wide / (float)block->step_event_count.wide) > axis_steps_per_sqr_second[X_AXIS]) @@ -1037,6 +1083,18 @@ Having the real displacement of the head, we can calculate the total movement le block->acceleration_rate = (long)((float)block->acceleration_st * (16777216.0 / (F_CPU / 8.0))); + #ifdef LIN_ADVANCE + if (block->use_advance_lead) { + block->advance_speed = ((F_CPU) * 0.125) / (extruder_advance_K * block->e_D_ratio * block->acceleration * axis_steps_per_unit[E_AXIS]); + #ifdef LA_DEBUG + if (extruder_advance_K * block->e_D_ratio * block->acceleration * 2 < block->nominal_speed * block->e_D_ratio) + SERIAL_ECHOLNPGM("More than 2 steps per eISR loop executed."); + if (block->advance_speed < 200) + SERIAL_ECHOLNPGM("eISR running at > 10kHz."); + #endif + } + #endif + // Start with a safe speed. // Safe speed is the speed, from which the machine may halt to stop immediately. float safe_speed = block->nominal_speed; @@ -1153,37 +1211,6 @@ Having the real displacement of the head, we can calculate the total movement le previous_nominal_speed = block->nominal_speed; previous_safe_speed = safe_speed; -#ifdef LIN_ADVANCE - - // - // Use LIN_ADVANCE for blocks if all these are true: - // - // esteps : We have E steps todo (a printing move) - // - // block->steps[X_AXIS] || block->steps[Y_AXIS] : We have a movement in XY direction (i.e., not retract / prime). - // - // extruder_advance_k : There is an advance factor set. - // - // block->steps[E_AXIS] != block->step_event_count : A problem occurs if the move before a retract is too small. - // In that case, the retract and move will be executed together. - // This leads to too many advance steps due to a huge e_acceleration. - // The math is good, but we must avoid retract moves with advance! - // de_float > 0.0 : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves) - // - block->use_advance_lead = block->steps_e.wide - && (block->steps_x.wide || block->steps_y.wide) - && extruder_advance_k - && (uint32_t)block->steps_e.wide != block->step_event_count.wide - && de_float > 0.0; - if (block->use_advance_lead) - block->abs_adv_steps_multiplier8 = lround( - extruder_advance_k - * ((advance_ed_ratio < 0.000001) ? de_float / mm_D_float : advance_ed_ratio) // Use the fixed ratio, if set - * (block->nominal_speed / (float)block->nominal_rate) - * cs.axis_steps_per_unit[E_AXIS] * 256.0 - ); -#endif - // Precalculate the division, so when all the trapezoids in the planner queue get recalculated, the division is not repeated. block->speed_factor = block->nominal_rate / block->nominal_speed; calculate_trapezoid_for_block(block, block->entry_speed, safe_speed); diff --git a/Firmware/planner.h b/Firmware/planner.h index b6a9f8361..a99f02ede 100644 --- a/Firmware/planner.h +++ b/Firmware/planner.h @@ -113,14 +113,17 @@ typedef struct { #ifdef LIN_ADVANCE bool use_advance_lead; - unsigned long abs_adv_steps_multiplier8; // Factorised by 2^8 to avoid float + uint16_t advance_speed, // Timer value for extruder speed offset + max_adv_steps, // max. advance steps to get cruising speed pressure (not always nominal_speed!) + final_adv_steps; // advance steps due to exit speed + float e_D_ratio; #endif uint16_t sdlen; } block_t; #ifdef LIN_ADVANCE - extern float extruder_advance_k, advance_ed_ratio; + extern float extruder_advance_K; #endif #ifdef ENABLE_AUTO_BED_LEVELING From 45563bfdd3d3cb2df1e08c9ea39e6a3abbb94dc5 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Mon, 18 Mar 2019 18:43:22 +0100 Subject: [PATCH 003/180] Formatting sanity --- Firmware/planner.cpp | 134 +++++++++++++++++++++---------------------- 1 file changed, 65 insertions(+), 69 deletions(-) diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index 43c9f10b7..a84411980 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -126,8 +126,8 @@ float extrude_min_temp=EXTRUDE_MINTEMP; #endif #ifdef LIN_ADVANCE - float extruder_advance_K = LIN_ADVANCE_K, - position_float[NUM_AXIS] = { 0 }; +float extruder_advance_K = LIN_ADVANCE_K; +float position_float[NUM_AXIS] = { 0 }; #endif // Returns the index of the next block in the ring buffer @@ -402,11 +402,11 @@ void planner_recalculate(const float &safe_final_speed) // NOTE: Entry and exit factors always > 0 by all previous logic operations. calculate_trapezoid_for_block(prev, prev->entry_speed, current->entry_speed); #ifdef LIN_ADVANCE - if (current->use_advance_lead) { - const float comp = current->e_D_ratio * extruder_advance_K * axis_steps_per_unit[E_AXIS]; - current->max_adv_steps = current->nominal_speed * comp; - current->final_adv_steps = next->entry_speed * comp; - } + if (current->use_advance_lead) { + const float comp = current->e_D_ratio * extruder_advance_K * axis_steps_per_unit[E_AXIS]; + current->max_adv_steps = current->nominal_speed * comp; + current->final_adv_steps = next->entry_speed * comp; + } #endif // Reset current only to ensure next trapezoid is computed. prev->flag &= ~BLOCK_FLAG_RECALCULATE; @@ -422,11 +422,11 @@ void planner_recalculate(const float &safe_final_speed) current = block_buffer + prev_block_index(block_buffer_head); calculate_trapezoid_for_block(current, current->entry_speed, safe_final_speed); #ifdef LIN_ADVANCE - if (current->use_advance_lead) { - const float comp = current->e_D_ratio * extruder_advance_K * axis_steps_per_unit[E_AXIS]; - current->max_adv_steps = current->nominal_speed * comp; - current->final_adv_steps = safe_final_speed * comp; - } + if (current->use_advance_lead) { + const float comp = current->e_D_ratio * extruder_advance_K * axis_steps_per_unit[E_AXIS]; + current->max_adv_steps = current->nominal_speed * comp; + current->final_adv_steps = safe_final_speed * comp; + } #endif current->flag &= ~BLOCK_FLAG_RECALCULATE; @@ -437,9 +437,9 @@ void plan_init() { block_buffer_head = 0; block_buffer_tail = 0; memset(position, 0, sizeof(position)); // clear position -#ifdef LIN_ADVANCE + #ifdef LIN_ADVANCE memset(position_float, 0, sizeof(position)); // clear position -#endif + #endif previous_speed[0] = 0.0; previous_speed[1] = 0.0; previous_speed[2] = 0.0; @@ -767,9 +767,9 @@ void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate if(degHotend(active_extruder)cs.axis_steps_per_unit[E_AXIS]*EXTRUDE_MAXLENGTH) { position[E_AXIS]=target[E_AXIS]; //behave as if the move really took place, but ignore E part -#ifdef LIN_ADVANCE - position_float[E_AXIS] = e; -#endif + #ifdef LIN_ADVANCE + position_float[E_AXIS] = e; + #endif SERIAL_ECHO_START; SERIAL_ECHOLNRPGM(_n(" too long extrusion prevented"));////MSG_ERR_LONG_EXTRUDE_STOP } @@ -1008,7 +1008,7 @@ Having the real displacement of the head, we can calculate the total movement le { block->acceleration_st = ceil(cs.retract_acceleration * steps_per_mm); // convert to: acceleration steps/sec^2 #ifdef LIN_ADVANCE - block->use_advance_lead = false; + block->use_advance_lead = false; #endif } else @@ -1016,39 +1016,35 @@ Having the real displacement of the head, we can calculate the total movement le block->acceleration_st = ceil(cs.acceleration * steps_per_mm); // convert to: acceleration steps/sec^2 #ifdef LIN_ADVANCE - /** - * - * Use LIN_ADVANCE for blocks if all these are true: - * - * block->steps_e : This is a print move, because we checked for X, Y, Z steps before. - * - * extruder_advance_K : There is an advance factor set. - * - * delta_mm[E_AXIS] > 0 : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves) - */ - block->use_advance_lead = block->steps_e - && extruder_advance_K - && delta_mm[E_AXIS] > 0; + /** + * Use LIN_ADVANCE for blocks if all these are true: + * + * block->steps_e : This is a print move, because we checked for X, Y, Z steps before. + * extruder_advance_K : There is an advance factor set. + * delta_mm[E_AXIS] > 0 : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves) + */ + block->use_advance_lead = block->steps_e + && extruder_advance_K + && delta_mm[E_AXIS] > 0; + if (block->use_advance_lead) { + block->e_D_ratio = (e - position_float[E_AXIS]) / + sqrt(sq(x - position_float[X_AXIS]) + + sq(y - position_float[Y_AXIS]) + + sq(z - position_float[Z_AXIS])); - if (block->use_advance_lead) { - block->e_D_ratio = (e - position_float[E_AXIS]) / - sqrt(sq(x - position_float[X_AXIS]) - + sq(y - position_float[Y_AXIS]) - + sq(z - position_float[Z_AXIS])); - - // Check for unusual high e_D ratio to detect if a retract move was combined with the last print move due to min. steps per segment. Never execute this with advance! - // This assumes no one will use a retract length of 0mm < retr_length < ~0.2mm and no one will print 100mm wide lines using 3mm filament or 35mm wide lines using 1.75mm filament. - if (block->e_D_ratio > 3.0) - block->use_advance_lead = false; - else { - const uint32_t max_accel_steps_per_s2 = max_jerk[E_AXIS] / (extruder_advance_K * block->e_D_ratio) * steps_per_mm; - #ifdef LA_DEBUG - if (block->acceleration_st > max_accel_steps_per_s2) - SERIAL_ECHOLNPGM("Acceleration limited."); - #endif - NOMORE(block->acceleration_st, max_accel_steps_per_s2); - } + // Check for unusual high e_D ratio to detect if a retract move was combined with the last print move due to min. steps per segment. Never execute this with advance! + // This assumes no one will use a retract length of 0mm < retr_length < ~0.2mm and no one will print 100mm wide lines using 3mm filament or 35mm wide lines using 1.75mm filament. + if (block->e_D_ratio > 3.0) + block->use_advance_lead = false; + else { + const uint32_t max_accel_steps_per_s2 = max_jerk[E_AXIS] / (extruder_advance_K * block->e_D_ratio) * steps_per_mm; + #ifdef LA_DEBUG + if (block->acceleration_st > max_accel_steps_per_s2) + SERIAL_ECHOLNPGM("Acceleration limited."); + #endif + NOMORE(block->acceleration_st, max_accel_steps_per_s2); } + } #endif // Limit acceleration per axis @@ -1084,15 +1080,15 @@ Having the real displacement of the head, we can calculate the total movement le block->acceleration_rate = (long)((float)block->acceleration_st * (16777216.0 / (F_CPU / 8.0))); #ifdef LIN_ADVANCE - if (block->use_advance_lead) { - block->advance_speed = ((F_CPU) * 0.125) / (extruder_advance_K * block->e_D_ratio * block->acceleration * axis_steps_per_unit[E_AXIS]); - #ifdef LA_DEBUG - if (extruder_advance_K * block->e_D_ratio * block->acceleration * 2 < block->nominal_speed * block->e_D_ratio) - SERIAL_ECHOLNPGM("More than 2 steps per eISR loop executed."); - if (block->advance_speed < 200) - SERIAL_ECHOLNPGM("eISR running at > 10kHz."); - #endif - } + if (block->use_advance_lead) { + block->advance_speed = (F_CPU / 8.0) / (extruder_advance_K * block->e_D_ratio * block->acceleration * axis_steps_per_unit[E_AXIS]); + #ifdef LA_DEBUG + if (extruder_advance_K * block->e_D_ratio * block->acceleration * 2 < block->nominal_speed * block->e_D_ratio) + SERIAL_ECHOLNPGM("More than 2 steps per eISR loop executed."); + if (block->advance_speed < 200) + SERIAL_ECHOLNPGM("eISR running at > 10kHz."); + #endif + } #endif // Start with a safe speed. @@ -1224,12 +1220,12 @@ Having the real displacement of the head, we can calculate the total movement le // Update position memcpy(position, target, sizeof(target)); // position[] = target[] -#ifdef LIN_ADVANCE + #ifdef LIN_ADVANCE position_float[X_AXIS] = x; position_float[Y_AXIS] = y; position_float[Z_AXIS] = z; position_float[E_AXIS] = e; -#endif + #endif // Recalculate the trapezoids to maximize speed at the segment transitions while respecting // the machine limits (maximum acceleration and maximum jerk). @@ -1292,12 +1288,12 @@ void plan_set_position(float x, float y, float z, const float &e) position[Z_AXIS] = lround(z*cs.axis_steps_per_unit[Z_AXIS]); #endif // ENABLE_MESH_BED_LEVELING position[E_AXIS] = lround(e*cs.axis_steps_per_unit[E_AXIS]); -#ifdef LIN_ADVANCE + #ifdef LIN_ADVANCE position_float[X_AXIS] = x; position_float[Y_AXIS] = y; position_float[Z_AXIS] = z; position_float[E_AXIS] = e; -#endif + #endif st_set_position(position[X_AXIS], position[Y_AXIS], position[Z_AXIS], position[E_AXIS]); previous_nominal_speed = 0.0; // Resets planner junction speeds. Assumes start from rest. previous_speed[0] = 0.0; @@ -1309,11 +1305,11 @@ void plan_set_position(float x, float y, float z, const float &e) // Only useful in the bed leveling routine, when the mesh bed leveling is off. void plan_set_z_position(const float &z) { - #ifdef LIN_ADVANCE - position_float[Z_AXIS] = z; - #endif - position[Z_AXIS] = lround(z*cs.axis_steps_per_unit[Z_AXIS]); - st_set_position(position[X_AXIS], position[Y_AXIS], position[Z_AXIS], position[E_AXIS]); + #ifdef LIN_ADVANCE + position_float[Z_AXIS] = z; + #endif + position[Z_AXIS] = lround(z*cs.axis_steps_per_unit[Z_AXIS]); + st_set_position(position[X_AXIS], position[Y_AXIS], position[Z_AXIS], position[E_AXIS]); } void plan_set_e_position(const float &e) From 124540a06f2f9140bcb1478433a24c7337633a7e Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Mon, 18 Mar 2019 20:58:01 +0100 Subject: [PATCH 004/180] Adapt LA changes to ConfigurationStore --- Firmware/planner.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index a84411980..f8ac2f596 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -127,7 +127,7 @@ float extrude_min_temp=EXTRUDE_MINTEMP; #ifdef LIN_ADVANCE float extruder_advance_K = LIN_ADVANCE_K; -float position_float[NUM_AXIS] = { 0 }; +float position_float[NUM_AXIS] = { 0, 0, 0, 0 }; #endif // Returns the index of the next block in the ring buffer @@ -403,7 +403,7 @@ void planner_recalculate(const float &safe_final_speed) calculate_trapezoid_for_block(prev, prev->entry_speed, current->entry_speed); #ifdef LIN_ADVANCE if (current->use_advance_lead) { - const float comp = current->e_D_ratio * extruder_advance_K * axis_steps_per_unit[E_AXIS]; + const float comp = current->e_D_ratio * extruder_advance_K * cs.axis_steps_per_unit[E_AXIS]; current->max_adv_steps = current->nominal_speed * comp; current->final_adv_steps = next->entry_speed * comp; } @@ -423,7 +423,7 @@ void planner_recalculate(const float &safe_final_speed) calculate_trapezoid_for_block(current, current->entry_speed, safe_final_speed); #ifdef LIN_ADVANCE if (current->use_advance_lead) { - const float comp = current->e_D_ratio * extruder_advance_K * axis_steps_per_unit[E_AXIS]; + const float comp = current->e_D_ratio * extruder_advance_K * cs.axis_steps_per_unit[E_AXIS]; current->max_adv_steps = current->nominal_speed * comp; current->final_adv_steps = safe_final_speed * comp; } @@ -1023,7 +1023,7 @@ Having the real displacement of the head, we can calculate the total movement le * extruder_advance_K : There is an advance factor set. * delta_mm[E_AXIS] > 0 : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves) */ - block->use_advance_lead = block->steps_e + block->use_advance_lead = block->steps_e.wide && extruder_advance_K && delta_mm[E_AXIS] > 0; if (block->use_advance_lead) { @@ -1037,12 +1037,13 @@ Having the real displacement of the head, we can calculate the total movement le if (block->e_D_ratio > 3.0) block->use_advance_lead = false; else { - const uint32_t max_accel_steps_per_s2 = max_jerk[E_AXIS] / (extruder_advance_K * block->e_D_ratio) * steps_per_mm; + const uint32_t max_accel_steps_per_s2 = cs.max_jerk[E_AXIS] / (extruder_advance_K * block->e_D_ratio) * steps_per_mm; + if (block->acceleration_st > max_accel_steps_per_s2) { + block->acceleration_st = max_accel_steps_per_s2; #ifdef LA_DEBUG - if (block->acceleration_st > max_accel_steps_per_s2) SERIAL_ECHOLNPGM("Acceleration limited."); #endif - NOMORE(block->acceleration_st, max_accel_steps_per_s2); + } } } #endif @@ -1081,7 +1082,7 @@ Having the real displacement of the head, we can calculate the total movement le #ifdef LIN_ADVANCE if (block->use_advance_lead) { - block->advance_speed = (F_CPU / 8.0) / (extruder_advance_K * block->e_D_ratio * block->acceleration * axis_steps_per_unit[E_AXIS]); + block->advance_speed = (F_CPU / 8.0) / (extruder_advance_K * block->e_D_ratio * block->acceleration * cs.axis_steps_per_unit[E_AXIS]); #ifdef LA_DEBUG if (extruder_advance_K * block->e_D_ratio * block->acceleration * 2 < block->nominal_speed * block->e_D_ratio) SERIAL_ECHOLNPGM("More than 2 steps per eISR loop executed."); From bf0c60dd4563d1dbaa2fdf72dd67b60f680702ad Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Mon, 29 Apr 2019 16:09:13 +0200 Subject: [PATCH 005/180] Factor-out some repetition into fsensor_step --- Firmware/stepper.cpp | 75 ++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 48 deletions(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 74d25777c..c80581a5e 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -352,6 +352,30 @@ FORCE_INLINE unsigned short calc_timer(uint16_t step_rate) { return timer; } + +#ifndef FILAMENT_SENSOR +#define fsensor_step(cnt) +#else +FORCE_INLINE void fsensor_step(uint8_t cnt) +{ + if (READ(E0_DIR_PIN) == INVERT_E0_DIR) + { + if (count_direction[E_AXIS] == 1) + fsensor_counter -= cnt; + else + fsensor_counter += cnt; + } + else + { + if (count_direction[E_AXIS] == 1) + fsensor_counter += cnt; + else + fsensor_counter -= cnt; + } +} +#endif + + // "The Stepper Driver Interrupt" - This timer interrupt is the workhorse. // It pops blocks from the block_buffer and executes them by pulsing the stepper pins appropriately. ISR(TIMER1_COMPA_vect) { @@ -372,22 +396,7 @@ ISR(TIMER1_COMPA_vect) { cnt++; WRITE_NC(E0_STEP_PIN, INVERT_E_STEP_PIN); } -#ifdef FILAMENT_SENSOR - if (READ(E0_DIR_PIN) == INVERT_E0_DIR) - { - if (count_direction[E_AXIS] == 1) - fsensor_counter -= cnt; - else - fsensor_counter += cnt; - } - else - { - if (count_direction[E_AXIS] == 1) - fsensor_counter += cnt; - else - fsensor_counter -= cnt; - } -#endif //FILAMENT_SENSOR + fsensor_step(cnt); if (e_steps) { // Plan another Linear Advance tick. OCR1A = eISR_Rate; @@ -916,22 +925,7 @@ FORCE_INLINE void isr() { estep_loops = (e_steps & 0x0ff00) ? 4 : e_steps; if (step_loops < estep_loops) estep_loops = step_loops; -#ifdef FILAMENT_SENSOR - if (READ(E0_DIR_PIN) == INVERT_E0_DIR) - { - if (count_direction[E_AXIS] == 1) - fsensor_counter -= estep_loops; - else - fsensor_counter += estep_loops; - } - else - { - if (count_direction[E_AXIS] == 1) - fsensor_counter += estep_loops; - else - fsensor_counter -= estep_loops; - } -#endif //FILAMENT_SENSOR + fsensor_step(estep_loops); do { WRITE_NC(E0_STEP_PIN, !INVERT_E_STEP_PIN); -- e_steps; @@ -1056,22 +1050,7 @@ FORCE_INLINE void isr() { // There is not enough time to fit even a single additional tick. // Tick all the extruder ticks now. MSerial.checkRx(); // Check for serial chars. -#ifdef FILAMENT_SENSOR - if (READ(E0_DIR_PIN) == INVERT_E0_DIR) - { - if (count_direction[E_AXIS] == 1) - fsensor_counter -= e_steps; - else - fsensor_counter += e_steps; - } - else - { - if (count_direction[E_AXIS] == 1) - fsensor_counter += e_steps; - else - fsensor_counter -= e_steps; - } -#endif //FILAMENT_SENSOR + fsensor_step(e_steps); do { WRITE_NC(E0_STEP_PIN, !INVERT_E_STEP_PIN); -- e_steps; From cbf1a85ec38fc57ca27fe77abf8f2be34e03ebf6 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sat, 4 May 2019 21:02:33 +0200 Subject: [PATCH 006/180] Switch original LA implementation with LA1.5 This discards several Prusa optimizations for LA1.0. We'll re-implement those later if needed. Debugging is turned on. --- Firmware/Configuration_adv.h | 2 + Firmware/planner.h | 10 +- Firmware/stepper.cpp | 356 +++++++++++++---------------------- Firmware/stepper.h | 4 +- 4 files changed, 140 insertions(+), 232 deletions(-) diff --git a/Firmware/Configuration_adv.h b/Firmware/Configuration_adv.h index d731e8633..455033024 100644 --- a/Firmware/Configuration_adv.h +++ b/Firmware/Configuration_adv.h @@ -292,6 +292,8 @@ * Mention @Sebastianv650 on GitHub to alert the author of any issues. */ #define LIN_ADVANCE +#define LA_DEBUG +#define DEBUG_STEPPER_TIMER_MISSED #ifdef LIN_ADVANCE #define LIN_ADVANCE_K 0 // Unit: mm compression per 1mm/s extruder speed diff --git a/Firmware/planner.h b/Firmware/planner.h index a99f02ede..41e4c61bf 100644 --- a/Firmware/planner.h +++ b/Firmware/planner.h @@ -112,10 +112,10 @@ typedef struct { float speed_factor; #ifdef LIN_ADVANCE - bool use_advance_lead; - uint16_t advance_speed, // Timer value for extruder speed offset - max_adv_steps, // max. advance steps to get cruising speed pressure (not always nominal_speed!) - final_adv_steps; // advance steps due to exit speed + bool use_advance_lead; // Whether the current block uses LA + uint16_t advance_speed, // Step-rate for extruder speed + max_adv_steps, // max. advance steps to get cruising speed pressure (not always nominal_speed!) + final_adv_steps; // advance steps due to exit speed float e_D_ratio; #endif @@ -123,7 +123,7 @@ typedef struct { } block_t; #ifdef LIN_ADVANCE - extern float extruder_advance_K; +extern float extruder_advance_K; // Linear-advance K factor #endif #ifdef ENABLE_AUTO_BED_LEVELING diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index c80581a5e..6b52c5ace 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -113,21 +113,24 @@ volatile long count_position[NUM_AXIS] = { 0, 0, 0, 0}; volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1}; #ifdef LIN_ADVANCE + void advance_isr_scheduler(); + void advance_isr(); + + static const uint16_t ADV_NEVER = 0xFFFF; static uint16_t nextMainISR = 0; - static uint16_t eISR_Rate; + static uint16_t nextAdvanceISR = ADV_NEVER; - // Extrusion steps to be executed by the stepper. - // If set to non zero, the timer ISR routine will tick the Linear Advance extruder ticks first. - // If e_steps is zero, then the timer ISR routine will perform the usual DDA step. - static volatile int16_t e_steps = 0; - // How many extruder steps shall be ticked at a single ISR invocation? - static uint8_t estep_loops; - // The current speed of the extruder, scaled by the linear advance constant, so it has the same measure - // as current_adv_steps. - static int current_estep_rate; - // The current pretension of filament expressed in extruder micro steps. - static int current_adv_steps; + static uint16_t eISR_Rate = ADV_NEVER; + + static bool use_advance_lead; + + static uint16_t current_adv_steps; + static uint16_t final_adv_steps; + static uint16_t max_adv_steps; + static uint32_t LA_decelerate_after; + + static volatile int8_t e_steps; #define _NEXT_ISR(T) nextMainISR = T #else @@ -353,29 +356,6 @@ FORCE_INLINE unsigned short calc_timer(uint16_t step_rate) { } -#ifndef FILAMENT_SENSOR -#define fsensor_step(cnt) -#else -FORCE_INLINE void fsensor_step(uint8_t cnt) -{ - if (READ(E0_DIR_PIN) == INVERT_E0_DIR) - { - if (count_direction[E_AXIS] == 1) - fsensor_counter -= cnt; - else - fsensor_counter += cnt; - } - else - { - if (count_direction[E_AXIS] == 1) - fsensor_counter += cnt; - else - fsensor_counter -= cnt; - } -} -#endif - - // "The Stepper Driver Interrupt" - This timer interrupt is the workhorse. // It pops blocks from the block_buffer and executes them by pulsing the stepper pins appropriately. ISR(TIMER1_COMPA_vect) { @@ -385,38 +365,10 @@ ISR(TIMER1_COMPA_vect) { #endif //DEBUG_STACK_MONITOR #ifdef LIN_ADVANCE - // If there are any e_steps planned, tick them. - bool run_main_isr = false; - if (e_steps) { - //WRITE_NC(LOGIC_ANALYZER_CH7, true); - uint8_t cnt = 0; - for (uint8_t i = estep_loops; e_steps && i --;) { - WRITE_NC(E0_STEP_PIN, !INVERT_E_STEP_PIN); - -- e_steps; - cnt++; - WRITE_NC(E0_STEP_PIN, INVERT_E_STEP_PIN); - } - fsensor_step(cnt); - if (e_steps) { - // Plan another Linear Advance tick. - OCR1A = eISR_Rate; - nextMainISR -= eISR_Rate; - } else if (! (nextMainISR & 0x8000) || nextMainISR < 16) { - // The timer did not overflow and it is big enough, so it makes sense to plan it. - OCR1A = nextMainISR; - } else { - // The timer has overflown, or it is too small. Run the main ISR just after the Linear Advance routine - // in the current interrupt tick. - run_main_isr = true; - //FIXME pick the serial line. - } - //WRITE_NC(LOGIC_ANALYZER_CH7, false); - } else - run_main_isr = true; - - if (run_main_isr) -#endif + advance_isr_scheduler(); +#else isr(); +#endif // Don't run the ISR faster than possible // Is there a 8us time left before the next interrupt triggers? @@ -517,9 +469,14 @@ FORCE_INLINE void stepper_next_block() step_loops_nominal = 0; acc_step_rate = uint16_t(current_block->initial_rate); acceleration_time = calc_timer(acc_step_rate); + #ifdef LIN_ADVANCE - current_estep_rate = ((unsigned long)acc_step_rate * current_block->abs_adv_steps_multiplier8) >> 17; -#endif /* LIN_ADVANCE */ + if ((use_advance_lead = current_block->use_advance_lead)) { + LA_decelerate_after = current_block->decelerate_after; + final_adv_steps = current_block->final_adv_steps; + max_adv_steps = current_block->max_adv_steps; + } +#endif if (current_block->flag & BLOCK_FLAG_DDA_LOWRES) { counter_x.lo = -(current_block->step_event_count.lo >> 1); @@ -788,7 +745,7 @@ FORCE_INLINE void stepper_tick_lowres() counter_e.lo -= current_block->step_event_count.lo; count_position[E_AXIS] += count_direction[E_AXIS]; #ifdef LIN_ADVANCE - ++ e_steps; + e_steps += count_direction[E_AXIS]; #else #ifdef FILAMENT_SENSOR ++ fsensor_counter; @@ -850,11 +807,11 @@ FORCE_INLINE void stepper_tick_highres() counter_e.wide -= current_block->step_event_count.wide; count_position[E_AXIS]+=count_direction[E_AXIS]; #ifdef LIN_ADVANCE - ++ e_steps; + e_steps += count_direction[E_AXIS]; #else - #ifdef FILAMENT_SENSOR + #ifdef FILAMENT_SENSOR ++ fsensor_counter; - #endif //FILAMENT_SENSOR + #endif //FILAMENT_SENSOR WRITE(E0_STEP_PIN, INVERT_E_STEP_PIN); #endif } @@ -863,9 +820,6 @@ FORCE_INLINE void stepper_tick_highres() } } -// 50us delay -#define LIN_ADV_FIRST_TICK_DELAY 100 - FORCE_INLINE void isr() { //WRITE_NC(LOGIC_ANALYZER_CH0, true); @@ -877,65 +831,11 @@ FORCE_INLINE void isr() { if (current_block != NULL) { stepper_check_endstops(); -#ifdef LIN_ADVANCE - e_steps = 0; -#endif /* LIN_ADVANCE */ if (current_block->flag & BLOCK_FLAG_DDA_LOWRES) stepper_tick_lowres(); else stepper_tick_highres(); -#ifdef LIN_ADVANCE - if (out_bits&(1<use_advance_lead) { - //int esteps_inc = 0; - //esteps_inc = current_estep_rate - current_adv_steps; - //e_steps += esteps_inc; - e_steps += current_estep_rate - current_adv_steps; -#if 0 - if (abs(esteps_inc) > 4) { - LOGIC_ANALYZER_SERIAL_TX_WRITE(esteps_inc); - if (esteps_inc < -511 || esteps_inc > 511) - LOGIC_ANALYZER_SERIAL_TX_WRITE(esteps_inc >> 9); - } -#endif - current_adv_steps = current_estep_rate; - } - // If we have esteps to execute, step some of them now. - if (e_steps) { - //WRITE_NC(LOGIC_ANALYZER_CH7, true); - // Set the step direction. - bool neg = e_steps < 0; - { - bool dir = - #ifdef SNMM - (neg == (mmu_extruder & 1)) - #else - neg - #endif - ? INVERT_E0_DIR : !INVERT_E0_DIR; //If we have SNMM, reverse every second extruder. - WRITE_NC(E0_DIR_PIN, dir); - if (neg) - // Flip the e_steps counter to be always positive. - e_steps = - e_steps; - } - // Tick min(step_loops, abs(e_steps)). - estep_loops = (e_steps & 0x0ff00) ? 4 : e_steps; - if (step_loops < estep_loops) - estep_loops = step_loops; - fsensor_step(estep_loops); - do { - WRITE_NC(E0_STEP_PIN, !INVERT_E_STEP_PIN); - -- e_steps; - WRITE_NC(E0_STEP_PIN, INVERT_E_STEP_PIN); - } while (-- estep_loops != 0); - //WRITE_NC(LOGIC_ANALYZER_CH7, false); - MSerial.checkRx(); // Check for serial chars. - } -#endif - // Calculare new timer value // 13.38-14.63us for steady state, // 25.12us for acceleration / deceleration. @@ -952,11 +852,18 @@ FORCE_INLINE void isr() { uint16_t timer = calc_timer(acc_step_rate); _NEXT_ISR(timer); acceleration_time += timer; - #ifdef LIN_ADVANCE - if (current_block->use_advance_lead) - // int32_t = (uint16_t * uint32_t) >> 17 - current_estep_rate = ((uint32_t)acc_step_rate * current_block->abs_adv_steps_multiplier8) >> 17; - #endif +#ifdef LIN_ADVANCE + if (current_block->use_advance_lead) { + if (step_events_completed.wide == (unsigned long int)step_loops || (e_steps && eISR_Rate != current_block->advance_speed)) { + nextAdvanceISR = 0; // Wake up eISR on first acceleration loop and fire ISR if final adv_rate is reached + eISR_Rate = current_block->advance_speed; + } + } + else { + eISR_Rate = ADV_NEVER; + if (e_steps) nextAdvanceISR = 0; + } +#endif } else if (step_events_completed.wide > (unsigned long int)current_block->decelerate_after) { uint16_t step_rate; @@ -970,103 +877,35 @@ FORCE_INLINE void isr() { uint16_t timer = calc_timer(step_rate); _NEXT_ISR(timer); deceleration_time += timer; - #ifdef LIN_ADVANCE - if (current_block->use_advance_lead) - current_estep_rate = ((uint32_t)step_rate * current_block->abs_adv_steps_multiplier8) >> 17; - #endif +#ifdef LIN_ADVANCE + if (current_block->use_advance_lead) { + if (step_events_completed.wide <= (unsigned long int)current_block->decelerate_after + step_loops || (e_steps && eISR_Rate != current_block->advance_speed)) { + nextAdvanceISR = 0; // Wake up eISR on first deceleration loop + eISR_Rate = current_block->advance_speed; + } + } + else { + eISR_Rate = ADV_NEVER; + if (e_steps) nextAdvanceISR = 0; + } +#endif } else { +#ifdef LIN_ADVANCE + // If we have esteps to execute, fire the next advance_isr "now" + if (e_steps && eISR_Rate != current_block->advance_speed) nextAdvanceISR = 0; +#endif if (! step_loops_nominal) { // Calculation of the steady state timer rate has been delayed to the 1st tick of the steady state to lower // the initial interrupt blocking. OCR1A_nominal = calc_timer(uint16_t(current_block->nominal_rate)); step_loops_nominal = step_loops; - #ifdef LIN_ADVANCE - if (current_block->use_advance_lead) - current_estep_rate = (current_block->nominal_rate * current_block->abs_adv_steps_multiplier8) >> 17; - #endif } _NEXT_ISR(OCR1A_nominal); } //WRITE_NC(LOGIC_ANALYZER_CH1, false); } -#ifdef LIN_ADVANCE - if (e_steps && current_block->use_advance_lead) { - //WRITE_NC(LOGIC_ANALYZER_CH7, true); - MSerial.checkRx(); // Check for serial chars. - // Some of the E steps were not ticked yet. Plan additional interrupts. - uint16_t now = TCNT1; - // Plan the first linear advance interrupt after 50us from now. - uint16_t to_go = nextMainISR - now - LIN_ADV_FIRST_TICK_DELAY; - eISR_Rate = 0; - if ((to_go & 0x8000) == 0) { - // The to_go number is not negative. - // Count the number of 7812,5 ticks, that fit into to_go 2MHz ticks. - uint8_t ticks = to_go >> 8; - if (ticks == 1) { - // Avoid running the following loop for a very short interval. - estep_loops = 255; - eISR_Rate = 1; - } else if ((e_steps & 0x0ff00) == 0) { - // e_steps <= 0x0ff - if (uint8_t(e_steps) <= ticks) { - // Spread the e_steps along the whole go_to interval. - eISR_Rate = to_go / uint8_t(e_steps); - estep_loops = 1; - } else if (ticks != 0) { - // At least one tick fits into the to_go interval. Calculate the e-step grouping. - uint8_t e = uint8_t(e_steps) >> 1; - estep_loops = 2; - while (e > ticks) { - e >>= 1; - estep_loops <<= 1; - } - // Now the estep_loops contains the number of loops of power of 2, that will be sufficient - // to squeeze enough of Linear Advance ticks until nextMainISR. - // Calculate the tick rate. - eISR_Rate = to_go / ticks; - } - } else { - // This is an exterme case with too many e_steps inserted by the linear advance. - // At least one tick fits into the to_go interval. Calculate the e-step grouping. - estep_loops = 2; - uint16_t e = e_steps >> 1; - while (e & 0x0ff00) { - e >>= 1; - estep_loops <<= 1; - } - while (uint8_t(e) > ticks) { - e >>= 1; - estep_loops <<= 1; - } - // Now the estep_loops contains the number of loops of power of 2, that will be sufficient - // to squeeze enough of Linear Advance ticks until nextMainISR. - // Calculate the tick rate. - eISR_Rate = to_go / ticks; - } - } - if (eISR_Rate == 0) { - // There is not enough time to fit even a single additional tick. - // Tick all the extruder ticks now. - MSerial.checkRx(); // Check for serial chars. - fsensor_step(e_steps); - do { - WRITE_NC(E0_STEP_PIN, !INVERT_E_STEP_PIN); - -- e_steps; - WRITE_NC(E0_STEP_PIN, INVERT_E_STEP_PIN); - } while (e_steps); - OCR1A = nextMainISR; - } else { - // Tick the 1st Linear Advance interrupt after 50us from now. - nextMainISR -= LIN_ADV_FIRST_TICK_DELAY; - OCR1A = now + LIN_ADV_FIRST_TICK_DELAY; - } - //WRITE_NC(LOGIC_ANALYZER_CH7, false); - } else - OCR1A = nextMainISR; -#endif - // If current block is finished, reset pointer if (step_events_completed.wide >= current_block->step_event_count.wide) { #ifdef FILAMENT_SENSOR @@ -1094,14 +933,84 @@ FORCE_INLINE void isr() { } #ifdef LIN_ADVANCE +// Timer interrupt for E. e_steps is set in the main routine. + +FORCE_INLINE void advance_isr() { + if (use_advance_lead) { + if (step_events_completed.wide > LA_decelerate_after && current_adv_steps > final_adv_steps) { + e_steps--; + current_adv_steps--; + nextAdvanceISR = eISR_Rate; + } + else if (step_events_completed.wide < LA_decelerate_after && current_adv_steps < max_adv_steps) { + e_steps++; + current_adv_steps++; + nextAdvanceISR = eISR_Rate; + } + else { + nextAdvanceISR = ADV_NEVER; + eISR_Rate = ADV_NEVER; + } + } + else + nextAdvanceISR = ADV_NEVER; + + if (e_steps) { + MSerial.checkRx(); // Check for serial chars. + + bool dir = +#ifdef SNMM + ((e_steps < 0) == (snmm_extruder & 1)) +#else + (e_steps < 0) +#endif + ? INVERT_E0_DIR : !INVERT_E0_DIR; //If we have SNMM, reverse every second extruder. + WRITE(E0_DIR_PIN, dir); + + if(e_steps < 0) e_steps = -e_steps; + fsensor_counter += e_steps; + while (e_steps) { + WRITE_NC(E0_STEP_PIN, !INVERT_E_STEP_PIN); + --e_steps; + WRITE_NC(E0_STEP_PIN, INVERT_E_STEP_PIN); + } + } +} + +FORCE_INLINE void advance_isr_scheduler() { + // Run main stepping ISR if flagged + if (!nextMainISR) isr(); + + // Run Advance stepping ISR if flagged + if (!nextAdvanceISR) advance_isr(); + + // Is the next advance ISR scheduled before the next main ISR? + if (nextAdvanceISR <= nextMainISR) { + // Set up the next interrupt + OCR1A = nextAdvanceISR; + // New interval for the next main ISR + if (nextMainISR) nextMainISR -= nextAdvanceISR; + // Will call Stepper::advance_isr on the next interrupt + nextAdvanceISR = 0; + } + else { + // The next main ISR comes first + OCR1A = nextMainISR; + // New interval for the next advance ISR, if any + if (nextAdvanceISR && nextAdvanceISR != ADV_NEVER) + nextAdvanceISR -= nextMainISR; + // Will call Stepper::isr on the next interrupt + nextMainISR = 0; + } +} void clear_current_adv_vars() { - e_steps = 0; //Should be already 0 at an filament change event, but just to be sure.. - current_adv_steps = 0; + e_steps = 0; + current_adv_steps = 0; } #endif // LIN_ADVANCE - + void st_init() { #ifdef TMC2130 @@ -1326,10 +1235,9 @@ void st_init() ENABLE_STEPPER_DRIVER_INTERRUPT(); #ifdef LIN_ADVANCE - e_steps = 0; - current_adv_steps = 0; + clear_current_adv_vars(); #endif - + enable_endstops(true); // Start with endstops active. After homing they can be disabled sei(); } diff --git a/Firmware/stepper.h b/Firmware/stepper.h index 6130f3bb1..23b791848 100644 --- a/Firmware/stepper.h +++ b/Firmware/stepper.h @@ -38,9 +38,7 @@ void st_init(); void isr(); #ifdef LIN_ADVANCE - void advance_isr(); - void advance_isr_scheduler(); - void clear_current_adv_vars(); //Used to reset the built up pretension and remaining esteps on filament change. +void clear_current_adv_vars(); // Used to reset the built up pretension and remaining esteps on filament change. #endif // Block until all buffered steps are executed From ebdc5e35e7587035f783466def32fed7922af72d Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sat, 4 May 2019 23:05:30 +0200 Subject: [PATCH 007/180] Remove two more OCR1A direct manipulations Use _NEXT_ISR and st_reset_timer to correctly reinitialize and re-schedule the advance ticks. --- Firmware/stepper.cpp | 33 +++++++++++++++++++++++++++------ Firmware/stepper.h | 10 +--------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 6b52c5ace..5a3d4010a 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -535,7 +535,7 @@ FORCE_INLINE void stepper_next_block() } } else { - OCR1A = 2000; // 1kHz. + _NEXT_ISR(2000); // 1kHz. } //WRITE_NC(LOGIC_ANALYZER_CH2, false); } @@ -1229,20 +1229,41 @@ void st_init() // create_speed_lookuptable.py TCCR1B = (TCCR1B & ~(0x07< Date: Sun, 5 May 2019 17:22:27 +0200 Subject: [PATCH 008/180] Move speed lookup defs into a separate source --- Firmware/speed_lookuptable.cpp | 147 ++++++++++++++++++++++ Firmware/speed_lookuptable.h | 217 ++++++++++++--------------------- Firmware/stepper.cpp | 86 ------------- 3 files changed, 224 insertions(+), 226 deletions(-) create mode 100644 Firmware/speed_lookuptable.cpp diff --git a/Firmware/speed_lookuptable.cpp b/Firmware/speed_lookuptable.cpp new file mode 100644 index 000000000..b8930e7bb --- /dev/null +++ b/Firmware/speed_lookuptable.cpp @@ -0,0 +1,147 @@ +#include "speed_lookuptable.h" + +#if F_CPU == 16000000 + +const uint16_t speed_lookuptable_fast[256][2] PROGMEM = {\ +{ 62500, 55556}, { 6944, 3268}, { 3676, 1176}, { 2500, 607}, { 1893, 369}, { 1524, 249}, { 1275, 179}, { 1096, 135}, +{ 961, 105}, { 856, 85}, { 771, 69}, { 702, 58}, { 644, 49}, { 595, 42}, { 553, 37}, { 516, 32}, +{ 484, 28}, { 456, 25}, { 431, 23}, { 408, 20}, { 388, 19}, { 369, 16}, { 353, 16}, { 337, 14}, +{ 323, 13}, { 310, 11}, { 299, 11}, { 288, 11}, { 277, 9}, { 268, 9}, { 259, 8}, { 251, 8}, +{ 243, 8}, { 235, 7}, { 228, 6}, { 222, 6}, { 216, 6}, { 210, 6}, { 204, 5}, { 199, 5}, +{ 194, 5}, { 189, 4}, { 185, 4}, { 181, 4}, { 177, 4}, { 173, 4}, { 169, 4}, { 165, 3}, +{ 162, 3}, { 159, 4}, { 155, 3}, { 152, 3}, { 149, 2}, { 147, 3}, { 144, 3}, { 141, 2}, +{ 139, 3}, { 136, 2}, { 134, 2}, { 132, 3}, { 129, 2}, { 127, 2}, { 125, 2}, { 123, 2}, +{ 121, 2}, { 119, 1}, { 118, 2}, { 116, 2}, { 114, 1}, { 113, 2}, { 111, 2}, { 109, 1}, +{ 108, 2}, { 106, 1}, { 105, 2}, { 103, 1}, { 102, 1}, { 101, 1}, { 100, 2}, { 98, 1}, +{ 97, 1}, { 96, 1}, { 95, 2}, { 93, 1}, { 92, 1}, { 91, 1}, { 90, 1}, { 89, 1}, +{ 88, 1}, { 87, 1}, { 86, 1}, { 85, 1}, { 84, 1}, { 83, 0}, { 83, 1}, { 82, 1}, +{ 81, 1}, { 80, 1}, { 79, 1}, { 78, 0}, { 78, 1}, { 77, 1}, { 76, 1}, { 75, 0}, +{ 75, 1}, { 74, 1}, { 73, 1}, { 72, 0}, { 72, 1}, { 71, 1}, { 70, 0}, { 70, 1}, +{ 69, 0}, { 69, 1}, { 68, 1}, { 67, 0}, { 67, 1}, { 66, 0}, { 66, 1}, { 65, 0}, +{ 65, 1}, { 64, 1}, { 63, 0}, { 63, 1}, { 62, 0}, { 62, 1}, { 61, 0}, { 61, 1}, +{ 60, 0}, { 60, 0}, { 60, 1}, { 59, 0}, { 59, 1}, { 58, 0}, { 58, 1}, { 57, 0}, +{ 57, 1}, { 56, 0}, { 56, 0}, { 56, 1}, { 55, 0}, { 55, 1}, { 54, 0}, { 54, 0}, +{ 54, 1}, { 53, 0}, { 53, 0}, { 53, 1}, { 52, 0}, { 52, 0}, { 52, 1}, { 51, 0}, +{ 51, 0}, { 51, 1}, { 50, 0}, { 50, 0}, { 50, 1}, { 49, 0}, { 49, 0}, { 49, 1}, +{ 48, 0}, { 48, 0}, { 48, 1}, { 47, 0}, { 47, 0}, { 47, 0}, { 47, 1}, { 46, 0}, +{ 46, 0}, { 46, 1}, { 45, 0}, { 45, 0}, { 45, 0}, { 45, 1}, { 44, 0}, { 44, 0}, +{ 44, 0}, { 44, 1}, { 43, 0}, { 43, 0}, { 43, 0}, { 43, 1}, { 42, 0}, { 42, 0}, +{ 42, 0}, { 42, 1}, { 41, 0}, { 41, 0}, { 41, 0}, { 41, 0}, { 41, 1}, { 40, 0}, +{ 40, 0}, { 40, 0}, { 40, 0}, { 40, 1}, { 39, 0}, { 39, 0}, { 39, 0}, { 39, 0}, +{ 39, 1}, { 38, 0}, { 38, 0}, { 38, 0}, { 38, 0}, { 38, 1}, { 37, 0}, { 37, 0}, +{ 37, 0}, { 37, 0}, { 37, 0}, { 37, 1}, { 36, 0}, { 36, 0}, { 36, 0}, { 36, 0}, +{ 36, 1}, { 35, 0}, { 35, 0}, { 35, 0}, { 35, 0}, { 35, 0}, { 35, 0}, { 35, 1}, +{ 34, 0}, { 34, 0}, { 34, 0}, { 34, 0}, { 34, 0}, { 34, 1}, { 33, 0}, { 33, 0}, +{ 33, 0}, { 33, 0}, { 33, 0}, { 33, 0}, { 33, 1}, { 32, 0}, { 32, 0}, { 32, 0}, +{ 32, 0}, { 32, 0}, { 32, 0}, { 32, 0}, { 32, 1}, { 31, 0}, { 31, 0}, { 31, 0}, +{ 31, 0}, { 31, 0}, { 31, 0}, { 31, 1}, { 30, 0}, { 30, 0}, { 30, 0}, { 30, 0} +}; + +const uint16_t speed_lookuptable_slow[256][2] PROGMEM = {\ +{ 62500, 12500}, { 50000, 8334}, { 41666, 5952}, { 35714, 4464}, { 31250, 3473}, { 27777, 2777}, { 25000, 2273}, { 22727, 1894}, +{ 20833, 1603}, { 19230, 1373}, { 17857, 1191}, { 16666, 1041}, { 15625, 920}, { 14705, 817}, { 13888, 731}, { 13157, 657}, +{ 12500, 596}, { 11904, 541}, { 11363, 494}, { 10869, 453}, { 10416, 416}, { 10000, 385}, { 9615, 356}, { 9259, 331}, +{ 8928, 308}, { 8620, 287}, { 8333, 269}, { 8064, 252}, { 7812, 237}, { 7575, 223}, { 7352, 210}, { 7142, 198}, +{ 6944, 188}, { 6756, 178}, { 6578, 168}, { 6410, 160}, { 6250, 153}, { 6097, 145}, { 5952, 139}, { 5813, 132}, +{ 5681, 126}, { 5555, 121}, { 5434, 115}, { 5319, 111}, { 5208, 106}, { 5102, 102}, { 5000, 99}, { 4901, 94}, +{ 4807, 91}, { 4716, 87}, { 4629, 84}, { 4545, 81}, { 4464, 79}, { 4385, 75}, { 4310, 73}, { 4237, 71}, +{ 4166, 68}, { 4098, 66}, { 4032, 64}, { 3968, 62}, { 3906, 60}, { 3846, 59}, { 3787, 56}, { 3731, 55}, +{ 3676, 53}, { 3623, 52}, { 3571, 50}, { 3521, 49}, { 3472, 48}, { 3424, 46}, { 3378, 45}, { 3333, 44}, +{ 3289, 43}, { 3246, 41}, { 3205, 41}, { 3164, 39}, { 3125, 39}, { 3086, 38}, { 3048, 36}, { 3012, 36}, +{ 2976, 35}, { 2941, 35}, { 2906, 33}, { 2873, 33}, { 2840, 32}, { 2808, 31}, { 2777, 30}, { 2747, 30}, +{ 2717, 29}, { 2688, 29}, { 2659, 28}, { 2631, 27}, { 2604, 27}, { 2577, 26}, { 2551, 26}, { 2525, 25}, +{ 2500, 25}, { 2475, 25}, { 2450, 23}, { 2427, 24}, { 2403, 23}, { 2380, 22}, { 2358, 22}, { 2336, 22}, +{ 2314, 21}, { 2293, 21}, { 2272, 20}, { 2252, 20}, { 2232, 20}, { 2212, 20}, { 2192, 19}, { 2173, 18}, +{ 2155, 19}, { 2136, 18}, { 2118, 18}, { 2100, 17}, { 2083, 17}, { 2066, 17}, { 2049, 17}, { 2032, 16}, +{ 2016, 16}, { 2000, 16}, { 1984, 16}, { 1968, 15}, { 1953, 16}, { 1937, 14}, { 1923, 15}, { 1908, 15}, +{ 1893, 14}, { 1879, 14}, { 1865, 14}, { 1851, 13}, { 1838, 14}, { 1824, 13}, { 1811, 13}, { 1798, 13}, +{ 1785, 12}, { 1773, 13}, { 1760, 12}, { 1748, 12}, { 1736, 12}, { 1724, 12}, { 1712, 12}, { 1700, 11}, +{ 1689, 12}, { 1677, 11}, { 1666, 11}, { 1655, 11}, { 1644, 11}, { 1633, 10}, { 1623, 11}, { 1612, 10}, +{ 1602, 10}, { 1592, 10}, { 1582, 10}, { 1572, 10}, { 1562, 10}, { 1552, 9}, { 1543, 10}, { 1533, 9}, +{ 1524, 9}, { 1515, 9}, { 1506, 9}, { 1497, 9}, { 1488, 9}, { 1479, 9}, { 1470, 9}, { 1461, 8}, +{ 1453, 8}, { 1445, 9}, { 1436, 8}, { 1428, 8}, { 1420, 8}, { 1412, 8}, { 1404, 8}, { 1396, 8}, +{ 1388, 7}, { 1381, 8}, { 1373, 7}, { 1366, 8}, { 1358, 7}, { 1351, 7}, { 1344, 8}, { 1336, 7}, +{ 1329, 7}, { 1322, 7}, { 1315, 7}, { 1308, 6}, { 1302, 7}, { 1295, 7}, { 1288, 6}, { 1282, 7}, +{ 1275, 6}, { 1269, 7}, { 1262, 6}, { 1256, 6}, { 1250, 7}, { 1243, 6}, { 1237, 6}, { 1231, 6}, +{ 1225, 6}, { 1219, 6}, { 1213, 6}, { 1207, 6}, { 1201, 5}, { 1196, 6}, { 1190, 6}, { 1184, 5}, +{ 1179, 6}, { 1173, 5}, { 1168, 6}, { 1162, 5}, { 1157, 5}, { 1152, 6}, { 1146, 5}, { 1141, 5}, +{ 1136, 5}, { 1131, 5}, { 1126, 5}, { 1121, 5}, { 1116, 5}, { 1111, 5}, { 1106, 5}, { 1101, 5}, +{ 1096, 5}, { 1091, 5}, { 1086, 4}, { 1082, 5}, { 1077, 5}, { 1072, 4}, { 1068, 5}, { 1063, 4}, +{ 1059, 5}, { 1054, 4}, { 1050, 4}, { 1046, 5}, { 1041, 4}, { 1037, 4}, { 1033, 5}, { 1028, 4}, +{ 1024, 4}, { 1020, 4}, { 1016, 4}, { 1012, 4}, { 1008, 4}, { 1004, 4}, { 1000, 4}, { 996, 4}, +{ 992, 4}, { 988, 4}, { 984, 4}, { 980, 4}, { 976, 4}, { 972, 4}, { 968, 3}, { 965, 3} +}; + +#elif F_CPU == 20000000 + +const uint16_t speed_lookuptable_fast[256][2] PROGMEM = { + {62500, 54055}, {8445, 3917}, {4528, 1434}, {3094, 745}, {2349, 456}, {1893, 307}, {1586, 222}, {1364, 167}, + {1197, 131}, {1066, 105}, {961, 86}, {875, 72}, {803, 61}, {742, 53}, {689, 45}, {644, 40}, + {604, 35}, {569, 32}, {537, 28}, {509, 25}, {484, 23}, {461, 21}, {440, 19}, {421, 17}, + {404, 16}, {388, 15}, {373, 14}, {359, 13}, {346, 12}, {334, 11}, {323, 10}, {313, 10}, + {303, 9}, {294, 9}, {285, 8}, {277, 7}, {270, 8}, {262, 7}, {255, 6}, {249, 6}, + {243, 6}, {237, 6}, {231, 5}, {226, 5}, {221, 5}, {216, 5}, {211, 4}, {207, 5}, + {202, 4}, {198, 4}, {194, 4}, {190, 3}, {187, 4}, {183, 3}, {180, 3}, {177, 4}, + {173, 3}, {170, 3}, {167, 2}, {165, 3}, {162, 3}, {159, 2}, {157, 3}, {154, 2}, + {152, 3}, {149, 2}, {147, 2}, {145, 2}, {143, 2}, {141, 2}, {139, 2}, {137, 2}, + {135, 2}, {133, 2}, {131, 2}, {129, 1}, {128, 2}, {126, 2}, {124, 1}, {123, 2}, + {121, 1}, {120, 2}, {118, 1}, {117, 1}, {116, 2}, {114, 1}, {113, 1}, {112, 2}, + {110, 1}, {109, 1}, {108, 1}, {107, 2}, {105, 1}, {104, 1}, {103, 1}, {102, 1}, + {101, 1}, {100, 1}, {99, 1}, {98, 1}, {97, 1}, {96, 1}, {95, 1}, {94, 1}, + {93, 1}, {92, 1}, {91, 0}, {91, 1}, {90, 1}, {89, 1}, {88, 1}, {87, 0}, + {87, 1}, {86, 1}, {85, 1}, {84, 0}, {84, 1}, {83, 1}, {82, 1}, {81, 0}, + {81, 1}, {80, 1}, {79, 0}, {79, 1}, {78, 0}, {78, 1}, {77, 1}, {76, 0}, + {76, 1}, {75, 0}, {75, 1}, {74, 1}, {73, 0}, {73, 1}, {72, 0}, {72, 1}, + {71, 0}, {71, 1}, {70, 0}, {70, 1}, {69, 0}, {69, 1}, {68, 0}, {68, 1}, + {67, 0}, {67, 1}, {66, 0}, {66, 1}, {65, 0}, {65, 0}, {65, 1}, {64, 0}, + {64, 1}, {63, 0}, {63, 1}, {62, 0}, {62, 0}, {62, 1}, {61, 0}, {61, 1}, + {60, 0}, {60, 0}, {60, 1}, {59, 0}, {59, 0}, {59, 1}, {58, 0}, {58, 0}, + {58, 1}, {57, 0}, {57, 0}, {57, 1}, {56, 0}, {56, 0}, {56, 1}, {55, 0}, + {55, 0}, {55, 1}, {54, 0}, {54, 0}, {54, 1}, {53, 0}, {53, 0}, {53, 0}, + {53, 1}, {52, 0}, {52, 0}, {52, 1}, {51, 0}, {51, 0}, {51, 0}, {51, 1}, + {50, 0}, {50, 0}, {50, 0}, {50, 1}, {49, 0}, {49, 0}, {49, 0}, {49, 1}, + {48, 0}, {48, 0}, {48, 0}, {48, 1}, {47, 0}, {47, 0}, {47, 0}, {47, 1}, + {46, 0}, {46, 0}, {46, 0}, {46, 0}, {46, 1}, {45, 0}, {45, 0}, {45, 0}, + {45, 1}, {44, 0}, {44, 0}, {44, 0}, {44, 0}, {44, 1}, {43, 0}, {43, 0}, + {43, 0}, {43, 0}, {43, 1}, {42, 0}, {42, 0}, {42, 0}, {42, 0}, {42, 0}, + {42, 1}, {41, 0}, {41, 0}, {41, 0}, {41, 0}, {41, 0}, {41, 1}, {40, 0}, + {40, 0}, {40, 0}, {40, 0}, {40, 1}, {39, 0}, {39, 0}, {39, 0}, {39, 0}, + {39, 0}, {39, 0}, {39, 1}, {38, 0}, {38, 0}, {38, 0}, {38, 0}, {38, 0}, +}; + +const uint16_t speed_lookuptable_slow[256][2] PROGMEM = { + {62500, 10417}, {52083, 7441}, {44642, 5580}, {39062, 4340}, {34722, 3472}, {31250, 2841}, {28409, 2368}, {26041, 2003}, + {24038, 1717}, {22321, 1488}, {20833, 1302}, {19531, 1149}, {18382, 1021}, {17361, 914}, {16447, 822}, {15625, 745}, + {14880, 676}, {14204, 618}, {13586, 566}, {13020, 520}, {12500, 481}, {12019, 445}, {11574, 414}, {11160, 385}, + {10775, 359}, {10416, 336}, {10080, 315}, {9765, 296}, {9469, 278}, {9191, 263}, {8928, 248}, {8680, 235}, + {8445, 222}, {8223, 211}, {8012, 200}, {7812, 191}, {7621, 181}, {7440, 173}, {7267, 165}, {7102, 158}, + {6944, 151}, {6793, 145}, {6648, 138}, {6510, 133}, {6377, 127}, {6250, 123}, {6127, 118}, {6009, 113}, + {5896, 109}, {5787, 106}, {5681, 101}, {5580, 98}, {5482, 95}, {5387, 91}, {5296, 88}, {5208, 86}, + {5122, 82}, {5040, 80}, {4960, 78}, {4882, 75}, {4807, 73}, {4734, 70}, {4664, 69}, {4595, 67}, + {4528, 64}, {4464, 63}, {4401, 61}, {4340, 60}, {4280, 58}, {4222, 56}, {4166, 55}, {4111, 53}, + {4058, 52}, {4006, 51}, {3955, 49}, {3906, 48}, {3858, 48}, {3810, 45}, {3765, 45}, {3720, 44}, + {3676, 43}, {3633, 42}, {3591, 40}, {3551, 40}, {3511, 39}, {3472, 38}, {3434, 38}, {3396, 36}, + {3360, 36}, {3324, 35}, {3289, 34}, {3255, 34}, {3221, 33}, {3188, 32}, {3156, 31}, {3125, 31}, + {3094, 31}, {3063, 30}, {3033, 29}, {3004, 28}, {2976, 28}, {2948, 28}, {2920, 27}, {2893, 27}, + {2866, 26}, {2840, 25}, {2815, 25}, {2790, 25}, {2765, 24}, {2741, 24}, {2717, 24}, {2693, 23}, + {2670, 22}, {2648, 22}, {2626, 22}, {2604, 22}, {2582, 21}, {2561, 21}, {2540, 20}, {2520, 20}, + {2500, 20}, {2480, 20}, {2460, 19}, {2441, 19}, {2422, 19}, {2403, 18}, {2385, 18}, {2367, 18}, + {2349, 17}, {2332, 18}, {2314, 17}, {2297, 16}, {2281, 17}, {2264, 16}, {2248, 16}, {2232, 16}, + {2216, 16}, {2200, 15}, {2185, 15}, {2170, 15}, {2155, 15}, {2140, 15}, {2125, 14}, {2111, 14}, + {2097, 14}, {2083, 14}, {2069, 14}, {2055, 13}, {2042, 13}, {2029, 13}, {2016, 13}, {2003, 13}, + {1990, 13}, {1977, 12}, {1965, 12}, {1953, 13}, {1940, 11}, {1929, 12}, {1917, 12}, {1905, 12}, + {1893, 11}, {1882, 11}, {1871, 11}, {1860, 11}, {1849, 11}, {1838, 11}, {1827, 11}, {1816, 10}, + {1806, 11}, {1795, 10}, {1785, 10}, {1775, 10}, {1765, 10}, {1755, 10}, {1745, 9}, {1736, 10}, + {1726, 9}, {1717, 10}, {1707, 9}, {1698, 9}, {1689, 9}, {1680, 9}, {1671, 9}, {1662, 9}, + {1653, 9}, {1644, 8}, {1636, 9}, {1627, 8}, {1619, 9}, {1610, 8}, {1602, 8}, {1594, 8}, + {1586, 8}, {1578, 8}, {1570, 8}, {1562, 8}, {1554, 7}, {1547, 8}, {1539, 8}, {1531, 7}, + {1524, 8}, {1516, 7}, {1509, 7}, {1502, 7}, {1495, 7}, {1488, 7}, {1481, 7}, {1474, 7}, + {1467, 7}, {1460, 7}, {1453, 7}, {1446, 6}, {1440, 7}, {1433, 7}, {1426, 6}, {1420, 6}, + {1414, 7}, {1407, 6}, {1401, 6}, {1395, 7}, {1388, 6}, {1382, 6}, {1376, 6}, {1370, 6}, + {1364, 6}, {1358, 6}, {1352, 6}, {1346, 5}, {1341, 6}, {1335, 6}, {1329, 5}, {1324, 6}, + {1318, 5}, {1313, 6}, {1307, 5}, {1302, 6}, {1296, 5}, {1291, 5}, {1286, 6}, {1280, 5}, + {1275, 5}, {1270, 5}, {1265, 5}, {1260, 5}, {1255, 5}, {1250, 5}, {1245, 5}, {1240, 5}, + {1235, 5}, {1230, 5}, {1225, 5}, {1220, 5}, {1215, 4}, {1211, 5}, {1206, 5}, {1201, 5}, +}; + +#endif diff --git a/Firmware/speed_lookuptable.h b/Firmware/speed_lookuptable.h index b7c00f1ae..6a1a44ef1 100644 --- a/Firmware/speed_lookuptable.h +++ b/Firmware/speed_lookuptable.h @@ -3,150 +3,87 @@ #include "Marlin.h" -#if F_CPU == 16000000 +extern const uint16_t speed_lookuptable_fast[256][2] PROGMEM; +extern const uint16_t speed_lookuptable_slow[256][2] PROGMEM; -const uint16_t speed_lookuptable_fast[256][2] PROGMEM = {\ -{ 62500, 55556}, { 6944, 3268}, { 3676, 1176}, { 2500, 607}, { 1893, 369}, { 1524, 249}, { 1275, 179}, { 1096, 135}, -{ 961, 105}, { 856, 85}, { 771, 69}, { 702, 58}, { 644, 49}, { 595, 42}, { 553, 37}, { 516, 32}, -{ 484, 28}, { 456, 25}, { 431, 23}, { 408, 20}, { 388, 19}, { 369, 16}, { 353, 16}, { 337, 14}, -{ 323, 13}, { 310, 11}, { 299, 11}, { 288, 11}, { 277, 9}, { 268, 9}, { 259, 8}, { 251, 8}, -{ 243, 8}, { 235, 7}, { 228, 6}, { 222, 6}, { 216, 6}, { 210, 6}, { 204, 5}, { 199, 5}, -{ 194, 5}, { 189, 4}, { 185, 4}, { 181, 4}, { 177, 4}, { 173, 4}, { 169, 4}, { 165, 3}, -{ 162, 3}, { 159, 4}, { 155, 3}, { 152, 3}, { 149, 2}, { 147, 3}, { 144, 3}, { 141, 2}, -{ 139, 3}, { 136, 2}, { 134, 2}, { 132, 3}, { 129, 2}, { 127, 2}, { 125, 2}, { 123, 2}, -{ 121, 2}, { 119, 1}, { 118, 2}, { 116, 2}, { 114, 1}, { 113, 2}, { 111, 2}, { 109, 1}, -{ 108, 2}, { 106, 1}, { 105, 2}, { 103, 1}, { 102, 1}, { 101, 1}, { 100, 2}, { 98, 1}, -{ 97, 1}, { 96, 1}, { 95, 2}, { 93, 1}, { 92, 1}, { 91, 1}, { 90, 1}, { 89, 1}, -{ 88, 1}, { 87, 1}, { 86, 1}, { 85, 1}, { 84, 1}, { 83, 0}, { 83, 1}, { 82, 1}, -{ 81, 1}, { 80, 1}, { 79, 1}, { 78, 0}, { 78, 1}, { 77, 1}, { 76, 1}, { 75, 0}, -{ 75, 1}, { 74, 1}, { 73, 1}, { 72, 0}, { 72, 1}, { 71, 1}, { 70, 0}, { 70, 1}, -{ 69, 0}, { 69, 1}, { 68, 1}, { 67, 0}, { 67, 1}, { 66, 0}, { 66, 1}, { 65, 0}, -{ 65, 1}, { 64, 1}, { 63, 0}, { 63, 1}, { 62, 0}, { 62, 1}, { 61, 0}, { 61, 1}, -{ 60, 0}, { 60, 0}, { 60, 1}, { 59, 0}, { 59, 1}, { 58, 0}, { 58, 1}, { 57, 0}, -{ 57, 1}, { 56, 0}, { 56, 0}, { 56, 1}, { 55, 0}, { 55, 1}, { 54, 0}, { 54, 0}, -{ 54, 1}, { 53, 0}, { 53, 0}, { 53, 1}, { 52, 0}, { 52, 0}, { 52, 1}, { 51, 0}, -{ 51, 0}, { 51, 1}, { 50, 0}, { 50, 0}, { 50, 1}, { 49, 0}, { 49, 0}, { 49, 1}, -{ 48, 0}, { 48, 0}, { 48, 1}, { 47, 0}, { 47, 0}, { 47, 0}, { 47, 1}, { 46, 0}, -{ 46, 0}, { 46, 1}, { 45, 0}, { 45, 0}, { 45, 0}, { 45, 1}, { 44, 0}, { 44, 0}, -{ 44, 0}, { 44, 1}, { 43, 0}, { 43, 0}, { 43, 0}, { 43, 1}, { 42, 0}, { 42, 0}, -{ 42, 0}, { 42, 1}, { 41, 0}, { 41, 0}, { 41, 0}, { 41, 0}, { 41, 1}, { 40, 0}, -{ 40, 0}, { 40, 0}, { 40, 0}, { 40, 1}, { 39, 0}, { 39, 0}, { 39, 0}, { 39, 0}, -{ 39, 1}, { 38, 0}, { 38, 0}, { 38, 0}, { 38, 0}, { 38, 1}, { 37, 0}, { 37, 0}, -{ 37, 0}, { 37, 0}, { 37, 0}, { 37, 1}, { 36, 0}, { 36, 0}, { 36, 0}, { 36, 0}, -{ 36, 1}, { 35, 0}, { 35, 0}, { 35, 0}, { 35, 0}, { 35, 0}, { 35, 0}, { 35, 1}, -{ 34, 0}, { 34, 0}, { 34, 0}, { 34, 0}, { 34, 0}, { 34, 1}, { 33, 0}, { 33, 0}, -{ 33, 0}, { 33, 0}, { 33, 0}, { 33, 0}, { 33, 1}, { 32, 0}, { 32, 0}, { 32, 0}, -{ 32, 0}, { 32, 0}, { 32, 0}, { 32, 0}, { 32, 1}, { 31, 0}, { 31, 0}, { 31, 0}, -{ 31, 0}, { 31, 0}, { 31, 0}, { 31, 1}, { 30, 0}, { 30, 0}, { 30, 0}, { 30, 0} -}; +#ifndef _NO_ASM -const uint16_t speed_lookuptable_slow[256][2] PROGMEM = {\ -{ 62500, 12500}, { 50000, 8334}, { 41666, 5952}, { 35714, 4464}, { 31250, 3473}, { 27777, 2777}, { 25000, 2273}, { 22727, 1894}, -{ 20833, 1603}, { 19230, 1373}, { 17857, 1191}, { 16666, 1041}, { 15625, 920}, { 14705, 817}, { 13888, 731}, { 13157, 657}, -{ 12500, 596}, { 11904, 541}, { 11363, 494}, { 10869, 453}, { 10416, 416}, { 10000, 385}, { 9615, 356}, { 9259, 331}, -{ 8928, 308}, { 8620, 287}, { 8333, 269}, { 8064, 252}, { 7812, 237}, { 7575, 223}, { 7352, 210}, { 7142, 198}, -{ 6944, 188}, { 6756, 178}, { 6578, 168}, { 6410, 160}, { 6250, 153}, { 6097, 145}, { 5952, 139}, { 5813, 132}, -{ 5681, 126}, { 5555, 121}, { 5434, 115}, { 5319, 111}, { 5208, 106}, { 5102, 102}, { 5000, 99}, { 4901, 94}, -{ 4807, 91}, { 4716, 87}, { 4629, 84}, { 4545, 81}, { 4464, 79}, { 4385, 75}, { 4310, 73}, { 4237, 71}, -{ 4166, 68}, { 4098, 66}, { 4032, 64}, { 3968, 62}, { 3906, 60}, { 3846, 59}, { 3787, 56}, { 3731, 55}, -{ 3676, 53}, { 3623, 52}, { 3571, 50}, { 3521, 49}, { 3472, 48}, { 3424, 46}, { 3378, 45}, { 3333, 44}, -{ 3289, 43}, { 3246, 41}, { 3205, 41}, { 3164, 39}, { 3125, 39}, { 3086, 38}, { 3048, 36}, { 3012, 36}, -{ 2976, 35}, { 2941, 35}, { 2906, 33}, { 2873, 33}, { 2840, 32}, { 2808, 31}, { 2777, 30}, { 2747, 30}, -{ 2717, 29}, { 2688, 29}, { 2659, 28}, { 2631, 27}, { 2604, 27}, { 2577, 26}, { 2551, 26}, { 2525, 25}, -{ 2500, 25}, { 2475, 25}, { 2450, 23}, { 2427, 24}, { 2403, 23}, { 2380, 22}, { 2358, 22}, { 2336, 22}, -{ 2314, 21}, { 2293, 21}, { 2272, 20}, { 2252, 20}, { 2232, 20}, { 2212, 20}, { 2192, 19}, { 2173, 18}, -{ 2155, 19}, { 2136, 18}, { 2118, 18}, { 2100, 17}, { 2083, 17}, { 2066, 17}, { 2049, 17}, { 2032, 16}, -{ 2016, 16}, { 2000, 16}, { 1984, 16}, { 1968, 15}, { 1953, 16}, { 1937, 14}, { 1923, 15}, { 1908, 15}, -{ 1893, 14}, { 1879, 14}, { 1865, 14}, { 1851, 13}, { 1838, 14}, { 1824, 13}, { 1811, 13}, { 1798, 13}, -{ 1785, 12}, { 1773, 13}, { 1760, 12}, { 1748, 12}, { 1736, 12}, { 1724, 12}, { 1712, 12}, { 1700, 11}, -{ 1689, 12}, { 1677, 11}, { 1666, 11}, { 1655, 11}, { 1644, 11}, { 1633, 10}, { 1623, 11}, { 1612, 10}, -{ 1602, 10}, { 1592, 10}, { 1582, 10}, { 1572, 10}, { 1562, 10}, { 1552, 9}, { 1543, 10}, { 1533, 9}, -{ 1524, 9}, { 1515, 9}, { 1506, 9}, { 1497, 9}, { 1488, 9}, { 1479, 9}, { 1470, 9}, { 1461, 8}, -{ 1453, 8}, { 1445, 9}, { 1436, 8}, { 1428, 8}, { 1420, 8}, { 1412, 8}, { 1404, 8}, { 1396, 8}, -{ 1388, 7}, { 1381, 8}, { 1373, 7}, { 1366, 8}, { 1358, 7}, { 1351, 7}, { 1344, 8}, { 1336, 7}, -{ 1329, 7}, { 1322, 7}, { 1315, 7}, { 1308, 6}, { 1302, 7}, { 1295, 7}, { 1288, 6}, { 1282, 7}, -{ 1275, 6}, { 1269, 7}, { 1262, 6}, { 1256, 6}, { 1250, 7}, { 1243, 6}, { 1237, 6}, { 1231, 6}, -{ 1225, 6}, { 1219, 6}, { 1213, 6}, { 1207, 6}, { 1201, 5}, { 1196, 6}, { 1190, 6}, { 1184, 5}, -{ 1179, 6}, { 1173, 5}, { 1168, 6}, { 1162, 5}, { 1157, 5}, { 1152, 6}, { 1146, 5}, { 1141, 5}, -{ 1136, 5}, { 1131, 5}, { 1126, 5}, { 1121, 5}, { 1116, 5}, { 1111, 5}, { 1106, 5}, { 1101, 5}, -{ 1096, 5}, { 1091, 5}, { 1086, 4}, { 1082, 5}, { 1077, 5}, { 1072, 4}, { 1068, 5}, { 1063, 4}, -{ 1059, 5}, { 1054, 4}, { 1050, 4}, { 1046, 5}, { 1041, 4}, { 1037, 4}, { 1033, 5}, { 1028, 4}, -{ 1024, 4}, { 1020, 4}, { 1016, 4}, { 1012, 4}, { 1008, 4}, { 1004, 4}, { 1000, 4}, { 996, 4}, -{ 992, 4}, { 988, 4}, { 984, 4}, { 980, 4}, { 976, 4}, { 972, 4}, { 968, 3}, { 965, 3} -}; +// intRes = intIn1 * intIn2 >> 16 +// uses: +// r26 to store 0 +// r27 to store the byte 1 of the 24 bit result +#define MultiU16X8toH16(intRes, charIn1, intIn2) \ +asm volatile ( \ +"clr r26 \n\t" \ +"mul %A1, %B2 \n\t" \ +"movw %A0, r0 \n\t" \ +"mul %A1, %A2 \n\t" \ +"add %A0, r1 \n\t" \ +"adc %B0, r26 \n\t" \ +"lsr r0 \n\t" \ +"adc %A0, r26 \n\t" \ +"adc %B0, r26 \n\t" \ +"clr r1 \n\t" \ +: \ +"=&r" (intRes) \ +: \ +"d" (charIn1), \ +"d" (intIn2) \ +: \ +"r26" \ +) -#elif F_CPU == 20000000 +// intRes = longIn1 * longIn2 >> 24 +// uses: +// r26 to store 0 +// r27 to store the byte 1 of the 48bit result +#define MultiU24X24toH16(intRes, longIn1, longIn2) \ +asm volatile ( \ +"clr r26 \n\t" \ +"mul %A1, %B2 \n\t" \ +"mov r27, r1 \n\t" \ +"mul %B1, %C2 \n\t" \ +"movw %A0, r0 \n\t" \ +"mul %C1, %C2 \n\t" \ +"add %B0, r0 \n\t" \ +"mul %C1, %B2 \n\t" \ +"add %A0, r0 \n\t" \ +"adc %B0, r1 \n\t" \ +"mul %A1, %C2 \n\t" \ +"add r27, r0 \n\t" \ +"adc %A0, r1 \n\t" \ +"adc %B0, r26 \n\t" \ +"mul %B1, %B2 \n\t" \ +"add r27, r0 \n\t" \ +"adc %A0, r1 \n\t" \ +"adc %B0, r26 \n\t" \ +"mul %C1, %A2 \n\t" \ +"add r27, r0 \n\t" \ +"adc %A0, r1 \n\t" \ +"adc %B0, r26 \n\t" \ +"mul %B1, %A2 \n\t" \ +"add r27, r1 \n\t" \ +"adc %A0, r26 \n\t" \ +"adc %B0, r26 \n\t" \ +"lsr r27 \n\t" \ +"adc %A0, r26 \n\t" \ +"adc %B0, r26 \n\t" \ +"clr r1 \n\t" \ +: \ +"=&r" (intRes) \ +: \ +"d" (longIn1), \ +"d" (longIn2) \ +: \ +"r26" , "r27" \ +) -const uint16_t speed_lookuptable_fast[256][2] PROGMEM = { - {62500, 54055}, {8445, 3917}, {4528, 1434}, {3094, 745}, {2349, 456}, {1893, 307}, {1586, 222}, {1364, 167}, - {1197, 131}, {1066, 105}, {961, 86}, {875, 72}, {803, 61}, {742, 53}, {689, 45}, {644, 40}, - {604, 35}, {569, 32}, {537, 28}, {509, 25}, {484, 23}, {461, 21}, {440, 19}, {421, 17}, - {404, 16}, {388, 15}, {373, 14}, {359, 13}, {346, 12}, {334, 11}, {323, 10}, {313, 10}, - {303, 9}, {294, 9}, {285, 8}, {277, 7}, {270, 8}, {262, 7}, {255, 6}, {249, 6}, - {243, 6}, {237, 6}, {231, 5}, {226, 5}, {221, 5}, {216, 5}, {211, 4}, {207, 5}, - {202, 4}, {198, 4}, {194, 4}, {190, 3}, {187, 4}, {183, 3}, {180, 3}, {177, 4}, - {173, 3}, {170, 3}, {167, 2}, {165, 3}, {162, 3}, {159, 2}, {157, 3}, {154, 2}, - {152, 3}, {149, 2}, {147, 2}, {145, 2}, {143, 2}, {141, 2}, {139, 2}, {137, 2}, - {135, 2}, {133, 2}, {131, 2}, {129, 1}, {128, 2}, {126, 2}, {124, 1}, {123, 2}, - {121, 1}, {120, 2}, {118, 1}, {117, 1}, {116, 2}, {114, 1}, {113, 1}, {112, 2}, - {110, 1}, {109, 1}, {108, 1}, {107, 2}, {105, 1}, {104, 1}, {103, 1}, {102, 1}, - {101, 1}, {100, 1}, {99, 1}, {98, 1}, {97, 1}, {96, 1}, {95, 1}, {94, 1}, - {93, 1}, {92, 1}, {91, 0}, {91, 1}, {90, 1}, {89, 1}, {88, 1}, {87, 0}, - {87, 1}, {86, 1}, {85, 1}, {84, 0}, {84, 1}, {83, 1}, {82, 1}, {81, 0}, - {81, 1}, {80, 1}, {79, 0}, {79, 1}, {78, 0}, {78, 1}, {77, 1}, {76, 0}, - {76, 1}, {75, 0}, {75, 1}, {74, 1}, {73, 0}, {73, 1}, {72, 0}, {72, 1}, - {71, 0}, {71, 1}, {70, 0}, {70, 1}, {69, 0}, {69, 1}, {68, 0}, {68, 1}, - {67, 0}, {67, 1}, {66, 0}, {66, 1}, {65, 0}, {65, 0}, {65, 1}, {64, 0}, - {64, 1}, {63, 0}, {63, 1}, {62, 0}, {62, 0}, {62, 1}, {61, 0}, {61, 1}, - {60, 0}, {60, 0}, {60, 1}, {59, 0}, {59, 0}, {59, 1}, {58, 0}, {58, 0}, - {58, 1}, {57, 0}, {57, 0}, {57, 1}, {56, 0}, {56, 0}, {56, 1}, {55, 0}, - {55, 0}, {55, 1}, {54, 0}, {54, 0}, {54, 1}, {53, 0}, {53, 0}, {53, 0}, - {53, 1}, {52, 0}, {52, 0}, {52, 1}, {51, 0}, {51, 0}, {51, 0}, {51, 1}, - {50, 0}, {50, 0}, {50, 0}, {50, 1}, {49, 0}, {49, 0}, {49, 0}, {49, 1}, - {48, 0}, {48, 0}, {48, 0}, {48, 1}, {47, 0}, {47, 0}, {47, 0}, {47, 1}, - {46, 0}, {46, 0}, {46, 0}, {46, 0}, {46, 1}, {45, 0}, {45, 0}, {45, 0}, - {45, 1}, {44, 0}, {44, 0}, {44, 0}, {44, 0}, {44, 1}, {43, 0}, {43, 0}, - {43, 0}, {43, 0}, {43, 1}, {42, 0}, {42, 0}, {42, 0}, {42, 0}, {42, 0}, - {42, 1}, {41, 0}, {41, 0}, {41, 0}, {41, 0}, {41, 0}, {41, 1}, {40, 0}, - {40, 0}, {40, 0}, {40, 0}, {40, 1}, {39, 0}, {39, 0}, {39, 0}, {39, 0}, - {39, 0}, {39, 0}, {39, 1}, {38, 0}, {38, 0}, {38, 0}, {38, 0}, {38, 0}, -}; +#else //_NO_ASM -const uint16_t speed_lookuptable_slow[256][2] PROGMEM = { - {62500, 10417}, {52083, 7441}, {44642, 5580}, {39062, 4340}, {34722, 3472}, {31250, 2841}, {28409, 2368}, {26041, 2003}, - {24038, 1717}, {22321, 1488}, {20833, 1302}, {19531, 1149}, {18382, 1021}, {17361, 914}, {16447, 822}, {15625, 745}, - {14880, 676}, {14204, 618}, {13586, 566}, {13020, 520}, {12500, 481}, {12019, 445}, {11574, 414}, {11160, 385}, - {10775, 359}, {10416, 336}, {10080, 315}, {9765, 296}, {9469, 278}, {9191, 263}, {8928, 248}, {8680, 235}, - {8445, 222}, {8223, 211}, {8012, 200}, {7812, 191}, {7621, 181}, {7440, 173}, {7267, 165}, {7102, 158}, - {6944, 151}, {6793, 145}, {6648, 138}, {6510, 133}, {6377, 127}, {6250, 123}, {6127, 118}, {6009, 113}, - {5896, 109}, {5787, 106}, {5681, 101}, {5580, 98}, {5482, 95}, {5387, 91}, {5296, 88}, {5208, 86}, - {5122, 82}, {5040, 80}, {4960, 78}, {4882, 75}, {4807, 73}, {4734, 70}, {4664, 69}, {4595, 67}, - {4528, 64}, {4464, 63}, {4401, 61}, {4340, 60}, {4280, 58}, {4222, 56}, {4166, 55}, {4111, 53}, - {4058, 52}, {4006, 51}, {3955, 49}, {3906, 48}, {3858, 48}, {3810, 45}, {3765, 45}, {3720, 44}, - {3676, 43}, {3633, 42}, {3591, 40}, {3551, 40}, {3511, 39}, {3472, 38}, {3434, 38}, {3396, 36}, - {3360, 36}, {3324, 35}, {3289, 34}, {3255, 34}, {3221, 33}, {3188, 32}, {3156, 31}, {3125, 31}, - {3094, 31}, {3063, 30}, {3033, 29}, {3004, 28}, {2976, 28}, {2948, 28}, {2920, 27}, {2893, 27}, - {2866, 26}, {2840, 25}, {2815, 25}, {2790, 25}, {2765, 24}, {2741, 24}, {2717, 24}, {2693, 23}, - {2670, 22}, {2648, 22}, {2626, 22}, {2604, 22}, {2582, 21}, {2561, 21}, {2540, 20}, {2520, 20}, - {2500, 20}, {2480, 20}, {2460, 19}, {2441, 19}, {2422, 19}, {2403, 18}, {2385, 18}, {2367, 18}, - {2349, 17}, {2332, 18}, {2314, 17}, {2297, 16}, {2281, 17}, {2264, 16}, {2248, 16}, {2232, 16}, - {2216, 16}, {2200, 15}, {2185, 15}, {2170, 15}, {2155, 15}, {2140, 15}, {2125, 14}, {2111, 14}, - {2097, 14}, {2083, 14}, {2069, 14}, {2055, 13}, {2042, 13}, {2029, 13}, {2016, 13}, {2003, 13}, - {1990, 13}, {1977, 12}, {1965, 12}, {1953, 13}, {1940, 11}, {1929, 12}, {1917, 12}, {1905, 12}, - {1893, 11}, {1882, 11}, {1871, 11}, {1860, 11}, {1849, 11}, {1838, 11}, {1827, 11}, {1816, 10}, - {1806, 11}, {1795, 10}, {1785, 10}, {1775, 10}, {1765, 10}, {1755, 10}, {1745, 9}, {1736, 10}, - {1726, 9}, {1717, 10}, {1707, 9}, {1698, 9}, {1689, 9}, {1680, 9}, {1671, 9}, {1662, 9}, - {1653, 9}, {1644, 8}, {1636, 9}, {1627, 8}, {1619, 9}, {1610, 8}, {1602, 8}, {1594, 8}, - {1586, 8}, {1578, 8}, {1570, 8}, {1562, 8}, {1554, 7}, {1547, 8}, {1539, 8}, {1531, 7}, - {1524, 8}, {1516, 7}, {1509, 7}, {1502, 7}, {1495, 7}, {1488, 7}, {1481, 7}, {1474, 7}, - {1467, 7}, {1460, 7}, {1453, 7}, {1446, 6}, {1440, 7}, {1433, 7}, {1426, 6}, {1420, 6}, - {1414, 7}, {1407, 6}, {1401, 6}, {1395, 7}, {1388, 6}, {1382, 6}, {1376, 6}, {1370, 6}, - {1364, 6}, {1358, 6}, {1352, 6}, {1346, 5}, {1341, 6}, {1335, 6}, {1329, 5}, {1324, 6}, - {1318, 5}, {1313, 6}, {1307, 5}, {1302, 6}, {1296, 5}, {1291, 5}, {1286, 6}, {1280, 5}, - {1275, 5}, {1270, 5}, {1265, 5}, {1260, 5}, {1255, 5}, {1250, 5}, {1245, 5}, {1240, 5}, - {1235, 5}, {1230, 5}, {1225, 5}, {1220, 5}, {1215, 4}, {1211, 5}, {1206, 5}, {1201, 5}, -}; - -#endif +// NOTE: currently not implemented +void MultiU16X8toH16(unsigned short& intRes, unsigned char& charIn1, unsigned short& intIn2); +void MultiU24X24toH16(uint16_t& intRes, int32_t& longIn1, long& longIn2); + +#endif //_NO_ASM #endif diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 5a3d4010a..ddf69c8cb 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -146,92 +146,6 @@ extern uint16_t stepper_timer_overflow_last; //=============================functions ============================ //=========================================================================== -#ifndef _NO_ASM - -// intRes = intIn1 * intIn2 >> 16 -// uses: -// r26 to store 0 -// r27 to store the byte 1 of the 24 bit result -#define MultiU16X8toH16(intRes, charIn1, intIn2) \ -asm volatile ( \ -"clr r26 \n\t" \ -"mul %A1, %B2 \n\t" \ -"movw %A0, r0 \n\t" \ -"mul %A1, %A2 \n\t" \ -"add %A0, r1 \n\t" \ -"adc %B0, r26 \n\t" \ -"lsr r0 \n\t" \ -"adc %A0, r26 \n\t" \ -"adc %B0, r26 \n\t" \ -"clr r1 \n\t" \ -: \ -"=&r" (intRes) \ -: \ -"d" (charIn1), \ -"d" (intIn2) \ -: \ -"r26" \ -) - -// intRes = longIn1 * longIn2 >> 24 -// uses: -// r26 to store 0 -// r27 to store the byte 1 of the 48bit result -#define MultiU24X24toH16(intRes, longIn1, longIn2) \ -asm volatile ( \ -"clr r26 \n\t" \ -"mul %A1, %B2 \n\t" \ -"mov r27, r1 \n\t" \ -"mul %B1, %C2 \n\t" \ -"movw %A0, r0 \n\t" \ -"mul %C1, %C2 \n\t" \ -"add %B0, r0 \n\t" \ -"mul %C1, %B2 \n\t" \ -"add %A0, r0 \n\t" \ -"adc %B0, r1 \n\t" \ -"mul %A1, %C2 \n\t" \ -"add r27, r0 \n\t" \ -"adc %A0, r1 \n\t" \ -"adc %B0, r26 \n\t" \ -"mul %B1, %B2 \n\t" \ -"add r27, r0 \n\t" \ -"adc %A0, r1 \n\t" \ -"adc %B0, r26 \n\t" \ -"mul %C1, %A2 \n\t" \ -"add r27, r0 \n\t" \ -"adc %A0, r1 \n\t" \ -"adc %B0, r26 \n\t" \ -"mul %B1, %A2 \n\t" \ -"add r27, r1 \n\t" \ -"adc %A0, r26 \n\t" \ -"adc %B0, r26 \n\t" \ -"lsr r27 \n\t" \ -"adc %A0, r26 \n\t" \ -"adc %B0, r26 \n\t" \ -"clr r1 \n\t" \ -: \ -"=&r" (intRes) \ -: \ -"d" (longIn1), \ -"d" (longIn2) \ -: \ -"r26" , "r27" \ -) - -#else //_NO_ASM - -void MultiU16X8toH16(unsigned short& intRes, unsigned char& charIn1, unsigned short& intIn2) -{ -} - -void MultiU24X24toH16(uint16_t& intRes, int32_t& longIn1, long& longIn2) -{ -} - -#endif //_NO_ASM - -// Some useful constants - void checkHitEndstops() { if( endstop_x_hit || endstop_y_hit || endstop_z_hit) { From 3b528196dd22db2237b6bd7e9699c8ea0f7c164d Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sat, 18 May 2019 16:41:25 +0200 Subject: [PATCH 009/180] Fixup prefix echomagic for the LA config report --- Firmware/ConfigurationStore.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/ConfigurationStore.cpp b/Firmware/ConfigurationStore.cpp index 8ed2dd708..0bd13a3a1 100644 --- a/Firmware/ConfigurationStore.cpp +++ b/Firmware/ConfigurationStore.cpp @@ -165,8 +165,8 @@ void Config_PrintSettings(uint8_t level) #endif if (level >= 10) { #ifdef LIN_ADVANCE - printf_P(PSTR("%SLinear advance settings:\n M900 K%.2f\n"), - echomagic, extruder_advance_K); + printf_P(PSTR("%SLinear advance settings:%S M900 K%.2f\n"), + echomagic, echomagic, extruder_advance_K); #endif //LIN_ADVANCE } } From 2c8e04bd5f7ee847203afae796c6546996453e24 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sat, 18 May 2019 18:03:20 +0200 Subject: [PATCH 010/180] Planner: use the correct block when updating LA factors --- Firmware/planner.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index f8ac2f596..af87f77e6 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -402,10 +402,10 @@ void planner_recalculate(const float &safe_final_speed) // NOTE: Entry and exit factors always > 0 by all previous logic operations. calculate_trapezoid_for_block(prev, prev->entry_speed, current->entry_speed); #ifdef LIN_ADVANCE - if (current->use_advance_lead) { - const float comp = current->e_D_ratio * extruder_advance_K * cs.axis_steps_per_unit[E_AXIS]; - current->max_adv_steps = current->nominal_speed * comp; - current->final_adv_steps = next->entry_speed * comp; + if (prev->use_advance_lead) { + const float comp = prev->e_D_ratio * extruder_advance_K * cs.axis_steps_per_unit[E_AXIS]; + prev->max_adv_steps = prev->nominal_speed * comp; + prev->final_adv_steps = current->entry_speed * comp; } #endif // Reset current only to ensure next trapezoid is computed. From 9425b6b07a69b7d7c75e9e5488822b36709f3ed5 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sat, 18 May 2019 20:10:20 +0200 Subject: [PATCH 011/180] Planner: do not recalculate max_adv_steps, since it doesn't change --- Firmware/planner.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index af87f77e6..76b53fbbc 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -404,7 +404,6 @@ void planner_recalculate(const float &safe_final_speed) #ifdef LIN_ADVANCE if (prev->use_advance_lead) { const float comp = prev->e_D_ratio * extruder_advance_K * cs.axis_steps_per_unit[E_AXIS]; - prev->max_adv_steps = prev->nominal_speed * comp; prev->final_adv_steps = current->entry_speed * comp; } #endif From 2d3fe3197c0344a88fd954f8f3e94a74f8d0af6b Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sat, 18 May 2019 20:16:05 +0200 Subject: [PATCH 012/180] Move calc_timer into speed_lookup_table for planner reuse --- Firmware/speed_lookuptable.h | 36 +++++++++++++++++++++++++++++ Firmware/stepper.cpp | 45 ++++-------------------------------- 2 files changed, 40 insertions(+), 41 deletions(-) diff --git a/Firmware/speed_lookuptable.h b/Firmware/speed_lookuptable.h index 6a1a44ef1..2748dd71a 100644 --- a/Firmware/speed_lookuptable.h +++ b/Firmware/speed_lookuptable.h @@ -86,4 +86,40 @@ void MultiU24X24toH16(uint16_t& intRes, int32_t& longIn1, long& longIn2); #endif //_NO_ASM + +FORCE_INLINE unsigned short calc_timer(uint16_t step_rate, uint8_t& step_loops) { + unsigned short timer; + if(step_rate > MAX_STEP_FREQUENCY) step_rate = MAX_STEP_FREQUENCY; + + if(step_rate > 20000) { // If steprate > 20kHz >> step 4 times + step_rate = (step_rate >> 2)&0x3fff; + step_loops = 4; + } + else if(step_rate > 10000) { // If steprate > 10kHz >> step 2 times + step_rate = (step_rate >> 1)&0x7fff; + step_loops = 2; + } + else { + step_loops = 1; + } + + if(step_rate < (F_CPU/500000)) step_rate = (F_CPU/500000); + step_rate -= (F_CPU/500000); // Correct for minimal speed + if(step_rate >= (8*256)){ // higher step rate + unsigned short table_address = (unsigned short)&speed_lookuptable_fast[(unsigned char)(step_rate>>8)][0]; + unsigned char tmp_step_rate = (step_rate & 0x00ff); + unsigned short gain = (unsigned short)pgm_read_word_near(table_address+2); + MultiU16X8toH16(timer, tmp_step_rate, gain); + timer = (unsigned short)pgm_read_word_near(table_address) - timer; + } + else { // lower step rates + unsigned short table_address = (unsigned short)&speed_lookuptable_slow[0][0]; + table_address += ((step_rate)>>1) & 0xfffc; + timer = (unsigned short)pgm_read_word_near(table_address); + timer -= (((unsigned short)pgm_read_word_near(table_address+2) * (unsigned char)(step_rate & 0x0007))>>3); + } + if(timer < 100) { timer = 100; }//(20kHz this should never happen)////MSG_STEPPER_TOO_HIGH c=0 r=0 + return timer; +} + #endif diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index ddf69c8cb..19cd5d816 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -233,43 +233,6 @@ void invert_z_endstop(bool endstop_invert) // step_events_completed reaches block->decelerate_after after which it decelerates until the trapezoid generator is reset. // The slope of acceleration is calculated with the leib ramp alghorithm. -FORCE_INLINE unsigned short calc_timer(uint16_t step_rate) { - unsigned short timer; - if(step_rate > MAX_STEP_FREQUENCY) step_rate = MAX_STEP_FREQUENCY; - - if(step_rate > 20000) { // If steprate > 20kHz >> step 4 times - step_rate = (step_rate >> 2)&0x3fff; - step_loops = 4; - } - else if(step_rate > 10000) { // If steprate > 10kHz >> step 2 times - step_rate = (step_rate >> 1)&0x7fff; - step_loops = 2; - } - else { - step_loops = 1; - } -// step_loops = 1; - - if(step_rate < (F_CPU/500000)) step_rate = (F_CPU/500000); - step_rate -= (F_CPU/500000); // Correct for minimal speed - if(step_rate >= (8*256)){ // higher step rate - unsigned short table_address = (unsigned short)&speed_lookuptable_fast[(unsigned char)(step_rate>>8)][0]; - unsigned char tmp_step_rate = (step_rate & 0x00ff); - unsigned short gain = (unsigned short)pgm_read_word_near(table_address+2); - MultiU16X8toH16(timer, tmp_step_rate, gain); - timer = (unsigned short)pgm_read_word_near(table_address) - timer; - } - else { // lower step rates - unsigned short table_address = (unsigned short)&speed_lookuptable_slow[0][0]; - table_address += ((step_rate)>>1) & 0xfffc; - timer = (unsigned short)pgm_read_word_near(table_address); - timer -= (((unsigned short)pgm_read_word_near(table_address+2) * (unsigned char)(step_rate & 0x0007))>>3); - } - if(timer < 100) { timer = 100; MYSERIAL.print(_N("Steprate too high: ")); MYSERIAL.println(step_rate); }//(20kHz this should never happen)////MSG_STEPPER_TOO_HIGH - return timer; -} - - // "The Stepper Driver Interrupt" - This timer interrupt is the workhorse. // It pops blocks from the block_buffer and executes them by pulsing the stepper pins appropriately. ISR(TIMER1_COMPA_vect) { @@ -382,7 +345,7 @@ FORCE_INLINE void stepper_next_block() // state is reached. step_loops_nominal = 0; acc_step_rate = uint16_t(current_block->initial_rate); - acceleration_time = calc_timer(acc_step_rate); + acceleration_time = calc_timer(acc_step_rate, step_loops); #ifdef LIN_ADVANCE if ((use_advance_lead = current_block->use_advance_lead)) { @@ -763,7 +726,7 @@ FORCE_INLINE void isr() { if(acc_step_rate > uint16_t(current_block->nominal_rate)) acc_step_rate = current_block->nominal_rate; // step_rate to timer interval - uint16_t timer = calc_timer(acc_step_rate); + uint16_t timer = calc_timer(acc_step_rate, step_loops); _NEXT_ISR(timer); acceleration_time += timer; #ifdef LIN_ADVANCE @@ -788,7 +751,7 @@ FORCE_INLINE void isr() { step_rate = uint16_t(current_block->final_rate); } // Step_rate to timer interval. - uint16_t timer = calc_timer(step_rate); + uint16_t timer = calc_timer(step_rate, step_loops); _NEXT_ISR(timer); deceleration_time += timer; #ifdef LIN_ADVANCE @@ -812,7 +775,7 @@ FORCE_INLINE void isr() { if (! step_loops_nominal) { // Calculation of the steady state timer rate has been delayed to the 1st tick of the steady state to lower // the initial interrupt blocking. - OCR1A_nominal = calc_timer(uint16_t(current_block->nominal_rate)); + OCR1A_nominal = calc_timer(uint16_t(current_block->nominal_rate), step_loops); step_loops_nominal = step_loops; } _NEXT_ISR(OCR1A_nominal); From a2fa8e5313f7f393b3dcd9381ea9bce37d99a893 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sat, 18 May 2019 21:55:03 +0200 Subject: [PATCH 013/180] Rewrite the advance_isr scheduler --- Firmware/Configuration_adv.h | 2 - Firmware/planner.cpp | 53 ++++---- Firmware/planner.h | 3 +- Firmware/stepper.cpp | 230 +++++++++++++++++++++-------------- 4 files changed, 167 insertions(+), 121 deletions(-) diff --git a/Firmware/Configuration_adv.h b/Firmware/Configuration_adv.h index 455033024..d731e8633 100644 --- a/Firmware/Configuration_adv.h +++ b/Firmware/Configuration_adv.h @@ -292,8 +292,6 @@ * Mention @Sebastianv650 on GitHub to alert the author of any issues. */ #define LIN_ADVANCE -#define LA_DEBUG -#define DEBUG_STEPPER_TIMER_MISSED #ifdef LIN_ADVANCE #define LIN_ADVANCE_K 0 // Unit: mm compression per 1mm/s extruder speed diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index 76b53fbbc..078abac4c 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -58,6 +58,7 @@ #include "ultralcd.h" #include "language.h" #include "ConfigurationStore.h" +#include "speed_lookuptable.h" #ifdef MESH_BED_LEVELING #include "mesh_bed_leveling.h" @@ -1023,27 +1024,27 @@ Having the real displacement of the head, we can calculate the total movement le * delta_mm[E_AXIS] > 0 : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves) */ block->use_advance_lead = block->steps_e.wide - && extruder_advance_K - && delta_mm[E_AXIS] > 0; + && extruder_advance_K + && delta_mm[E_AXIS] > 0; if (block->use_advance_lead) { - block->e_D_ratio = (e - position_float[E_AXIS]) / - sqrt(sq(x - position_float[X_AXIS]) - + sq(y - position_float[Y_AXIS]) - + sq(z - position_float[Z_AXIS])); + block->e_D_ratio = (e - position_float[E_AXIS]) / + sqrt(sq(x - position_float[X_AXIS]) + + sq(y - position_float[Y_AXIS]) + + sq(z - position_float[Z_AXIS])); - // Check for unusual high e_D ratio to detect if a retract move was combined with the last print move due to min. steps per segment. Never execute this with advance! - // This assumes no one will use a retract length of 0mm < retr_length < ~0.2mm and no one will print 100mm wide lines using 3mm filament or 35mm wide lines using 1.75mm filament. - if (block->e_D_ratio > 3.0) - block->use_advance_lead = false; - else { - const uint32_t max_accel_steps_per_s2 = cs.max_jerk[E_AXIS] / (extruder_advance_K * block->e_D_ratio) * steps_per_mm; - if (block->acceleration_st > max_accel_steps_per_s2) { - block->acceleration_st = max_accel_steps_per_s2; - #ifdef LA_DEBUG - SERIAL_ECHOLNPGM("Acceleration limited."); - #endif - } - } + // Check for unusual high e_D ratio to detect if a retract move was combined with the last print move due to min. steps per segment. Never execute this with advance! + // This assumes no one will use a retract length of 0mm < retr_length < ~0.2mm and no one will print 100mm wide lines using 3mm filament or 35mm wide lines using 1.75mm filament. + if (block->e_D_ratio > 3.0) + block->use_advance_lead = false; + else { + const uint32_t max_accel_steps_per_s2 = cs.max_jerk[E_AXIS] / (extruder_advance_K * block->e_D_ratio) * steps_per_mm; + if (block->acceleration_st > max_accel_steps_per_s2) { + block->acceleration_st = max_accel_steps_per_s2; + #ifdef LA_DEBUG + SERIAL_ECHOLNPGM("Acceleration limited."); + #endif + } + } } #endif @@ -1081,13 +1082,13 @@ Having the real displacement of the head, we can calculate the total movement le #ifdef LIN_ADVANCE if (block->use_advance_lead) { - block->advance_speed = (F_CPU / 8.0) / (extruder_advance_K * block->e_D_ratio * block->acceleration * cs.axis_steps_per_unit[E_AXIS]); - #ifdef LA_DEBUG - if (extruder_advance_K * block->e_D_ratio * block->acceleration * 2 < block->nominal_speed * block->e_D_ratio) - SERIAL_ECHOLNPGM("More than 2 steps per eISR loop executed."); - if (block->advance_speed < 200) - SERIAL_ECHOLNPGM("eISR running at > 10kHz."); - #endif + float advance_speed = (extruder_advance_K * block->e_D_ratio * block->acceleration * cs.axis_steps_per_unit[E_AXIS]); + block->advance_rate = calc_timer(advance_speed, block->advance_step_loops); + + #ifdef LA_DEBUG + if (block->advance_step_loops > 2) + SERIAL_ECHOLNPGM("More than 2 steps per eISR loop executed."); + #endif } #endif diff --git a/Firmware/planner.h b/Firmware/planner.h index 41e4c61bf..56e1c66c3 100644 --- a/Firmware/planner.h +++ b/Firmware/planner.h @@ -113,9 +113,10 @@ typedef struct { #ifdef LIN_ADVANCE bool use_advance_lead; // Whether the current block uses LA - uint16_t advance_speed, // Step-rate for extruder speed + uint16_t advance_rate, // Step-rate for extruder speed max_adv_steps, // max. advance steps to get cruising speed pressure (not always nominal_speed!) final_adv_steps; // advance steps due to exit speed + uint8_t advance_step_loops; // Number of stepper ticks for each advance isr float e_D_ratio; #endif diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 19cd5d816..a98c8ff29 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -117,22 +117,24 @@ volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1}; void advance_isr(); static const uint16_t ADV_NEVER = 0xFFFF; - - static uint16_t nextMainISR = 0; - static uint16_t nextAdvanceISR = ADV_NEVER; - - static uint16_t eISR_Rate = ADV_NEVER; - static bool use_advance_lead; - static uint16_t current_adv_steps; + static uint16_t nextMainISR; + static uint16_t nextAdvanceISR; + + static uint16_t main_Rate; + static uint16_t eISR_Rate; + + static volatile uint16_t current_adv_steps; static uint16_t final_adv_steps; static uint16_t max_adv_steps; static uint32_t LA_decelerate_after; - static volatile int8_t e_steps; + static int8_t e_steps; + static uint8_t e_step_loops; + static int8_t LA_phase; - #define _NEXT_ISR(T) nextMainISR = T + #define _NEXT_ISR(T) main_Rate = nextMainISR = T #else #define _NEXT_ISR(T) OCR1A = T #endif @@ -352,6 +354,13 @@ FORCE_INLINE void stepper_next_block() LA_decelerate_after = current_block->decelerate_after; final_adv_steps = current_block->final_adv_steps; max_adv_steps = current_block->max_adv_steps; + e_step_loops = current_block->advance_step_loops; + LA_phase = -1; + } else { + nextAdvanceISR = ADV_NEVER; + eISR_Rate = ADV_NEVER; + e_step_loops = 1; + LA_phase = -1; } #endif @@ -731,15 +740,12 @@ FORCE_INLINE void isr() { acceleration_time += timer; #ifdef LIN_ADVANCE if (current_block->use_advance_lead) { - if (step_events_completed.wide == (unsigned long int)step_loops || (e_steps && eISR_Rate != current_block->advance_speed)) { - nextAdvanceISR = 0; // Wake up eISR on first acceleration loop and fire ISR if final adv_rate is reached - eISR_Rate = current_block->advance_speed; + if (step_events_completed.wide <= (unsigned long int)step_loops) { + // First acceleration loop + eISR_Rate = current_block->advance_rate; + nextAdvanceISR = 0; } } - else { - eISR_Rate = ADV_NEVER; - if (e_steps) nextAdvanceISR = 0; - } #endif } else if (step_events_completed.wide > (unsigned long int)current_block->decelerate_after) { @@ -756,22 +762,15 @@ FORCE_INLINE void isr() { deceleration_time += timer; #ifdef LIN_ADVANCE if (current_block->use_advance_lead) { - if (step_events_completed.wide <= (unsigned long int)current_block->decelerate_after + step_loops || (e_steps && eISR_Rate != current_block->advance_speed)) { - nextAdvanceISR = 0; // Wake up eISR on first deceleration loop - eISR_Rate = current_block->advance_speed; + if (step_events_completed.wide <= (unsigned long int)current_block->decelerate_after + step_loops) { + // First deceleration loop + eISR_Rate = current_block->advance_rate; + nextAdvanceISR = 0; } } - else { - eISR_Rate = ADV_NEVER; - if (e_steps) nextAdvanceISR = 0; - } #endif } else { -#ifdef LIN_ADVANCE - // If we have esteps to execute, fire the next advance_isr "now" - if (e_steps && eISR_Rate != current_block->advance_speed) nextAdvanceISR = 0; -#endif if (! step_loops_nominal) { // Calculation of the steady state timer rate has been delayed to the 1st tick of the steady state to lower // the initial interrupt blocking. @@ -813,76 +812,111 @@ FORCE_INLINE void isr() { // Timer interrupt for E. e_steps is set in the main routine. FORCE_INLINE void advance_isr() { - if (use_advance_lead) { - if (step_events_completed.wide > LA_decelerate_after && current_adv_steps > final_adv_steps) { - e_steps--; - current_adv_steps--; - nextAdvanceISR = eISR_Rate; + if (step_events_completed.wide > LA_decelerate_after && current_adv_steps > final_adv_steps) { + // decompression + e_steps -= e_step_loops; + current_adv_steps -= e_step_loops; + nextAdvanceISR = eISR_Rate; + if(nextAdvanceISR == ADV_NEVER) + { + LA_phase = 1; + e_step_loops = 1; } - else if (step_events_completed.wide < LA_decelerate_after && current_adv_steps < max_adv_steps) { - e_steps++; - current_adv_steps++; - nextAdvanceISR = eISR_Rate; - } - else { - nextAdvanceISR = ADV_NEVER; - eISR_Rate = ADV_NEVER; + else + { + if (step_loops == e_step_loops) + LA_phase = (eISR_Rate > main_Rate); + else + { + // avoid overflow through division (TODO: this can be + // improved as both step_loops and e_step_loops are + // guaranteed to be powers of two) + LA_phase = (eISR_Rate / step_loops > main_Rate / e_step_loops); + } } } - else + else if (step_events_completed.wide < LA_decelerate_after && current_adv_steps < max_adv_steps) { + // compression + e_steps += e_step_loops; + current_adv_steps += e_step_loops; + nextAdvanceISR = eISR_Rate; + LA_phase = -1; + if(nextAdvanceISR == ADV_NEVER) + e_step_loops = 1; + } + else { + // advance steps completed nextAdvanceISR = ADV_NEVER; - - if (e_steps) { - MSerial.checkRx(); // Check for serial chars. - - bool dir = -#ifdef SNMM - ((e_steps < 0) == (snmm_extruder & 1)) -#else - (e_steps < 0) -#endif - ? INVERT_E0_DIR : !INVERT_E0_DIR; //If we have SNMM, reverse every second extruder. - WRITE(E0_DIR_PIN, dir); - - if(e_steps < 0) e_steps = -e_steps; - fsensor_counter += e_steps; - while (e_steps) { - WRITE_NC(E0_STEP_PIN, !INVERT_E_STEP_PIN); - --e_steps; - WRITE_NC(E0_STEP_PIN, INVERT_E_STEP_PIN); - } + eISR_Rate = ADV_NEVER; + LA_phase = -1; + e_step_loops = 1; } } FORCE_INLINE void advance_isr_scheduler() { - // Run main stepping ISR if flagged - if (!nextMainISR) isr(); - - // Run Advance stepping ISR if flagged - if (!nextAdvanceISR) advance_isr(); - - // Is the next advance ISR scheduled before the next main ISR? - if (nextAdvanceISR <= nextMainISR) { - // Set up the next interrupt - OCR1A = nextAdvanceISR; - // New interval for the next main ISR - if (nextMainISR) nextMainISR -= nextAdvanceISR; - // Will call Stepper::advance_isr on the next interrupt - nextAdvanceISR = 0; + // Integrate the final timer value, accounting for scheduling adjustments + if(nextAdvanceISR && nextAdvanceISR != ADV_NEVER) + { + if(nextAdvanceISR > OCR1A) + nextAdvanceISR -= OCR1A; + else + nextAdvanceISR = 0; } - else { - // The next main ISR comes first - OCR1A = nextMainISR; - // New interval for the next advance ISR, if any - if (nextAdvanceISR && nextAdvanceISR != ADV_NEVER) - nextAdvanceISR -= nextMainISR; - // Will call Stepper::isr on the next interrupt + if(nextMainISR > OCR1A) + nextMainISR -= OCR1A; + else nextMainISR = 0; + + // Run main stepping ISR if flagged + if (!nextMainISR) + { +#ifdef LA_DEBUG_LOGIC + WRITE_NC(LOGIC_ANALYZER_CH0, true); +#endif + isr(); +#ifdef LA_DEBUG_LOGIC + WRITE_NC(LOGIC_ANALYZER_CH0, false); +#endif } + + // Run the next advance isr if triggered now or soon enough + bool eisr = nextAdvanceISR < (TCNT1 + nextAdvanceISR / 8); + if (eisr) + { +#ifdef LA_DEBUG_LOGIC + WRITE_NC(LOGIC_ANALYZER_CH1, true); +#endif + advance_isr(); +#ifdef LA_DEBUG_LOGIC + WRITE_NC(LOGIC_ANALYZER_CH1, false); +#endif + } + + // Tick E steps if any + if (e_steps && (LA_phase < 0 || LA_phase == eisr)) { + uint8_t max_ticks = max(e_step_loops, step_loops); + max_ticks = min(abs(e_steps), max_ticks); +#ifdef FILAMENT_SENSOR + fsensor_counter += max_ticks; +#endif + WRITE(E0_DIR_PIN, e_steps < 0? INVERT_E0_DIR: !INVERT_E0_DIR); + while(max_ticks--) + { + WRITE_NC(E0_STEP_PIN, !INVERT_E_STEP_PIN); + e_steps += (e_steps < 0)? 1: -1; + WRITE_NC(E0_STEP_PIN, INVERT_E_STEP_PIN); + } + } + + // Schedule the next closest tick, ignoring advance if scheduled to + // soon in order to avoid skewing the regular stepper acceleration + if (nextAdvanceISR != ADV_NEVER && (nextAdvanceISR + TCNT1 + nextAdvanceISR / 8) < nextMainISR) + OCR1A = nextAdvanceISR; + else + OCR1A = nextMainISR; } void clear_current_adv_vars() { - e_steps = 0; current_adv_steps = 0; } @@ -1106,15 +1140,28 @@ void st_init() // create_speed_lookuptable.py TCCR1B = (TCCR1B & ~(0x07< Date: Sun, 19 May 2019 14:23:37 +0200 Subject: [PATCH 014/180] Use a define instead of hard-coding a divider --- Firmware/stepper.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index a98c8ff29..8f0fef2ac 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -853,6 +853,10 @@ FORCE_INLINE void advance_isr() { } } +#define LA_FREQ_MDIV 8 // divider for the advance frequency for maximum + // time allotted to merge regular and advance + // ticks (stick to a power-of-two) + FORCE_INLINE void advance_isr_scheduler() { // Integrate the final timer value, accounting for scheduling adjustments if(nextAdvanceISR && nextAdvanceISR != ADV_NEVER) @@ -880,7 +884,7 @@ FORCE_INLINE void advance_isr_scheduler() { } // Run the next advance isr if triggered now or soon enough - bool eisr = nextAdvanceISR < (TCNT1 + nextAdvanceISR / 8); + bool eisr = nextAdvanceISR < (TCNT1 + nextAdvanceISR / LA_FREQ_MDIV); if (eisr) { #ifdef LA_DEBUG_LOGIC @@ -910,7 +914,7 @@ FORCE_INLINE void advance_isr_scheduler() { // Schedule the next closest tick, ignoring advance if scheduled to // soon in order to avoid skewing the regular stepper acceleration - if (nextAdvanceISR != ADV_NEVER && (nextAdvanceISR + TCNT1 + nextAdvanceISR / 8) < nextMainISR) + if (nextAdvanceISR != ADV_NEVER && (nextAdvanceISR + TCNT1 + nextAdvanceISR / LA_FREQ_MDIV) < nextMainISR) OCR1A = nextAdvanceISR; else OCR1A = nextMainISR; From a1be8b6784f7363dbf5436c2d212942d7d363ce8 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 19 May 2019 14:26:23 +0200 Subject: [PATCH 015/180] Initialize current_adv_steps correctly Initialize at 0 both on startup and on reset on regular (non-LA) segments to avoid cumulating errors. --- Firmware/stepper.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 8f0fef2ac..9339b4bf3 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -361,6 +361,7 @@ FORCE_INLINE void stepper_next_block() eISR_Rate = ADV_NEVER; e_step_loops = 1; LA_phase = -1; + current_adv_steps = 0; } #endif @@ -1165,6 +1166,7 @@ void st_init() e_steps = 0; e_step_loops = 1; LA_phase = -1; + current_adv_steps = 0; #endif enable_endstops(true); // Start with endstops active. After homing they can be disabled From 9586d71adbbaf4e459961b491216801f0c963397 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 19 May 2019 14:31:26 +0200 Subject: [PATCH 016/180] Mention LA_DEBUG_LOGIC --- Firmware/Configuration_adv.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Firmware/Configuration_adv.h b/Firmware/Configuration_adv.h index d731e8633..e464b4de4 100644 --- a/Firmware/Configuration_adv.h +++ b/Firmware/Configuration_adv.h @@ -294,8 +294,9 @@ #define LIN_ADVANCE #ifdef LIN_ADVANCE - #define LIN_ADVANCE_K 0 // Unit: mm compression per 1mm/s extruder speed - //#define LA_DEBUG // If enabled, this will generate debug information output over USB. + #define LIN_ADVANCE_K 0 // Unit: mm compression per 1mm/s extruder speed + //#define LA_DEBUG // If enabled, this will generate debug information output over USB. + //#define LA_DEBUG_LOGIC // @wavexx: setup logic channels for isr debugging #endif // Arc interpretation settings: From 942c38c18bbc28cf2f68dd1aafa3dc9cf3b62c9d Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 19 May 2019 14:34:03 +0200 Subject: [PATCH 017/180] Minor reformatting --- Firmware/planner.cpp | 18 ++++++++++-------- Firmware/planner.h | 4 ++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index 078abac4c..0d0f3e36e 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -1019,21 +1019,23 @@ Having the real displacement of the head, we can calculate the total movement le /** * Use LIN_ADVANCE for blocks if all these are true: * - * block->steps_e : This is a print move, because we checked for X, Y, Z steps before. - * extruder_advance_K : There is an advance factor set. - * delta_mm[E_AXIS] > 0 : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves) + * block->steps_e : This is a print move, because we checked for X, Y, Z steps before. + * extruder_advance_K : There is an advance factor set. + * delta_mm[E_AXIS] > 0 : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves) */ - block->use_advance_lead = block->steps_e.wide - && extruder_advance_K - && delta_mm[E_AXIS] > 0; + block->use_advance_lead = block->steps_e.wide + && extruder_advance_K + && delta_mm[E_AXIS] > 0; if (block->use_advance_lead) { block->e_D_ratio = (e - position_float[E_AXIS]) / sqrt(sq(x - position_float[X_AXIS]) + sq(y - position_float[Y_AXIS]) + sq(z - position_float[Z_AXIS])); - // Check for unusual high e_D ratio to detect if a retract move was combined with the last print move due to min. steps per segment. Never execute this with advance! - // This assumes no one will use a retract length of 0mm < retr_length < ~0.2mm and no one will print 100mm wide lines using 3mm filament or 35mm wide lines using 1.75mm filament. + // Check for unusual high e_D ratio to detect if a retract move was combined with the last + // print move due to min. steps per segment. Never execute this with advance! This assumes + // no one will use a retract length of 0mm < retr_length < ~0.2mm and no one will print + // 100mm wide lines using 3mm filament or 35mm wide lines using 1.75mm filament. if (block->e_D_ratio > 3.0) block->use_advance_lead = false; else { diff --git a/Firmware/planner.h b/Firmware/planner.h index 56e1c66c3..44c57ea5e 100644 --- a/Firmware/planner.h +++ b/Firmware/planner.h @@ -110,10 +110,10 @@ typedef struct { // Pre-calculated division for the calculate_trapezoid_for_block() routine to run faster. float speed_factor; - + #ifdef LIN_ADVANCE bool use_advance_lead; // Whether the current block uses LA - uint16_t advance_rate, // Step-rate for extruder speed + uint16_t advance_rate, // Step-rate for extruder speed max_adv_steps, // max. advance steps to get cruising speed pressure (not always nominal_speed!) final_adv_steps; // advance steps due to exit speed uint8_t advance_step_loops; // Number of stepper ticks for each advance isr From c6dbcc494f6fff2915fcb1f29c451f4d41079a9b Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 19 May 2019 15:42:14 +0200 Subject: [PATCH 018/180] Typo --- Firmware/stepper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 9339b4bf3..5fc0006b3 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -913,7 +913,7 @@ FORCE_INLINE void advance_isr_scheduler() { } } - // Schedule the next closest tick, ignoring advance if scheduled to + // Schedule the next closest tick, ignoring advance if scheduled too // soon in order to avoid skewing the regular stepper acceleration if (nextAdvanceISR != ADV_NEVER && (nextAdvanceISR + TCNT1 + nextAdvanceISR / LA_FREQ_MDIV) < nextMainISR) OCR1A = nextAdvanceISR; From aae5cce28f177a65df8823ddf8d908723036b45d Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 19 May 2019 16:32:14 +0200 Subject: [PATCH 019/180] Use the nominal frequency to merge ticks --- Firmware/stepper.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 5fc0006b3..65f39c7d9 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -885,7 +885,7 @@ FORCE_INLINE void advance_isr_scheduler() { } // Run the next advance isr if triggered now or soon enough - bool eisr = nextAdvanceISR < (TCNT1 + nextAdvanceISR / LA_FREQ_MDIV); + bool eisr = nextAdvanceISR < (TCNT1 + eISR_Rate / LA_FREQ_MDIV); if (eisr) { #ifdef LA_DEBUG_LOGIC @@ -915,7 +915,7 @@ FORCE_INLINE void advance_isr_scheduler() { // Schedule the next closest tick, ignoring advance if scheduled too // soon in order to avoid skewing the regular stepper acceleration - if (nextAdvanceISR != ADV_NEVER && (nextAdvanceISR + TCNT1 + nextAdvanceISR / LA_FREQ_MDIV) < nextMainISR) + if (nextAdvanceISR != ADV_NEVER && (nextAdvanceISR + TCNT1 + eISR_Rate / LA_FREQ_MDIV) < nextMainISR) OCR1A = nextAdvanceISR; else OCR1A = nextMainISR; From 53b77bab360349d88936785a934cee24bbb74108 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 21 May 2019 11:54:14 +0200 Subject: [PATCH 020/180] Do not operate on the prev block when already in use --- Firmware/planner.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index 0d0f3e36e..b9e693e7c 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -400,14 +400,18 @@ void planner_recalculate(const float &safe_final_speed) } // Recalculate if current block entry or exit junction speed has changed. if ((prev->flag | current->flag) & BLOCK_FLAG_RECALCULATE) { - // NOTE: Entry and exit factors always > 0 by all previous logic operations. - calculate_trapezoid_for_block(prev, prev->entry_speed, current->entry_speed); - #ifdef LIN_ADVANCE - if (prev->use_advance_lead) { - const float comp = prev->e_D_ratio * extruder_advance_K * cs.axis_steps_per_unit[E_AXIS]; - prev->final_adv_steps = current->entry_speed * comp; + // @wavexx: FIXME: the following check is not really enough. calculate_trapezoid does block + // the isr to update the rates, but we don't. we should update atomically + if (!prev->busy) { + // NOTE: Entry and exit factors always > 0 by all previous logic operations. + calculate_trapezoid_for_block(prev, prev->entry_speed, current->entry_speed); + #ifdef LIN_ADVANCE + if (prev->use_advance_lead) { + const float comp = prev->e_D_ratio * extruder_advance_K * cs.axis_steps_per_unit[E_AXIS]; + prev->final_adv_steps = current->entry_speed * comp; + } + #endif } - #endif // Reset current only to ensure next trapezoid is computed. prev->flag &= ~BLOCK_FLAG_RECALCULATE; } From 294bf4068de454ed2c86f8096722621db51ee888 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 21 May 2019 21:28:31 +0200 Subject: [PATCH 021/180] Improve debug messages --- Firmware/planner.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index b9e693e7c..466cd340c 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -1047,7 +1047,7 @@ Having the real displacement of the head, we can calculate the total movement le if (block->acceleration_st > max_accel_steps_per_s2) { block->acceleration_st = max_accel_steps_per_s2; #ifdef LA_DEBUG - SERIAL_ECHOLNPGM("Acceleration limited."); + SERIAL_ECHOLNPGM("LA: Block acceleration limited due to max E-jerk"); #endif } } @@ -1093,7 +1093,11 @@ Having the real displacement of the head, we can calculate the total movement le #ifdef LA_DEBUG if (block->advance_step_loops > 2) - SERIAL_ECHOLNPGM("More than 2 steps per eISR loop executed."); + // @wavexx: we should really check for the difference between step_loops and + // advance_step_loops instead. A difference of more than 1 will lead + // to uneven speed and *should* be adjusted here by furthermore + // reducing the speed. + SERIAL_ECHOLNPGM("LA: More than 2 steps per eISR loop executed."); #endif } #endif From 282b5023932358fa4d5c49c746e7b4ddf830a882 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 21 May 2019 21:32:38 +0200 Subject: [PATCH 022/180] Improve the distribution of the advance steps --- Firmware/stepper.cpp | 117 ++++++++++++++++++++++++++----------------- 1 file changed, 71 insertions(+), 46 deletions(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 65f39c7d9..f0b39905f 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -124,8 +124,9 @@ volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1}; static uint16_t main_Rate; static uint16_t eISR_Rate; + static uint16_t eISR_Err; - static volatile uint16_t current_adv_steps; + static uint16_t current_adv_steps; static uint16_t final_adv_steps; static uint16_t max_adv_steps; static uint32_t LA_decelerate_after; @@ -355,14 +356,13 @@ FORCE_INLINE void stepper_next_block() final_adv_steps = current_block->final_adv_steps; max_adv_steps = current_block->max_adv_steps; e_step_loops = current_block->advance_step_loops; - LA_phase = -1; } else { - nextAdvanceISR = ADV_NEVER; - eISR_Rate = ADV_NEVER; + e_steps = 0; e_step_loops = 1; - LA_phase = -1; current_adv_steps = 0; } + nextAdvanceISR = ADV_NEVER; + LA_phase = -1; #endif if (current_block->flag & BLOCK_FLAG_DDA_LOWRES) { @@ -707,6 +707,39 @@ FORCE_INLINE void stepper_tick_highres() } } + +#ifdef LIN_ADVANCE +FORCE_INLINE void advance_spread(uint16_t timer) +{ + if(eISR_Err > timer) + { + // advance-step skipped + eISR_Err -= timer; + eISR_Rate = timer; + nextAdvanceISR = timer; + return; + } + + // at least one step + uint8_t ticks = 1; + uint32_t block = current_block->advance_rate; + uint16_t max_t = timer - eISR_Err; + while (block < max_t) + { + ++ticks; + block += current_block->advance_rate; + } + if (block > timer) + eISR_Err += block - timer; + else + eISR_Err -= timer - block; + + eISR_Rate = timer / ticks; + nextAdvanceISR = eISR_Rate / 2; +} +#endif + + FORCE_INLINE void isr() { //WRITE_NC(LOGIC_ANALYZER_CH0, true); @@ -741,11 +774,10 @@ FORCE_INLINE void isr() { acceleration_time += timer; #ifdef LIN_ADVANCE if (current_block->use_advance_lead) { - if (step_events_completed.wide <= (unsigned long int)step_loops) { - // First acceleration loop - eISR_Rate = current_block->advance_rate; - nextAdvanceISR = 0; - } + bool first = (step_events_completed.wide <= (unsigned long int)step_loops); + if (first) eISR_Err = current_block->advance_rate / 2; + if (first || nextAdvanceISR != ADV_NEVER) + advance_spread(timer); } #endif } @@ -763,10 +795,20 @@ FORCE_INLINE void isr() { deceleration_time += timer; #ifdef LIN_ADVANCE if (current_block->use_advance_lead) { - if (step_events_completed.wide <= (unsigned long int)current_block->decelerate_after + step_loops) { - // First deceleration loop - eISR_Rate = current_block->advance_rate; - nextAdvanceISR = 0; + bool first = (step_events_completed.wide <= (unsigned long int)current_block->decelerate_after + step_loops); + if (first) eISR_Err = current_block->advance_rate / 2; + if (first || nextAdvanceISR != ADV_NEVER) + { + advance_spread(timer); + if (step_loops == e_step_loops) + LA_phase = (eISR_Rate > main_Rate); + else + { + // avoid overflow through division (TODO: this can be + // improved as both step_loops and e_step_loops are + // currently guaranteed to be powers of two) + LA_phase = (eISR_Rate / step_loops > main_Rate / e_step_loops); + } } } #endif @@ -779,6 +821,11 @@ FORCE_INLINE void isr() { step_loops_nominal = step_loops; } _NEXT_ISR(OCR1A_nominal); +#ifdef LIN_ADVANCE + if (current_block->use_advance_lead && nextAdvanceISR != ADV_NEVER) { + advance_spread(OCR1A_nominal); + } +#endif } //WRITE_NC(LOGIC_ANALYZER_CH1, false); } @@ -816,48 +863,26 @@ FORCE_INLINE void advance_isr() { if (step_events_completed.wide > LA_decelerate_after && current_adv_steps > final_adv_steps) { // decompression e_steps -= e_step_loops; - current_adv_steps -= e_step_loops; - nextAdvanceISR = eISR_Rate; - if(nextAdvanceISR == ADV_NEVER) - { - LA_phase = 1; - e_step_loops = 1; - } + if(current_adv_steps > e_step_loops) + current_adv_steps -= e_step_loops; else - { - if (step_loops == e_step_loops) - LA_phase = (eISR_Rate > main_Rate); - else - { - // avoid overflow through division (TODO: this can be - // improved as both step_loops and e_step_loops are - // guaranteed to be powers of two) - LA_phase = (eISR_Rate / step_loops > main_Rate / e_step_loops); - } - } + current_adv_steps = 0; + nextAdvanceISR = eISR_Rate; } else if (step_events_completed.wide < LA_decelerate_after && current_adv_steps < max_adv_steps) { // compression e_steps += e_step_loops; current_adv_steps += e_step_loops; nextAdvanceISR = eISR_Rate; - LA_phase = -1; - if(nextAdvanceISR == ADV_NEVER) - e_step_loops = 1; } else { // advance steps completed nextAdvanceISR = ADV_NEVER; - eISR_Rate = ADV_NEVER; LA_phase = -1; e_step_loops = 1; } } -#define LA_FREQ_MDIV 8 // divider for the advance frequency for maximum - // time allotted to merge regular and advance - // ticks (stick to a power-of-two) - FORCE_INLINE void advance_isr_scheduler() { // Integrate the final timer value, accounting for scheduling adjustments if(nextAdvanceISR && nextAdvanceISR != ADV_NEVER) @@ -884,8 +909,8 @@ FORCE_INLINE void advance_isr_scheduler() { #endif } - // Run the next advance isr if triggered now or soon enough - bool eisr = nextAdvanceISR < (TCNT1 + eISR_Rate / LA_FREQ_MDIV); + // Run the next advance isr if triggered + bool eisr = !nextAdvanceISR; if (eisr) { #ifdef LA_DEBUG_LOGIC @@ -899,23 +924,24 @@ FORCE_INLINE void advance_isr_scheduler() { // Tick E steps if any if (e_steps && (LA_phase < 0 || LA_phase == eisr)) { - uint8_t max_ticks = max(e_step_loops, step_loops); + uint8_t max_ticks = (eisr? e_step_loops: step_loops); max_ticks = min(abs(e_steps), max_ticks); #ifdef FILAMENT_SENSOR fsensor_counter += max_ticks; #endif WRITE(E0_DIR_PIN, e_steps < 0? INVERT_E0_DIR: !INVERT_E0_DIR); - while(max_ticks--) + do { WRITE_NC(E0_STEP_PIN, !INVERT_E_STEP_PIN); e_steps += (e_steps < 0)? 1: -1; WRITE_NC(E0_STEP_PIN, INVERT_E_STEP_PIN); } + while(--max_ticks); } // Schedule the next closest tick, ignoring advance if scheduled too // soon in order to avoid skewing the regular stepper acceleration - if (nextAdvanceISR != ADV_NEVER && (nextAdvanceISR + TCNT1 + eISR_Rate / LA_FREQ_MDIV) < nextMainISR) + if (nextAdvanceISR != ADV_NEVER && (nextAdvanceISR + TCNT1 + 40) < nextMainISR) OCR1A = nextAdvanceISR; else OCR1A = nextMainISR; @@ -1162,7 +1188,6 @@ void st_init() nextMainISR = 0; nextAdvanceISR = ADV_NEVER; main_Rate = ADV_NEVER; - eISR_Rate = ADV_NEVER; e_steps = 0; e_step_loops = 1; LA_phase = -1; From 0a26de1e7f2aeb544273ef48969140bff32cb4d2 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sat, 25 May 2019 17:49:18 +0200 Subject: [PATCH 023/180] Allow to live-tune K during a print --- Firmware/menu.cpp | 4 +-- Firmware/menu.h | 3 +++ Firmware/ultralcd.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/Firmware/menu.cpp b/Firmware/menu.cpp index 847e63c80..42bfd0d93 100755 --- a/Firmware/menu.cpp +++ b/Firmware/menu.cpp @@ -96,7 +96,7 @@ void menu_back(void) menu_back(1); } -static void menu_back_no_reset(void) +void menu_back_no_reset(void) { if (menu_depth > 0) { @@ -130,7 +130,7 @@ void menu_submenu(menu_func_t submenu) } } -static void menu_submenu_no_reset(menu_func_t submenu) +void menu_submenu_no_reset(menu_func_t submenu) { if (menu_depth < MENU_DEPTH_MAX) { diff --git a/Firmware/menu.h b/Firmware/menu.h index 9800550b9..a129dfc82 100755 --- a/Firmware/menu.h +++ b/Firmware/menu.h @@ -54,6 +54,7 @@ void menu_start(void); extern void menu_end(void); extern void menu_back(void); +extern void menu_back_no_reset(void); extern void menu_back(uint8_t nLevel); extern void menu_back_if_clicked(void); @@ -61,6 +62,7 @@ extern void menu_back_if_clicked(void); extern void menu_back_if_clicked_fb(void); extern void menu_submenu(menu_func_t submenu); +extern void menu_submenu_no_reset(menu_func_t submenu); extern uint8_t menu_item_ret(void); @@ -98,6 +100,7 @@ extern const char menu_fmt_int3[]; extern const char menu_fmt_float31[]; extern const char menu_fmt_float13[]; +extern const char menu_fmt_float13off[]; extern void menu_draw_float31(const char* str, float val); diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 97304adb2..8036c3a82 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -6606,6 +6606,60 @@ static void lcd_colorprint_change() { lcd_draw_update = 3; } + +#ifdef LIN_ADVANCE +// @wavexx: looks like there's no generic float editing function in menu.cpp so we +// redefine our custom handling functions to mimick other tunables +#define MSG_ADVANCE_K PSTR("Advance K:") + +static void lcd_advance_draw_K(char chr, float val) +{ + if (val <= 0) + lcd_printf_P(menu_fmt_float13off, chr, MSG_ADVANCE_K, " [off]"); + else + lcd_printf_P(menu_fmt_float13, chr, MSG_ADVANCE_K, val); +} + +static void lcd_advance_edit_K(void) +{ + if (lcd_draw_update) + { + if (lcd_encoder < 0) lcd_encoder = 0; + if (lcd_encoder > 999) lcd_encoder = 999; + lcd_set_cursor(0, 1); + lcd_advance_draw_K(' ', 0.01 * lcd_encoder); + } + if (LCD_CLICKED) + { + extruder_advance_K = 0.01 * lcd_encoder; + menu_back_no_reset(); + } +} + +static uint8_t lcd_advance_K() +{ + if (menu_item == menu_line) + { + if (lcd_draw_update) + { + lcd_set_cursor(0, menu_row); + lcd_advance_draw_K((lcd_encoder == menu_item)?'>':' ', extruder_advance_K); + } + if (menu_clicked && (lcd_encoder == menu_item)) + { + menu_submenu_no_reset(lcd_advance_edit_K); + lcd_encoder = 100. * extruder_advance_K; + return menu_item_ret(); + } + } + menu_item++; + return 0; +} + +#define MENU_ITEM_EDIT_advance_K() do { if (lcd_advance_K()) return; } while (0) +#endif + + static void lcd_tune_menu() { typedef struct @@ -6644,8 +6698,11 @@ static void lcd_tune_menu() MENU_ITEM_EDIT_int3_P(_T(MSG_FAN_SPEED), &fanSpeed, 0, 255);//5 MENU_ITEM_EDIT_int3_P(_i("Flow"), &extrudemultiply, 10, 999);//6////MSG_FLOW +#ifdef LIN_ADVANCE + MENU_ITEM_EDIT_advance_K();//7 +#endif #ifdef FILAMENTCHANGEENABLE - MENU_ITEM_FUNCTION_P(_T(MSG_FILAMENTCHANGE), lcd_colorprint_change);//7 + MENU_ITEM_FUNCTION_P(_T(MSG_FILAMENTCHANGE), lcd_colorprint_change);//8 #endif #ifdef FILAMENT_SENSOR From fa7ecfc38e534c5623068b3d7eed76e8fee91af9 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sat, 25 May 2019 18:39:50 +0200 Subject: [PATCH 024/180] Check for serial roughtly in the middle of the stepper isr --- Firmware/stepper.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index f0b39905f..37898f9ce 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -830,6 +830,12 @@ FORCE_INLINE void isr() { //WRITE_NC(LOGIC_ANALYZER_CH1, false); } +#ifdef LIN_ADVANCE + // Check for serial chars. This executes roughtly between 50-60% of the total length of the isr, + // making this spot a much better choice than checking during esteps + MSerial.checkRx(); +#endif + // If current block is finished, reset pointer if (step_events_completed.wide >= current_block->step_event_count.wide) { #ifdef FILAMENT_SENSOR From 935a7982369da88b56d6d6b10453559f9448c46b Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sat, 25 May 2019 21:38:59 +0200 Subject: [PATCH 025/180] Speedup advance_spread for common divisors --- Firmware/stepper.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 37898f9ce..b3e6427a8 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -734,7 +734,14 @@ FORCE_INLINE void advance_spread(uint16_t timer) else eISR_Err -= timer - block; - eISR_Rate = timer / ticks; + if (ticks == 1) + eISR_Rate = timer; + else if (ticks == 2) + eISR_Rate = timer / 2; + else if (ticks == 4) + eISR_Rate = timer / 4; + else + eISR_Rate = timer / ticks; nextAdvanceISR = eISR_Rate / 2; } #endif @@ -822,9 +829,8 @@ FORCE_INLINE void isr() { } _NEXT_ISR(OCR1A_nominal); #ifdef LIN_ADVANCE - if (current_block->use_advance_lead && nextAdvanceISR != ADV_NEVER) { + if (current_block->use_advance_lead && nextAdvanceISR != ADV_NEVER) advance_spread(OCR1A_nominal); - } #endif } //WRITE_NC(LOGIC_ANALYZER_CH1, false); From aae03ad83eac79afb49e6e3899abc4e00fade6e5 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sat, 25 May 2019 21:49:43 +0200 Subject: [PATCH 026/180] Correctly handle direction for the filament sensor --- Firmware/stepper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index b3e6427a8..ffbfed195 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -939,7 +939,7 @@ FORCE_INLINE void advance_isr_scheduler() { uint8_t max_ticks = (eisr? e_step_loops: step_loops); max_ticks = min(abs(e_steps), max_ticks); #ifdef FILAMENT_SENSOR - fsensor_counter += max_ticks; + fsensor_counter += (e_steps < 0? -max_ticks: max_ticks); #endif WRITE(E0_DIR_PIN, e_steps < 0? INVERT_E0_DIR: !INVERT_E0_DIR); do From bddc3e84ab5ee72a00af426e4ef055b0d60ab4db Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sat, 25 May 2019 21:50:53 +0200 Subject: [PATCH 027/180] Use WRITE_NC directly in the isr --- Firmware/stepper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index ffbfed195..4a34105e5 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -941,7 +941,7 @@ FORCE_INLINE void advance_isr_scheduler() { #ifdef FILAMENT_SENSOR fsensor_counter += (e_steps < 0? -max_ticks: max_ticks); #endif - WRITE(E0_DIR_PIN, e_steps < 0? INVERT_E0_DIR: !INVERT_E0_DIR); + WRITE_NC(E0_DIR_PIN, e_steps < 0? INVERT_E0_DIR: !INVERT_E0_DIR); do { WRITE_NC(E0_STEP_PIN, !INVERT_E_STEP_PIN); From 6f6cef65b5c254b17565e029fb6925ff2b6fefee Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 26 May 2019 15:35:13 +0200 Subject: [PATCH 028/180] Revert "Correctly handle direction for the filament sensor" This reverts commit aae03ad83eac79afb49e6e3899abc4e00fade6e5. --- Firmware/stepper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 4a34105e5..e45e5eaf5 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -939,7 +939,7 @@ FORCE_INLINE void advance_isr_scheduler() { uint8_t max_ticks = (eisr? e_step_loops: step_loops); max_ticks = min(abs(e_steps), max_ticks); #ifdef FILAMENT_SENSOR - fsensor_counter += (e_steps < 0? -max_ticks: max_ticks); + fsensor_counter += max_ticks; #endif WRITE_NC(E0_DIR_PIN, e_steps < 0? INVERT_E0_DIR: !INVERT_E0_DIR); do From daa8007de5903c43100971cd1bcce26cbd5c007c Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 26 May 2019 16:30:59 +0200 Subject: [PATCH 029/180] Allow to exclude Live K from the build --- Firmware/Configuration_adv.h | 1 + Firmware/ultralcd.cpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Firmware/Configuration_adv.h b/Firmware/Configuration_adv.h index e464b4de4..f739cde26 100644 --- a/Firmware/Configuration_adv.h +++ b/Firmware/Configuration_adv.h @@ -295,6 +295,7 @@ #ifdef LIN_ADVANCE #define LIN_ADVANCE_K 0 // Unit: mm compression per 1mm/s extruder speed + #define LA_LIVE_K // Allow adjusting K in the Tune menu //#define LA_DEBUG // If enabled, this will generate debug information output over USB. //#define LA_DEBUG_LOGIC // @wavexx: setup logic channels for isr debugging #endif diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 8036c3a82..dd1da7201 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -6607,7 +6607,7 @@ static void lcd_colorprint_change() { } -#ifdef LIN_ADVANCE +#ifdef LA_LIVE_K // @wavexx: looks like there's no generic float editing function in menu.cpp so we // redefine our custom handling functions to mimick other tunables #define MSG_ADVANCE_K PSTR("Advance K:") @@ -6698,7 +6698,7 @@ static void lcd_tune_menu() MENU_ITEM_EDIT_int3_P(_T(MSG_FAN_SPEED), &fanSpeed, 0, 255);//5 MENU_ITEM_EDIT_int3_P(_i("Flow"), &extrudemultiply, 10, 999);//6////MSG_FLOW -#ifdef LIN_ADVANCE +#ifdef LA_LIVE_K MENU_ITEM_EDIT_advance_K();//7 #endif #ifdef FILAMENTCHANGEENABLE From a28fb65bb21e1cb65a42934dd974cb666de000fa Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 26 May 2019 14:58:57 +0200 Subject: [PATCH 030/180] Optimize advance_spread further --- Firmware/stepper.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index e45e5eaf5..63ded9d59 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -709,6 +709,14 @@ FORCE_INLINE void stepper_tick_highres() #ifdef LIN_ADVANCE +// @wavexx: fast uint16_t division for small dividends<5 +// q/3 based on "Hacker's delight" formula +FORCE_INLINE uint16_t fastdiv(uint16_t q, uint8_t d) +{ + if(d != 3) return q >> (d / 2); + else return ((uint32_t)0xAAAB * q) >> 17; +} + FORCE_INLINE void advance_spread(uint16_t timer) { if(eISR_Err > timer) @@ -734,14 +742,14 @@ FORCE_INLINE void advance_spread(uint16_t timer) else eISR_Err -= timer - block; - if (ticks == 1) - eISR_Rate = timer; - else if (ticks == 2) - eISR_Rate = timer / 2; - else if (ticks == 4) - eISR_Rate = timer / 4; + if (ticks <= 4) + eISR_Rate = fastdiv(timer, ticks); else + { + // >4 ticks are still possible on slow moves eISR_Rate = timer / ticks; + } + nextAdvanceISR = eISR_Rate / 2; } #endif @@ -811,10 +819,9 @@ FORCE_INLINE void isr() { LA_phase = (eISR_Rate > main_Rate); else { - // avoid overflow through division (TODO: this can be - // improved as both step_loops and e_step_loops are - // currently guaranteed to be powers of two) - LA_phase = (eISR_Rate / step_loops > main_Rate / e_step_loops); + // avoid overflow through division. warning: we need to _guarantee_ step_loops + // and e_step_loops are <= 4 due to fastdiv's limit + LA_phase = (fastdiv(eISR_Rate, step_loops) > fastdiv(main_Rate, e_step_loops)); } } } From 20694aeabc8d23a1680f6c22f7819f54abd948ac Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 26 May 2019 15:34:05 +0200 Subject: [PATCH 031/180] Save 316 bytes by avoiding advance_spread copies --- Firmware/stepper.cpp | 51 ++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 63ded9d59..372f16f09 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -116,7 +116,10 @@ volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1}; void advance_isr_scheduler(); void advance_isr(); - static const uint16_t ADV_NEVER = 0xFFFF; + static const uint16_t ADV_NEVER = 0xFFFF; + static const uint8_t ADV_INIT = 0b01; + static const uint8_t ADV_DECELERATE = 0b10; + static bool use_advance_lead; static uint16_t nextMainISR; @@ -771,6 +774,11 @@ FORCE_INLINE void isr() { else stepper_tick_highres(); + +#ifdef LIN_ADVANCE + uint8_t la_state = 0; +#endif + // Calculare new timer value // 13.38-14.63us for steady state, // 25.12us for acceleration / deceleration. @@ -789,10 +797,8 @@ FORCE_INLINE void isr() { acceleration_time += timer; #ifdef LIN_ADVANCE if (current_block->use_advance_lead) { - bool first = (step_events_completed.wide <= (unsigned long int)step_loops); - if (first) eISR_Err = current_block->advance_rate / 2; - if (first || nextAdvanceISR != ADV_NEVER) - advance_spread(timer); + if (step_events_completed.wide <= (unsigned long int)step_loops) + la_state = ADV_INIT; } #endif } @@ -810,20 +816,8 @@ FORCE_INLINE void isr() { deceleration_time += timer; #ifdef LIN_ADVANCE if (current_block->use_advance_lead) { - bool first = (step_events_completed.wide <= (unsigned long int)current_block->decelerate_after + step_loops); - if (first) eISR_Err = current_block->advance_rate / 2; - if (first || nextAdvanceISR != ADV_NEVER) - { - advance_spread(timer); - if (step_loops == e_step_loops) - LA_phase = (eISR_Rate > main_Rate); - else - { - // avoid overflow through division. warning: we need to _guarantee_ step_loops - // and e_step_loops are <= 4 due to fastdiv's limit - LA_phase = (fastdiv(eISR_Rate, step_loops) > fastdiv(main_Rate, e_step_loops)); - } - } + if (step_events_completed.wide <= (unsigned long int)current_block->decelerate_after + step_loops) + la_state = ADV_INIT | ADV_DECELERATE; } #endif } @@ -835,15 +829,26 @@ FORCE_INLINE void isr() { step_loops_nominal = step_loops; } _NEXT_ISR(OCR1A_nominal); -#ifdef LIN_ADVANCE - if (current_block->use_advance_lead && nextAdvanceISR != ADV_NEVER) - advance_spread(OCR1A_nominal); -#endif } //WRITE_NC(LOGIC_ANALYZER_CH1, false); } #ifdef LIN_ADVANCE + // avoid multiple instances or function calls to advance_spread + if (la_state & ADV_INIT) eISR_Rate = current_block->advance_rate; + if (la_state & ADV_INIT || nextAdvanceISR != ADV_NEVER) { + advance_spread(main_Rate); + if (la_state & ADV_DECELERATE) { + if (step_loops == e_step_loops) + LA_phase = (eISR_Rate > main_Rate); + else { + // avoid overflow through division. warning: we need to _guarantee_ step_loops + // and e_step_loops are <= 4 due to fastdiv's limit + LA_phase = (fastdiv(eISR_Rate, step_loops) > fastdiv(main_Rate, e_step_loops)); + } + } + } + // Check for serial chars. This executes roughtly between 50-60% of the total length of the isr, // making this spot a much better choice than checking during esteps MSerial.checkRx(); From ab478ec2810700689698cad48b9f343792f263aa Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 26 May 2019 16:05:41 +0200 Subject: [PATCH 032/180] Save another 144b by avoiding a calc_timer copy --- Firmware/planner.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index 466cd340c..ddf94cb81 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -1088,8 +1088,17 @@ Having the real displacement of the head, we can calculate the total movement le #ifdef LIN_ADVANCE if (block->use_advance_lead) { + // to save more space we avoid another copy of calc_timer and go through slow division, but we + // still need to replicate the *exact* same step grouping policy (see below) float advance_speed = (extruder_advance_K * block->e_D_ratio * block->acceleration * cs.axis_steps_per_unit[E_AXIS]); - block->advance_rate = calc_timer(advance_speed, block->advance_step_loops); + if (advance_speed > MAX_STEP_FREQUENCY) advance_speed = MAX_STEP_FREQUENCY; + block->advance_rate = (F_CPU / 8.0) / advance_speed; + if (block->advance_rate > 20000) + block->advance_step_loops = 4; + else if (block->advance_rate > 10000) + block->advance_step_loops = 2; + else + block->advance_step_loops = 1; #ifdef LA_DEBUG if (block->advance_step_loops > 2) From 3abb2188dff6c781e93ac6bb7ff78312fc65024d Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 26 May 2019 16:58:57 +0200 Subject: [PATCH 033/180] Fixup initial error by defect --- Firmware/stepper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 372f16f09..6eaa9003d 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -835,7 +835,7 @@ FORCE_INLINE void isr() { #ifdef LIN_ADVANCE // avoid multiple instances or function calls to advance_spread - if (la_state & ADV_INIT) eISR_Rate = current_block->advance_rate; + if (la_state & ADV_INIT) eISR_Rate = current_block->advance_rate / 2; if (la_state & ADV_INIT || nextAdvanceISR != ADV_NEVER) { advance_spread(main_Rate); if (la_state & ADV_DECELERATE) { From 9d834925c03f82994cb1c93471966eca536c8d01 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 26 May 2019 17:05:47 +0200 Subject: [PATCH 034/180] Recalculate LA_phase correctly --- Firmware/stepper.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 6eaa9003d..ed265da61 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -816,8 +816,9 @@ FORCE_INLINE void isr() { deceleration_time += timer; #ifdef LIN_ADVANCE if (current_block->use_advance_lead) { + la_state = ADV_DECELERATE; if (step_events_completed.wide <= (unsigned long int)current_block->decelerate_after + step_loops) - la_state = ADV_INIT | ADV_DECELERATE; + la_state |= ADV_INIT; } #endif } From 823f7b069c6e047291990b458b1e8a1663809f87 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 26 May 2019 19:56:31 +0200 Subject: [PATCH 035/180] Fix filament sensor direction again --- Firmware/stepper.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index ed265da61..d0b1d3120 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -951,14 +951,18 @@ FORCE_INLINE void advance_isr_scheduler() { if (e_steps && (LA_phase < 0 || LA_phase == eisr)) { uint8_t max_ticks = (eisr? e_step_loops: step_loops); max_ticks = min(abs(e_steps), max_ticks); + bool rev = (e_steps < 0); #ifdef FILAMENT_SENSOR - fsensor_counter += max_ticks; + if (count_direction[E_AXIS] == 1) + fsensor_counter += (rev? -max_ticks: max_ticks); + else + fsensor_counter -= (rev? -max_ticks: max_ticks); #endif - WRITE_NC(E0_DIR_PIN, e_steps < 0? INVERT_E0_DIR: !INVERT_E0_DIR); + WRITE_NC(E0_DIR_PIN, rev? INVERT_E0_DIR: !INVERT_E0_DIR); do { WRITE_NC(E0_STEP_PIN, !INVERT_E_STEP_PIN); - e_steps += (e_steps < 0)? 1: -1; + e_steps += (rev? 1: -1); WRITE_NC(E0_STEP_PIN, INVERT_E_STEP_PIN); } while(--max_ticks); From 47d2562510c7dd7c3bb9a0b86ee779040558b0a8 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 26 May 2019 17:14:06 +0200 Subject: [PATCH 036/180] Typos --- Firmware/Configuration_adv.h | 2 +- Firmware/stepper.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Firmware/Configuration_adv.h b/Firmware/Configuration_adv.h index f739cde26..9225ec250 100644 --- a/Firmware/Configuration_adv.h +++ b/Firmware/Configuration_adv.h @@ -281,7 +281,7 @@ * Assumption: advance [steps] = k * (delta velocity [steps/s]) * K=0 means advance disabled. * - * NOTE: K values for LIN_ADVANCE 1.5 differ from earlier versions! + * NOTE: K values for LIN_ADVANCE 1.5 differs from earlier versions! * * Set K around 0.22 for 3mm PLA Direct Drive with ~6.5cm between the drive gear and heatbreak. * Larger K values will be needed for flexible filament and greater distances. diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index d0b1d3120..fda9f11c7 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -779,7 +779,7 @@ FORCE_INLINE void isr() { uint8_t la_state = 0; #endif - // Calculare new timer value + // Calculate new timer value // 13.38-14.63us for steady state, // 25.12us for acceleration / deceleration. { @@ -850,8 +850,8 @@ FORCE_INLINE void isr() { } } - // Check for serial chars. This executes roughtly between 50-60% of the total length of the isr, - // making this spot a much better choice than checking during esteps + // Check for serial chars. This executes roughtly inbetween 50-60% of the total runtime of the + // entire isr, making this spot a much better choice than checking during esteps MSerial.checkRx(); #endif From 4772532524327bf92f398b1113c82c3c0b42a462 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 26 May 2019 22:14:31 +0200 Subject: [PATCH 037/180] Allow Live-K to be used on stock 3.7.1 using a stub --- Firmware/ultralcd.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index dd1da7201..ceccfbe57 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -6612,6 +6612,18 @@ static void lcd_colorprint_change() { // redefine our custom handling functions to mimick other tunables #define MSG_ADVANCE_K PSTR("Advance K:") +#if FW_COMMIT_NR <= 2266 +// TODO: this is a stub to be removed for FW >3.7.1 +const static char menu_fmt_float13_k[] PROGMEM = "%c%-13.13S%+5.3f"; +const static char menu_fmt_float13off_k[] PROGMEM = "%c%-13.13S%6.6s"; +static void lcd_advance_draw_K(char chr, float val) +{ + if (val <= 0) + lcd_printf_P(menu_fmt_float13off_k, chr, MSG_ADVANCE_K, " [off]"); + else + lcd_printf_P(menu_fmt_float13_k, chr, MSG_ADVANCE_K, val); +} +#else static void lcd_advance_draw_K(char chr, float val) { if (val <= 0) @@ -6619,6 +6631,7 @@ static void lcd_advance_draw_K(char chr, float val) else lcd_printf_P(menu_fmt_float13, chr, MSG_ADVANCE_K, val); } +#endif static void lcd_advance_edit_K(void) { From a742afcebd743920791937da6c7b0eee7839adbe Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 26 May 2019 22:43:06 +0200 Subject: [PATCH 038/180] Remove version check --- Firmware/ultralcd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index ceccfbe57..5d774eb14 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -6612,7 +6612,7 @@ static void lcd_colorprint_change() { // redefine our custom handling functions to mimick other tunables #define MSG_ADVANCE_K PSTR("Advance K:") -#if FW_COMMIT_NR <= 2266 +#if 1 // TODO: this is a stub to be removed for FW >3.7.1 const static char menu_fmt_float13_k[] PROGMEM = "%c%-13.13S%+5.3f"; const static char menu_fmt_float13off_k[] PROGMEM = "%c%-13.13S%6.6s"; From 51d6904dad10e1554233e508dfa23f8e0db97018 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Mon, 27 May 2019 00:44:17 +0200 Subject: [PATCH 039/180] Multiply the step rate when grouping advance steps --- Firmware/planner.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index ddf94cb81..67aa3c9a1 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -1093,10 +1093,14 @@ Having the real displacement of the head, we can calculate the total movement le float advance_speed = (extruder_advance_K * block->e_D_ratio * block->acceleration * cs.axis_steps_per_unit[E_AXIS]); if (advance_speed > MAX_STEP_FREQUENCY) advance_speed = MAX_STEP_FREQUENCY; block->advance_rate = (F_CPU / 8.0) / advance_speed; - if (block->advance_rate > 20000) + if (block->advance_rate > 20000) { + block->advance_rate = (block->advance_rate >> 2)&0x3fff; block->advance_step_loops = 4; - else if (block->advance_rate > 10000) + } + else if (block->advance_rate > 10000) { + block->advance_rate = (block->advance_rate >> 1)&0x7fff; block->advance_step_loops = 2; + } else block->advance_step_loops = 1; From c50b1c035156a0abfc4f0bd8c688b9ed420ed711 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sat, 1 Jun 2019 19:59:39 +0200 Subject: [PATCH 040/180] Rework the filament counter logic - Move direction checks out of fsensor: fsensor_counter is now always in the same direction as e_steps - Check the filament chunk after e_steps have been physically done, using the real e_step count so far --- Firmware/fsensor.cpp | 11 +++++------ Firmware/fsensor.h | 4 ++-- Firmware/stepper.cpp | 33 +++++++++++++++++++-------------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index d520ba533..d296a6e74 100644 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -492,11 +492,10 @@ void fsensor_setup_interrupt(void) #endif //PAT9125 -void fsensor_st_block_begin(block_t* bl) +void fsensor_st_block_begin(bool rev) { if (!fsensor_enabled) return; - if (((fsensor_st_cnt > 0) && (bl->direction_bits & 0x8)) || - ((fsensor_st_cnt < 0) && !(bl->direction_bits & 0x8))) + if (fsensor_st_cnt && ((fsensor_st_cnt > 0) ^ rev)) { // !!! bit toggling (PINxn <- 1) (for PinChangeInterrupt) does not work for some MCU pins if (PIN_GET(FSENSOR_INT_PIN)) {PIN_VAL(FSENSOR_INT_PIN, LOW);} @@ -504,11 +503,11 @@ void fsensor_st_block_begin(block_t* bl) } } -void fsensor_st_block_chunk(block_t* bl, int cnt) +void fsensor_st_block_chunk(int cnt) { if (!fsensor_enabled) return; - fsensor_st_cnt += (bl->direction_bits & 0x8)?-cnt:cnt; - if ((fsensor_st_cnt >= fsensor_chunk_len) || (fsensor_st_cnt <= -fsensor_chunk_len)) + fsensor_st_cnt += cnt; + if (abs(fsensor_st_cnt) >= fsensor_chunk_len) { // !!! bit toggling (PINxn <- 1) (for PinChangeInterrupt) does not work for some MCU pins if (PIN_GET(FSENSOR_INT_PIN)) {PIN_VAL(FSENSOR_INT_PIN, LOW);} diff --git a/Firmware/fsensor.h b/Firmware/fsensor.h index 71922fbfc..85992d39d 100644 --- a/Firmware/fsensor.h +++ b/Firmware/fsensor.h @@ -60,8 +60,8 @@ extern bool fsensor_oq_result(void); #include "planner.h" //! @name callbacks from stepper //! @{ -extern void fsensor_st_block_begin(block_t* bl); -extern void fsensor_st_block_chunk(block_t* bl, int cnt); +extern void fsensor_st_block_begin(bool rev); +extern void fsensor_st_block_chunk(int cnt); //! @} #endif //FSENSOR_H diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index fda9f11c7..111d1fa7a 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -339,7 +339,7 @@ FORCE_INLINE void stepper_next_block() #ifdef FILAMENT_SENSOR fsensor_counter = 0; - fsensor_st_block_begin(current_block); + fsensor_st_block_begin(count_direction[E_AXIS] < 0); #endif //FILAMENT_SENSOR // The busy flag is set by the plan_get_current_block() call. // current_block->busy = true; @@ -638,7 +638,7 @@ FORCE_INLINE void stepper_tick_lowres() e_steps += count_direction[E_AXIS]; #else #ifdef FILAMENT_SENSOR - ++ fsensor_counter; + fsensor_counter += count_direction[E_AXIS]; #endif //FILAMENT_SENSOR WRITE(E0_STEP_PIN, INVERT_E_STEP_PIN); #endif @@ -700,7 +700,7 @@ FORCE_INLINE void stepper_tick_highres() e_steps += count_direction[E_AXIS]; #else #ifdef FILAMENT_SENSOR - ++ fsensor_counter; + fsensor_counter += count_direction[E_AXIS]; #endif //FILAMENT_SENSOR WRITE(E0_STEP_PIN, INVERT_E_STEP_PIN); #endif @@ -857,18 +857,18 @@ FORCE_INLINE void isr() { // If current block is finished, reset pointer if (step_events_completed.wide >= current_block->step_event_count.wide) { -#ifdef FILAMENT_SENSOR - fsensor_st_block_chunk(current_block, fsensor_counter); +#if !defined(LIN_ADVANCE) && defined(FILAMENT_SENSOR) + fsensor_st_block_chunk(fsensor_counter); fsensor_counter = 0; #endif //FILAMENT_SENSOR current_block = NULL; plan_discard_current_block(); } -#ifdef FILAMENT_SENSOR - else if ((fsensor_counter >= fsensor_chunk_len)) +#if !defined(LIN_ADVANCE) && defined(FILAMENT_SENSOR) + else if ((abs(fsensor_counter) >= fsensor_chunk_len)) { - fsensor_st_block_chunk(current_block, fsensor_counter); + fsensor_st_block_chunk(fsensor_counter); fsensor_counter = 0; } #endif //FILAMENT_SENSOR @@ -952,20 +952,25 @@ FORCE_INLINE void advance_isr_scheduler() { uint8_t max_ticks = (eisr? e_step_loops: step_loops); max_ticks = min(abs(e_steps), max_ticks); bool rev = (e_steps < 0); -#ifdef FILAMENT_SENSOR - if (count_direction[E_AXIS] == 1) - fsensor_counter += (rev? -max_ticks: max_ticks); - else - fsensor_counter -= (rev? -max_ticks: max_ticks); -#endif WRITE_NC(E0_DIR_PIN, rev? INVERT_E0_DIR: !INVERT_E0_DIR); do { WRITE_NC(E0_STEP_PIN, !INVERT_E_STEP_PIN); e_steps += (rev? 1: -1); WRITE_NC(E0_STEP_PIN, INVERT_E_STEP_PIN); +#ifdef FILAMENT_SENSOR + fsensor_counter += (rev? -1: 1); +#endif } while(--max_ticks); + +#ifdef FILAMENT_SENSOR + if (!current_block || (abs(fsensor_counter) >= fsensor_chunk_len)) + { + fsensor_st_block_chunk(fsensor_counter); + fsensor_counter = 0; + } +#endif } // Schedule the next closest tick, ignoring advance if scheduled too From b4bf79297f804568f2f1cb82a3bfd0968e8e4a94 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 2 Jun 2019 00:42:32 +0200 Subject: [PATCH 041/180] Remove unneeded includes from fsensor --- Firmware/fsensor.cpp | 3 --- Firmware/fsensor.h | 2 -- 2 files changed, 5 deletions(-) diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index d296a6e74..471518b22 100644 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -6,12 +6,9 @@ #include #include "pat9125.h" #include "stepper.h" -#include "planner.h" -#include "fastio.h" #include "io_atmega2560.h" #include "cmdqueue.h" #include "ultralcd.h" -#include "ConfigurationStore.h" #include "mmu.h" #include "cardreader.h" diff --git a/Firmware/fsensor.h b/Firmware/fsensor.h index 85992d39d..1abf13b9a 100644 --- a/Firmware/fsensor.h +++ b/Firmware/fsensor.h @@ -56,8 +56,6 @@ extern void fsensor_oq_meassure_stop(void); extern bool fsensor_oq_result(void); //! @} - -#include "planner.h" //! @name callbacks from stepper //! @{ extern void fsensor_st_block_begin(bool rev); From 5cd0177389c5f0dc93da3b70dd404582e3022f4a Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 2 Jun 2019 15:01:56 +0200 Subject: [PATCH 042/180] Cleanup fsensor_st_block_begin --- Firmware/fsensor.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index 471518b22..563d37d65 100644 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -489,15 +489,13 @@ void fsensor_setup_interrupt(void) #endif //PAT9125 -void fsensor_st_block_begin(bool rev) +void fsensor_st_block_begin(bool rev __attribute__((unused))) { - if (!fsensor_enabled) return; - if (fsensor_st_cnt && ((fsensor_st_cnt > 0) ^ rev)) - { -// !!! bit toggling (PINxn <- 1) (for PinChangeInterrupt) does not work for some MCU pins - if (PIN_GET(FSENSOR_INT_PIN)) {PIN_VAL(FSENSOR_INT_PIN, LOW);} - else {PIN_VAL(FSENSOR_INT_PIN, HIGH);} - } + // There's really nothing to do here: the stepper ISR likely has called us + // already at the end of the last block, making this integration redundant. + // LA1.5 might not always do that during a coasting move, so attempt to drain + // fsensor_st_cnt anyway at the beginning of the new block. + fsensor_st_block_chunk(0); } void fsensor_st_block_chunk(int cnt) From d2432056bdcb570884f92f53ab6d2468d82260f5 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Mon, 3 Jun 2019 11:48:36 +0200 Subject: [PATCH 043/180] Elide fsensor_st_block_begin, saving some cycles/bytes --- Firmware/fsensor.cpp | 9 --------- Firmware/fsensor.h | 7 ++++++- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index 563d37d65..4ab87586c 100644 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -489,15 +489,6 @@ void fsensor_setup_interrupt(void) #endif //PAT9125 -void fsensor_st_block_begin(bool rev __attribute__((unused))) -{ - // There's really nothing to do here: the stepper ISR likely has called us - // already at the end of the last block, making this integration redundant. - // LA1.5 might not always do that during a coasting move, so attempt to drain - // fsensor_st_cnt anyway at the beginning of the new block. - fsensor_st_block_chunk(0); -} - void fsensor_st_block_chunk(int cnt) { if (!fsensor_enabled) return; diff --git a/Firmware/fsensor.h b/Firmware/fsensor.h index 1abf13b9a..e40568bb1 100644 --- a/Firmware/fsensor.h +++ b/Firmware/fsensor.h @@ -58,8 +58,13 @@ extern bool fsensor_oq_result(void); //! @name callbacks from stepper //! @{ -extern void fsensor_st_block_begin(bool rev); extern void fsensor_st_block_chunk(int cnt); + +// There's really nothing to do in block_begin: the stepper ISR likely has +// called us already at the end of the last block, making this integration +// redundant. LA1.5 might not always do that during a coasting move, so attempt +// to drain fsensor_st_cnt anyway at the beginning of the new block. +#define fsensor_st_block_begin(rev) fsensor_st_block_chunk(0) //! @} #endif //FSENSOR_H From fa7c0fb2c92f5bfaa0f996ee2c650df7116d1694 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Mon, 3 Jun 2019 12:24:08 +0200 Subject: [PATCH 044/180] Avoid triggering LA during a Z-priming move When recovering from a pause, the nozzle is often primed while being lowered. If LA is triggered under such a move, the pressure advance will be wasted. --- Firmware/planner.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index 67aa3c9a1..e1b04702a 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -1023,13 +1023,15 @@ Having the real displacement of the head, we can calculate the total movement le /** * Use LIN_ADVANCE for blocks if all these are true: * - * block->steps_e : This is a print move, because we checked for X, Y, Z steps before. - * extruder_advance_K : There is an advance factor set. - * delta_mm[E_AXIS] > 0 : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves) + * block->steps_e : This is a print move, because we checked for X, Y, Z steps before. + * extruder_advance_K : There is an advance factor set. + * delta_mm[E_AXIS] > 0 : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves) + * |delta_mm[Z_AXIS]| < 0.5 : Z is only moved for leveling (_not_ for priming) */ block->use_advance_lead = block->steps_e.wide && extruder_advance_K - && delta_mm[E_AXIS] > 0; + && delta_mm[E_AXIS] > 0 + && abs(delta_mm[Z_AXIS]) < 0.5; if (block->use_advance_lead) { block->e_D_ratio = (e - position_float[E_AXIS]) / sqrt(sq(x - position_float[X_AXIS]) From 84009e1e8e80ccc48374beed9d3e90272b1ed1dd Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Mon, 3 Jun 2019 14:52:12 +0200 Subject: [PATCH 045/180] Do a full fsensor_update() when initializing the sensor This correctly populates the "extruder info" details even when the menu is entered for the first time after starting a print. --- Firmware/fsensor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index 4ab87586c..29673231f 100644 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -216,7 +216,7 @@ void fsensor_autoload_check_start(void) if (!fsensor_enabled) return; if (!fsensor_autoload_enabled) return; if (fsensor_watch_autoload) return; - if (!pat9125_update_y()) //update sensor + if (!pat9125_update()) //update sensor { fsensor_disable(); fsensor_not_responding = true; From bca5618145dcee174f01ba82aa66742f1bb5b173 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Mon, 3 Jun 2019 16:53:55 +0200 Subject: [PATCH 046/180] Save/restore K during a power panic --- Firmware/Marlin_main.cpp | 6 ++++++ Firmware/eeprom.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index b9af28b7a..663d36e57 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -8801,6 +8801,9 @@ void uvlo_() #endif #endif eeprom_update_word((uint16_t*)(EEPROM_EXTRUDEMULTIPLY), (uint16_t)extrudemultiply); +#ifdef LIN_ADVANCE + eeprom_update_float((float*)(EEPROM_UVLO_LA_K), extruder_advance_K); +#endif // Finaly store the "power outage" flag. if(sd_print) eeprom_update_byte((uint8_t*)EEPROM_UVLO, 1); @@ -9046,6 +9049,9 @@ void recover_machine_state_after_power_panic(bool bTiny) #endif #endif extrudemultiply = (int)eeprom_read_word((uint16_t*)(EEPROM_EXTRUDEMULTIPLY)); +#ifdef LIN_ADVANCE + extruder_advance_K = eeprom_read_float((float*)EEPROM_UVLO_LA_K); +#endif } void restore_print_from_eeprom() { diff --git a/Firmware/eeprom.h b/Firmware/eeprom.h index c96e1d8db..624025e8b 100644 --- a/Firmware/eeprom.h +++ b/Firmware/eeprom.h @@ -160,6 +160,8 @@ #define EEPROM_MBL_POINTS_NR (EEPROM_MBL_MAGNET_ELIMINATION -1) //uint8_t number of points in one exis for mesh bed leveling #define EEPROM_MBL_PROBE_NR (EEPROM_MBL_POINTS_NR-1) //number of measurements for each point #define EEPROM_MMU_STEALTH (EEPROM_MBL_PROBE_NR-1) + +#define EEPROM_UVLO_LA_K (EEPROM_MMU_STEALTH-4) // float // !!!!! // !!!!! this is end of EEPROM section ... all updates MUST BE inserted before this mark !!!!! // !!!!! From 8ce1c047405aec9fd383e55f47fbcd9297e15461 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 4 Jun 2019 14:36:41 +0200 Subject: [PATCH 047/180] Remove useless "extruder under pressure" flag That's exactly what LA does --- Firmware/Marlin_main.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 663d36e57..a1eec5a61 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -356,10 +356,6 @@ unsigned long starttime=0; unsigned long stoptime=0; unsigned long _usb_timer = 0; - -bool extruder_under_pressure = true; - - bool Stopped=false; #if NUM_SERVOS > 0 @@ -385,7 +381,6 @@ static float saved_pos[4] = { 0, 0, 0, 0 }; static float saved_feedrate2 = 0; static uint8_t saved_active_extruder = 0; static float saved_extruder_temperature = 0.0; //!< Active extruder temperature -static bool saved_extruder_under_pressure = false; static bool saved_extruder_relative_mode = false; static int saved_fanSpeed = 0; //!< Print fan speed //! @} @@ -9270,8 +9265,6 @@ void stop_and_save_print_to_ram(float z_move, float e_move) memcpy(saved_pos, current_position, sizeof(saved_pos)); saved_active_extruder = active_extruder; //save active_extruder saved_extruder_temperature = degTargetHotend(active_extruder); - - saved_extruder_under_pressure = extruder_under_pressure; //extruder under pressure flag - currently unused saved_extruder_relative_mode = axis_relative_modes[E_AXIS]; saved_fanSpeed = fanSpeed; cmdqueue_reset(); //empty cmdqueue From 1bed8cfa941a29ec304f0cbc19677c24338fbc78 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 4 Jun 2019 16:02:03 +0200 Subject: [PATCH 048/180] Don't call fsensor_st_next_block repeatedly during the last step Rely on st_block_begin to perform a single call instead of calling block_chunk for each advance tick in the last step --- Firmware/stepper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 111d1fa7a..68f36342f 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -965,7 +965,7 @@ FORCE_INLINE void advance_isr_scheduler() { while(--max_ticks); #ifdef FILAMENT_SENSOR - if (!current_block || (abs(fsensor_counter) >= fsensor_chunk_len)) + if (abs(fsensor_counter) >= fsensor_chunk_len) { fsensor_st_block_chunk(fsensor_counter); fsensor_counter = 0; From cda9ed4a1d404d676fd975b3d4e4fdadcf74a079 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 4 Jun 2019 14:37:35 +0200 Subject: [PATCH 049/180] Reset LA state more carefully during stop conditions --- Firmware/stepper.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 68f36342f..cd590013b 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -426,6 +426,13 @@ FORCE_INLINE void stepper_next_block() } else { _NEXT_ISR(2000); // 1kHz. + +#ifdef LIN_ADVANCE + // reset LA state and pressure when there's no block + nextAdvanceISR = ADV_NEVER; + e_steps = 0; + current_adv_steps = 0; +#endif } //WRITE_NC(LOGIC_ANALYZER_CH2, false); } @@ -982,6 +989,8 @@ FORCE_INLINE void advance_isr_scheduler() { } void clear_current_adv_vars() { + nextAdvanceISR = ADV_NEVER; + e_steps = 0; current_adv_steps = 0; } @@ -1336,6 +1345,9 @@ void quickStop() DISABLE_STEPPER_DRIVER_INTERRUPT(); while (blocks_queued()) plan_discard_current_block(); current_block = NULL; +#ifdef LIN_ADVANCE + clear_current_adv_vars(); +#endif st_reset_timer(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } From fa454f61e41c9373de27c255be7694842f40e102 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 5 Jun 2019 15:23:59 +0200 Subject: [PATCH 050/180] Drop unused "speed_lookup_table.h" from planner.cpp --- Firmware/planner.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index e1b04702a..57c312e84 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -58,7 +58,6 @@ #include "ultralcd.h" #include "language.h" #include "ConfigurationStore.h" -#include "speed_lookuptable.h" #ifdef MESH_BED_LEVELING #include "mesh_bed_leveling.h" From dc436b71fe6052b8b31192bd113197895c4c277a Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 5 Jun 2019 13:00:26 +0200 Subject: [PATCH 051/180] Fix position_float after a quickStop condition --- Firmware/planner.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index 57c312e84..c8f18f417 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -127,7 +127,7 @@ float extrude_min_temp=EXTRUDE_MINTEMP; #ifdef LIN_ADVANCE float extruder_advance_K = LIN_ADVANCE_K; -float position_float[NUM_AXIS] = { 0, 0, 0, 0 }; +float position_float[NUM_AXIS]; #endif // Returns the index of the next block in the ring buffer @@ -441,7 +441,7 @@ void plan_init() { block_buffer_tail = 0; memset(position, 0, sizeof(position)); // clear position #ifdef LIN_ADVANCE - memset(position_float, 0, sizeof(position)); // clear position + memset(position_float, 0, sizeof(position_float)); // clear position #endif previous_speed[0] = 0.0; previous_speed[1] = 0.0; @@ -655,7 +655,9 @@ void planner_abort_hard() // Apply inverse world correction matrix. machine2world(current_position[X_AXIS], current_position[Y_AXIS]); memcpy(destination, current_position, sizeof(destination)); - +#ifdef LIN_ADVANCE + memcpy(position_float, current_position, sizeof(position_float)); +#endif // Resets planner junction speeds. Assumes start from rest. previous_nominal_speed = 0.0; previous_speed[0] = 0.0; From 7d33089d9aa1a3442149f2362aa6a90cef0a72e3 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 5 Jun 2019 13:02:04 +0200 Subject: [PATCH 052/180] Remove use_advance_lead The per-step state is kept implicitly using nextAdvanceISR, while the current pressure is decoupled anyway. --- Firmware/stepper.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index cd590013b..6daddaa43 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -120,8 +120,6 @@ volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1}; static const uint8_t ADV_INIT = 0b01; static const uint8_t ADV_DECELERATE = 0b10; - static bool use_advance_lead; - static uint16_t nextMainISR; static uint16_t nextAdvanceISR; @@ -354,7 +352,7 @@ FORCE_INLINE void stepper_next_block() acceleration_time = calc_timer(acc_step_rate, step_loops); #ifdef LIN_ADVANCE - if ((use_advance_lead = current_block->use_advance_lead)) { + if (current_block->use_advance_lead) { LA_decelerate_after = current_block->decelerate_after; final_adv_steps = current_block->final_adv_steps; max_adv_steps = current_block->max_adv_steps; @@ -1227,7 +1225,6 @@ void st_init() #endif // Initialize state for the linear advance scheduler - use_advance_lead = false; nextMainISR = 0; nextAdvanceISR = ADV_NEVER; main_Rate = ADV_NEVER; From 048628083a637c356bec59a5a1f8ffff331d85dd Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 5 Jun 2019 13:03:25 +0200 Subject: [PATCH 053/180] Remove clear_current_adv_vars() The pressure state is already reset implicitly at the end of each block, meaning an extruder switch will never have to reset the internal state anyway. We clear the internal backpressure in the following conditions: - when switching to a non-LA block - when quickStop is called - when the scheduler is idling (losing pressure) --- Firmware/Marlin_main.cpp | 7 ------- Firmware/stepper.cpp | 17 +++++++---------- Firmware/stepper.h | 4 ---- 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index a1eec5a61..c423df1bf 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -7086,15 +7086,8 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) else { #ifdef SNMM - -#ifdef LIN_ADVANCE - if (mmu_extruder != tmp_extruder) - clear_current_adv_vars(); //Check if the selected extruder is not the active one and reset LIN_ADVANCE variables if so. -#endif - mmu_extruder = tmp_extruder; - _delay(100); disable_e0(); diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 6daddaa43..ba5e84141 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -426,10 +426,13 @@ FORCE_INLINE void stepper_next_block() _NEXT_ISR(2000); // 1kHz. #ifdef LIN_ADVANCE - // reset LA state and pressure when there's no block + // reset LA state when there's no block nextAdvanceISR = ADV_NEVER; e_steps = 0; - current_adv_steps = 0; + + // incrementally lose pressure + if(current_adv_steps) + --current_adv_steps; #endif } //WRITE_NC(LOGIC_ANALYZER_CH2, false); @@ -985,13 +988,6 @@ FORCE_INLINE void advance_isr_scheduler() { else OCR1A = nextMainISR; } - -void clear_current_adv_vars() { - nextAdvanceISR = ADV_NEVER; - e_steps = 0; - current_adv_steps = 0; -} - #endif // LIN_ADVANCE void st_init() @@ -1343,7 +1339,8 @@ void quickStop() while (blocks_queued()) plan_discard_current_block(); current_block = NULL; #ifdef LIN_ADVANCE - clear_current_adv_vars(); + nextAdvanceISR = ADV_NEVER; + current_adv_steps = 0; #endif st_reset_timer(); ENABLE_STEPPER_DRIVER_INTERRUPT(); diff --git a/Firmware/stepper.h b/Firmware/stepper.h index 1bdb1f17a..7c41743cd 100644 --- a/Firmware/stepper.h +++ b/Firmware/stepper.h @@ -37,10 +37,6 @@ void st_init(); void isr(); -#ifdef LIN_ADVANCE -void clear_current_adv_vars(); // Used to reset the built up pretension and remaining esteps on filament change. -#endif - // Block until all buffered steps are executed void st_synchronize(); From 0239f4bce19f1dabe430c51087771798b7449d6f Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 5 Jun 2019 15:10:31 +0200 Subject: [PATCH 054/180] Update/compute advance steps inside calculate_trapezoid_for_block Do not store the block e_D ratio, store directly the computed compression factor so that we can recompute the advance steps quickly and update them in sync with the acceleration rates. --- Firmware/planner.cpp | 59 ++++++++++++++++++++++---------------------- Firmware/planner.h | 2 +- Firmware/stepper.cpp | 3 ++- 3 files changed, 33 insertions(+), 31 deletions(-) diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index c8f18f417..cb286c586 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -261,6 +261,13 @@ void calculate_trapezoid_for_block(block_t *block, float entry_speed, float exit } } +#ifdef LIN_ADVANCE + uint16_t final_adv_steps = 0; + if (block->use_advance_lead) { + final_adv_steps = exit_speed * block->adv_comp; + } +#endif + CRITICAL_SECTION_START; // Fill variables used by the stepper in a critical section // This block locks the interrupts globally for 4.38 us, // which corresponds to a maximum repeat frequency of 228.57 kHz. @@ -271,6 +278,9 @@ void calculate_trapezoid_for_block(block_t *block, float entry_speed, float exit block->decelerate_after = accelerate_steps+plateau_steps; block->initial_rate = initial_rate; block->final_rate = final_rate; +#ifdef LIN_ADVANCE + block->final_adv_steps = final_adv_steps; +#endif } CRITICAL_SECTION_END; } @@ -399,18 +409,8 @@ void planner_recalculate(const float &safe_final_speed) } // Recalculate if current block entry or exit junction speed has changed. if ((prev->flag | current->flag) & BLOCK_FLAG_RECALCULATE) { - // @wavexx: FIXME: the following check is not really enough. calculate_trapezoid does block - // the isr to update the rates, but we don't. we should update atomically - if (!prev->busy) { - // NOTE: Entry and exit factors always > 0 by all previous logic operations. - calculate_trapezoid_for_block(prev, prev->entry_speed, current->entry_speed); - #ifdef LIN_ADVANCE - if (prev->use_advance_lead) { - const float comp = prev->e_D_ratio * extruder_advance_K * cs.axis_steps_per_unit[E_AXIS]; - prev->final_adv_steps = current->entry_speed * comp; - } - #endif - } + // NOTE: Entry and exit factors always > 0 by all previous logic operations. + calculate_trapezoid_for_block(prev, prev->entry_speed, current->entry_speed); // Reset current only to ensure next trapezoid is computed. prev->flag &= ~BLOCK_FLAG_RECALCULATE; } @@ -424,13 +424,6 @@ void planner_recalculate(const float &safe_final_speed) // Last/newest block in buffer. Exit speed is set with safe_final_speed. Always recalculated. current = block_buffer + prev_block_index(block_buffer_head); calculate_trapezoid_for_block(current, current->entry_speed, safe_final_speed); - #ifdef LIN_ADVANCE - if (current->use_advance_lead) { - const float comp = current->e_D_ratio * extruder_advance_K * cs.axis_steps_per_unit[E_AXIS]; - current->max_adv_steps = current->nominal_speed * comp; - current->final_adv_steps = safe_final_speed * comp; - } - #endif current->flag &= ~BLOCK_FLAG_RECALCULATE; // SERIAL_ECHOLNPGM("planner_recalculate - 4"); @@ -1005,6 +998,9 @@ Having the real displacement of the head, we can calculate the total movement le block->nominal_rate *= speed_factor; } +#ifdef LIN_ADVANCE + float e_D_ratio = 0; +#endif // Compute and limit the acceleration rate for the trapezoid generator. // block->step_event_count ... event count of the fastest axis // block->millimeters ... Euclidian length of the XYZ movement or the E length, if no XYZ movement. @@ -1022,7 +1018,7 @@ Having the real displacement of the head, we can calculate the total movement le #ifdef LIN_ADVANCE /** - * Use LIN_ADVANCE for blocks if all these are true: + * Use LIN_ADVANCE within this block if all these are true: * * block->steps_e : This is a print move, because we checked for X, Y, Z steps before. * extruder_advance_K : There is an advance factor set. @@ -1034,19 +1030,19 @@ Having the real displacement of the head, we can calculate the total movement le && delta_mm[E_AXIS] > 0 && abs(delta_mm[Z_AXIS]) < 0.5; if (block->use_advance_lead) { - block->e_D_ratio = (e - position_float[E_AXIS]) / - sqrt(sq(x - position_float[X_AXIS]) - + sq(y - position_float[Y_AXIS]) - + sq(z - position_float[Z_AXIS])); + e_D_ratio = (e - position_float[E_AXIS]) / + sqrt(sq(x - position_float[X_AXIS]) + + sq(y - position_float[Y_AXIS]) + + sq(z - position_float[Z_AXIS])); // Check for unusual high e_D ratio to detect if a retract move was combined with the last // print move due to min. steps per segment. Never execute this with advance! This assumes // no one will use a retract length of 0mm < retr_length < ~0.2mm and no one will print // 100mm wide lines using 3mm filament or 35mm wide lines using 1.75mm filament. - if (block->e_D_ratio > 3.0) + if (e_D_ratio > 3.0) block->use_advance_lead = false; else { - const uint32_t max_accel_steps_per_s2 = cs.max_jerk[E_AXIS] / (extruder_advance_K * block->e_D_ratio) * steps_per_mm; + const uint32_t max_accel_steps_per_s2 = cs.max_jerk[E_AXIS] / (extruder_advance_K * e_D_ratio) * steps_per_mm; if (block->acceleration_st > max_accel_steps_per_s2) { block->acceleration_st = max_accel_steps_per_s2; #ifdef LA_DEBUG @@ -1089,11 +1085,16 @@ Having the real displacement of the head, we can calculate the total movement le block->acceleration_rate = (long)((float)block->acceleration_st * (16777216.0 / (F_CPU / 8.0))); - #ifdef LIN_ADVANCE +#ifdef LIN_ADVANCE if (block->use_advance_lead) { + // the nominal speed doesn't change past this point: calculate the compression ratio for the + // segment and the required advance steps + block->adv_comp = extruder_advance_K * e_D_ratio * cs.axis_steps_per_unit[E_AXIS]; + block->max_adv_steps = block->nominal_speed * block->adv_comp; + // to save more space we avoid another copy of calc_timer and go through slow division, but we // still need to replicate the *exact* same step grouping policy (see below) - float advance_speed = (extruder_advance_K * block->e_D_ratio * block->acceleration * cs.axis_steps_per_unit[E_AXIS]); + float advance_speed = (extruder_advance_K * e_D_ratio * block->acceleration * cs.axis_steps_per_unit[E_AXIS]); if (advance_speed > MAX_STEP_FREQUENCY) advance_speed = MAX_STEP_FREQUENCY; block->advance_rate = (F_CPU / 8.0) / advance_speed; if (block->advance_rate > 20000) { @@ -1116,7 +1117,7 @@ Having the real displacement of the head, we can calculate the total movement le SERIAL_ECHOLNPGM("LA: More than 2 steps per eISR loop executed."); #endif } - #endif +#endif // Start with a safe speed. // Safe speed is the speed, from which the machine may halt to stop immediately. diff --git a/Firmware/planner.h b/Firmware/planner.h index 44c57ea5e..bb7b17c8a 100644 --- a/Firmware/planner.h +++ b/Firmware/planner.h @@ -117,7 +117,7 @@ typedef struct { max_adv_steps, // max. advance steps to get cruising speed pressure (not always nominal_speed!) final_adv_steps; // advance steps due to exit speed uint8_t advance_step_loops; // Number of stepper ticks for each advance isr - float e_D_ratio; + float adv_comp; // Precomputed E compression factor #endif uint16_t sdlen; diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index ba5e84141..d6faee967 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -430,7 +430,8 @@ FORCE_INLINE void stepper_next_block() nextAdvanceISR = ADV_NEVER; e_steps = 0; - // incrementally lose pressure + // incrementally lose pressure to give a chance for + // a new LA block to be scheduled and recover if(current_adv_steps) --current_adv_steps; #endif From c40e3b550dde8118d1c1ba8c7e0662c09e9913cf Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Mon, 10 Jun 2019 19:34:00 +0200 Subject: [PATCH 055/180] Remove stubs and live K by default --- Firmware/Configuration_adv.h | 2 +- Firmware/ultralcd.cpp | 13 ------------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/Firmware/Configuration_adv.h b/Firmware/Configuration_adv.h index 9225ec250..50496704a 100644 --- a/Firmware/Configuration_adv.h +++ b/Firmware/Configuration_adv.h @@ -295,7 +295,7 @@ #ifdef LIN_ADVANCE #define LIN_ADVANCE_K 0 // Unit: mm compression per 1mm/s extruder speed - #define LA_LIVE_K // Allow adjusting K in the Tune menu + //#define LA_LIVE_K // Allow adjusting K in the Tune menu //#define LA_DEBUG // If enabled, this will generate debug information output over USB. //#define LA_DEBUG_LOGIC // @wavexx: setup logic channels for isr debugging #endif diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 5d774eb14..dd1da7201 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -6612,18 +6612,6 @@ static void lcd_colorprint_change() { // redefine our custom handling functions to mimick other tunables #define MSG_ADVANCE_K PSTR("Advance K:") -#if 1 -// TODO: this is a stub to be removed for FW >3.7.1 -const static char menu_fmt_float13_k[] PROGMEM = "%c%-13.13S%+5.3f"; -const static char menu_fmt_float13off_k[] PROGMEM = "%c%-13.13S%6.6s"; -static void lcd_advance_draw_K(char chr, float val) -{ - if (val <= 0) - lcd_printf_P(menu_fmt_float13off_k, chr, MSG_ADVANCE_K, " [off]"); - else - lcd_printf_P(menu_fmt_float13_k, chr, MSG_ADVANCE_K, val); -} -#else static void lcd_advance_draw_K(char chr, float val) { if (val <= 0) @@ -6631,7 +6619,6 @@ static void lcd_advance_draw_K(char chr, float val) else lcd_printf_P(menu_fmt_float13, chr, MSG_ADVANCE_K, val); } -#endif static void lcd_advance_edit_K(void) { From 4b3af0d2dfc82cb5a605ed2ea5cbad5b32111c18 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 18 Jun 2019 17:49:59 +0200 Subject: [PATCH 056/180] Respect minimum direction change delay --- Firmware/stepper.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index d6faee967..b9d151266 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -785,6 +785,7 @@ FORCE_INLINE void isr() { #ifdef LIN_ADVANCE + WRITE_NC(E0_DIR_PIN, e_steps < 0? INVERT_E0_DIR: !INVERT_E0_DIR); uint8_t la_state = 0; #endif @@ -897,6 +898,7 @@ FORCE_INLINE void advance_isr() { if (step_events_completed.wide > LA_decelerate_after && current_adv_steps > final_adv_steps) { // decompression e_steps -= e_step_loops; + WRITE_NC(E0_DIR_PIN, e_steps < 0? INVERT_E0_DIR: !INVERT_E0_DIR); if(current_adv_steps > e_step_loops) current_adv_steps -= e_step_loops; else @@ -906,6 +908,7 @@ FORCE_INLINE void advance_isr() { else if (step_events_completed.wide < LA_decelerate_after && current_adv_steps < max_adv_steps) { // compression e_steps += e_step_loops; + WRITE_NC(E0_DIR_PIN, e_steps < 0? INVERT_E0_DIR: !INVERT_E0_DIR); current_adv_steps += e_step_loops; nextAdvanceISR = eISR_Rate; } @@ -961,7 +964,6 @@ FORCE_INLINE void advance_isr_scheduler() { uint8_t max_ticks = (eisr? e_step_loops: step_loops); max_ticks = min(abs(e_steps), max_ticks); bool rev = (e_steps < 0); - WRITE_NC(E0_DIR_PIN, rev? INVERT_E0_DIR: !INVERT_E0_DIR); do { WRITE_NC(E0_STEP_PIN, !INVERT_E_STEP_PIN); From 2e073527fb872021555d1248f05a8ae79f15d780 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 19 Jun 2019 14:18:23 +0200 Subject: [PATCH 057/180] Also avoid E direction inversions while coasting --- Firmware/stepper.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index b9d151266..1283675c4 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -785,7 +785,7 @@ FORCE_INLINE void isr() { #ifdef LIN_ADVANCE - WRITE_NC(E0_DIR_PIN, e_steps < 0? INVERT_E0_DIR: !INVERT_E0_DIR); + if (e_steps) WRITE_NC(E0_DIR_PIN, e_steps < 0? INVERT_E0_DIR: !INVERT_E0_DIR); uint8_t la_state = 0; #endif @@ -898,7 +898,7 @@ FORCE_INLINE void advance_isr() { if (step_events_completed.wide > LA_decelerate_after && current_adv_steps > final_adv_steps) { // decompression e_steps -= e_step_loops; - WRITE_NC(E0_DIR_PIN, e_steps < 0? INVERT_E0_DIR: !INVERT_E0_DIR); + if (e_steps) WRITE_NC(E0_DIR_PIN, e_steps < 0? INVERT_E0_DIR: !INVERT_E0_DIR); if(current_adv_steps > e_step_loops) current_adv_steps -= e_step_loops; else @@ -908,7 +908,7 @@ FORCE_INLINE void advance_isr() { else if (step_events_completed.wide < LA_decelerate_after && current_adv_steps < max_adv_steps) { // compression e_steps += e_step_loops; - WRITE_NC(E0_DIR_PIN, e_steps < 0? INVERT_E0_DIR: !INVERT_E0_DIR); + if (e_steps) WRITE_NC(E0_DIR_PIN, e_steps < 0? INVERT_E0_DIR: !INVERT_E0_DIR); current_adv_steps += e_step_loops; nextAdvanceISR = eISR_Rate; } From b6bcb901f35a2558c349e468b28c9e3b04c8e022 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Thu, 27 Jun 2019 12:50:53 +0200 Subject: [PATCH 058/180] Correct initialization of eISR_Err Further tweak the initial term to improve the linearity of the resulting speed after BW filtering. --- Firmware/stepper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 1283675c4..b30f77e67 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -846,7 +846,7 @@ FORCE_INLINE void isr() { #ifdef LIN_ADVANCE // avoid multiple instances or function calls to advance_spread - if (la_state & ADV_INIT) eISR_Rate = current_block->advance_rate / 2; + if (la_state & ADV_INIT) eISR_Err = current_block->advance_rate / 4; if (la_state & ADV_INIT || nextAdvanceISR != ADV_NEVER) { advance_spread(main_Rate); if (la_state & ADV_DECELERATE) { From 9ff1f6c3ee827d5af07af19109e7f44662c32aed Mon Sep 17 00:00:00 2001 From: leptun Date: Tue, 30 Jul 2019 16:05:40 +0300 Subject: [PATCH 059/180] Re-enable Tone --- Firmware/system_timer.h | 8 ++++---- Firmware/timer02.c | 10 ---------- Firmware/timer02.h | 7 ------- 3 files changed, 4 insertions(+), 21 deletions(-) diff --git a/Firmware/system_timer.h b/Firmware/system_timer.h index ca8f2f9ab..626e82348 100644 --- a/Firmware/system_timer.h +++ b/Firmware/system_timer.h @@ -11,8 +11,8 @@ #define _millis millis2 #define _micros micros2 #define _delay delay2 -#define _tone tone2 -#define _noTone noTone2 +#define _tone tone +#define _noTone noTone #define timer02_set_pwm0(pwm0) @@ -20,8 +20,8 @@ #define _millis millis #define _micros micros #define _delay delay -#define _tone(x, y) /*tone*/ -#define _noTone(x) /*noTone*/ +#define _tone tone +#define _noTone noTone #define timer02_set_pwm0(pwm0) #endif //SYSTEM_TIMER_2 diff --git a/Firmware/timer02.c b/Firmware/timer02.c index 6b6cbe2cf..1f8989406 100644 --- a/Firmware/timer02.c +++ b/Firmware/timer02.c @@ -136,14 +136,4 @@ void delay2(unsigned long ms) } } -void tone2(__attribute__((unused)) uint8_t _pin, __attribute__((unused)) unsigned int frequency/*, unsigned long duration*/) -{ - PIN_SET(BEEPER); -} - -void noTone2(__attribute__((unused)) uint8_t _pin) -{ - PIN_CLR(BEEPER); -} - #endif //SYSTEM_TIMER_2 diff --git a/Firmware/timer02.h b/Firmware/timer02.h index 48a4842fe..2eef98f6e 100644 --- a/Firmware/timer02.h +++ b/Firmware/timer02.h @@ -23,13 +23,6 @@ extern unsigned long micros2(void); ///! Reimplemented original delay() using timer2 extern void delay2(unsigned long ms); -///! Reimplemented original tone() using timer2 -///! Does not perform any PWM tone generation, it just sets the beeper pin to 1 -extern void tone2(uint8_t _pin, unsigned int frequency/*, unsigned long duration*/); - -///! Turn off beeping - set beeper pin to 0 -extern void noTone2(uint8_t _pin); - #if defined(__cplusplus) } #endif //defined(__cplusplus) From 1435e4a68d3be539fa55b6f4cbb0e054dd4816b7 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 16 Jul 2019 18:12:21 +0200 Subject: [PATCH 060/180] Use the computed direction in fsensor_st_block_begin --- Firmware/stepper.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index b30f77e67..15e809b47 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -335,10 +335,6 @@ FORCE_INLINE void stepper_next_block() } #endif -#ifdef FILAMENT_SENSOR - fsensor_counter = 0; - fsensor_st_block_begin(count_direction[E_AXIS] < 0); -#endif //FILAMENT_SENSOR // The busy flag is set by the plan_get_current_block() call. // current_block->busy = true; // Initializes the trapezoid generator from the current block. Called whenever a new @@ -421,6 +417,10 @@ FORCE_INLINE void stepper_next_block() #endif /* LIN_ADVANCE */ count_direction[E_AXIS] = 1; } +#ifdef FILAMENT_SENSOR + fsensor_counter = 0; + fsensor_st_block_begin(count_direction[E_AXIS] < 0); +#endif //FILAMENT_SENSOR } else { _NEXT_ISR(2000); // 1kHz. From 7cae064611c7dfae0b20df623d4095ac5b7c4f99 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 4 Aug 2019 18:39:28 +0200 Subject: [PATCH 061/180] Update EEPROM_LAST_ITEM --- Firmware/eeprom.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/eeprom.h b/Firmware/eeprom.h index 6b4b3318f..4cd616cbb 100644 --- a/Firmware/eeprom.h +++ b/Firmware/eeprom.h @@ -206,7 +206,7 @@ static Sheets * const EEPROM_Sheets_base = (Sheets*)(EEPROM_SHEETS_BASE); #define EEPROM_UVLO_LA_K (EEPROM_SHEETS_BASE-4) // float //This is supposed to point to last item to allow EEPROM overrun check. Please update when adding new items. -#define EEPROM_LAST_ITEM EEPROM_SHEETS_BASE +#define EEPROM_LAST_ITEM EEPROM_UVLO_LA_K // !!!!! // !!!!! this is end of EEPROM section ... all updates MUST BE inserted before this mark !!!!! // !!!!! From 608aa6ff3c1293cec62393c395adc188fb7a3b4c Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Tue, 10 Sep 2019 18:49:23 +0200 Subject: [PATCH 062/180] Increase number of MMU load tries, so the same number of retries are done without cutter as before enabling cutter. --- Firmware/mmu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/mmu.cpp b/Firmware/mmu.cpp index f44bad97b..8f2c0400b 100755 --- a/Firmware/mmu.cpp +++ b/Firmware/mmu.cpp @@ -1566,7 +1566,7 @@ void mmu_continue_loading(bool blocking) }; Ls state = Ls::Enter; - const uint_least8_t max_retry = 2; + const uint_least8_t max_retry = 3; uint_least8_t retry = 0; while (!success) From 570b5989f4972b399e39ee2d74330928292e4cce Mon Sep 17 00:00:00 2001 From: leptun Date: Sun, 6 Oct 2019 10:50:11 +0300 Subject: [PATCH 063/180] Disable bed PWM while probing bed. --- Firmware/heatbed_pwm.cpp | 6 ++++++ Firmware/mesh_bed_calibration.cpp | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/Firmware/heatbed_pwm.cpp b/Firmware/heatbed_pwm.cpp index a3e5444c3..6f5a93162 100755 --- a/Firmware/heatbed_pwm.cpp +++ b/Firmware/heatbed_pwm.cpp @@ -61,6 +61,8 @@ enum class States : uint8_t { ///! Inner states of the finite automaton static States state = States::ZERO_START; +bool bedPWMDisabled = 0; + ///! Fast PWM counter is used in the RISE and FALL states (62.5kHz) static uint8_t slowCounter = 0; ///! Slow PWM counter is used in the ZERO and ONE states (62.5kHz/8 or 64) @@ -93,6 +95,7 @@ ISR(TIMER0_OVF_vect) // timer compare interrupt service routine { switch(state){ case States::ZERO_START: + if (bedPWMDisabled) break; pwm = soft_pwm_bed << 1;// expecting soft_pwm_bed to be 7bit! if( pwm != 0 ){ state = States::ZERO; // do nothing, let it tick once again after the 30Hz period @@ -144,6 +147,9 @@ ISR(TIMER0_OVF_vect) // timer compare interrupt service routine // if slowInc==2, soft_pwm == 251 will be the first to do short drops to zero. 252 will keep full heating return; // want full duty for the next ONE cycle again - so keep on heating and just wait for the next timer ovf } + if (bedPWMDisabled){ + return; + } // otherwise moving towards FALL // @@TODO it looks like ONE_TO_FALL isn't necessary, there are no artefacts at all state = States::ONE;//_TO_FALL; diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index 6466edc45..36fbfda42 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -23,6 +23,7 @@ float world2machine_shift[2]; #define WEIGHT_FIRST_ROW_Y_HIGH (0.3f) #define WEIGHT_FIRST_ROW_Y_LOW (0.0f) +extern bool bedPWMDisabled; // Scaling of the real machine axes against the programmed dimensions in the firmware. @@ -946,6 +947,7 @@ inline bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, i ) { bool high_deviation_occured = false; + bedPWMDisabled = 1; #ifdef TMC2130 FORCE_HIGH_POWER_START; #endif @@ -1044,6 +1046,7 @@ inline bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, i #ifdef TMC2130 FORCE_HIGH_POWER_END; #endif + bedPWMDisabled = 0; return true; error: @@ -1053,6 +1056,7 @@ error: #ifdef TMC2130 FORCE_HIGH_POWER_END; #endif + bedPWMDisabled = 0; return false; } From 7650e2b60cf6404924af8ae026bd92d10a75486a Mon Sep 17 00:00:00 2001 From: leptun Date: Sun, 6 Oct 2019 12:43:03 +0300 Subject: [PATCH 064/180] Handle disable_heater() --- Firmware/mesh_bed_calibration.cpp | 2 +- Firmware/temperature.cpp | 1 + Firmware/temperature.h | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index 36fbfda42..88cbc671a 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -6,6 +6,7 @@ #include "mesh_bed_leveling.h" #include "stepper.h" #include "ultralcd.h" +#include "temperature.h" #ifdef TMC2130 #include "tmc2130.h" @@ -23,7 +24,6 @@ float world2machine_shift[2]; #define WEIGHT_FIRST_ROW_Y_HIGH (0.3f) #define WEIGHT_FIRST_ROW_Y_LOW (0.0f) -extern bool bedPWMDisabled; // Scaling of the real machine axes against the programmed dimensions in the firmware. diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index df8a39e09..15f2d3a3a 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -1394,6 +1394,7 @@ void disable_heater() target_temperature_bed=0; soft_pwm_bed=0; timer02_set_pwm0(soft_pwm_bed << 1); + bedPWMDisabled = 0; #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 //WRITE(HEATER_BED_PIN,LOW); #endif diff --git a/Firmware/temperature.h b/Firmware/temperature.h index 7c40eae65..cbebb3f2c 100755 --- a/Firmware/temperature.h +++ b/Firmware/temperature.h @@ -79,6 +79,8 @@ extern int current_voltage_raw_bed; extern unsigned char soft_pwm_bed; #endif +extern bool bedPWMDisabled; + #ifdef PIDTEMP extern int pid_cycle, pid_number_of_cycles; extern float Kc,_Kp,_Ki,_Kd; From dde61bb444cebe490636baaa5a695475d46109a3 Mon Sep 17 00:00:00 2001 From: leptun Date: Sun, 6 Oct 2019 12:44:45 +0300 Subject: [PATCH 065/180] Automaton changes. Keep heater ON during probing only if pwm is high --- Firmware/heatbed_pwm.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Firmware/heatbed_pwm.cpp b/Firmware/heatbed_pwm.cpp index 6f5a93162..1e467c4e8 100755 --- a/Firmware/heatbed_pwm.cpp +++ b/Firmware/heatbed_pwm.cpp @@ -140,14 +140,16 @@ ISR(TIMER0_OVF_vect) // timer compare interrupt service routine case States::ONE: // state ONE - we'll either stay in ONE or change to FALL OCR0B = 255; slowCounter += slowInc; // this does software timer_clk/256 or less - if( slowCounter < pwm ){ - return; + if (!bedPWMDisabled){ //disable heating as soon as possible + if( slowCounter < pwm ){ + return; + } + if( (soft_pwm_bed << 1) >= (255 - slowInc - 1) ){ //@@TODO simplify & explain + // if slowInc==2, soft_pwm == 251 will be the first to do short drops to zero. 252 will keep full heating + return; // want full duty for the next ONE cycle again - so keep on heating and just wait for the next timer ovf + } } - if( (soft_pwm_bed << 1) >= (255 - slowInc - 1) ){ //@@TODO simplify & explain - // if slowInc==2, soft_pwm == 251 will be the first to do short drops to zero. 252 will keep full heating - return; // want full duty for the next ONE cycle again - so keep on heating and just wait for the next timer ovf - } - if (bedPWMDisabled){ + else if (pwm > 200){ //if duty cycle is high and BED PWM is disabled keep heater on. Prevents overcooling return; } // otherwise moving towards FALL From 8f05627747697632c1e55ea729556ed12584bd21 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Fri, 25 Oct 2019 13:04:04 +0200 Subject: [PATCH 066/180] Update #1 gcodes doxygen documentation added some RepRap G-codes Wiki external links. --- Firmware/Marlin_main.cpp | 42 ++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index a2cbece56..f4971efc6 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3322,8 +3322,7 @@ extern uint8_t st_backlash_y; //! @brief Parse and process commands //! -//! look here for descriptions of G-codes: http://linuxcnc.org/handbook/gcode/g-code.html -//! http://objects.reprap.org/wiki/Mendel_User_Manual:_RepRapGCodes +//! look here for descriptions of G-codes: https://reprap.org/wiki/G-code //! //! //! Implemented Codes @@ -3663,7 +3662,7 @@ void process_commands() } else if( code_seen("FANPINTST") ){ gcode_PRUSA_BadRAMBoFanTest(); - }else if (code_seen("FAN")) { //! PRUSA FAN + }else if (code_seen("FAN")) { // PRUSA FAN printf_P(_N("E0:%d RPM\nPRN0:%d RPM\n"), 60*fan_speed[0], 60*fan_speed[1]); }else if (code_seen("fn")) { // PRUSA fn if (farm_mode) { @@ -3838,7 +3837,7 @@ eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,0xFFFF); switch (gcode_in_progress) { - //! ### G0, G1 - Coordinated movement X Y Z E + //! ### G0, G1 - Coordinated movement X Y Z E G0 & G1: Move // -------------------------------------- case 0: // G0 -> G1 case 1: // G1 @@ -4038,7 +4037,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; - //! ### G2 - CW ARC + //! ### G2 - CW ARC G2 & G3: Controlled Arc Move // ------------------------------ case 2: if(Stopped == false) { @@ -4048,7 +4047,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; - //! ### G3 - CCW ARC + //! ### G3 - CCW ARC G2 & G3: Controlled Arc Move // ------------------------------- case 3: if(Stopped == false) { @@ -4058,7 +4057,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; - //! ### G4 - Dwell + //! ### G4 - Dwell G4: Dwell // ------------------------------- case 4: codenum = 0; @@ -4077,7 +4076,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) #ifdef FWRETRACT - //! ### G10 Retract + //! ### G10 - Retract G10: Retract // ------------------------------ case 10: #if EXTRUDERS > 1 @@ -4089,7 +4088,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; - //! ### G11 - Retract recover + //! ### G11 - Retract recover G11: Unretract // ----------------------------- case 11: #if EXTRUDERS > 1 @@ -4101,8 +4100,21 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) #endif //FWRETRACT - //! ### G28 - Home all Axis one at a time - // -------------------------------------------- + /*! + * + ### G28 - Home all Axis one at a time G28: Move to Origin (Home) + Unsing G28 without any paramters will perfom on the Prusa i3 printers home AND mesh bed leveling, while the default G-code G28 is just homeing the printer + + G28 [ X | Y | Z | W | C ] + + - `X` - Flag to go back to the X axis origin + - `Y` - Flag to go back to the Y axis origin + - `Z` - Flag to go back to the Z axis origin + - `W` - Suppress mesh bed leveling + - `C` - Calibrate X and Y origin (home) + * + */ + // ------------------------------ case 28: { long home_x_value = 0; @@ -4134,7 +4146,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) #ifdef ENABLE_AUTO_BED_LEVELING - //! ### G29 - Detailed Z-Probe + //! ### G29 - Detailed Z-Probe G29: Detailed Z-Probe // -------------------------------- case 29: { @@ -4280,7 +4292,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; #ifndef Z_PROBE_SLED - //! ### G30 - Single Z Probe + //! ### G30 - Single Z Probe G30: Single Z-Probe // ------------------------------------ case 30: { @@ -4305,14 +4317,14 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; #else - //! ### G31 - Dock the sled + //! ### G31 - Dock the sled G31: Dock Z Probe sled // --------------------------- case 31: dock_sled(true); break; - //! ### G32 - Undock the sled + //! ### G32 - Undock the sled G32: Undock Z Probe sled // ---------------------------- case 32: dock_sled(false); From 986ac95c456b340d88edc81e2500d843dd99c249 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Wed, 30 Oct 2019 11:19:51 +0100 Subject: [PATCH 067/180] G codes documented ... next M commands --- Firmware/Marlin_main.cpp | 482 ++++++++++++++++++++++----------------- 1 file changed, 274 insertions(+), 208 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index f4971efc6..6386fc460 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3458,7 +3458,11 @@ extern uint8_t st_backlash_y; /** \ingroup GCodes */ -//! _This is a list of currently implemented G Codes in Prusa firmware (dynamically generated from doxygen)_ +//! _This is a list of currently implemented G Codes in Prusa firmware (dynamically generated from doxygen)._ +/** +They are shown in order of appierence in the code. +There are reasons why some G Codes aren't in numerical order. +*/ void process_commands() @@ -3502,7 +3506,22 @@ void process_commands() float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD; int8_t SilentMode; #endif + /** + *--------------------------------------------------------------------------------- + *### M117 - Display Message M117: Display Message + *This causes the given message to be shown in the status line on an attached LCD. + * + *It is also used by internal to display status messages on LCD. + * Here the internal status messages: + * Only on MK3/s (TMC2130) + * - CRASH DETECTED + * - CRASH RECOVER + * - CRASH_CANCEL + * - TMC_SET_WAVE + * - TMC_SET_STEP + * - TMC_SET_CHOP + */ if (code_seen("M117")) { //moved to highest priority place to be able to to print strings which includes "G", "PRUSA" and "^" starpos = (strchr(strchr_pointer + 5, '*')); if (starpos != NULL) @@ -3514,7 +3533,7 @@ void process_commands() else if (strncmp_P(CMDBUFFER_CURRENT_STRING, PSTR("CRASH_"), 6) == 0) { - //! ### CRASH_DETECTED - TMC2130 + // ### CRASH_DETECTED - TMC2130 // --------------------------------- if(code_seen("CRASH_DETECTED")) { @@ -3524,12 +3543,12 @@ void process_commands() crashdet_detected(mask); } - //! ### CRASH_RECOVER - TMC2130 + // ### CRASH_RECOVER - TMC2130 // ---------------------------------- else if(code_seen("CRASH_RECOVER")) crashdet_recover(); - //! ### CRASH_CANCEL - TMC2130 + // ### CRASH_CANCEL - TMC2130 // ---------------------------------- else if(code_seen("CRASH_CANCEL")) crashdet_cancel(); @@ -3537,7 +3556,7 @@ void process_commands() else if (strncmp_P(CMDBUFFER_CURRENT_STRING, PSTR("TMC_"), 4) == 0) { - //! ### TMC_SET_WAVE_ + // ### TMC_SET_WAVE_ // -------------------- if (strncmp_P(CMDBUFFER_CURRENT_STRING + 4, PSTR("SET_WAVE_"), 9) == 0) { @@ -3550,7 +3569,7 @@ void process_commands() } } - //! ### TMC_SET_STEP_ + // ### TMC_SET_STEP_ // ------------------ else if (strncmp_P(CMDBUFFER_CURRENT_STRING + 4, PSTR("SET_STEP_"), 9) == 0) { @@ -3564,7 +3583,7 @@ void process_commands() } } - //! ### TMC_SET_CHOP_ + // ### TMC_SET_CHOP_ // ------------------- else if (strncmp_P(CMDBUFFER_CURRENT_STRING + 4, PSTR("SET_CHOP_"), 9) == 0) { @@ -3618,36 +3637,35 @@ void process_commands() #endif //BACKLASH_Y #endif //TMC2130 else if(code_seen("PRUSA")){ - /*! - * - ### PRUSA - Internal command set - - Set of internal PRUSA commands - - PRUSA [ Ping | PRN | FAN | fn | thx | uvlo | fsensor_recover | MMURES | RESET | fv | M28 | SN | Fir | Rev | Lang | Lz | Beat | FR ] - - - `Ping` - - `PRN` - Prints revision of the printer - - `FAN` - Prints fan details - - `fn` - Prints farm no. - - `thx` - - `uvlo` - - `fsensor_recover` - Filament sensor recover - restore print and continue - - `MMURES` - Reset MMU - - `RESET` - (Careful!) - - `fv` - ? - - `M28` - - `SN` - - `Fir` - Prints firmware version - - `Rev`- Prints filament size, elelectronics, nozzle type - - `Lang` - Reset the language - - `Lz` - - `Beat` - Kick farm link timer - - `FR` - Full factory reset - - `nozzle set ` - set nozzle diameter (farm mode only), e.g. `PRUSA nozzle set 0.4` - - `nozzle D` - check the nozzle diameter (farm mode only), works like M862.1 P, e.g. `PRUSA nozzle D0.4` - - `nozzle` - prints nozzle diameter (farm mode only), works like M862.1 P, e.g. `PRUSA nozzle` + /** + *--------------------------------------------------------------------------------- + *### PRUSA - Internal command set G98: Activate farm mode - Notes * + *Set of internal PRUSA commands + * + * PRUSA [ Ping | PRN | FAN | fn | thx | uvlo | fsensor_recover | MMURES | RESET | fv | M28 | SN | Fir | Rev | Lang | Lz | Beat | FR ] + * + * - `Ping` + * - `PRN` - Prints revision of the printer + * - `FAN` - Prints fan details + * - `fn` - Prints farm no. + * - `thx` + * - `uvlo` + * - `fsensor_recover` - Filament sensor recover - restore print and continue + * - `MMURES` - Reset MMU + * - `RESET` - (Careful!) + * - `fv` - ? + * - `M28` + * - `SN` + * - `Fir` - Prints firmware version + * - `Rev`- Prints filament size, elelectronics, nozzle type + * - `Lang` - Reset the language + * - `Lz` + * - `Beat` - Kick farm link timer + * - `FR` - Full factory reset + * - `nozzle set ` - set nozzle diameter (farm mode only), e.g. `PRUSA nozzle set 0.4` + * - `nozzle D` - check the nozzle diameter (farm mode only), works like M862.1 P, e.g. `PRUSA nozzle D0.4` + * - `nozzle` - prints nozzle diameter (farm mode only), works like M862.1 P, e.g. `PRUSA nozzle` */ @@ -3837,8 +3855,11 @@ eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,0xFFFF); switch (gcode_in_progress) { - //! ### G0, G1 - Coordinated movement X Y Z E G0 & G1: Move - // -------------------------------------- + /** + *--------------------------------------------------------------------------------- + * # G Codes + *### G0, G1 - Coordinated movement X Y Z E G0 & G1: Move + */ -------------------------------------- case 0: // G0 -> G1 case 1: // G1 if(Stopped == false) { @@ -4037,8 +4058,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; - //! ### G2 - CW ARC G2 & G3: Controlled Arc Move - // ------------------------------ + /** + *### G2 - CW ARC G2 & G3: Controlled Arc Move + */ ------------------------------ case 2: if(Stopped == false) { get_arc_coordinates(); @@ -4047,8 +4069,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; - //! ### G3 - CCW ARC G2 & G3: Controlled Arc Move - // ------------------------------- + /** + *### G3 - CCW ARC G2 & G3: Controlled Arc Move + */ ------------------------------- case 3: if(Stopped == false) { get_arc_coordinates(); @@ -4057,8 +4080,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; - //! ### G4 - Dwell G4: Dwell - // ------------------------------- + /** + *### G4 - Dwell G4: Dwell + */ ------------------------------- case 4: codenum = 0; if(code_seen('P')) codenum = code_value(); // milliseconds to wait @@ -4076,8 +4100,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) #ifdef FWRETRACT - //! ### G10 - Retract G10: Retract - // ------------------------------ + /** + *### G10 - Retract G10: Retract + */ ------------------------------ case 10: #if EXTRUDERS > 1 retracted_swap[active_extruder]=(code_seen('S') && code_value_long() == 1); // checks for swap retract argument @@ -4088,8 +4113,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; - //! ### G11 - Retract recover G11: Unretract - // ----------------------------- + /** + *### G11 - Retract recover G11: Unretract + */ ----------------------------- case 11: #if EXTRUDERS > 1 retract(false,retracted_swap[active_extruder]); @@ -4100,19 +4126,17 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) #endif //FWRETRACT - /*! - * - ### G28 - Home all Axis one at a time G28: Move to Origin (Home) + /** + *### G28 - Home all Axis one at a time G28: Move to Origin (Home) Unsing G28 without any paramters will perfom on the Prusa i3 printers home AND mesh bed leveling, while the default G-code G28 is just homeing the printer - - G28 [ X | Y | Z | W | C ] - - - `X` - Flag to go back to the X axis origin - - `Y` - Flag to go back to the Y axis origin - - `Z` - Flag to go back to the Z axis origin - - `W` - Suppress mesh bed leveling - - `C` - Calibrate X and Y origin (home) - * + * + * G28 [ X | Y | Z | W | C ] + * + * - `X` - Flag to go back to the X axis origin + * - `Y` - Flag to go back to the Y axis origin + * - `Z` - Flag to go back to the Z axis origin + * - `W` - Suppress mesh bed leveling + * - `C` - Calibrate X and Y origin (home) - Only on MK3/s */ // ------------------------------ case 28: @@ -4146,8 +4170,10 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) #ifdef ENABLE_AUTO_BED_LEVELING - //! ### G29 - Detailed Z-Probe G29: Detailed Z-Probe - // -------------------------------- + /** + *### G29 - Detailed Z-Probe G29: Detailed Z-Probe + *See G81 + */ -------------------------------- case 29: { #if Z_MIN_PIN == -1 @@ -4292,8 +4318,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; #ifndef Z_PROBE_SLED - //! ### G30 - Single Z Probe G30: Single Z-Probe - // ------------------------------------ + /** + *### G30 - Single Z Probe G30: Single Z-Probe + */ ------------------------------------ case 30: { st_synchronize(); @@ -4317,15 +4344,17 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; #else - //! ### G31 - Dock the sled G31: Dock Z Probe sled - // --------------------------- + /** + *### G31 - Dock the sled G31: Dock Z Probe sled + */ --------------------------- case 31: dock_sled(true); break; - //! ### G32 - Undock the sled G32: Undock Z Probe sled - // ---------------------------- + /** + *### G32 - Undock the sled G32: Undock Z Probe sled + */ ---------------------------- case 32: dock_sled(false); break; @@ -4334,8 +4363,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) #ifdef MESH_BED_LEVELING - //! ### G30 - Single Z Probe - // ---------------------------- + /** + *### G30 - Single Z Probe G30: Single Z-Probe + */ ---------------------------- case 30: { st_synchronize(); @@ -4352,8 +4382,10 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; - //! ### G75 - Print temperature interpolation - // --------------------------------------------- + /** + *### G75 - Print temperature interpolation G75: Print temperature interpolation + *Show/print PINDA temperature interpolating. + */ --------------------------------------------- case 75: { for (int i = 40; i <= 110; i++) @@ -4361,9 +4393,16 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; - //! ### G76 - PINDA probe temperature calibration - // ------------------------------------------------ - case 76: + /** + *### G76 - PINDA probe temperature calibration G76: PINDA probe temperature calibration + *This G-code is used to calibrate the temperature drift of the PINDA (inductive Sensor). + * + *The PINDAv2 sensor has a built-in thermistor which has the advantage that the calibration can be done once for all materials. + * + *The Original i3 Prusa MK2/s uses PINDAv1 and this calibration improves the temperature drift, but not as good as the PINDAv2. + */ + ------------------------------------------------ + case 76: { #ifdef PINDA_THERMISTOR if (true) @@ -4620,7 +4659,23 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; - //! ### G80 - Mesh-based Z probe + /** + *### G80 - Mesh-based Z probe G80: Mesh-based Z probe + *Default 3x3 grid can be changed on MK2.5/s and MK3/s to 7x7 grid. + * + * G80 [ N | R | V | L | R | F | B ] + * + * - `N` - Number of mesh points on x axis. Default is 3. Valid values are 3 and 7. + * - `R` - Probe retries. Default 3 max. 10 + * - `V` - Verbosity level 1=low, 10=mid, 20=high. It can be only used if firmware has been compiled with SUPPORT_VERBOSITY active. + * + * Using the following parameters enables additional "manual" bed leveling correction. Valid values are -100 microns to 100 microns. + + * - `L` - Left Bed Level correct value in um. + * - `R` - Right Bed Level correct value in um. + * - `F` - Front Bed Level correct value in um. + * - `B` - Back Bed Level correct value in um. + */ // ----------------------------------- /* @@ -5049,8 +5104,11 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; - //! ### G81 - Mesh bed leveling status - // ----------------------------------------- + /** + *### G81 - Mesh bed leveling status G81: Mesh bed leveling status + + *Prints mesh bed leveling status and bed profile if activated. + */ ----------------------------------------- /* * Prints mesh bed leveling status and bed profile if activated @@ -5077,12 +5135,11 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; #if 0 - /* - * G82: Single Z probe at current location - * - * WARNING! USE WITH CAUTION! If you'll try to probe where is no leveling pad, nasty things can happen! - * - */ + /** + *### G82: Single Z probe at current location - Not active G82: Single Z probe at current location + * + *WARNING! USE WITH CAUTION! If you'll try to probe where is no leveling pad, nasty things can happen! + **/ case 82: SERIAL_PROTOCOLLNPGM("Finding bed "); int l_feedmultiply = setup_for_endstop_move(); @@ -5093,9 +5150,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) SERIAL_PROTOCOLPGM("\n"); break; - /* - * G83: Prusa3D specific: Babystep in Z and store to EEPROM - */ + /** + *### G83: Babystep in Z and store to EEPROM - Not active G83: Babystep in Z and store to EEPROM + */ case 83: { int babystepz = code_seen('S') ? code_value() : 0; @@ -5118,35 +5175,35 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; - /* - * G84: Prusa3D specific: UNDO Babystep Z (move Z axis back) - */ + /** + *### G84: UNDO Babystep Z (move Z axis back) - Not active G84: UNDO Babystep Z (move Z axis back) + */ case 84: babystepsTodoZsubtract(babystepLoadZ); // babystepLoadZ = 0; break; - /* - * G85: Prusa3D specific: Pick best babystep - */ + /** + * ### G85: Pick best babystep - Not active G86: Disable babystep correction after home + * + * This G-code will be performed at the start of a calibration script. + * (Prusa3D specific) + */ case 86: calibration_status_store(CALIBRATION_STATUS_LIVE_ADJUST); break; /** - * ### G87 - Enable babystep correction after home + * ### G87 - Enable babystep correction after home G87: Enable babystep correction after home * * * This G-code will be performed at the end of a calibration script. @@ -5158,7 +5215,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /** - * ### G88 - Reserved + * ### G88 - Reserved G88: Reserved * * Currently has no effect. */ @@ -5171,20 +5228,22 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) #endif // ENABLE_MESH_BED_LEVELING - //! ### G90 - Switch off relative mode - // ------------------------------- + /** + *### G90 - Switch off relative mode G90: Set to Absolute Positioning + */ ------------------------------- case 90: relative_mode = false; break; - //! ### G91 - Switch on relative mode + //! ### G91 - Switch on relative mode G91: Set to Relative Positioning // ------------------------------- case 91: relative_mode = true; break; - //! ### G92 - Set position - // ----------------------------- + /** + *### G92 - Set position G92: Set Position + */ ----------------------------- case 92: if(!code_seen(axis_codes[E_AXIS])) st_synchronize(); @@ -5203,8 +5262,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; - //! ### G98 - Activate farm mode - // ----------------------------------- + /** + *### G98 - Activate farm mode G98: Activate farm mode + */ ----------------------------------- case 98: farm_mode = 1; PingTime = _millis(); @@ -5215,7 +5275,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) fCheckModeInit(); // alternatively invoke printer reset break; - //! ### G99 - Deactivate farm mode + //! ### G99 - Deactivate farm mode G99: Deactivate farm mode // ------------------------------------- case 99: farm_mode = 0; @@ -5232,7 +5292,11 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } // end if(code_seen('G')) - //! --------------------------------------------------------------------------------- + /** + *--------------------------------------------------------------------------------- + * # M Commands + * + */ else if(code_seen('M')) { @@ -5252,7 +5316,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) switch(mcode_in_progress) { - //! ### M0, M1 - Stop the printer + //! ### M0, M1 - Stop the printer G32: Undock Z Probe sled // --------------------------------------------------------------- case 0: // M0 - Unconditional stop - Wait for user button press on LCD case 1: // M1 - Conditional stop - Wait for user button press on LCD @@ -5302,7 +5366,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; - //! ### M17 - Enable axes + //! ### M17 - Enable axes G32: Undock Z Probe sled // --------------------------------- case 17: LCD_MESSAGERPGM(_i("No move."));////MSG_NO_MOVE @@ -5316,7 +5380,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) #ifdef SDSUPPORT - //! ### M20 - SD Card file list + //! ### M20 - SD Card file list G32: Undock Z Probe sled // ----------------------------------- case 20: SERIAL_PROTOCOLLNRPGM(_N("Begin file list"));////MSG_BEGIN_FILE_LIST @@ -5324,19 +5388,19 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) SERIAL_PROTOCOLLNRPGM(_N("End file list"));////MSG_END_FILE_LIST break; - //! ### M21 - Init SD card + //! ### M21 - Init SD card G32: Undock Z Probe sled // ------------------------------------ case 21: card.initsd(); break; - //! ### M22 - Release SD card + //! ### M22 - Release SD card G32: Undock Z Probe sled // ----------------------------------- case 22: card.release(); break; - //! ### M23 - Select file + //! ### M23 - Select file G32: Undock Z Probe sled // ----------------------------------- case 23: starpos = (strchr(strchr_pointer + 4,'*')); @@ -5345,7 +5409,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) card.openFile(strchr_pointer + 4,true); break; - //! ### M24 - Start SD print + //! ### M24 - Start SD print G32: Undock Z Probe sled // ---------------------------------- case 24: if (!card.paused) @@ -5354,13 +5418,13 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) starttime=_millis(); break; - //! ### M25 - Pause SD print + //! ### M25 - Pause SD print G32: Undock Z Probe sled // ---------------------------------- case 25: card.pauseSDPrint(); break; - //! ### M26 S\ - Set SD index + //! ### M26 S\ - Set SD index G32: Undock Z Probe sled //! Set position in SD card file to index in bytes. //! This command is expected to be called after M23 and before M24. //! Otherwise effect of this command is undefined. @@ -5375,13 +5439,13 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; - //! ### M27 - Get SD status + //! ### M27 - Get SD status G32: Undock Z Probe sled // ---------------------------------- case 27: card.getStatus(); break; - //! ### M28 - Start SD write + //! ### M28 - Start SD write G32: Undock Z Probe sled // --------------------------------- case 28: starpos = (strchr(strchr_pointer + 4,'*')); @@ -5393,7 +5457,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) card.openFile(strchr_pointer+4,false); break; - //! ### M29 - Stop SD write + //! ### M29 - Stop SD write G32: Undock Z Probe sled // ------------------------------------- //! Currently has no effect. case 29: @@ -5401,7 +5465,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) //card,saving = false; break; - //! ### M30 - Delete file + //! ### M30 - Delete file G32: Undock Z Probe sled // ---------------------------------- case 30: if (card.cardOK){ @@ -5416,7 +5480,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; - //! ### M32 - Select file and start SD print + //! ### M32 - Select file and start SD print G32: Undock Z Probe sled // ------------------------------------ case 32: { @@ -5454,7 +5518,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } } break; - //! ### M982 - Start SD write + //! ### M982 - Start SD write G32: Undock Z Probe sled // --------------------------------- case 928: starpos = (strchr(strchr_pointer + 5,'*')); @@ -5468,7 +5532,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) #endif //SDSUPPORT - //! ### M31 - Report current print time + //! ### M31 - Report current print time G32: Undock Z Probe sled // -------------------------------------------------- case 31: //M31 take time since the start of the SD print or an M109 command { @@ -5486,7 +5550,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; - //! ### M42 - Set pin state + //! ### M42 - Set pin state G32: Undock Z Probe sled // ----------------------------- case 42: if (code_seen('S')) @@ -5517,7 +5581,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; - //! ### M44 - Reset the bed skew and offset calibration (Prusa specific) + //! ### M44 - Reset the bed skew and offset calibration (Prusa specific) G32: Undock Z Probe sled // -------------------------------------------------------------------- case 44: // M44: Prusa3D: Reset the bed skew and offset calibration. @@ -5533,7 +5597,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) world2machine_revert_to_uncorrected(); break; - //! ### M45 - Bed skew and offset with manual Z up (Prusa specific) + //! ### M45 - Bed skew and offset with manual Z up (Prusa specific) G32: Undock Z Probe sled // ------------------------------------------------------ case 45: // M45: Prusa3D: bed skew and offset with manual Z up { @@ -5574,7 +5638,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } */ - //! ### M47 - Show end stops dialog on the display (Prusa specific) + //! ### M47 - Show end stops dialog on the display (Prusa specific) G32: Undock Z Probe sled // ---------------------------------------------------- case 47: @@ -5623,7 +5687,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) #ifdef ENABLE_AUTO_BED_LEVELING #ifdef Z_PROBE_REPEATABILITY_TEST - //! ### M48 - Z-Probe repeatability measurement function. + //! ### M48 - Z-Probe repeatability measurement function. G32: Undock Z Probe sled // ------------------------------------------------------ //! //! _Usage:_ @@ -5877,7 +5941,7 @@ Sigma_Exit: #endif // Z_PROBE_REPEATABILITY_TEST #endif // ENABLE_AUTO_BED_LEVELING - //! ### M73 - Set/get print progress + //! ### M73 - Set/get print progress G32: Undock Z Probe sled // ------------------------------------- //! _Usage:_ //! @@ -5896,7 +5960,7 @@ Sigma_Exit: } break; - //! ### M104 - Set hotend temperature + //! ### M104 - Set hotend temperature G32: Undock Z Probe sled // ----------------------------------------- case 104: // M104 { @@ -5911,19 +5975,19 @@ Sigma_Exit: break; } - //! ### M112 - Emergency stop + //! ### M112 - Emergency stop G32: Undock Z Probe sled // ----------------------------------------- case 112: kill(_n(""), 3); break; - //! ### M140 - Set bed temperature + //! ### M140 - Set bed temperature G32: Undock Z Probe sled // ----------------------------------------- case 140: if (code_seen('S')) setTargetBed(code_value()); break; - //! ### M105 - Report temperatures + //! ### M105 - Report temperatures G32: Undock Z Probe sled // ----------------------------------------- case 105: { @@ -6020,7 +6084,7 @@ Sigma_Exit: break; } - //! ### M109 - Wait for extruder temperature + //! ### M109 - Wait for extruder temperature G32: Undock Z Probe sled //! Parameters (not mandatory): //! * S \ set extruder temperature //! * R \ set extruder temperature @@ -6079,7 +6143,7 @@ Sigma_Exit: } break; - //! ### M190 - Wait for bed temperature + //! ### M190 - Wait for bed temperature G32: Undock Z Probe sled //! Parameters (not mandatory): //! * S \ set extruder temperature and wait for heating //! * R \ set extruder temperature and wait for heating or cooling @@ -6139,7 +6203,7 @@ Sigma_Exit: #if defined(FAN_PIN) && FAN_PIN > -1 - //! ### M106 - Set fan speed + //! ### M106 - Set fan speed G32: Undock Z Probe sled // ------------------------------------------- case 106: // M106 Sxxx Fan On S 0 .. 255 if (code_seen('S')){ @@ -6159,7 +6223,7 @@ Sigma_Exit: #if defined(PS_ON_PIN) && PS_ON_PIN > -1 - //! ### M80 - Turn on the Power Supply + //! ### M80 - Turn on the Power Supply G32: Undock Z Probe sled // ------------------------------- case 80: SET_OUTPUT(PS_ON_PIN); //GND @@ -6179,7 +6243,7 @@ Sigma_Exit: break; #endif - //! ### M81 - Turn off Power Supply + //! ### M81 - Turn off Power Supply G32: Undock Z Probe sled // -------------------------------------- case 81: disable_heater(); @@ -6202,19 +6266,19 @@ Sigma_Exit: lcd_update(0); break; - //! ### M82 - Set E axis to absolute mode + //! ### M82 - Set E axis to absolute mode G32: Undock Z Probe sled // --------------------------------------- case 82: axis_relative_modes[3] = false; break; - //! ### M83 - Set E axis to relative mode + //! ### M83 - Set E axis to relative mode G32: Undock Z Probe sled // --------------------------------------- case 83: axis_relative_modes[3] = true; break; - //! ### M84, M18 - Disable steppers + //! ### M84, M18 - Disable steppers G32: Undock Z Probe sled //--------------------------------------- //! This command can be used to set the stepper inactivity timeout (`S`) or to disable steppers (`X`,`Y`,`Z`,`E`) //! @@ -6256,7 +6320,7 @@ Sigma_Exit: snmm_filaments_used = 0; break; - //! ### M85 - Set max inactive time + //! ### M85 - Set max inactive time G32: Undock Z Probe sled // --------------------------------------- case 85: // M85 if(code_seen('S')) { @@ -6265,7 +6329,7 @@ Sigma_Exit: break; #ifdef SAFETYTIMER - //! ### M86 - Set safety timer expiration time + //! ### M86 - Set safety timer expiration time G32: Undock Z Probe sled //! //! _Usage:_ //! M86 S @@ -6280,7 +6344,7 @@ Sigma_Exit: break; #endif - //! ### M92 Set Axis steps-per-unit + //! ### M92 Set Axis steps-per-unit G32: Undock Z Probe sled // --------------------------------------- //! Same syntax as G92 case 92: @@ -6305,14 +6369,14 @@ Sigma_Exit: } break; - //! ### M110 - Set Line number + //! ### M110 - Set Line number G32: Undock Z Probe sled // --------------------------------------- case 110: if (code_seen('N')) gcode_LastN = code_value_long(); break; - //! ### M113 - Get or set host keep-alive interval + //! ### M113 - Get or set host keep-alive interval G32: Undock Z Probe sled // ------------------------------------------ case 113: if (code_seen('S')) { @@ -6326,7 +6390,7 @@ Sigma_Exit: } break; - //! ### M115 - Firmware info + //! ### M115 - Firmware info G32: Undock Z Probe sled // -------------------------------------- //! Print the firmware info and capabilities //! @@ -6357,7 +6421,7 @@ Sigma_Exit: } break; - //! ### M114 - Get current position + //! ### M114 - Get current position G32: Undock Z Probe sled // ------------------------------------- case 114: gcode_M114(); @@ -6365,7 +6429,7 @@ Sigma_Exit: - //! ### M117 - Set LCD Message + //! ### M117 - Set LCD Message G32: Undock Z Probe sled // -------------------------------------- /* @@ -6378,19 +6442,19 @@ Sigma_Exit: lcd_setstatus(strchr_pointer + 5); break;*/ - //! ### M120 - Disable endstops + //! ### M120 - Disable endstops G32: Undock Z Probe sled // ---------------------------------------- case 120: enable_endstops(false) ; break; - //! ### M121 - Enable endstops + //! ### M121 - Enable endstops G32: Undock Z Probe sled // ---------------------------------------- case 121: enable_endstops(true) ; break; - //! ### M119 - Get endstop states + //! ### M119 - Get endstop states G32: Undock Z Probe sled // ---------------------------------------- case 119: SERIAL_PROTOCOLRPGM(_N("Reporting endstop status"));////MSG_M119_REPORT @@ -6454,7 +6518,7 @@ Sigma_Exit: #ifdef BLINKM - //! ### M150 - Set RGB(W) Color + //! ### M150 - Set RGB(W) Color G32: Undock Z Probe sled // ------------------------------------------- case 150: { @@ -6471,7 +6535,7 @@ Sigma_Exit: break; #endif //BLINKM - //! ### M200 - Set filament diameter + //! ### M200 - Set filament diameter G32: Undock Z Probe sled // ---------------------------------------- case 200: // M200 D set filament diameter and set E axis units to cubic millimeters (use S0 to set back to millimeters). { @@ -6512,7 +6576,7 @@ Sigma_Exit: } break; - //! ### M201 - Set Print Max Acceleration + //! ### M201 - Set Print Max Acceleration G32: Undock Z Probe sled // ------------------------------------------- case 201: for (int8_t i = 0; i < NUM_AXIS; i++) @@ -6547,7 +6611,7 @@ Sigma_Exit: break; #endif - //! ### M203 - Set Max Feedrate + //! ### M203 - Set Max Feedrate G32: Undock Z Probe sled // --------------------------------------- case 203: // M203 max feedrate mm/sec for (int8_t i = 0; i < NUM_AXIS; i++) @@ -6573,7 +6637,7 @@ Sigma_Exit: } break; - //! ### M204 - Acceleration settings + //! ### M204 - Acceleration settings G32: Undock Z Probe sled // ------------------------------------------ //! Supporting old format: //! @@ -6607,7 +6671,7 @@ Sigma_Exit: } break; - //! ### M205 - Set advanced settings + //! ### M205 - Set advanced settings G32: Undock Z Probe sled // --------------------------------------------- //! Set some advanced settings related to movement. //! @@ -6632,7 +6696,7 @@ Sigma_Exit: } break; - //! ### M206 - Set additional homing offsets + //! ### M206 - Set additional homing offsets G32: Undock Z Probe sled // ---------------------------------------------- case 206: for(int8_t i=0; i < 3; i++) @@ -6642,7 +6706,7 @@ Sigma_Exit: break; #ifdef FWRETRACT - //! ### M207 - Set firmware retraction + //! ### M207 - Set firmware retraction G32: Undock Z Probe sled // -------------------------------------------------- case 207: //M207 - set retract length S[positive mm] F[feedrate mm/min] Z[additional zlift/hop] { @@ -6660,7 +6724,7 @@ Sigma_Exit: } }break; - //! ### M208 - Set retract recover length + //! ### M208 - Set retract recover length G32: Undock Z Probe sled // -------------------------------------------- case 208: // M208 - set retract recover length S[positive mm surplus to the M207 S*] F[feedrate mm/min] { @@ -6674,7 +6738,7 @@ Sigma_Exit: } }break; - //! ### M209 - Enable/disable automatict retract + //! ### M209 - Enable/disable automatict retract G32: Undock Z Probe sled // --------------------------------------------- case 209: // M209 - S<1=true/0=false> enable automatic retract detect if the slicer did not support G10/11: every normal extrude-only move will be classified as retract depending on the direction. { @@ -6746,7 +6810,7 @@ Sigma_Exit: }break; #endif - //! ### M220 Set feedrate percentage + //! ### M220 Set feedrate percentage G32: Undock Z Probe sled // ----------------------------------------------- case 220: // M220 S- set speed factor override percentage { @@ -6764,7 +6828,7 @@ Sigma_Exit: } break; - //! ### M221 - Set extrude factor override percentage + //! ### M221 - Set extrude factor override percentage G32: Undock Z Probe sled // ---------------------------------------------------- case 221: // M221 S- set extrude factor override percentage { @@ -6788,7 +6852,7 @@ Sigma_Exit: } break; - //! ### M226 - Wait for Pin state + //! ### M226 - Wait for Pin state G32: Undock Z Probe sled // ------------------------------------------ case 226: // M226 P S- Wait until the specified pin reaches the state required { @@ -6844,7 +6908,7 @@ Sigma_Exit: #if NUM_SERVOS > 0 - //! ### M280 - Set/Get servo position + //! ### M280 - Set/Get servo position G32: Undock Z Probe sled // -------------------------------------------- case 280: // M280 - set servo position absolute. P: servo index, S: angle or microseconds { @@ -6885,7 +6949,7 @@ Sigma_Exit: #if (LARGE_FLASH == true && ( BEEPER > 0 || defined(ULTRALCD) || defined(LCD_USE_I2C_BUZZER))) - //! ### M300 - Play tone + //! ### M300 - Play tone G32: Undock Z Probe sled // ----------------------- case 300: // M300 { @@ -6907,7 +6971,7 @@ Sigma_Exit: #ifdef PIDTEMP - //! ### M301 - Set hotend PID + //! ### M301 - Set hotend PID G32: Undock Z Probe sled // --------------------------------------- case 301: { @@ -6938,7 +7002,7 @@ Sigma_Exit: #endif //PIDTEMP #ifdef PIDTEMPBED - //! ### M304 - Set bed PID + //! ### M304 - Set bed PID G32: Undock Z Probe sled // -------------------------------------- case 304: { @@ -6959,7 +7023,7 @@ Sigma_Exit: break; #endif //PIDTEMP - //! ### M240 - Trigger camera + //! ### M240 - Trigger camera G32: Undock Z Probe sled // -------------------------------------------- case 240: // M240 Triggers a camera by emulating a Canon RC-1 : http://www.doc-diy.net/photo/rc-1_hacked/ { @@ -6994,7 +7058,7 @@ Sigma_Exit: break; #ifdef PREVENT_DANGEROUS_EXTRUDE - //! ### M302 - Allow cold extrude, or set minimum extrude temperature + //! ### M302 - Allow cold extrude, or set minimum extrude temperature G32: Undock Z Probe sled // ------------------------------------------------------------------- case 302: { @@ -7005,7 +7069,7 @@ Sigma_Exit: break; #endif - //! ### M303 - PID autotune + //! ### M303 - PID autotune G32: Undock Z Probe sled // ------------------------------------- case 303: { @@ -7021,7 +7085,7 @@ Sigma_Exit: } break; - //! ### M400 - Wait for all moves to finish + //! ### M400 - Wait for all moves to finish G32: Undock Z Probe sled // ----------------------------------------- case 400: { @@ -7029,7 +7093,7 @@ Sigma_Exit: } break; - //! ### M403 - Set filament type (material) for particular extruder and notify the MMU + //! ### M403 - Set filament type (material) for particular extruder and notify the MMU G32: Undock Z Probe sled // ---------------------------------------------- case 403: { @@ -7047,7 +7111,7 @@ Sigma_Exit: } break; - //! ### M500 - Store settings in EEPROM + //! ### M500 - Store settings in EEPROM G32: Undock Z Probe sled // ----------------------------------------- case 500: { @@ -7055,7 +7119,7 @@ Sigma_Exit: } break; - //! ### M501 - Read settings from EEPROM + //! ### M501 - Read settings from EEPROM G32: Undock Z Probe sled // ---------------------------------------- case 501: { @@ -7063,7 +7127,7 @@ Sigma_Exit: } break; - //! ### M502 - Revert all settings to factory default + //! ### M502 - Revert all settings to factory default G32: Undock Z Probe sled // ------------------------------------------------- case 502: { @@ -7071,7 +7135,7 @@ Sigma_Exit: } break; - //! ### M503 - Repport all settings currently in memory + //! ### M503 - Repport all settings currently in memory G32: Undock Z Probe sled // ------------------------------------------------- case 503: { @@ -7079,7 +7143,7 @@ Sigma_Exit: } break; - //! ### M509 - Force language selection + //! ### M509 - Force language selection G32: Undock Z Probe sled // ------------------------------------------------ case 509: { @@ -7090,7 +7154,7 @@ Sigma_Exit: break; #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED - //! ### M540 - Abort print on endstop hit (enable/disable) + //! ### M540 - Abort print on endstop hit (enable/disable) G32: Undock Z Probe sled // ----------------------------------------------------- case 540: { @@ -7137,7 +7201,7 @@ Sigma_Exit: #ifdef FILAMENTCHANGEENABLE - //! ### M600 - Initiate Filament change procedure + //! ### M600 - Initiate Filament change procedure G32: Undock Z Probe sled // -------------------------------------- case 600: //Pause for filament change X[pos] Y[pos] Z[relative lift] E[initial retract] L[later retract distance for removal] { @@ -7214,7 +7278,7 @@ Sigma_Exit: break; #endif //FILAMENTCHANGEENABLE - //! ### M601 - Pause print + //! ### M601 - Pause print G32: Undock Z Probe sled // ------------------------------- case 601: { @@ -7223,21 +7287,21 @@ Sigma_Exit: } break; - //! ### M602 - Resume print + //! ### M602 - Resume print G32: Undock Z Probe sled // ------------------------------- case 602: { lcd_resume_print(); } break; - //! ### M603 - Stop print + //! ### M603 - Stop print G32: Undock Z Probe sled // ------------------------------- case 603: { lcd_print_stop(); } #ifdef PINDA_THERMISTOR - //! ### M860 - Wait for extruder temperature (PINDA) + //! ### M860 - Wait for extruder temperature (PINDA) G32: Undock Z Probe sled // -------------------------------------------------------------- /*! Wait for PINDA thermistor to reach target temperature @@ -7289,7 +7353,7 @@ Sigma_Exit: break; } - //! ### M861 - Set/Get PINDA temperature compensation offsets + //! ### M861 - Set/Get PINDA temperature compensation offsets G32: Undock Z Probe sled // ----------------------------------------------------------- /*! @@ -7372,7 +7436,7 @@ Sigma_Exit: #endif //PINDA_THERMISTOR - //! ### M862 - Print checking + //! ### M862 - Print checking G32: Undock Z Probe sled // ---------------------------------------------- /*! Checks the parameters of the printer and gcode and performs compatibility check @@ -7465,14 +7529,14 @@ Sigma_Exit: break; #ifdef LIN_ADVANCE - //! ### M900 - Set Linear advance options + //! ### M900 - Set Linear advance options G32: Undock Z Probe sled // ---------------------------------------------- case 900: gcode_M900(); break; #endif - //! ### M907 - Set digital trimpot motor current in mA using axis codes + //! ### M907 - Set digital trimpot motor current in mA using axis codes G32: Undock Z Probe sled // --------------------------------------------------------------- case 907: { @@ -7507,7 +7571,7 @@ Sigma_Exit: } break; - //! ### M908 - Control digital trimpot directly + //! ### M908 - Control digital trimpot directly G32: Undock Z Probe sled // --------------------------------------------------------- case 908: { @@ -7522,7 +7586,7 @@ Sigma_Exit: #ifdef TMC2130_SERVICE_CODES_M910_M918 - //! ### M910 - TMC2130 init + //! ### M910 - TMC2130 init G32: Undock Z Probe sled // ----------------------------------------------- case 910: { @@ -7530,7 +7594,7 @@ Sigma_Exit: } break; - //! ### M911 - Set TMC2130 holding currents + //! ### M911 - Set TMC2130 holding currents G32: Undock Z Probe sled // ------------------------------------------------- case 911: { @@ -7541,7 +7605,7 @@ Sigma_Exit: } break; - //! ### M912 - Set TMC2130 running currents + //! ### M912 - Set TMC2130 running currents G32: Undock Z Probe sled // ----------------------------------------------- case 912: { @@ -7552,7 +7616,7 @@ Sigma_Exit: } break; - //! ### M913 - Print TMC2130 currents + //! ### M913 - Print TMC2130 currents G32: Undock Z Probe sled // ----------------------------- case 913: { @@ -7560,7 +7624,7 @@ Sigma_Exit: } break; - //! ### M914 - Set TMC2130 normal mode + //! ### M914 - Set TMC2130 normal mode G32: Undock Z Probe sled // ------------------------------ case 914: { @@ -7570,7 +7634,7 @@ Sigma_Exit: } break; - //! ### M95 - Set TMC2130 silent mode + //! ### M915 - Set TMC2130 silent mode G32: Undock Z Probe sled // ------------------------------ case 915: { @@ -7580,7 +7644,7 @@ Sigma_Exit: } break; - //! ### M916 - Set TMC2130 Stallguard sensitivity threshold + //! ### M916 - Set TMC2130 Stallguard sensitivity threshold G32: Undock Z Probe sled // ------------------------------------------------------- case 916: { @@ -7593,7 +7657,7 @@ Sigma_Exit: } break; - //! ### M917 - Set TMC2130 PWM amplitude offset (pwm_ampl) + //! ### M917 - Set TMC2130 PWM amplitude offset (pwm_ampl) G32: Undock Z Probe sled // -------------------------------------------------------------- case 917: { @@ -7604,7 +7668,7 @@ Sigma_Exit: } break; - //! ### M918 - Set TMC2130 PWM amplitude gradient (pwm_grad) + //! ### M918 - Set TMC2130 PWM amplitude gradient (pwm_grad) G32: Undock Z Probe sled // ------------------------------------------------------------- case 918: { @@ -7617,7 +7681,7 @@ Sigma_Exit: #endif //TMC2130_SERVICE_CODES_M910_M918 - //! ### M350 - Set microstepping mode + //! ### M350 - Set microstepping mode G32: Undock Z Probe sled // --------------------------------------------------- //! Warning: Steps per unit remains unchanged. S code sets stepping mode for all drivers. case 350: @@ -7658,7 +7722,7 @@ Sigma_Exit: } break; - //! ### M351 - Toggle Microstep Pins + //! ### M351 - Toggle Microstep Pins G32: Undock Z Probe sled // ----------------------------------- //! Toggle MS1 MS2 pins directly, S# determines MS1 or MS2, X# sets the pin high/low. //! @@ -7682,7 +7746,7 @@ Sigma_Exit: } break; - //! ### M701 - Load filament + //! ### M701 - Load filament G32: Undock Z Probe sled // ------------------------- case 701: { @@ -7692,7 +7756,7 @@ Sigma_Exit: } break; - //! ### M702 - Unload filament + //! ### M702 - Unload filament G32: Undock Z Probe sled // ------------------------ /*! @@ -7724,7 +7788,7 @@ Sigma_Exit: } break; - //! ### M999 - Restart after being stopped + //! ### M999 - Restart after being stopped G32: Undock Z Probe sled // ------------------------------------ case 999: Stopped = false; @@ -7937,8 +8001,10 @@ Sigma_Exit: } } // end if(code_seen('T')) (end of T codes) - //! ---------------------------------------------------------------------------------------------- - + /** + *--------------------------------------------------------------------------------- + *# D codes + */ else if (code_seen('D')) // D codes (debug) { switch((int)code_value()) From d472f0730c0d772c8ded162a27404542b8f9619b Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Wed, 30 Oct 2019 15:50:23 +0100 Subject: [PATCH 068/180] Change doxygen format --- Firmware/Marlin_main.cpp | 145 ++++++++++++++++++++------------------- 1 file changed, 73 insertions(+), 72 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 6386fc460..3fe14e8be 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3506,21 +3506,22 @@ void process_commands() float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD; int8_t SilentMode; #endif - /** - *--------------------------------------------------------------------------------- - *### M117 - Display Message M117: Display Message + /*! - *This causes the given message to be shown in the status line on an attached LCD. - * - *It is also used by internal to display status messages on LCD. - * Here the internal status messages: - * Only on MK3/s (TMC2130) - * - CRASH DETECTED - * - CRASH RECOVER - * - CRASH_CANCEL - * - TMC_SET_WAVE - * - TMC_SET_STEP - * - TMC_SET_CHOP + --------------------------------------------------------------------------------- + ### M117 - Display Message M117: Display Message + + This causes the given message to be shown in the status line on an attached LCD. + + It is also used by internal to display status messages on LCD. + Here the internal status messages: + Only on MK3/s (TMC2130) + - CRASH DETECTED + - CRASH RECOVER + - CRASH_CANCEL + - TMC_SET_WAVE + - TMC_SET_STEP + - TMC_SET_CHOP */ if (code_seen("M117")) { //moved to highest priority place to be able to to print strings which includes "G", "PRUSA" and "^" starpos = (strchr(strchr_pointer + 5, '*')); @@ -3637,35 +3638,35 @@ void process_commands() #endif //BACKLASH_Y #endif //TMC2130 else if(code_seen("PRUSA")){ - /** - *--------------------------------------------------------------------------------- - *### PRUSA - Internal command set G98: Activate farm mode - Notes - * - *Set of internal PRUSA commands - * - * PRUSA [ Ping | PRN | FAN | fn | thx | uvlo | fsensor_recover | MMURES | RESET | fv | M28 | SN | Fir | Rev | Lang | Lz | Beat | FR ] - * - * - `Ping` - * - `PRN` - Prints revision of the printer - * - `FAN` - Prints fan details - * - `fn` - Prints farm no. - * - `thx` - * - `uvlo` - * - `fsensor_recover` - Filament sensor recover - restore print and continue - * - `MMURES` - Reset MMU - * - `RESET` - (Careful!) - * - `fv` - ? - * - `M28` - * - `SN` - * - `Fir` - Prints firmware version - * - `Rev`- Prints filament size, elelectronics, nozzle type - * - `Lang` - Reset the language - * - `Lz` - * - `Beat` - Kick farm link timer - * - `FR` - Full factory reset - * - `nozzle set ` - set nozzle diameter (farm mode only), e.g. `PRUSA nozzle set 0.4` - * - `nozzle D` - check the nozzle diameter (farm mode only), works like M862.1 P, e.g. `PRUSA nozzle D0.4` - * - `nozzle` - prints nozzle diameter (farm mode only), works like M862.1 P, e.g. `PRUSA nozzle` + /*! + --------------------------------------------------------------------------------- + ### PRUSA - Internal command set G98: Activate farm mode - Notes + + Set of internal PRUSA commands + + PRUSA [ Ping | PRN | FAN | fn | thx | uvlo | fsensor_recover | MMURES | RESET | fv | M28 | SN | Fir | Rev | Lang | Lz | Beat | FR ] + + - `Ping` + - `PRN` - Prints revision of the printer + - `FAN` - Prints fan details + - `fn` - Prints farm no. + - `thx` + - `uvlo` + - `fsensor_recover` - Filament sensor recover - restore print and continue + - `MMURES` - Reset MMU + - `RESET` - (Careful!) + - `fv` - ? + - `M28` + - `SN` + - `Fir` - Prints firmware version + - `Rev`- Prints filament size, elelectronics, nozzle type + - `Lang` - Reset the language + - `Lz` + - `Beat` - Kick farm link timer + - `FR` - Full factory reset + - `nozzle set ` - set nozzle diameter (farm mode only), e.g. `PRUSA nozzle set 0.4` + - `nozzle D` - check the nozzle diameter (farm mode only), works like M862.1 P, e.g. `PRUSA nozzle D0.4` + - `nozzle` - prints nozzle diameter (farm mode only), works like M862.1 P, e.g. `PRUSA nozzle` */ @@ -3855,10 +3856,10 @@ eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,0xFFFF); switch (gcode_in_progress) { - /** - *--------------------------------------------------------------------------------- - * # G Codes - *### G0, G1 - Coordinated movement X Y Z E G0 & G1: Move + /*! + --------------------------------------------------------------------------------- + # G Codes + ### G0, G1 - Coordinated movement X Y Z E G0 & G1: Move */ -------------------------------------- case 0: // G0 -> G1 case 1: // G1 @@ -4058,8 +4059,8 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; - /** - *### G2 - CW ARC G2 & G3: Controlled Arc Move + /*! + ### G2 - CW ARC G2 & G3: Controlled Arc Move */ ------------------------------ case 2: if(Stopped == false) { @@ -4069,8 +4070,8 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; - /** - *### G3 - CCW ARC G2 & G3: Controlled Arc Move + /*! + ### G3 - CCW ARC G2 & G3: Controlled Arc Move */ ------------------------------- case 3: if(Stopped == false) { @@ -4080,8 +4081,8 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; - /** - *### G4 - Dwell G4: Dwell + /*! + ### G4 - Dwell G4: Dwell */ ------------------------------- case 4: codenum = 0; @@ -4100,8 +4101,8 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) #ifdef FWRETRACT - /** - *### G10 - Retract G10: Retract + /*! + ### G10 - Retract G10: Retract */ ------------------------------ case 10: #if EXTRUDERS > 1 @@ -4113,8 +4114,8 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; - /** - *### G11 - Retract recover G11: Unretract + /*! + ### G11 - Retract recover G11: Unretract */ ----------------------------- case 11: #if EXTRUDERS > 1 @@ -4126,17 +4127,17 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) #endif //FWRETRACT - /** - *### G28 - Home all Axis one at a time G28: Move to Origin (Home) + /*! + ### G28 - Home all Axis one at a time G28: Move to Origin (Home) Unsing G28 without any paramters will perfom on the Prusa i3 printers home AND mesh bed leveling, while the default G-code G28 is just homeing the printer - * - * G28 [ X | Y | Z | W | C ] - * - * - `X` - Flag to go back to the X axis origin - * - `Y` - Flag to go back to the Y axis origin - * - `Z` - Flag to go back to the Z axis origin - * - `W` - Suppress mesh bed leveling - * - `C` - Calibrate X and Y origin (home) - Only on MK3/s + + G28 [ X | Y | Z | W | C ] + + - `X` - Flag to go back to the X axis origin + - `Y` - Flag to go back to the Y axis origin + - `Z` - Flag to go back to the Z axis origin + - `W` - Suppress mesh bed leveling + - `C` - Calibrate X and Y origin (home) - Only on MK3/s */ // ------------------------------ case 28: @@ -4170,9 +4171,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) #ifdef ENABLE_AUTO_BED_LEVELING - /** - *### G29 - Detailed Z-Probe G29: Detailed Z-Probe - *See G81 + /*! + ### G29 - Detailed Z-Probe G29: Detailed Z-Probe + See `G81` */ -------------------------------- case 29: { @@ -5150,7 +5151,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) SERIAL_PROTOCOLPGM("\n"); break; - /** + /* *### G83: Babystep in Z and store to EEPROM - Not active G83: Babystep in Z and store to EEPROM */ case 83: @@ -6676,7 +6677,7 @@ Sigma_Exit: //! Set some advanced settings related to movement. //! //! M205 [S] [T] [B] [X] [Y] [Z] [E] - /*! + /** - `S` - Minimum feedrate for print moves (unit/s) - `T` - Minimum feedrate for travel moves (units/s) - `B` - Minimum segment time (us) From b9dca5f89531f790842fe8f27fe91ef7901cc85c Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Wed, 30 Oct 2019 15:52:27 +0100 Subject: [PATCH 069/180] other doxygen format changes --- Firmware/Marlin_main.cpp | 167 ++++++++++++++++++++------------------- 1 file changed, 84 insertions(+), 83 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 3fe14e8be..8723d8b06 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -4173,7 +4173,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G29 - Detailed Z-Probe G29: Detailed Z-Probe - See `G81` + See G81 */ -------------------------------- case 29: { @@ -4319,8 +4319,8 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; #ifndef Z_PROBE_SLED - /** - *### G30 - Single Z Probe G30: Single Z-Probe + /*! + ### G30 - Single Z Probe G30: Single Z-Probe */ ------------------------------------ case 30: { @@ -4345,16 +4345,16 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; #else - /** - *### G31 - Dock the sled G31: Dock Z Probe sled + /*! + ### G31 - Dock the sled G31: Dock Z Probe sled */ --------------------------- case 31: dock_sled(true); break; - /** - *### G32 - Undock the sled G32: Undock Z Probe sled + /*! + ### G32 - Undock the sled G32: Undock Z Probe sled */ ---------------------------- case 32: dock_sled(false); @@ -4364,8 +4364,8 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) #ifdef MESH_BED_LEVELING - /** - *### G30 - Single Z Probe G30: Single Z-Probe + /*! + ### G30 - Single Z Probe G30: Single Z-Probe */ ---------------------------- case 30: { @@ -4383,9 +4383,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; - /** - *### G75 - Print temperature interpolation G75: Print temperature interpolation - *Show/print PINDA temperature interpolating. + /*! + ### G75 - Print temperature interpolation G75: Print temperature interpolation + Show/print PINDA temperature interpolating. */ --------------------------------------------- case 75: { @@ -4394,13 +4394,13 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; - /** - *### G76 - PINDA probe temperature calibration G76: PINDA probe temperature calibration - *This G-code is used to calibrate the temperature drift of the PINDA (inductive Sensor). - * - *The PINDAv2 sensor has a built-in thermistor which has the advantage that the calibration can be done once for all materials. - * - *The Original i3 Prusa MK2/s uses PINDAv1 and this calibration improves the temperature drift, but not as good as the PINDAv2. + /*! + ### G76 - PINDA probe temperature calibration G76: PINDA probe temperature calibration + This G-code is used to calibrate the temperature drift of the PINDA (inductive Sensor). + + The PINDAv2 sensor has a built-in thermistor which has the advantage that the calibration can be done once for all materials. + + The Original i3 Prusa MK2/s uses PINDAv1 and this calibration improves the temperature drift, but not as good as the PINDAv2. */ ------------------------------------------------ case 76: @@ -4660,22 +4660,22 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; - /** - *### G80 - Mesh-based Z probe G80: Mesh-based Z probe - *Default 3x3 grid can be changed on MK2.5/s and MK3/s to 7x7 grid. - * - * G80 [ N | R | V | L | R | F | B ] - * - * - `N` - Number of mesh points on x axis. Default is 3. Valid values are 3 and 7. - * - `R` - Probe retries. Default 3 max. 10 - * - `V` - Verbosity level 1=low, 10=mid, 20=high. It can be only used if firmware has been compiled with SUPPORT_VERBOSITY active. - * - * Using the following parameters enables additional "manual" bed leveling correction. Valid values are -100 microns to 100 microns. - - * - `L` - Left Bed Level correct value in um. - * - `R` - Right Bed Level correct value in um. - * - `F` - Front Bed Level correct value in um. - * - `B` - Back Bed Level correct value in um. + /*! + ### G80 - Mesh-based Z probe G80: Mesh-based Z probe + Default 3x3 grid can be changed on MK2.5/s and MK3/s to 7x7 grid. + + G80 [ N | R | V | L | R | F | B ] + + - `N` - Number of mesh points on x axis. Default is 3. Valid values are 3 and 7. + - `R` - Probe retries. Default 3 max. 10 + - `V` - Verbosity level 1=low, 10=mid, 20=high. It can be only used if firmware has been compiled with SUPPORT_VERBOSITY active. + + Using the following parameters enables additional "manual" bed leveling correction. Valid values are -100 microns to 100 microns. + + - `L` - Left Bed Level correct value in um. + - `R` - Right Bed Level correct value in um. + - `F` - Front Bed Level correct value in um. + - `B` - Back Bed Level correct value in um. */ // ----------------------------------- @@ -5105,10 +5105,10 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; - /** - *### G81 - Mesh bed leveling status G81: Mesh bed leveling status + /*! + ### G81 - Mesh bed leveling status G81: Mesh bed leveling status - *Prints mesh bed leveling status and bed profile if activated. + Prints mesh bed leveling status and bed profile if activated. */ ----------------------------------------- /* @@ -5136,11 +5136,11 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; #if 0 - /** - *### G82: Single Z probe at current location - Not active G82: Single Z probe at current location - * - *WARNING! USE WITH CAUTION! If you'll try to probe where is no leveling pad, nasty things can happen! - **/ + /*! + ### G82: Single Z probe at current location - Not active G82: Single Z probe at current location + + WARNING! USE WITH CAUTION! If you'll try to probe where is no leveling pad, nasty things can happen! + */ case 82: SERIAL_PROTOCOLLNPGM("Finding bed "); int l_feedmultiply = setup_for_endstop_move(); @@ -5151,8 +5151,8 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) SERIAL_PROTOCOLPGM("\n"); break; - /* - *### G83: Babystep in Z and store to EEPROM - Not active G83: Babystep in Z and store to EEPROM + /*! + ### G83: Babystep in Z and store to EEPROM - Not active G83: Babystep in Z and store to EEPROM */ case 83: { @@ -5176,50 +5176,50 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; - /** - *### G84: UNDO Babystep Z (move Z axis back) - Not active G84: UNDO Babystep Z (move Z axis back) + /*! + ### G84: UNDO Babystep Z (move Z axis back) - Not active G84: UNDO Babystep Z (move Z axis back) */ case 84: babystepsTodoZsubtract(babystepLoadZ); // babystepLoadZ = 0; break; - /** - * ### G85: Pick best babystep - Not active G85: Pick best babystep */ case 85: lcd_pick_babystep(); break; #endif - /** - *### G86 - Disable babystep correction after home G86: Disable babystep correction after home - * - * This G-code will be performed at the start of a calibration script. - * (Prusa3D specific) + /*! + ### G86 - Disable babystep correction after home G86: Disable babystep correction after home + + This G-code will be performed at the start of a calibration script. + (Prusa3D specific) */ case 86: calibration_status_store(CALIBRATION_STATUS_LIVE_ADJUST); break; - /** - * ### G87 - Enable babystep correction after home G87: Enable babystep correction after home - * - * - * This G-code will be performed at the end of a calibration script. - * (Prusa3D specific) - */ + /*! + ### G87 - Enable babystep correction after home G87: Enable babystep correction after home + + + This G-code will be performed at the end of a calibration script. + (Prusa3D specific) + */ case 87: calibration_status_store(CALIBRATION_STATUS_CALIBRATED); break; - /** - * ### G88 - Reserved G88: Reserved - * - * Currently has no effect. - */ + /*! + ### G88 - Reserved G88: Reserved + + Currently has no effect. + */ // Prusa3D specific: Don't know what it is for, it is in V2Calibration.gcode @@ -5229,21 +5229,21 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) #endif // ENABLE_MESH_BED_LEVELING - /** - *### G90 - Switch off relative mode G90: Set to Absolute Positioning + /*! + ### G90 - Switch off relative mode G90: Set to Absolute Positioning */ ------------------------------- case 90: relative_mode = false; break; - //! ### G91 - Switch on relative mode G91: Set to Relative Positioning - // ------------------------------- + /*! ### G91 - Switch on relative mode G91: Set to Relative Positioning + */ ------------------------------- case 91: relative_mode = true; break; - /** - *### G92 - Set position G92: Set Position + /*! + ### G92 - Set position G92: Set Position */ ----------------------------- case 92: if(!code_seen(axis_codes[E_AXIS])) @@ -5263,9 +5263,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; - /** - *### G98 - Activate farm mode G98: Activate farm mode - */ ----------------------------------- + /*! + ### G98 - Activate farm mode G98: Activate farm mode + */ ----------------------------------- case 98: farm_mode = 1; PingTime = _millis(); @@ -5276,8 +5276,8 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) fCheckModeInit(); // alternatively invoke printer reset break; - //! ### G99 - Deactivate farm mode G99: Deactivate farm mode - // ------------------------------------- + /*! ### G99 - Deactivate farm mode G99: Deactivate farm mode + */ ------------------------------------- case 99: farm_mode = 0; lcd_printer_connected(); @@ -5293,10 +5293,10 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } // end if(code_seen('G')) - /** - *--------------------------------------------------------------------------------- - * # M Commands - * + /*! + --------------------------------------------------------------------------------- + # M Commands + */ else if(code_seen('M')) @@ -5317,8 +5317,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) switch(mcode_in_progress) { - //! ### M0, M1 - Stop the printer G32: Undock Z Probe sled - // --------------------------------------------------------------- + /*! + ### M0, M1 - Stop the printer G32: Undock Z Probe sled + */ --------------------------------------------------------------- case 0: // M0 - Unconditional stop - Wait for user button press on LCD case 1: // M1 - Conditional stop - Wait for user button press on LCD { From ce8dbb5013c1971b377398b17ebe84dc8d2510d3 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Wed, 30 Oct 2019 18:52:25 +0100 Subject: [PATCH 070/180] M commands documentation #1 --- Firmware/Marlin_main.cpp | 191 ++++++++++++++++++++++++--------------- 1 file changed, 119 insertions(+), 72 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 8723d8b06..eddf70bfc 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -5318,7 +5318,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) { /*! - ### M0, M1 - Stop the printer G32: Undock Z Probe sled + ### M0, M1 - Stop the printer M0: Stop or Unconditional stop */ --------------------------------------------------------------- case 0: // M0 - Unconditional stop - Wait for user button press on LCD case 1: // M1 - Conditional stop - Wait for user button press on LCD @@ -5368,7 +5368,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; - //! ### M17 - Enable axes G32: Undock Z Probe sled + //! ### M17 - Enable axes M17: Enable/Power all stepper motors // --------------------------------- case 17: LCD_MESSAGERPGM(_i("No move."));////MSG_NO_MOVE @@ -5382,28 +5382,32 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) #ifdef SDSUPPORT - //! ### M20 - SD Card file list G32: Undock Z Probe sled - // ----------------------------------- + /*! + ### M20 - SD Card file list M20: List SD card + */ ----------------------------------- case 20: SERIAL_PROTOCOLLNRPGM(_N("Begin file list"));////MSG_BEGIN_FILE_LIST card.ls(); SERIAL_PROTOCOLLNRPGM(_N("End file list"));////MSG_END_FILE_LIST break; - //! ### M21 - Init SD card G32: Undock Z Probe sled - // ------------------------------------ + /*! + ### M21 - Init SD card M21: Initialize SD card + */ ------------------------------------ case 21: card.initsd(); break; - //! ### M22 - Release SD card G32: Undock Z Probe sled - // ----------------------------------- + /*! + ### M22 - Release SD card M22: Release SD card + */ ----------------------------------- case 22: card.release(); break; - //! ### M23 - Select file G32: Undock Z Probe sled - // ----------------------------------- + /*! + ### M23 - Select file M23: Select SD file + */ ----------------------------------- case 23: starpos = (strchr(strchr_pointer + 4,'*')); if(starpos!=NULL) @@ -5411,8 +5415,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) card.openFile(strchr_pointer + 4,true); break; - //! ### M24 - Start SD print G32: Undock Z Probe sled - // ---------------------------------- + /*! + ### M24 - Start SD print M24: Start/resume SD print + */ ---------------------------------- case 24: if (!card.paused) failstats_reset_print(); @@ -5420,17 +5425,19 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) starttime=_millis(); break; - //! ### M25 - Pause SD print G32: Undock Z Probe sled - // ---------------------------------- + /*! + ### M25 - Pause SD print M25: Pause SD print + */ ---------------------------------- case 25: card.pauseSDPrint(); break; - //! ### M26 S\ - Set SD index G32: Undock Z Probe sled - //! Set position in SD card file to index in bytes. - //! This command is expected to be called after M23 and before M24. - //! Otherwise effect of this command is undefined. - // ---------------------------------- + /*! + ### M26 S\ - Set SD index M26: Set SD position + Set position in SD card file to index in bytes. + This command is expected to be called after M23 and before M24. + Otherwise effect of this command is undefined. + */ ---------------------------------- case 26: if(card.cardOK && code_seen('S')) { long index = code_value_long(); @@ -5441,14 +5448,16 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; - //! ### M27 - Get SD status G32: Undock Z Probe sled - // ---------------------------------- + /*! + ### M27 - Get SD status M27: Report SD print status + */ ---------------------------------- case 27: card.getStatus(); break; - //! ### M28 - Start SD write G32: Undock Z Probe sled - // --------------------------------- + /*! + ### M28 - Start SD write M28: Begin write to SD card + */ --------------------------------- case 28: starpos = (strchr(strchr_pointer + 4,'*')); if(starpos != NULL){ @@ -5459,16 +5468,17 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) card.openFile(strchr_pointer+4,false); break; - //! ### M29 - Stop SD write G32: Undock Z Probe sled - // ------------------------------------- - //! Currently has no effect. + /*! ### M29 - Stop SD write M29: Stop writing to SD card + Currently has no effect. + */ ------------------------------------- case 29: //processed in write to file routine above //card,saving = false; break; - //! ### M30 - Delete file G32: Undock Z Probe sled - // ---------------------------------- + /*! + ### M30 - Delete file M30: Delete a file on the SD card + */ ---------------------------------- case 30: if (card.cardOK){ card.closefile(); @@ -5482,8 +5492,10 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; - //! ### M32 - Select file and start SD print G32: Undock Z Probe sled - // ------------------------------------ + /*! + ### M32 - Select file and start SD print M32: Select file and start SD print + @todo What are the parameters P and S for in M32? + */ ------------------------------------ case 32: { if(card.sdprinting) { @@ -5520,8 +5532,8 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } } break; - //! ### M982 - Start SD write G32: Undock Z Probe sled - // --------------------------------- + /*! ### M982 - Start SD logging M928: Start SD logging + */ --------------------------------- case 928: starpos = (strchr(strchr_pointer + 5,'*')); if(starpos != NULL){ @@ -5534,8 +5546,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) #endif //SDSUPPORT - //! ### M31 - Report current print time G32: Undock Z Probe sled - // -------------------------------------------------- + /*! + ### M31 - Report current print time M31: Output time since last M109 or SD card start to serial + */ -------------------------------------------------- case 31: //M31 take time since the start of the SD print or an M109 command { stoptime=_millis(); @@ -5552,8 +5565,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; - //! ### M42 - Set pin state G32: Undock Z Probe sled - // ----------------------------- + /*! + ### M42 - Set pin state M42: Switch I/O pin + */ ----------------------------- case 42: if (code_seen('S')) { @@ -5583,8 +5597,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; - //! ### M44 - Reset the bed skew and offset calibration (Prusa specific) G32: Undock Z Probe sled - // -------------------------------------------------------------------- + /*! + ### M44 - Reset the bed skew and offset calibration (Prusa specific) M44: Reset the bed skew and offset calibration + */ -------------------------------------------------------------------- case 44: // M44: Prusa3D: Reset the bed skew and offset calibration. // Reset the baby step value and the baby step applied flag. @@ -5599,8 +5614,12 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) world2machine_revert_to_uncorrected(); break; - //! ### M45 - Bed skew and offset with manual Z up (Prusa specific) G32: Undock Z Probe sled - // ------------------------------------------------------ + /*! + ### M45 - Bed skew and offset with manual Z up (Prusa specific) M45: Bed skew and offset with manual Z up + + G80 [ V ] + - V Verbosity level 1, 10 and 20 (low, mid, high). Only when SUPPORT_VERBOSITY is defined. + */ ------------------------------------------------------ case 45: // M45: Prusa3D: bed skew and offset with manual Z up { int8_t verbosity_level = 0; @@ -5640,8 +5659,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } */ - //! ### M47 - Show end stops dialog on the display (Prusa specific) G32: Undock Z Probe sled - // ---------------------------------------------------- + /*! + ### M47 - Show end stops dialog on the displayM47: Show end stops dialog on the display + */ ---------------------------------------------------- case 47: KEEPALIVE_STATE(PAUSED_FOR_USER); @@ -5689,22 +5709,22 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) #ifdef ENABLE_AUTO_BED_LEVELING #ifdef Z_PROBE_REPEATABILITY_TEST - //! ### M48 - Z-Probe repeatability measurement function. G32: Undock Z Probe sled - // ------------------------------------------------------ - //! - //! _Usage:_ - //! - //! M48 - //! - //! This function assumes the bed has been homed. Specifically, that a G28 command - //! as been issued prior to invoking the M48 Z-Probe repeatability measurement function. - //! Any information generated by a prior G29 Bed leveling command will be lost and need to be - //! regenerated. - //! - //! The number of samples will default to 10 if not specified. You can use upper or lower case - //! letters for any of the options EXCEPT n. n must be in lower case because Marlin uses a capital - //! N for its communication protocol and will get horribly confused if you send it a capital N. - //! + /*! + ### M48 - Z-Probe repeatability measurement function. M48: Measure Z-Probe repeatability + + This function assumes the bed has been homed. Specifically, that a G28 command as been issued prior to invoking the M48 Z-Probe repeatability measurement function. Any information generated by a prior G29 Bed leveling command will be lost and need to be regenerated. + + The number of samples will default to 10 if not specified. You can use upper or lower case letters for any of the options EXCEPT n. n must be in lower case because Marlin uses a capital N for its communication protocol and will get horribly confused if you send it a capital N. + + M48 [ n | X | Y | V | L ] + - n - Number of samples. Valid values 4-50 + - X - X position for samples + - Y - Y position for samples + - V - Verbose level. Valid values 1-4 + - L - Legs of movementprior to doing probe. Valid values 1-15 + + + */ case 48: // M48 Z-Probe repeatability { #if Z_MIN_PIN == -1 @@ -5943,12 +5963,17 @@ Sigma_Exit: #endif // Z_PROBE_REPEATABILITY_TEST #endif // ENABLE_AUTO_BED_LEVELING - //! ### M73 - Set/get print progress G32: Undock Z Probe sled - // ------------------------------------- - //! _Usage:_ - //! - //! M73 P R Q S - //! + /*! + ### M73 - Set/get print progress M73: Set/Get build percentage + Prusa firmware just shows percent done and time remaining. + + M73 [ P | R | Q | S ] + + - P - Percent in normal mode + - R - Time remaining in normal mode + - Q - Percent in silent mode + - S - Time in silent mode + */ case 73: //M73 show percent done and time remaining if(code_seen('P')) print_percent_done_normal = code_value(); if(code_seen('R')) print_time_remaining_normal = code_value(); @@ -5962,8 +5987,13 @@ Sigma_Exit: } break; - //! ### M104 - Set hotend temperature G32: Undock Z Probe sled - // ----------------------------------------- + /*! + ### M104 - Set hotend temperature M104: Set Extruder Temperature + + M104 [ S ] + + - S - Target temperature + */ ----------------------------------------- case 104: // M104 { uint8_t extruder; @@ -5977,20 +6007,37 @@ Sigma_Exit: break; } - //! ### M112 - Emergency stop G32: Undock Z Probe sled - // ----------------------------------------- + /*! + ### M112 - Emergency stop M112: Full (Emergency) Stop + */ ----------------------------------------- case 112: kill(_n(""), 3); break; - //! ### M140 - Set bed temperature G32: Undock Z Probe sled - // ----------------------------------------- + /*! + ### M140 - Set bed temperature M140: Set Bed Temperature (Fast) + */ ----------------------------------------- case 140: if (code_seen('S')) setTargetBed(code_value()); break; - //! ### M105 - Report temperatures G32: Undock Z Probe sled - // ----------------------------------------- + /*! + ### M105 - Report temperatures M105: Get Extruder Temperature + Prints temperatures: + + - T: - Hotend (actual / target) + - B: - Bed (actual / target) + - Tx: - x Tool (actual / target) + - @: - Hotend power + - B@: - Bed power + - P: - PINDAv2 actual (only MK2.5/s and MK3.5/s) + - A: - Ambient actual (only MK3/s) + + _Example:_ + + ok T:20.2 /0.0 B:19.1 /0.0 T0:20.2 /0.0 @:0 B@:0 P:19.8 A:26.4 + + */ ----------------------------------------- case 105: { uint8_t extruder; From 4501f9d7600a1eb60274f667095f7108425bc759 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Thu, 31 Oct 2019 15:46:23 +0100 Subject: [PATCH 071/180] M commands documentation #2 --- Firmware/Marlin_main.cpp | 277 +++++++++++++++++++++++++-------------- 1 file changed, 178 insertions(+), 99 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index eddf70bfc..f2873ade9 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -5618,7 +5618,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) ### M45 - Bed skew and offset with manual Z up (Prusa specific) M45: Bed skew and offset with manual Z up G80 [ V ] - - V Verbosity level 1, 10 and 20 (low, mid, high). Only when SUPPORT_VERBOSITY is defined. + - `V` - Verbosity level 1, 10 and 20 (low, mid, high). Only when SUPPORT_VERBOSITY is defined. */ ------------------------------------------------------ case 45: // M45: Prusa3D: bed skew and offset with manual Z up { @@ -5717,11 +5717,11 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) The number of samples will default to 10 if not specified. You can use upper or lower case letters for any of the options EXCEPT n. n must be in lower case because Marlin uses a capital N for its communication protocol and will get horribly confused if you send it a capital N. M48 [ n | X | Y | V | L ] - - n - Number of samples. Valid values 4-50 - - X - X position for samples - - Y - Y position for samples - - V - Verbose level. Valid values 1-4 - - L - Legs of movementprior to doing probe. Valid values 1-15 + - `n` - Number of samples. Valid values 4-50 + - `X` - X position for samples + - `Y` - Y position for samples + - `V` - Verbose level. Valid values 1-4 + - `L` - Legs of movementprior to doing probe. Valid values 1-15 */ @@ -5969,10 +5969,10 @@ Sigma_Exit: M73 [ P | R | Q | S ] - - P - Percent in normal mode - - R - Time remaining in normal mode - - Q - Percent in silent mode - - S - Time in silent mode + - `P` - Percent in normal mode + - `R` - Time remaining in normal mode + - `Q` - Percent in silent mode + - `S` - Time in silent mode */ case 73: //M73 show percent done and time remaining if(code_seen('P')) print_percent_done_normal = code_value(); @@ -5992,7 +5992,7 @@ Sigma_Exit: M104 [ S ] - - S - Target temperature + - `S` - Target temperature */ ----------------------------------------- case 104: // M104 { @@ -6025,13 +6025,13 @@ Sigma_Exit: ### M105 - Report temperatures M105: Get Extruder Temperature Prints temperatures: - - T: - Hotend (actual / target) - - B: - Bed (actual / target) - - Tx: - x Tool (actual / target) - - @: - Hotend power - - B@: - Bed power - - P: - PINDAv2 actual (only MK2.5/s and MK3.5/s) - - A: - Ambient actual (only MK3/s) + - `T:` - Hotend (actual / target) + - `B:` - Bed (actual / target) + - `Tx:` - x Tool (actual / target) + - `@:` - Hotend power + - `B@:` - Bed power + - `P:` - PINDAv2 actual (only MK2.5/s and MK3.5/s) + - `A:` - Ambient actual (only MK3/s) _Example:_ @@ -6133,16 +6133,19 @@ Sigma_Exit: break; } - //! ### M109 - Wait for extruder temperature G32: Undock Z Probe sled - //! Parameters (not mandatory): - //! * S \ set extruder temperature - //! * R \ set extruder temperature - //! - //! Parameters S and R are treated identically. - //! Command always waits for both cool down and heat up. - //! If no parameters are supplied waits for previously - //! set extruder temperature. - // ------------------------------------------------- + /*! + ### M109 - Wait for extruder temperature M109: Set Extruder Temperature and Wait + Parameters (not mandatory): + + - `S` - Set extruder temperature + - `R` - Set extruder temperature + - `B` - Set max. extruder temperature, while `S` is min. temperature. Not active in default, only if AUTOTEMP is defined in source code. + + Parameters S and R are treated identically. + Command always waits for both cool down and heat up. + If no parameters are supplied waits for previously + set extruder temperature. + */ ------------------------------------------------- case 109: { uint8_t extruder; @@ -6192,12 +6195,15 @@ Sigma_Exit: } break; - //! ### M190 - Wait for bed temperature G32: Undock Z Probe sled - //! Parameters (not mandatory): - //! * S \ set extruder temperature and wait for heating - //! * R \ set extruder temperature and wait for heating or cooling - //! - //! If no parameter is supplied, waits for heating or cooling to previously set temperature. + /*! + ### M190 - Wait for bed temperature M190: Wait for bed temperature to reach target temp + Parameters (not mandatory): + + - `S` - Set extruder temperature and wait for heating + - `R` - Set extruder temperature and wait for heating or cooling + + If no parameter is supplied, waits for heating or cooling to previously set temperature. + */ case 190: #if defined(TEMP_BED_PIN) && TEMP_BED_PIN > -1 { @@ -6252,8 +6258,9 @@ Sigma_Exit: #if defined(FAN_PIN) && FAN_PIN > -1 - //! ### M106 - Set fan speed G32: Undock Z Probe sled - // ------------------------------------------- + /*! + ### M106 - Set fan speed M106: Fan On + */ ------------------------------------------- case 106: // M106 Sxxx Fan On S 0 .. 255 if (code_seen('S')){ fanSpeed=constrain(code_value(),0,255); @@ -6263,8 +6270,9 @@ Sigma_Exit: } break; - //! ### M107 - Fan off - // ------------------------------- + /*! + ### M107 - Fan off M107: Fan Off + */ ------------------------------- case 107: fanSpeed = 0; break; @@ -6272,8 +6280,9 @@ Sigma_Exit: #if defined(PS_ON_PIN) && PS_ON_PIN > -1 - //! ### M80 - Turn on the Power Supply G32: Undock Z Probe sled - // ------------------------------- + /*! + ### M80 - Turn on the Power Supply M80: ATX Power On + */ ------------------------------- case 80: SET_OUTPUT(PS_ON_PIN); //GND WRITE(PS_ON_PIN, PS_ON_AWAKE); @@ -6292,8 +6301,9 @@ Sigma_Exit: break; #endif - //! ### M81 - Turn off Power Supply G32: Undock Z Probe sled - // -------------------------------------- + /*! + ### M81 - Turn off Power Supply M81: ATX Power Off + */ -------------------------------------- case 81: disable_heater(); st_synchronize(); @@ -6315,24 +6325,40 @@ Sigma_Exit: lcd_update(0); break; - //! ### M82 - Set E axis to absolute mode G32: Undock Z Probe sled - // --------------------------------------- + /*! + ### M82 - Set E axis to absolute mode M82: Set extruder to absolute mode + Makes the extruder interpret extrusion as absolute positions. + */ --------------------------------------- case 82: axis_relative_modes[3] = false; break; - //! ### M83 - Set E axis to relative mode G32: Undock Z Probe sled - // --------------------------------------- + /*! + ### M83 - Set E axis to relative mode M83: Set extruder to relative mode + Makes the extruder interpret extrusion values as relative positions. + */ --------------------------------------- case 83: axis_relative_modes[3] = true; break; - //! ### M84, M18 - Disable steppers G32: Undock Z Probe sled - //--------------------------------------- - //! This command can be used to set the stepper inactivity timeout (`S`) or to disable steppers (`X`,`Y`,`Z`,`E`) - //! - //! M84 [E] [S] [X] [Y] [Z] - //! + /*! + ### M84 - Disable steppers M84: Stop idle hold + + This command can be used to set the stepper inactivity timeout (`S`) or to disable steppers (`X`,`Y`,`Z`,`E`) + + _This command can be used without any additional parameters._ + + M84 [ S | X | Y | Z | E ] + + - `S` - Seconds + - `X` - X axsis + - `Y` - Y axis + - `Z` - Z axis + - `E` - Exruder drive(s) + + ### M18 - Disable steppers M18: Disable all stepper motors + Equal to M84 (compatibility) + */ case 18: //compatibility case 84: // M84 if(code_seen('S')){ @@ -6369,8 +6395,10 @@ Sigma_Exit: snmm_filaments_used = 0; break; - //! ### M85 - Set max inactive time G32: Undock Z Probe sled - // --------------------------------------- + /*! + ### M85 - Set max inactive time M85: Set Inactivity Shutdown Timer + Set Inactivity Shutdown Timer with parameter S. "M85 S0" will disable the inactivity shutdown time (default) + */ --------------------------------------- case 85: // M85 if(code_seen('S')) { max_inactive_time = code_value() * 1000; @@ -6378,13 +6406,17 @@ Sigma_Exit: break; #ifdef SAFETYTIMER - //! ### M86 - Set safety timer expiration time G32: Undock Z Probe sled - //! - //! _Usage:_ - //! M86 S - //! - //! Sets the safety timer expiration time in seconds. M86 S0 will disable safety timer. - //! When safety timer expires, heatbed and nozzle target temperatures are set to zero. + /*! + ### M86 - Set safety timer expiration time M86: Set Safety Timer expiration time + Sets the safety timer expiration time in seconds. + + When safety timer expires, heatbed and nozzle target temperatures are set to zero. + + M86 [ S ] + + - `S` - Seconds Setting it to 0 will disable safety timer. + + */ case 86: if (code_seen('S')) { safetytimer_inactive_time = code_value() * 1000; @@ -6393,9 +6425,17 @@ Sigma_Exit: break; #endif - //! ### M92 Set Axis steps-per-unit G32: Undock Z Probe sled - // --------------------------------------- - //! Same syntax as G92 + /*! + ### M92 Set Axis steps-per-unit M92: Set axis_steps_per_unit + Allows programming of steps per unit (usually mm) for motor drives. These values are reset to firmware defaults on power on, unless saved to EEPROM if available (M500 in Marlin) + + M92 [ X | Y | Z | E ] + + - `X` - Steps per unit for the X drive + - `Y` - Steps per unit for the Y drive + - `Z` - Steps per unit for the Z drive + - `E` - Steps per unit for the extruder drive(s) + */ --------------------------------------- case 92: for(int8_t i=0; i < NUM_AXIS; i++) { @@ -6418,15 +6458,27 @@ Sigma_Exit: } break; - //! ### M110 - Set Line number G32: Undock Z Probe sled - // --------------------------------------- + /*! + ### M110 - Set Line number M110: Set Current Line Number + Sets the line number in G-code + + M110 [ N ] + + - `N` - Line number + */ --------------------------------------- case 110: if (code_seen('N')) gcode_LastN = code_value_long(); break; - //! ### M113 - Get or set host keep-alive interval G32: Undock Z Probe sled - // ------------------------------------------ + /*! + ### M113 - Get or set host keep-alive interval M113: Host Keepalive + During some lengthy processes, such as G29, Marlin may appear to the host to have “gone away.” The “host keepalive” feature will send messages to the host when Marlin is busy or waiting for user response so the host won’t try to reconnect. + + M113 [ S ] + + - `S` - Seconds Default is 2 seconds between "busy" messages + */ ------------------------------------------ case 113: if (code_seen('S')) { host_keepalive_interval = (uint8_t)code_value_short(); @@ -6439,16 +6491,34 @@ Sigma_Exit: } break; - //! ### M115 - Firmware info G32: Undock Z Probe sled - // -------------------------------------- - //! Print the firmware info and capabilities - //! - //! M115 [V] [U] - //! - //! Without any arguments, prints Prusa firmware version number, machine type, extruder count and UUID. - //! `M115 U` Checks the firmware version provided. If the firmware version provided by the U code is higher than the currently running firmware, - //! pause the print for 30s and ask the user to upgrade the firmware. - case 115: // M115 + /*! + ### M115 - Firmware info M115: Get Firmware Version and Capabilities + Print the firmware info and capabilities + + M115 [ V | U ] + + - V - Report current installed firmware version + - U - Firmware version provided by G-code to be compared to current one. + + + Without any arguments, prints Prusa firmware version number, machine type, extruder count and UUID. + `M115 U` Checks the firmware version provided. If the firmware version provided by the U code is higher than the currently running firmware, it will pause the print for 30s and ask the user to upgrade the firmware. + + _Examples:_ + + `M115` results: + + `FIRMWARE_NAME:Prusa-Firmware 3.8.1 based on Marlin FIRMWARE_URL:https://github.com/prusa3d/Prusa-Firmware PROTOCOL_VERSION:1.0 MACHINE_TYPE:Prusa i3 MK3S EXTRUDER_COUNT:1 UUID:00000000-0000-0000-0000-000000000000` + + `M115 V` results: + + `3.8.1` + + `M115 U3.8.2-RC1` results on LCD display for 30s or user interaction: + + `New firmware version available: 3.8.2-RC1 Please upgrade.` + */ + case 115: // M115 if (code_seen('V')) { // Report the Prusa version number. SERIAL_PROTOCOLLNRPGM(FW_VERSION_STR_P()); @@ -6470,16 +6540,13 @@ Sigma_Exit: } break; - //! ### M114 - Get current position G32: Undock Z Probe sled - // ------------------------------------- + /*! + ### M114 - Get current position M114: Get Current Position + */ ------------------------------------- case 114: gcode_M114(); break; - - - //! ### M117 - Set LCD Message G32: Undock Z Probe sled - // -------------------------------------- /* M117 moved up to get the high priority @@ -6491,20 +6558,24 @@ Sigma_Exit: lcd_setstatus(strchr_pointer + 5); break;*/ - //! ### M120 - Disable endstops G32: Undock Z Probe sled - // ---------------------------------------- + /*! + ### M120 - Enable endstops G32: Undock Z Probe sled - // ---------------------------------------- + /*! + ### M121 - Disable endstops M121: Disable endstop detection + */ ---------------------------------------- case 121: enable_endstops(true) ; break; - //! ### M119 - Get endstop states G32: Undock Z Probe sled - // ---------------------------------------- + /*! + ### M119 - Get endstop states M119: Get Endstop Status + Returns the current state of the configured X, Y, Z endstops. Takes into account any 'inverted endstop' settings, so one can confirm that the machine is interpreting the endstops correctly. + */ ---------------------------------------- case 119: SERIAL_PROTOCOLRPGM(_N("Reporting endstop status"));////MSG_M119_REPORT SERIAL_PROTOCOLLN(""); @@ -6565,10 +6636,12 @@ Sigma_Exit: break; //TODO: update for all axis, use for loop - #ifdef BLINKM - //! ### M150 - Set RGB(W) Color G32: Undock Z Probe sled - // ------------------------------------------- + #ifdef BLINKM + /*! + ### M150 - Set RGB(W) Color M150: Set LED color + In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code by defining BLINKM and its dependencies. + */ ------------------------------------------- case 150: { byte red; @@ -6584,8 +6657,14 @@ Sigma_Exit: break; #endif //BLINKM - //! ### M200 - Set filament diameter G32: Undock Z Probe sled - // ---------------------------------------- + /*! + ### M200 - Set filament diameter M200: Set filament diameter + + M200 [ D | T ] + + - `D` - Diameter in mm + - `T` - Number of extruder (MMUs) + */ ---------------------------------------- case 200: // M200 D set filament diameter and set E axis units to cubic millimeters (use S0 to set back to millimeters). { @@ -6610,10 +6689,10 @@ Sigma_Exit: // make sure all extruders have some sane value for the filament size cs.filament_size[0] = (cs.filament_size[0] == 0.0 ? DEFAULT_NOMINAL_FILAMENT_DIA : cs.filament_size[0]); #if EXTRUDERS > 1 - cs.filament_size[1] = (cs.filament_size[1] == 0.0 ? DEFAULT_NOMINAL_FILAMENT_DIA : cs.filament_size[1]); - #if EXTRUDERS > 2 - cs.filament_size[2] = (cs.filament_size[2] == 0.0 ? DEFAULT_NOMINAL_FILAMENT_DIA : cs.filament_size[2]); - #endif + cs.filament_size[1] = (cs.filament_size[1] == 0.0 ? DEFAULT_NOMINAL_FILAMENT_DIA : cs.filament_size[1]); + #if EXTRUDERS > 2 + cs.filament_size[2] = (cs.filament_size[2] == 0.0 ? DEFAULT_NOMINAL_FILAMENT_DIA : cs.filament_size[2]); + #endif #endif cs.volumetric_enabled = true; } From 8114bd5b1c7d90f7debf378696b1d49bc7a8ab42 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Tue, 5 Nov 2019 09:05:05 +0100 Subject: [PATCH 072/180] Merge with MK3 and few spaces --- Firmware/Marlin_main.cpp | 50 ++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index f2873ade9..11e734c2a 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3643,30 +3643,30 @@ void process_commands() ### PRUSA - Internal command set G98: Activate farm mode - Notes Set of internal PRUSA commands - - PRUSA [ Ping | PRN | FAN | fn | thx | uvlo | fsensor_recover | MMURES | RESET | fv | M28 | SN | Fir | Rev | Lang | Lz | Beat | FR ] - - - `Ping` - - `PRN` - Prints revision of the printer - - `FAN` - Prints fan details - - `fn` - Prints farm no. - - `thx` - - `uvlo` - - `fsensor_recover` - Filament sensor recover - restore print and continue - - `MMURES` - Reset MMU - - `RESET` - (Careful!) - - `fv` - ? - - `M28` - - `SN` - - `Fir` - Prints firmware version - - `Rev`- Prints filament size, elelectronics, nozzle type - - `Lang` - Reset the language - - `Lz` - - `Beat` - Kick farm link timer - - `FR` - Full factory reset - - `nozzle set ` - set nozzle diameter (farm mode only), e.g. `PRUSA nozzle set 0.4` - - `nozzle D` - check the nozzle diameter (farm mode only), works like M862.1 P, e.g. `PRUSA nozzle D0.4` - - `nozzle` - prints nozzle diameter (farm mode only), works like M862.1 P, e.g. `PRUSA nozzle` + + P RUSA [ Ping | PRN | FAN | fn | thx | uvlo | fsensor_recover | MMURES | RESET | fv | M28 | SN | Fir | Rev | Lang | Lz | Beat | FR ] + + - `Ping` + - `PRN` - Prints revision of the printer + - `FAN` - Prints fan details + - `fn` - Prints farm no. + - `thx` + - `uvlo` + - `fsensor_recover` - Filament sensor recover - restore print and continue + - `MMURES` - Reset MMU + - `RESET` - (Careful!) + - `fv` - ? + - `M28` + - `SN` + - `Fir` - Prints firmware version + - `Rev`- Prints filament size, elelectronics, nozzle type + - `Lang` - Reset the language + - `Lz` + - `Beat` - Kick farm link timer + - `FR` - Full factory reset + - `nozzle set ` - set nozzle diameter (farm mode only), e.g. `PRUSA nozzle set 0.4` + - `nozzle D` - check the nozzle diameter (farm mode only), works like M862.1 P, e.g. `PRUSA nozzle D0.4` + - `nozzle` - prints nozzle diameter (farm mode only), works like M862.1 P, e.g. `PRUSA nozzle` */ @@ -7934,7 +7934,7 @@ Sigma_Exit: // end if(code_seen('M')) (end of M codes) //! ----------------------------------------------------------------------------------------- - //! T Codes + //! # T Codes //! //! T - select extruder in case of multi extruder printer //! select filament in case of MMU_V2 From ca234a11edae5ad134eea5c93237bcf7aa79ced2 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Tue, 5 Nov 2019 12:40:51 +0100 Subject: [PATCH 073/180] M-Commands to M240 --- Firmware/Marlin_main.cpp | 201 +++++++++++++++++++++++++++++---------- 1 file changed, 152 insertions(+), 49 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 11e734c2a..870d724ae 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -5598,7 +5598,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! - ### M44 - Reset the bed skew and offset calibration (Prusa specific) M44: Reset the bed skew and offset calibration + ### M44 - Reset the bed skew and offset calibrationM44: Reset the bed skew and offset calibration */ -------------------------------------------------------------------- case 44: // M44: Prusa3D: Reset the bed skew and offset calibration. @@ -5615,7 +5615,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; /*! - ### M45 - Bed skew and offset with manual Z up (Prusa specific) M45: Bed skew and offset with manual Z up + ### M45 - Bed skew and offset with manual Z upM45: Bed skew and offset with manual Z up G80 [ V ] - `V` - Verbosity level 1, 10 and 20 (low, mid, high). Only when SUPPORT_VERBOSITY is defined. @@ -6559,7 +6559,7 @@ Sigma_Exit: break;*/ /*! - ### M120 - Enable endstops M120: Enable endstop detection */ ---------------------------------------- case 120: enable_endstops(false) ; @@ -6704,8 +6704,9 @@ Sigma_Exit: } break; - //! ### M201 - Set Print Max Acceleration G32: Undock Z Probe sled - // ------------------------------------------- + /*! + ### M201 - Set Print Max Acceleration M201: Set max printing acceleration + */ ------------------------------------------- case 201: for (int8_t i = 0; i < NUM_AXIS; i++) { @@ -6739,8 +6740,9 @@ Sigma_Exit: break; #endif - //! ### M203 - Set Max Feedrate G32: Undock Z Probe sled - // --------------------------------------- + /*! + ### M203 - Set Max Feedrate M203: Set maximum feedrate + */ --------------------------------------- case 203: // M203 max feedrate mm/sec for (int8_t i = 0; i < NUM_AXIS; i++) { @@ -6765,15 +6767,22 @@ Sigma_Exit: } break; - //! ### M204 - Acceleration settings G32: Undock Z Probe sled - // ------------------------------------------ - //! Supporting old format: - //! - //! M204 S[normal moves] T[filmanent only moves] - //! - //! and new format: - //! - //! M204 P[printing moves] R[filmanent only moves] T[travel moves] (as of now T is ignored) + /*! + ### M204 - Acceleration settings M204: Set default acceleration + */ ------------------------------------------ + /*! Supporting old format: + + M204 [ S | T ] + - `S` - normal moves + - `T` - filmanent only moves + + and new format: + + M204 [ P | R | T ] + - `P` - printing moves + - `R` - filmanent only moves + - `T` - travel moves (as of now T is ignored) + */ case 204: { if(code_seen('S')) { @@ -6799,16 +6808,20 @@ Sigma_Exit: } break; - //! ### M205 - Set advanced settings G32: Undock Z Probe sled - // --------------------------------------------- - //! Set some advanced settings related to movement. - //! - //! M205 [S] [T] [B] [X] [Y] [Z] [E] - /** + /*! + ### M205 - Set advanced settings M205: Advanced settings + */ --------------------------------------------- + /*! Set some advanced settings related to movement. + + M205 [ S | T | B | X | Y | Z | E ] + - `S` - Minimum feedrate for print moves (unit/s) - `T` - Minimum feedrate for travel moves (units/s) - `B` - Minimum segment time (us) - - `X` - Maximum X jerk (units/s), similarly for other axes + - `X` - Maximum X jerk (units/s) + - `Y` - Maximum Y jerk (units/s) + - `Z` - Maximum Z jerk (units/s) + - `E` - Maximum E jerk (units/s) */ case 205: { @@ -6824,8 +6837,15 @@ Sigma_Exit: } break; - //! ### M206 - Set additional homing offsets G32: Undock Z Probe sled - // ---------------------------------------------- + /*! + ### M206 - Set additional homing offsets M206: Offset axes + + M206 [ X | Y | Z] + + - `X` - X axis offset + - `Y` - Y axis offset + - `Z` - Z axis offset + */ ---------------------------------------------- case 206: for(int8_t i=0; i < 3; i++) { @@ -6834,8 +6854,15 @@ Sigma_Exit: break; #ifdef FWRETRACT - //! ### M207 - Set firmware retraction G32: Undock Z Probe sled - // -------------------------------------------------- + /*! + ### M207 - Set firmware retraction M207: Set retract length + + M207 [ S | F | Z] + + - `S` - positive length to retract, in mm + - `F` - retraction feedrate, in mm/min + - `Z` - additional zlift/hop + */ -------------------------------------------------- case 207: //M207 - set retract length S[positive mm] F[feedrate mm/min] Z[additional zlift/hop] { if(code_seen('S')) @@ -6852,8 +6879,14 @@ Sigma_Exit: } }break; - //! ### M208 - Set retract recover length G32: Undock Z Probe sled - // -------------------------------------------- + /*! + ### M208 - Set retract recover length M208: Set unretract length + + M208 [ S | F ] + + - `S` - positive length surplus to the M207 Snnn, in mm + - `F` - feedrate, in mm/sec + */ -------------------------------------------- case 208: // M208 - set retract recover length S[positive mm surplus to the M207 S*] F[feedrate mm/min] { if(code_seen('S')) @@ -6866,8 +6899,15 @@ Sigma_Exit: } }break; - //! ### M209 - Enable/disable automatict retract G32: Undock Z Probe sled - // --------------------------------------------- + /*! + ### M209 - Enable/disable automatict retract M209: Enable automatic retract + + M209 [ S ] + + - `S` - 1=true or 0=false + + This boolean value S 1=true or 0=false enables automatic retract detect if the slicer did not support G10/G11: every normal extrude-only move will be classified as retract depending on the direction. + */ --------------------------------------------- case 209: // M209 - S<1=true/0=false> enable automatic retract detect if the slicer did not support G10/11: every normal extrude-only move will be classified as retract depending on the direction. { if(code_seen('S')) @@ -6909,8 +6949,10 @@ Sigma_Exit: #endif // FWRETRACT #if EXTRUDERS > 1 - // ### M218 - Set hotend offset - // ---------------------------------------- + /*! + ### M218 - Set hotend offset M218: Set Hotend Offset + In Prusa Firmware this G-code is only active if `EXTRUDERS` is higher then 1 in the source code. On Original i3 Prusa MK2/s MK2.5/s MK3/s it is not active. + */ ---------------------------------------- case 218: // M218 - set hotend offset (in mm), T X Y { uint8_t extruder; @@ -6938,8 +6980,16 @@ Sigma_Exit: }break; #endif - //! ### M220 Set feedrate percentage G32: Undock Z Probe sled - // ----------------------------------------------- + /*! + ### M220 Set feedrate percentage M220: Set speed factor override percentage + + M220 [ B | S | R ] + + - `B` - Backup current speed factor + - `S` - Speed factor override percentage (0..100 or higher) + - `R` - Restore previous speed factor + + */ ----------------------------------------------- case 220: // M220 S- set speed factor override percentage { if (code_seen('B')) //backup current speed factor @@ -6956,8 +7006,15 @@ Sigma_Exit: } break; - //! ### M221 - Set extrude factor override percentage G32: Undock Z Probe sled - // ---------------------------------------------------- + /*! + ### M221 - Set extrude factor override percentage M221: Set extrude factor override percentage + + M221 [ S | T ] + + - `S` - Extrude factor override percentage (0..100 or higher), default 100% + - `T` - Extruder drive number (Prusa Firmware only), default 0 if not set. + + */ ---------------------------------------------------- case 221: // M221 S- set extrude factor override percentage { if(code_seen('S')) @@ -6980,8 +7037,16 @@ Sigma_Exit: } break; - //! ### M226 - Wait for Pin state G32: Undock Z Probe sled - // ------------------------------------------ + /*! + ### M226 - Wait for Pin state M226: Wait for pin state + + M226 [ P | S ] + + - `P` - pin number + - `S` - pin state + + Wait until the specified pin reaches the state required + */ ------------------------------------------ case 226: // M226 P S- Wait until the specified pin reaches the state required { if(code_seen('P')){ @@ -7036,8 +7101,10 @@ Sigma_Exit: #if NUM_SERVOS > 0 - //! ### M280 - Set/Get servo position G32: Undock Z Probe sled - // -------------------------------------------- + /*! + ### M280 - Set/Get servo position M280: Set servo position + In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code. + */ -------------------------------------------- case 280: // M280 - set servo position absolute. P: servo index, S: angle or microseconds { int servo_index = -1; @@ -7077,8 +7144,16 @@ Sigma_Exit: #if (LARGE_FLASH == true && ( BEEPER > 0 || defined(ULTRALCD) || defined(LCD_USE_I2C_BUZZER))) - //! ### M300 - Play tone G32: Undock Z Probe sled - // ----------------------- + /*! + ### M300 - Play tone M300: Play beep sound + + M300 [ S | P ] + + - `S` - frequency in Hz + - `P` - duration in milliseconds + + In Prusa Firmware the defaults are `100Hz` and `1000ms`, so that `M300` without parameters will beep for a second. + */ ----------------------- case 300: // M300 { int beepS = code_seen('S') ? code_value() : 110; @@ -7099,8 +7174,20 @@ Sigma_Exit: #ifdef PIDTEMP - //! ### M301 - Set hotend PID G32: Undock Z Probe sled - // --------------------------------------- + /*! + ### M301 - Set hotend PID M301: Set PID parameters + + M301 [ P | I | D | C ] + + - `P` - proportional (Kp) + - `I` - integral (Ki) + - `D` - derivative (Kd) + - `C` - heating power=Kc*(e_speed0) + + Sets Proportional (P), Integral (I) and Derivative (D) values for hot end. + + See also PID Tuning. + */ --------------------------------------- case 301: { if(code_seen('P')) cs.Kp = code_value(); @@ -7130,8 +7217,19 @@ Sigma_Exit: #endif //PIDTEMP #ifdef PIDTEMPBED - //! ### M304 - Set bed PID G32: Undock Z Probe sled - // -------------------------------------- + /*! + ### M304 - Set bed PID M304: Set PID parameters - Bed + + M304 [ P | I | D ] + + - `P` - proportional (Kp) + - `I` - integral (Ki) + - `D` - derivative (Kd) + + Sets Proportional (P), Integral (I) and Derivative (D) values for bed. + + See also PID Tuning. + */ -------------------------------------- case 304: { if(code_seen('P')) cs.bedKp = code_value(); @@ -7151,8 +7249,13 @@ Sigma_Exit: break; #endif //PIDTEMP - //! ### M240 - Trigger camera G32: Undock Z Probe sled - // -------------------------------------------- + /*! + ### M240 - Trigger camera M240: Trigger camera + + In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code. + + You need to define `CHDK` and assign a `PHOTOGRAPH_PIN` to bea ble to use it. + */ -------------------------------------------- case 240: // M240 Triggers a camera by emulating a Canon RC-1 : http://www.doc-diy.net/photo/rc-1_hacked/ { #ifdef CHDK From e6eeafd20c774473cfd9aee703e8ab5115d9f037 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Tue, 5 Nov 2019 15:47:04 +0100 Subject: [PATCH 074/180] More M-Commands ... --- Firmware/Marlin_main.cpp | 375 ++++++++++++++++++++++++++------------- 1 file changed, 252 insertions(+), 123 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 870d724ae..759df56f0 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -5291,7 +5291,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) // printf_P(_N("END G-CODE=%u\n"), gcode_in_progress); gcode_in_progress = 0; } // end if(code_seen('G')) - + /*! + #### End of G-Codes + */ /*! --------------------------------------------------------------------------------- @@ -7289,8 +7291,15 @@ Sigma_Exit: break; #ifdef PREVENT_DANGEROUS_EXTRUDE - //! ### M302 - Allow cold extrude, or set minimum extrude temperature G32: Undock Z Probe sled - // ------------------------------------------------------------------- + /*! + ### M302 - Allow cold extrude, or set minimum extrude temperature M302: Allow cold extrudes + + M302 [ S ] + + - `S` - Cold extrude minimum temperature + + This tells the printer to allow movement of the extruder motor above a certain temperature, or if disabled, to allow extruder movement when the hotend is below a safe printing temperature. + */ ------------------------------------------------------------------- case 302: { float temp = .0; @@ -7300,8 +7309,17 @@ Sigma_Exit: break; #endif - //! ### M303 - PID autotune G32: Undock Z Probe sled - // ------------------------------------- + /*! + ### M303 - PID autotune M303: Run PID tuning + + M303 [ E | S | C ] + + - `E` - Extruder, default `E0`. + - `S` - Target temperature, default `210°C` + - `C` - Cycles, default `5` + + PID Tuning refers to a control algorithm used in some repraps to tune heating behavior for hot ends and heated beds. This command generates Proportional (Kp), Integral (Ki), and Derivative (Kd) values for the hotend or bed (`E-1`). Send the appropriate code and wait for the output to update the firmware. + */ ------------------------------------- case 303: { float temp = 150.0; @@ -7316,17 +7334,30 @@ Sigma_Exit: } break; - //! ### M400 - Wait for all moves to finish G32: Undock Z Probe sled - // ----------------------------------------- + /*! + ### M400 - Wait for all moves to finish M400: Wait for current moves to finish + + Finishes all current moves and and thus clears the buffer. + */ ----------------------------------------- case 400: { st_synchronize(); } break; - //! ### M403 - Set filament type (material) for particular extruder and notify the MMU G32: Undock Z Probe sled - // ---------------------------------------------- - case 403: + /*! + ### M403 - Set filament type (material) for particular extruder and notify the MMU M403 - Set filament type (material) for particular extruder and notify the MMU + + M403 [ E | F ] + + - `E` - Extruder number + - `F` - Filament type + + Currently three different materials are needed (default, flex and PVA). + + And storing this information for different load/unload profiles etc. in the future firmware does not have to wait for "ok" from MMU. + */ ---------------------------------------------- + case 403: { // currently three different materials are needed (default, flex and PVA) // add storing this information for different load/unload profiles etc. in the future @@ -7342,40 +7373,56 @@ Sigma_Exit: } break; - //! ### M500 - Store settings in EEPROM G32: Undock Z Probe sled - // ----------------------------------------- + /*! + ### M500 - Store settings in EEPROM M500: Store parameters in non-volatile storage + + Save current parameters to EEPROM, SD card or other non-volatile storage. + */ ----------------------------------------- case 500: { Config_StoreSettings(); } break; - //! ### M501 - Read settings from EEPROM G32: Undock Z Probe sled - // ---------------------------------------- + /*! + ### M501 - Read settings from EEPROM M501: Read parameters from EEPROM + + Set the active parameters to those stored in the EEPROM, SD card or other non-volatile storage. This is useful to revert parameters after experimenting with them. + */ ---------------------------------------- case 501: { Config_RetrieveSettings(); } break; - //! ### M502 - Revert all settings to factory default G32: Undock Z Probe sled - // ------------------------------------------------- + /*! + ### M502 - Revert all settings to factory default M502: Restore Default Settings + + This command resets all tunable parameters to their default values, as set in the firmware's configuration files. This doesn't reset any parameters stored in the EEPROM, so it must be followed with M500 to reboot with default settings. + */ ------------------------------------------------- case 502: { Config_ResetDefault(); } break; - //! ### M503 - Repport all settings currently in memory G32: Undock Z Probe sled - // ------------------------------------------------- + /*! + ### M503 - Repport all settings currently in memory M503: Report Current Settings + + This command asks the firmware to reply with the current print settings as set in memory. Settings will differ from EEPROM contents if changed since the last load / save. The reply output includes the G-Code commands to produce each setting. For example, Steps-Per-Unit values are displayed as an M92 command. + */ ------------------------------------------------- case 503: { Config_PrintSettings(); } break; - //! ### M509 - Force language selection G32: Undock Z Probe sled - // ------------------------------------------------ + /*! + ### M509 - Force language selection M509: Force language selection + + Resets the language to English. + Only on Original Prusa i3 MK2.5/s and MK3/s with multiple languages. + */ ------------------------------------------------ case 509: { lang_reset(); @@ -7385,8 +7432,11 @@ Sigma_Exit: break; #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED - //! ### M540 - Abort print on endstop hit (enable/disable) G32: Undock Z Probe sled - // ----------------------------------------------------- + /*! + ### M540 - Abort print on endstop hit (enable/disable) M540 in Marlin: Enable/Disable "Stop SD Print on Endstop Hit" + + In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code. You must define `ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED`. + */ ----------------------------------------------------- case 540: { if(code_seen('S')) abort_on_endstop_hit = code_value() > 0; @@ -7394,6 +7444,17 @@ Sigma_Exit: break; #endif + /*! + ### M851 - Set Z-Probe Offset M851: Set Z-Probe Offset" + + M4861 [ Z ] + + - `Z` - Z offset probe to nozzle. + + Sets the Z-probe Z offset. This offset is used to determine the actual Z position of the nozzle when using a probe to home Z with G28. This value may also be used by G81 (Prusa) / G29 (Marlin) to apply correction to the Z position. + + This value represents the distance from nozzle to the bed surface at the point where the probe is triggered. This value will be negative for typical switch probes, inductive probes, and setups where the nozzle makes a circuit with a raised metal contact. This setting will be greater than zero on machines where the nozzle itself is used as the probe, pressing down on the bed to press a switch. (This is a common setup on delta machines.) + */ ----------------------------------------------------- #ifdef CUSTOM_M_CODE_SET_Z_PROBE_OFFSET case CUSTOM_M_CODE_SET_Z_PROBE_OFFSET: { @@ -7432,8 +7493,22 @@ Sigma_Exit: #ifdef FILAMENTCHANGEENABLE - //! ### M600 - Initiate Filament change procedure G32: Undock Z Probe sled - // -------------------------------------- + /*! + ### M600 - Initiate Filament change procedure M600: Filament change pause + + M600 [ X | Y | Z | E | L | AUTO ] + + - `X` - X position, default 211 + - `Y` - Y position, default 0 + - `Z` - relative lift Z, default 2. + - `E` - initial retract, default -2 + - `L` - later retract distance for removal, default -80 + - `AUTO` - Automatically (only with MMU) + + Initiates Filament change, it is also used during Filament Runout Sensor process. + + If the `M600` is triggered under 25mm it will do a Z-lift of 25mm to prevent a filament blob. + */ -------------------------------------- case 600: //Pause for filament change X[pos] Y[pos] Z[relative lift] E[initial retract] L[later retract distance for removal] { st_synchronize(); @@ -7509,8 +7584,9 @@ Sigma_Exit: break; #endif //FILAMENTCHANGEENABLE - //! ### M601 - Pause print G32: Undock Z Probe sled - // ------------------------------- + /*! + ### M601 - Pause print G32: Undock Z Probe sled + */ ------------------------------- case 601: { cmdqueue_pop_front(); //trick because we want skip this command (M601) after restore @@ -7518,28 +7594,31 @@ Sigma_Exit: } break; - //! ### M602 - Resume print G32: Undock Z Probe sled - // ------------------------------- + /*! + ### M602 - Resume print G32: Undock Z Probe sled + */ ------------------------------- case 602: { lcd_resume_print(); } break; - //! ### M603 - Stop print G32: Undock Z Probe sled - // ------------------------------- - case 603: { + /*! + ### M603 - Stop print G32: Undock Z Probe sled + */ ------------------------------- + case 603: { lcd_print_stop(); } #ifdef PINDA_THERMISTOR - //! ### M860 - Wait for extruder temperature (PINDA) G32: Undock Z Probe sled - // -------------------------------------------------------------- - /*! - Wait for PINDA thermistor to reach target temperature + /*! + ### M860 - Wait for extruder temperature (PINDA) M860 Wait for Probe Temperature - M860 [S] + M860 [ S ] - */ + - `S` - Target temperature + + Wait for PINDA thermistor to reach target temperature + */ -------------------------------------------------------------- case 860: { int set_target_pinda = 0; @@ -7584,17 +7663,19 @@ Sigma_Exit: break; } - //! ### M861 - Set/Get PINDA temperature compensation offsets G32: Undock Z Probe sled - // ----------------------------------------------------------- - /*! + /*! + ### M861 - Set/Get PINDA temperature compensation offsets M861 Set Probe Thermal Compensation - M861 [ ? | ! | Z | S [I] ] + M861 [ ? | ! | Z | S | I ] - `?` - Print current EEPROM offset values - `!` - Set factory default values - `Z` - Set all values to 0 (effectively disabling PINDA temperature compensation) - - `S` `I` - Set compensation ustep value S for compensation table index I - */ + - `S` - Microsteps + - `I` - Table index + + Set compensation ustep value `S` for compensation table index `I`. + */ ----------------------------------------------------------- case 861: if (code_seen('?')) { // ? - Print out current EEPROM offset values uint8_t cal_status = calibration_status_pinda(); @@ -7667,39 +7748,41 @@ Sigma_Exit: #endif //PINDA_THERMISTOR - //! ### M862 - Print checking G32: Undock Z Probe sled - // ---------------------------------------------- - /*! - Checks the parameters of the printer and gcode and performs compatibility check - - M862.1 { P | Q } - - M862.2 { P | Q } - - M862.3 { P"" | Q } - - M862.4 { P | Q } - - M862.5 { P | Q } - - When run with P<> argument, the check is performed against the input value. - When run with Q argument, the current value is shown. - - M862.3 accepts text identifiers of printer types too. - The syntax of M862.3 is (note the quotes around the type): - - M862.3 P "MK3S" - - Accepted printer type identifiers and their numeric counterparts: - - MK1 (100) - - MK2 (200) - - MK2MM (201) - - MK2S (202) - - MK2SMM (203) - - MK2.5 (250) - - MK2.5MMU2 (20250) - - MK2.5S (252) - - MK2.5SMMU2S (20252) - - MK3 (300) - - MK3MMU2 (20300) - - MK3S (302) - - MK3SMMU2S (20302) - */ + /*! + ### M862 - Print checking G32: Undock Z Probe sled + Checks the parameters of the printer and gcode and performs compatibility check + + - M862.1 { P | Q } + - M862.2 { P | Q } + - M862.3 { P"" | Q } + - M862.4 { P | Q } + - M862.5 { P | Q } + + When run with P<> argument, the check is performed against the input value. + When run with Q argument, the current value is shown. + + M862.3 accepts text identifiers of printer types too. + The syntax of M862.3 is (note the quotes around the type): + + M862.3 P "MK3S" + + Accepted printer type identifiers and their numeric counterparts: + + - MK1 (100) + - MK2 (200) + - MK2MM (201) + - MK2S (202) + - MK2SMM (203) + - MK2.5 (250) + - MK2.5MMU2 (20250) + - MK2.5S (252) + - MK2.5SMMU2S (20252) + - MK3 (300) + - MK3MMU2 (20300) + - MK3S (302) + - MK3SMMU2S (20302) + + */ ---------------------------------------------- case 862: // M862: print checking float nDummy; uint8_t nCommand; @@ -7760,19 +7843,42 @@ Sigma_Exit: break; #ifdef LIN_ADVANCE - //! ### M900 - Set Linear advance options G32: Undock Z Probe sled - // ---------------------------------------------- + /*! + ### M900 - Set Linear advance options M900 Set Linear Advance Scaling Factors + Sets the advance extrusion factors for Linear Advance. If any of the R, W, H, or D parameters are set to zero the ratio will be computed dynamically during printing. + + M900 [ K | R | W | H | D] + + - `K` - Advance K factor + - `R` - Set ratio directly (overrides WH/D) + - `W` - Width + - `H` - Height + - `D` - Diameter Set ratio from WH/D + */ ---------------------------------------------- case 900: gcode_M900(); break; #endif - //! ### M907 - Set digital trimpot motor current in mA using axis codes G32: Undock Z Probe sled - // --------------------------------------------------------------- + /*! + ### M907 - Set digital trimpot motor current in mA using axis codes M907: Set digital trimpot motor + Set digital trimpot motor current using axis codes (X, Y, Z, E, B, S). + + M907 [ X | Y | Z | E | B | S ] + + - `X` - X motor driver + - `Y` - Y motor driver + - `Z` - Z motor driver + - `E` - Extruder motor driver + - `B` - ?? + - `S` - ?? + + @todo What are `B` and `S` in M907? + */ --------------------------------------------------------------- case 907: { #ifdef TMC2130 - //! See tmc2130_cur2val() for translation to 0 .. 63 range + // See tmc2130_cur2val() for translation to 0 .. 63 range for (int i = 0; i < NUM_AXIS; i++) if(code_seen(axis_codes[i])) { @@ -7802,8 +7908,10 @@ Sigma_Exit: } break; - //! ### M908 - Control digital trimpot directly G32: Undock Z Probe sled - // --------------------------------------------------------- + /*! + ### M908 - Control digital trimpot directly M908: Control digital trimpot directly + In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code. + */ --------------------------------------------------------- case 908: { #if defined(DIGIPOTSS_PIN) && DIGIPOTSS_PIN > -1 @@ -7817,16 +7925,18 @@ Sigma_Exit: #ifdef TMC2130_SERVICE_CODES_M910_M918 - //! ### M910 - TMC2130 init G32: Undock Z Probe sled - // ----------------------------------------------- + /*! + ### M910 - TMC2130 init G32: Undock Z Probe sled + */ ----------------------------------------------- case 910: { tmc2130_init(); } break; - //! ### M911 - Set TMC2130 holding currents G32: Undock Z Probe sled - // ------------------------------------------------- + /*! + ### M911 - Set TMC2130 holding currents G32: Undock Z Probe sled + */ ------------------------------------------------- case 911: { if (code_seen('X')) tmc2130_set_current_h(0, code_value()); @@ -7836,8 +7946,9 @@ Sigma_Exit: } break; - //! ### M912 - Set TMC2130 running currents G32: Undock Z Probe sled - // ----------------------------------------------- + /*! + ### M912 - Set TMC2130 running currents G32: Undock Z Probe sled + */ ----------------------------------------------- case 912: { if (code_seen('X')) tmc2130_set_current_r(0, code_value()); @@ -7847,17 +7958,19 @@ Sigma_Exit: } break; - //! ### M913 - Print TMC2130 currents G32: Undock Z Probe sled - // ----------------------------- + /*! + ### M913 - Print TMC2130 currents G32: Undock Z Probe sled + */ ----------------------------- case 913: { tmc2130_print_currents(); } break; - //! ### M914 - Set TMC2130 normal mode G32: Undock Z Probe sled - // ------------------------------ - case 914: + /*! + ### M914 - Set TMC2130 normal mode G32: Undock Z Probe sled + */ ------------------------------ + case 914: { tmc2130_mode = TMC2130_MODE_NORMAL; update_mode_profile(); @@ -7865,9 +7978,10 @@ Sigma_Exit: } break; - //! ### M915 - Set TMC2130 silent mode G32: Undock Z Probe sled - // ------------------------------ - case 915: + /*! + ### M915 - Set TMC2130 silent mode G32: Undock Z Probe sled + */ ------------------------------ + case 915: { tmc2130_mode = TMC2130_MODE_SILENT; update_mode_profile(); @@ -7875,8 +7989,9 @@ Sigma_Exit: } break; - //! ### M916 - Set TMC2130 Stallguard sensitivity threshold G32: Undock Z Probe sled - // ------------------------------------------------------- + /*! + ### M916 - Set TMC2130 Stallguard sensitivity threshold G32: Undock Z Probe sled + */ ------------------------------------------------------- case 916: { if (code_seen('X')) tmc2130_sg_thr[X_AXIS] = code_value(); @@ -7888,8 +8003,9 @@ Sigma_Exit: } break; - //! ### M917 - Set TMC2130 PWM amplitude offset (pwm_ampl) G32: Undock Z Probe sled - // -------------------------------------------------------------- + /*! + ### M917 - Set TMC2130 PWM amplitude offset (pwm_ampl) G32: Undock Z Probe sled + */ -------------------------------------------------------------- case 917: { if (code_seen('X')) tmc2130_set_pwm_ampl(0, code_value()); @@ -7899,8 +8015,9 @@ Sigma_Exit: } break; - //! ### M918 - Set TMC2130 PWM amplitude gradient (pwm_grad) G32: Undock Z Probe sled - // ------------------------------------------------------------- + /*! + ### M918 - Set TMC2130 PWM amplitude gradient (pwm_grad) G32: Undock Z Probe sled + */ ------------------------------------------------------------- case 918: { if (code_seen('X')) tmc2130_set_pwm_grad(0, code_value()); @@ -7912,9 +8029,10 @@ Sigma_Exit: #endif //TMC2130_SERVICE_CODES_M910_M918 - //! ### M350 - Set microstepping mode G32: Undock Z Probe sled - // --------------------------------------------------- - //! Warning: Steps per unit remains unchanged. S code sets stepping mode for all drivers. + /*! + ### M350 - Set microstepping mode M350: Set microstepping mode + Warning: Steps per unit remains unchanged. S code sets stepping mode for all drivers. + */ --------------------------------------------------- case 350: { #ifdef TMC2130 @@ -7953,11 +8071,12 @@ Sigma_Exit: } break; - //! ### M351 - Toggle Microstep Pins G32: Undock Z Probe sled - // ----------------------------------- - //! Toggle MS1 MS2 pins directly, S# determines MS1 or MS2, X# sets the pin high/low. - //! - //! M351 [B<0|1>] [E<0|1>] S<1|2> [X<0|1>] [Y<0|1>] [Z<0|1>] + /*! + ### M351 - Toggle Microstep Pins M351: Toggle MS1 MS2 pins directly + Toggle MS1 MS2 pins directly, S# determines MS1 or MS2, X# sets the pin high/low. + + M351 [B<0|1>] [E<0|1>] S<1|2> [X<0|1>] [Y<0|1>] [Z<0|1>] + */ ----------------------------------- case 351: { #if defined(X_MS1_PIN) && X_MS1_PIN > -1 @@ -7977,8 +8096,10 @@ Sigma_Exit: } break; - //! ### M701 - Load filament G32: Undock Z Probe sled - // ------------------------- + /*! + ### M701 - Load filament M701: Load filament + + */ ------------------------- case 701: { if (mmu_enabled && code_seen('E')) @@ -7987,16 +8108,15 @@ Sigma_Exit: } break; - //! ### M702 - Unload filament G32: Undock Z Probe sled - // ------------------------ - /*! + /*! + ### M702 - Unload filament G32: Undock Z Probe sled - M702 [U C] + M702 [ U | C] - - `U` Unload all filaments used in current print - - `C` Unload just current filament + - `U` - Unload all filaments used in current print + - `C` - Unload just current filament - without any parameters unload all filaments - */ + */ ------------------------ case 702: { #ifdef SNMM @@ -8019,14 +8139,18 @@ Sigma_Exit: } break; - //! ### M999 - Restart after being stopped G32: Undock Z Probe sled - // ------------------------------------ + /*! + ### M999 - Restart after being stopped M999: Restart after being stopped by error + */ ------------------------------------ case 999: Stopped = false; lcd_reset_alert_level(); gcode_LastN = Stopped_gcode_LastN; FlushSerialRequestResend(); break; + /*! + #### End of M-Commands + */ ------------------------------------ default: printf_P(PSTR("Unknown M code: %s \n"), cmdbuffer + bufindr + CMDHDRSIZE); } @@ -8231,6 +8355,9 @@ Sigma_Exit: } } } // end if(code_seen('T')) (end of T codes) + /*! + #### End of T-Codes + */ /** *--------------------------------------------------------------------------------- @@ -8460,7 +8587,9 @@ Sigma_Exit: ClearToSend(); } - +/*! +#### End of D-Codes +*/ /** @defgroup GCodes G-Code List */ From 5bd995b21b12448cf487619c2757bc80b854b4bf Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Wed, 6 Nov 2019 11:14:06 +0100 Subject: [PATCH 075/180] Added more info to doxygen G-Codes --- Firmware/Marlin_main.cpp | 169 ++++++++++++++++++++++++++++++++------- 1 file changed, 139 insertions(+), 30 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 759df56f0..9a048d533 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3510,7 +3510,6 @@ void process_commands() --------------------------------------------------------------------------------- ### M117 - Display Message M117: Display Message - This causes the given message to be shown in the status line on an attached LCD. It is also used by internal to display status messages on LCD. @@ -3643,9 +3642,11 @@ void process_commands() ### PRUSA - Internal command set G98: Activate farm mode - Notes Set of internal PRUSA commands - + #### Usage + P RUSA [ Ping | PRN | FAN | fn | thx | uvlo | fsensor_recover | MMURES | RESET | fv | M28 | SN | Fir | Rev | Lang | Lz | Beat | FR ] - + + #### Parameters - `Ping` - `PRN` - Prints revision of the printer - `FAN` - Prints fan details @@ -3859,7 +3860,20 @@ eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,0xFFFF); /*! --------------------------------------------------------------------------------- # G Codes - ### G0, G1 - Coordinated movement X Y Z E G0 & G1: Move + ### G0, G1 - Coordinated movement X Y Z E G0 & G1: Move + In Prusa Frimware G0 and G1 are the same. + #### Usage + + G0 [ X | Y | Z | E | F | S ] + G1 [ X | Y | Z | E | F | S ] + + #### Parameters + - `X` - The position to move to on the X axis + - `Y` - The position to move to on the Y axis + - `Z` - The position to move to on the Z axis + - `E` - The amount to extrude between the starting point and ending point + - `F` - The feedrate per minute of the move between the starting point and ending point (if supplied) + */ -------------------------------------- case 0: // G0 -> G1 case 1: // G1 @@ -4060,7 +4074,21 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; /*! - ### G2 - CW ARC G2 & G3: Controlled Arc Move + ### G2, G3 - Controlled Arc Move G2 & G3: Controlled Arc Move + + #### Usage + + G2 [ X | Y | I | E | F ] (Clockwise Arc) + G3 [ X | Y | I | E | F ] (Counter-Clockwise Arc) + + #### Parameters + - `X` - The position to move to on the X axis + - `Y` - The position to move to on the Y axis + - `I` - The point in X space from the current X position to maintain a constant distance from + - `J` - The point in Y space from the current Y position to maintain a constant distance from + - `E` - The amount to extrude between the starting point and ending point + - `F` - The feedrate per minute of the move between the starting point and ending point (if supplied) + */ ------------------------------ case 2: if(Stopped == false) { @@ -4069,10 +4097,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; - - /*! - ### G3 - CCW ARC G2 & G3: Controlled Arc Move - */ ------------------------------- + // ------------------------------- case 3: if(Stopped == false) { get_arc_coordinates(); @@ -4083,6 +4108,16 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G4 - Dwell G4: Dwell + Pause the machine for a period of time. + + #### Usage + + G4 [ P | S ] + + #### Parameters + - `P` - Time to wait, in milliseconds + - `S` - Time to wait, in seconds + */ ------------------------------- case 4: codenum = 0; @@ -4103,6 +4138,12 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G10 - Retract G10: Retract + Retracts filament according to settings of `M207` + + #### Usage + + G10 + */ ------------------------------ case 10: #if EXTRUDERS > 1 @@ -4116,6 +4157,11 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G11 - Retract recover G11: Unretract + Unretracts/recovers filament according to settings of `M208` + #### Usage + + G11 + */ ----------------------------- case 11: #if EXTRUDERS > 1 @@ -4129,10 +4175,12 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G28 - Home all Axis one at a time G28: Move to Origin (Home) - Unsing G28 without any paramters will perfom on the Prusa i3 printers home AND mesh bed leveling, while the default G-code G28 is just homeing the printer - + Unsing `G28` without any paramters will perfom on the Prusa i3 printers home AND mesh bed leveling, while `G28 W` will just home the printer + #### Usage + G28 [ X | Y | Z | W | C ] + #### Parameters - `X` - Flag to go back to the X axis origin - `Y` - Flag to go back to the Y axis origin - `Z` - Flag to go back to the Z axis origin @@ -4173,7 +4221,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G29 - Detailed Z-Probe G29: Detailed Z-Probe - See G81 + In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code. + + See `G81` */ -------------------------------- case 29: { @@ -4321,6 +4371,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G30 - Single Z Probe G30: Single Z-Probe + In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code. */ ------------------------------------ case 30: { @@ -4347,6 +4398,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G31 - Dock the sled G31: Dock Z Probe sled + In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code. */ --------------------------- case 31: dock_sled(true); @@ -4355,6 +4407,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G32 - Undock the sled G32: Undock Z Probe sled + In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code. */ ---------------------------- case 32: dock_sled(false); @@ -4386,6 +4439,10 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G75 - Print temperature interpolation G75: Print temperature interpolation Show/print PINDA temperature interpolating. + #### Usage + + G75 + */ --------------------------------------------- case 75: { @@ -4401,6 +4458,21 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) The PINDAv2 sensor has a built-in thermistor which has the advantage that the calibration can be done once for all materials. The Original i3 Prusa MK2/s uses PINDAv1 and this calibration improves the temperature drift, but not as good as the PINDAv2. + + #### Usage + + G76 + + #### Example + + ``` + G76 + + echo PINDA probe calibration start + echo start temperature: 35.0° + echo ... + echo PINDA temperature -- Z shift (mm): 0.--- + ``` */ ------------------------------------------------ case 76: @@ -4663,15 +4735,17 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G80 - Mesh-based Z probe G80: Mesh-based Z probe Default 3x3 grid can be changed on MK2.5/s and MK3/s to 7x7 grid. - + #### Usage + G80 [ N | R | V | L | R | F | B ] + #### Parameters - `N` - Number of mesh points on x axis. Default is 3. Valid values are 3 and 7. - `R` - Probe retries. Default 3 max. 10 - `V` - Verbosity level 1=low, 10=mid, 20=high. It can be only used if firmware has been compiled with SUPPORT_VERBOSITY active. Using the following parameters enables additional "manual" bed leveling correction. Valid values are -100 microns to 100 microns. - + #### Additional Parameters - `L` - Left Bed Level correct value in um. - `R` - Right Bed Level correct value in um. - `F` - Front Bed Level correct value in um. @@ -5107,13 +5181,12 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G81 - Mesh bed leveling status G81: Mesh bed leveling status - Prints mesh bed leveling status and bed profile if activated. + #### Usage + + G81 + */ ----------------------------------------- - - /* - * Prints mesh bed leveling status and bed profile if activated - */ case 81: if (mbl.active) { SERIAL_PROTOCOLPGM("Num X,Y: "); @@ -5140,7 +5213,8 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) ### G82: Single Z probe at current location - Not active G82: Single Z probe at current location WARNING! USE WITH CAUTION! If you'll try to probe where is no leveling pad, nasty things can happen! - */ + In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code. + */ ----------------------------------------- case 82: SERIAL_PROTOCOLLNPGM("Finding bed "); int l_feedmultiply = setup_for_endstop_move(); @@ -5151,9 +5225,10 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) SERIAL_PROTOCOLPGM("\n"); break; - /*! - ### G83: Babystep in Z and store to EEPROM - Not active G83: Babystep in Z and store to EEPROM - */ + /*! + ### G83: Babystep in Z and store to EEPROM - Not active G83: Babystep in Z and store to EEPROM + In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code. + */ ----------------------------------------- case 83: { int babystepz = code_seen('S') ? code_value() : 0; @@ -5178,7 +5253,8 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; /*! ### G84: UNDO Babystep Z (move Z axis back) - Not active G84: UNDO Babystep Z (move Z axis back) - */ + In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code. + */ ----------------------------------------- case 84: babystepsTodoZsubtract(babystepLoadZ); // babystepLoadZ = 0; @@ -5186,7 +5262,8 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G85: Pick best babystep - Not active G87: Enable babystep correction after home - This G-code will be performed at the end of a calibration script. (Prusa3D specific) */ @@ -5214,7 +5290,6 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) calibration_status_store(CALIBRATION_STATUS_CALIBRATED); break; - /*! ### G88 - Reserved G88: Reserved @@ -5231,19 +5306,42 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G90 - Switch off relative mode G90: Set to Absolute Positioning + #### Usage + + G90 + + All coordinates from now on are absolute relative to the origin of the machine. */ ------------------------------- case 90: relative_mode = false; break; /*! ### G91 - Switch on relative mode G91: Set to Relative Positioning - */ ------------------------------- + #### Usage + + G91 + + All coordinates from now on are relative to the last position. + */ ------------------------------- case 91: relative_mode = true; break; /*! ### G92 - Set position G92: Set Position + #### Usage + + G92 [ X | Y | Z | E ] + + #### Parameters + - `X` - new X axis position + - `Y` - new Y axis position + - `Z` - new Z axis position + - `E` - new extruder position + + Allows programming of absolute zero point, by reseting the current position to the values specified. This would set the machine's X coordinate to 10, and the extrude coordinate to 90. No physical motion will occur. + + A G92 without coordinates will reset all axes to zero on some firmware. */ ----------------------------- case 92: if(!code_seen(axis_codes[E_AXIS])) @@ -5265,6 +5363,12 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G98 - Activate farm mode G98: Activate farm mode + Enable Prusa-specific Farm functions and g-code. + #### Usage + + G98 + + See Internal Prusa commands */ ----------------------------------- case 98: farm_mode = 1; @@ -5277,7 +5381,12 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; /*! ### G99 - Deactivate farm mode G99: Deactivate farm mode - */ ------------------------------------- + Disables Prusa-specific Farm functions and g-code. + #### Usage + + G99 + + */ ------------------------------------- case 99: farm_mode = 0; lcd_printer_connected(); @@ -5292,7 +5401,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) gcode_in_progress = 0; } // end if(code_seen('G')) /*! - #### End of G-Codes + ### End of G-Codes */ /*! From 28e812d91fe2b4633c9427abdf554e5a9449dd17 Mon Sep 17 00:00:00 2001 From: leptun Date: Wed, 2 Oct 2019 17:34:09 +0300 Subject: [PATCH 076/180] Mesh bed leveling testing --- Firmware/Marlin_main.cpp | 10 +++------- Firmware/mesh_bed_calibration.cpp | 8 ++++---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 45dd118c4..f65ec4b68 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -4767,11 +4767,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) z_offset_u = eeprom_read_word((uint16_t*)(EEPROM_BED_CALIBRATION_Z_JITTER + 2 * (ix + iy * 3 - 1))); } z0 = mbl.z_values[0][0] + *reinterpret_cast(&z_offset_u) * 0.01; - #ifdef SUPPORT_VERBOSITY - if (verbosity_level >= 1) { - printf_P(PSTR("Bed leveling, point: %d, calibration Z stored in eeprom: %d, calibration z: %f \n"), mesh_point, z_offset_u, z0); - } - #endif // SUPPORT_VERBOSITY + // printf_P(PSTR("Bed leveling, point: %d, calibration Z stored in eeprom: %d, calibration z: %f \n"), mesh_point, z_offset_u, z0); } // Move Z up to MESH_HOME_Z_SEARCH. @@ -4798,7 +4794,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]); #endif // SUPPORT_VERBOSITY - //printf_P(PSTR("after clamping: [%f;%f]\n"), current_position[X_AXIS], current_position[Y_AXIS]); + printf_P(PSTR("after clamping: [%f;%f]\n"), current_position[X_AXIS], current_position[Y_AXIS]); plan_buffer_line_curposXYZE(XY_AXIS_FEEDRATE, active_extruder); st_synchronize(); @@ -4809,7 +4805,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; } if (init_z_bckp - current_position[Z_AXIS] < 0.1f) { //broken cable or initial Z coordinate too low. Go to MESH_HOME_Z_SEARCH and repeat last step (z-probe) again to distinguish between these two cases. - //printf_P(PSTR("Another attempt! Current Z position: %f\n"), current_position[Z_AXIS]); + printf_P(PSTR("Another attempt! Current Z position: %f\n"), current_position[Z_AXIS]); current_position[Z_AXIS] = MESH_HOME_Z_SEARCH; plan_buffer_line_curposXYZE(Z_LIFT_FEEDRATE, active_extruder); st_synchronize(); diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index 88cbc671a..fed100e68 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -991,7 +991,7 @@ inline bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, i update_current_position_z(); //printf_P(PSTR("Zs: %f, Z: %f, delta Z: %f"), z_bckp, current_position[Z_AXIS], (z_bckp - current_position[Z_AXIS])); if (abs(current_position[Z_AXIS] - z_bckp) < 0.025) { - //printf_P(PSTR("PINDA triggered immediately, move Z higher and repeat measurement\n")); + printf_P(PSTR("PINDA triggered immediately, move Z higher and repeat measurement\n")); current_position[Z_AXIS] += 0.5; go_to_current(homing_feedrate[Z_AXIS]/60); current_position[Z_AXIS] = minimum_z; @@ -1019,10 +1019,10 @@ inline bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, i float dz = i?abs(current_position[Z_AXIS] - (z / i)):0; z += current_position[Z_AXIS]; //printf_P(PSTR("Z[%d] = %d, dz=%d\n"), i, (int)(current_position[Z_AXIS] * 1000), (int)(dz * 1000)); - //printf_P(PSTR("Z- measurement deviation from avg value %f um\n"), dz); + printf_P(PSTR("Z- measurement deviation from avg value %f um\n"), dz); if (dz > 0.05) { //deviation > 50um if (high_deviation_occured == false) { //first occurence may be caused in some cases by mechanic resonance probably especially if printer is placed on unstable surface - //printf_P(PSTR("high dev. first occurence\n")); + printf_P(PSTR("high dev. first occurence\n")); delay_keep_alive(500); //damping //start measurement from the begining, but this time with higher movements in Z axis which should help to reduce mechanical resonance high_deviation_occured = true; @@ -1033,7 +1033,7 @@ inline bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, i goto error; } } - //printf_P(PSTR("PINDA triggered at %f\n"), current_position[Z_AXIS]); + printf_P(PSTR("PINDA triggered at %f\n"), current_position[Z_AXIS]); } current_position[Z_AXIS] = z; if (n_iter > 1) From 84cb37390570e0bc624cac83599eb64abb7f5476 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Tue, 26 Nov 2019 20:11:55 +0100 Subject: [PATCH 077/180] More G codes documented in RR wiki M44, M45, M47, M403, M509, M851, M601, M602, M603, M862 --- Firmware/Marlin_main.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index c6e9783c5..5ffb54602 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -5739,7 +5739,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! - ### M44 - Reset the bed skew and offset calibrationM44: Reset the bed skew and offset calibration + ### M44 - Reset the bed skew and offset calibration M44: Reset the bed skew and offset calibration */ -------------------------------------------------------------------- case 44: // M44: Prusa3D: Reset the bed skew and offset calibration. @@ -5756,9 +5756,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; /*! - ### M45 - Bed skew and offset with manual Z upM45: Bed skew and offset with manual Z up + ### M45 - Bed skew and offset with manual Z up M45: Bed skew and offset with manual Z up - G80 [ V ] + M45 [ V ] - `V` - Verbosity level 1, 10 and 20 (low, mid, high). Only when SUPPORT_VERBOSITY is defined. */ ------------------------------------------------------ case 45: // M45: Prusa3D: bed skew and offset with manual Z up @@ -5777,8 +5777,11 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; + /*! + ### M46 - Show the assigned IP address M46: Show the assigned IP address. + */ ---------------------------------------------------- /* - case 46: + case 46: { // M46: Prusa3D: Show the assigned IP address. uint8_t ip[4]; @@ -5801,7 +5804,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) */ /*! - ### M47 - Show end stops dialog on the displayM47: Show end stops dialog on the display + ### M47 - Show end stops dialog on the display M47: Show end stops dialog on the display */ ---------------------------------------------------- case 47: @@ -5851,7 +5854,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) #ifdef Z_PROBE_REPEATABILITY_TEST /*! - ### M48 - Z-Probe repeatability measurement function. M48: Measure Z-Probe repeatability + ### M48 - Z-Probe repeatability measurement function M48: Measure Z-Probe repeatability This function assumes the bed has been homed. Specifically, that a G28 command as been issued prior to invoking the M48 Z-Probe repeatability measurement function. Any information generated by a prior G29 Bed leveling command will be lost and need to be regenerated. @@ -7485,7 +7488,7 @@ Sigma_Exit: break; /*! - ### M403 - Set filament type (material) for particular extruder and notify the MMU M403 - Set filament type (material) for particular extruder and notify the MMU + ### M403 - Set filament type (material) for particular extruder and notify the MMU M403 - Set filament type (material) for particular extruder and notify the MMU M403 [ E | F ] @@ -7724,7 +7727,7 @@ Sigma_Exit: #endif //FILAMENTCHANGEENABLE /*! - ### M601 - Pause print G32: Undock Z Probe sled + ### M601 - Pause print M601: Pause print */ ------------------------------- case 601: { @@ -7734,7 +7737,7 @@ Sigma_Exit: break; /*! - ### M602 - Resume print G32: Undock Z Probe sled + ### M602 - Resume print M602: Resume print */ ------------------------------- case 602: { lcd_resume_print(); @@ -7742,7 +7745,7 @@ Sigma_Exit: break; /*! - ### M603 - Stop print G32: Undock Z Probe sled + ### M603 - Stop print M603: Stop print */ ------------------------------- case 603: { lcd_print_stop(); @@ -7889,14 +7892,14 @@ Sigma_Exit: #endif //PINDA_THERMISTOR /*! - ### M862 - Print checking G32: Undock Z Probe sled + ### M862 - Print checking M862: Print checking Checks the parameters of the printer and gcode and performs compatibility check - - M862.1 { P | Q } + - M862.1 { P | Q } 0.25/0.40/0.60 - M862.2 { P | Q } - M862.3 { P"" | Q } - M862.4 { P | Q } - - M862.5 { P | Q } + - M862.5 { P | Q } 0 = none, 1 = warn, 2 = strict When run with P<> argument, the check is performed against the input value. When run with Q argument, the current value is shown. @@ -7920,7 +7923,7 @@ Sigma_Exit: - MK3 (300) - MK3MMU2 (20300) - MK3S (302) - - MK3SMMU2S (20302) + - MK3SMMU2S (20302) */ ---------------------------------------------- case 862: // M862: print checking From 475551431c494572d30011126ee698b429df0230 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Tue, 26 Nov 2019 20:21:05 +0100 Subject: [PATCH 078/180] How does M862.5 P works??? --- Firmware/Marlin_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 5ffb54602..394c818c6 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -7899,7 +7899,7 @@ Sigma_Exit: - M862.2 { P | Q } - M862.3 { P"" | Q } - M862.4 { P | Q } - - M862.5 { P | Q } 0 = none, 1 = warn, 2 = strict + - M862.5 { P | Q } When run with P<> argument, the check is performed against the input value. When run with Q argument, the current value is shown. From 660b646b57a5bd6404549d69ccfab291af250bf8 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Wed, 27 Nov 2019 11:29:55 +0100 Subject: [PATCH 079/180] RR Wiki for Dcodes open D-1, D80, D81, D106, D2130 --- Firmware/Dcodes.cpp | 146 +++++++++++++++++++++++++++++++++- Firmware/Marlin_main.cpp | 164 ++++++++++++++++++++++++++++++++------- 2 files changed, 283 insertions(+), 27 deletions(-) diff --git a/Firmware/Dcodes.cpp b/Firmware/Dcodes.cpp index d2016ded5..86dd1aa4a 100644 --- a/Firmware/Dcodes.cpp +++ b/Firmware/Dcodes.cpp @@ -99,7 +99,19 @@ void print_mem(uint32_t address, uint16_t count, uint8_t type, uint8_t countperl #ifdef DEBUG_DCODE3 #define EEPROM_SIZE 0x1000 -void dcode_3() + /*! + * + ### D3 - Read/Write EEPROM D3: Read/Write EEPROM + This command can be used without any additional parameters. It will read the entire eeprom. + + D3 [ A | C | X ] + + - `A` - Address (0x0000-0x0fff) + - `C` - Count (0x0001-0x1000) + - `X` - Data + * + */ + void dcode_3() { DBG(_N("D3 - Read/Write EEPROM\n")); uint16_t address = 0x0000; //default 0x0000 @@ -176,6 +188,14 @@ extern float axis_steps_per_unit[NUM_AXIS]; #endif //0 #define LOG(args...) + /*! + * + ### D-1 - Endless Loop D-1: Endless Loop + + D-1 + + * + */ void dcode__1() { printf_P(PSTR("D-1 - Endless loop\n")); @@ -185,6 +205,15 @@ void dcode__1() #ifdef DEBUG_DCODES + /*! + * + ### D0 - Reset D0: Reset + + D0 [ B ] + + - `B` - Bootloader + * + */ void dcode_0() { if (*(strchr_pointer + 1) == 0) return; @@ -203,6 +232,14 @@ void dcode_0() } } + /*! + * + ### D1 - Clear EEPROM and RESET D1: Clear EEPROM and RESET + + D1 + + * + */ void dcode_1() { LOG("D1 - Clear EEPROM and RESET\n"); @@ -213,6 +250,18 @@ void dcode_1() while(1); } + /*! + * + ### D2 - Read/Write RAM D3: Read/Write RAM + This command can be used without any additional parameters. It will read the entire eeprom. + + D3 [ A | C | X ] + + - `A` - Address (0x0000-0x1fff) + - `C` - Count (0x0001-0x2000) + - `X` - Data + * + */ void dcode_2() { LOG("D2 - Read/Write RAM\n"); @@ -256,6 +305,19 @@ void dcode_2() }*/ } + /*! + * + ### D4 - Read/Write PIN D4: Read/Write PIN + + To read the digital value of a pin you need only to define the pin number. + + D4 [ P | F | V ] + + - `P` - Pin (0-255) + - `F` - Function in/out (0/1) + - `V` - Value (0/1) + * + */ void dcode_4() { LOG("D4 - Read/Write PIN\n"); @@ -288,6 +350,19 @@ void dcode_4() #ifdef DEBUG_DCODE5 + /*! + * + ### D5 - Read/Write FLASH D5: Read/Write Flash + This command can be used without any additional parameters. It will read the 1kb FLASH. + + D3 [ A | C | X | E ] + + - `A` - Address (0x00000-0x3ffff) + - `C` - Count (0x0001-0x2000) + - `X` - Data + - `E` - Erase + * + */ void dcode_5() { printf_P(PSTR("D5 - Read/Write FLASH\n")); @@ -351,11 +426,25 @@ void dcode_5() #ifdef DEBUG_DCODES + /*! + * + ### D6 - Read/Write external FLASH D6: Read/Write external Flash + + Reserved + * + */ void dcode_6() { LOG("D6 - Read/Write external FLASH\n"); } + /*! + * + ### D7 - Read/Write Bootloader D7: Read/Write Bootloader + + Reserved + * + */ void dcode_7() { LOG("D7 - Read/Write Bootloader\n"); @@ -371,6 +460,18 @@ void dcode_7() */ } + /*! + * + ### D8 - Read/Write PINDA D8: Read/Write PINDA + + D8 [ ? | ! | P | Z ] + + - `?` - Read PINDA temperature shift values + - `!` - Reset PINDA temperature shift values to default + - `P` - Pinda temperature [C] + - `Z` - Z Offset [mm] + * + */ void dcode_8() { printf_P(PSTR("D8 - Read/Write PINDA\n")); @@ -412,6 +513,23 @@ void dcode_8() printf_P(PSTR("temp_pinda=%d offset_z=%d.%03d\n"), (int)temp_pinda, (int)offset_z, ((int)(1000 * offset_z) % 1000)); } + /*! + * + ### D9 - Read ADC D9: Read ADC + + D9 [ I | V ] + + - `I` - ADC channel index + - `0` - Heater 0 temperature + - `1` - Heater 1 temperature + - `2` - Bed temperature + - `3` - PINDA temperature + - `4` - PWR voltage + - `5` - Ambient temperature + - `6` - BED voltage + - `V` Value to be written as simulated + * + */ const char* dcode_9_ADC_name(uint8_t i) { switch (i) @@ -485,12 +603,24 @@ void dcode_9() } } + /*! + * + ### D10 - Set XYZ calibration = OK D10: Set XYZ calibration = OK + + * + */ void dcode_10() {//Tell the printer that XYZ calibration went OK LOG("D10 - XYZ calibration = OK\n"); calibration_status_store(CALIBRATION_STATUS_LIVE_ADJUST); } + /*! + * + ### D12 - Time D12: Time + + * + */ void dcode_12() {//Time LOG("D12 - Time\n"); @@ -636,6 +766,20 @@ void dcode_2130() #endif //TMC2130 #ifdef PAT9125 + /*! + * + ### D9125 - PAT9125 filament sensor D9125: PAT9125 filament sensor + + D9125 [ ? | ! | R | X | Y | L ] + + - `?` - Print values + - `!` - Print values + - `R` - Resolution. Not active in code + - `X` - X values + - `Y` - Y values + - `L` - Activate filament sensor log + * + */ void dcode_9125() { LOG("D9125 - PAT9125\n"); diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 394c818c6..2674ba829 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -8517,73 +8517,173 @@ Sigma_Exit: switch((int)code_value()) { - //! ### D-1 - Endless loop - // ------------------- + /*! + * + ### D-1 - Endless Loop D-1: Endless Loop + + D-1 + + * + */ case -1: dcode__1(); break; #ifdef DEBUG_DCODES - //! ### D0 - Reset - // -------------- + /*! + * + ### D0 - Reset D0: Reset + + D0 [ B ] + + - `B` - Bootloader + * + */ case 0: dcode_0(); break; - //! ### D1 - Clear EEPROM - // ------------------ + /*! + * + ### D1 - Clear EEPROM and RESET D1: Clear EEPROM and RESET + + D1 + + * + */ case 1: dcode_1(); break; - //! ### D2 - Read/Write RAM - // -------------------- + /*! + * + ### D2 - Read/Write RAM D3: Read/Write RAM + This command can be used without any additional parameters. It will read the entire eeprom. + + D3 [ A | C | X ] + + - `A` - Address (0x0000-0x1fff) + - `C` - Count (0x0001-0x2000) + - `X` - Data + * + */ case 2: dcode_2(); break; #endif //DEBUG_DCODES #ifdef DEBUG_DCODE3 - //! ### D3 - Read/Write EEPROM - // ----------------------- + /*! + * + ### D3 - Read/Write EEPROM D3: Read/Write EEPROM + This command can be used without any additional parameters. It will read the entire eeprom. + + D3 [ A | C | X ] + + - `A` - Address (0x0000-0x0fff) + - `C` - Count (0x0001-0x1000) + - `X` - Data + * + */ case 3: dcode_3(); break; #endif //DEBUG_DCODE3 #ifdef DEBUG_DCODES - //! ### D4 - Read/Write PIN - // --------------------- + /*! + * + ### D4 - Read/Write PIN D4: Read/Write PIN + + To read the digital value of a pin you need only to define the pin number. + + D4 [ P | F | V ] + + - `P` - Pin (0-255) + - `F` - Function in/out (0/1) + - `V` - Value (0/1) + * + */ case 4: dcode_4(); break; #endif //DEBUG_DCODES #ifdef DEBUG_DCODE5 - //! ### D5 - Read/Write FLASH - // ------------------------ + /*! + * + ### D5 - Read/Write FLASH D5: Read/Write Flash + This command can be used without any additional parameters. It will read the 1kb FLASH. + + D3 [ A | C | X | E ] + + - `A` - Address (0x00000-0x3ffff) + - `C` - Count (0x0001-0x2000) + - `X` - Data + - `E` - Erase + * + */ case 5: dcode_5(); break; break; #endif //DEBUG_DCODE5 #ifdef DEBUG_DCODES - //! ### D6 - Read/Write external FLASH - // --------------------------------------- + /*! + * + ### D6 - Read/Write external FLASH D6: Read/Write external Flash + + Reserved + * + */ case 6: dcode_6(); break; - //! ### D7 - Read/Write Bootloader - // ------------------------------- + /*! + * + ### D7 - Read/Write Bootloader D7: Read/Write Bootloader + + Reserved + * + */ case 7: dcode_7(); break; - //! ### D8 - Read/Write PINDA - // --------------------------- + /*! + * + ### D8 - Read/Write PINDA D8: Read/Write PINDA + + D8 [ ? | ! | P | Z ] + + - `?` - Read PINDA temperature shift values + - `!` - Reset PINDA temperature shift values to default + - `P` - Pinda temperature [C] + - `Z` - Z Offset [mm] + * + */ case 8: dcode_8(); break; - // ### D9 - Read/Write ADC - // ------------------------ + /*! + * + ### D9 - Read ADC D9: Read ADC + + D9 [ I | V ] + + - `I` - ADC channel index + - `0` - Heater 0 temperature + - `1` - Heater 1 temperature + - `2` - Bed temperature + - `3` - PINDA temperature + - `4` - PWR voltage + - `5` - Ambient temperature + - `6` - BED voltage + - `V` Value to be written as simulated + * + */ case 9: dcode_9(); break; - //! ### D10 - XYZ calibration = OK - // ------------------------------ + /*! + * + ### D10 - Set XYZ calibration = OK D10: Set XYZ calibration = OK + + * + */ case 10: dcode_10(); break; #endif //DEBUG_DCODES @@ -8715,8 +8815,20 @@ Sigma_Exit: #if (defined (FILAMENT_SENSOR) && defined(PAT9125)) - //! ### D9125 - FILAMENT_SENSOR - // --------------------------------- + /*! + * + ### D9125 - PAT9125 filament sensor D9125: PAT9125 filament sensor + + D9125 [ ? | ! | R | X | Y | L ] + + - `?` - Print values + - `!` - Print values + - `R` - Resolution. Not active in code + - `X` - X values + - `Y` - Y values + - `L` - Activate filament sensor log + * + */ case 9125: dcode_9125(); break; #endif //FILAMENT_SENSOR From 3ce631052dbda683c3666b268bceadc688aea63c Mon Sep 17 00:00:00 2001 From: unknown <3d.gussner@gmail.com> Date: Fri, 29 Nov 2019 22:35:07 +0100 Subject: [PATCH 080/180] Set PF-build.sh to use v1.0.2 Arduino_Boards --- PF-build.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/PF-build.sh b/PF-build.sh index 7f538ea09..984df8a58 100755 --- a/PF-build.sh +++ b/PF-build.sh @@ -213,12 +213,12 @@ fi #### Set build environment ARDUINO_ENV="1.8.5" BUILD_ENV="1.0.6" -BOARD="rambo" +BOARD="prusa_einsy_rambo" BOARD_PACKAGE_NAME="PrusaResearchRambo" -BOARD_VERSION="1.0.1" +BOARD_VERSION="1.0.2" BOARD_URL="https://raw.githubusercontent.com/prusa3d/Arduino_Boards/master/IDE_Board_Manager/package_prusa3d_index.json" -BOARD_FILENAME="prusa3drambo" -BOARD_FILE_URL="https://raw.githubusercontent.com/prusa3d/Arduino_Boards/master/IDE_Board_Manager/prusa3drambo-1.0.1.tar.bz2" +BOARD_FILENAME="prusa3dboards" +BOARD_FILE_URL="https://raw.githubusercontent.com/prusa3d/Arduino_Boards/master/IDE_Board_Manager/prusa3dboards-1.0.2.tar.bz2" PF_BUILD_FILE_URL="https://github.com/3d-gussner/PF-build-env/releases/download/$BUILD_ENV/PF-build-env-$BUILD_ENV.zip" LIB="PrusaLibrary" SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )" From 0ce7c51c1d8b96e6b10cc53bdd0b5cd520aeba1e Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Tue, 3 Dec 2019 20:02:58 +0100 Subject: [PATCH 081/180] Added more D-codes to RR Wiki and doxygen D-1, D80, D81, D106 --- Firmware/Dcodes.cpp | 2 +- Firmware/Marlin_main.cpp | 72 ++++++++++++++++++++++++++-------------- 2 files changed, 48 insertions(+), 26 deletions(-) diff --git a/Firmware/Dcodes.cpp b/Firmware/Dcodes.cpp index 86dd1aa4a..9649d62bb 100644 --- a/Firmware/Dcodes.cpp +++ b/Firmware/Dcodes.cpp @@ -253,7 +253,7 @@ void dcode_1() /*! * ### D2 - Read/Write RAM D3: Read/Write RAM - This command can be used without any additional parameters. It will read the entire eeprom. + This command can be used without any additional parameters. It will read the entire RAM. D3 [ A | C | X ] diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 2674ba829..ec3102fd8 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -5574,10 +5574,13 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; /*! - ### M26 S\ - Set SD index M26: Set SD position + ### M26 - Set SD index M26: Set SD position Set position in SD card file to index in bytes. This command is expected to be called after M23 and before M24. Otherwise effect of this command is undefined. + M26 [ S ] + + - `S` - Index in bytes */ ---------------------------------- case 26: if(card.cardOK && code_seen('S')) { @@ -8519,7 +8522,7 @@ Sigma_Exit: /*! * - ### D-1 - Endless Loop D-1: Endless Loop + ### D-1 - Endless Loop D-1: Endless Loop D-1 @@ -8555,7 +8558,7 @@ Sigma_Exit: /*! * ### D2 - Read/Write RAM D3: Read/Write RAM - This command can be used without any additional parameters. It will read the entire eeprom. + This command can be used without any additional parameters. It will read the entire RAM. D3 [ A | C | X ] @@ -8682,22 +8685,35 @@ Sigma_Exit: * ### D10 - Set XYZ calibration = OK D10: Set XYZ calibration = OK - * - */ + * + */ case 10: dcode_10(); break; + + /*! + * + ### D12 - Time D12: Time + + Writes the actual time in the log file. + * + */ + #endif //DEBUG_DCODES #ifdef HEATBED_ANALYSIS - //! ### D80 - Bed check - // --------------------- - /*! - - `E` - dimension x - - `F` - dimention y - - `G` - points_x - - `H` - points_y - - `I` - offset_x - - `J` - offset_y + /*! + * + ### D80 - Bed check D80: Bed check + This command will log data to SD card file "mesh.txt". + + D80 [ E | F | G | H | I | J ] + + - `E` - Dimension X (default 40) + - `F` - Dimention Y (default 40) + - `G` - Points X (default 40) + - `H` - Points Y (default 40) + - `I` - Offset X (default 74) + - `J` - Offset Y (default 34) */ case 80: { @@ -8723,15 +8739,19 @@ Sigma_Exit: bed_check(dimension_x,dimension_y,points_x,points_y,offset_x,offset_y); }break; - //! ### D81 - Bed analysis - // ----------------------------- - /*! - - `E` - dimension x - - `F` - dimention y - - `G` - points_x - - `H` - points_y - - `I` - offset_x - - `J` - offset_y + /*! + * + ### D81 - Bed analysis D80: Bed analysis + This command will log data to SD card file "wldsd.txt". + + D81 [ E | F | G | H | I | J ] + + - `E` - Dimension X (default 40) + - `F` - Dimention Y (default 40) + - `G` - Points X (default 40) + - `H` - Points Y (default 40) + - `I` - Offset X (default 74) + - `J` - Offset Y (default 34) */ case 81: { @@ -8756,8 +8776,10 @@ Sigma_Exit: #endif //HEATBED_ANALYSIS #ifdef DEBUG_DCODES - //! ### D106 print measured fan speed for different pwm values - // -------------------------------------------------------------- + /*! + * + ### D106 - Print measured fan speed for different pwm values D106: Print measured fan speed for different pwm values + */ case 106: { for (int i = 255; i > 0; i = i - 5) { From a5f3027ee18064be0ea3610ac5cb83ea9ccbbac9 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Wed, 4 Dec 2019 11:38:29 +0100 Subject: [PATCH 082/180] D2130 updated Needs review --- Firmware/Marlin_main.cpp | 54 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index ec3102fd8..7181b7303 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -8829,7 +8829,59 @@ Sigma_Exit: D2130E!wave220 ... (sin(x))^1.1 extruder microstep compensation curve used */ - + /*! + * + ### D2130 - Trinamic stepper controller D2130: Trinamic stepper controller + Unsing G28 without any paramters will perfom on the Prusa i3 printers home AND mesh bed leveling, while the default G-code G28 is just homeing the printer + + D2130 [ Axis | Command | Subcommand | Value ] + + - Axis + - `X` - X stepper driver + - `Y` - Y stepper driver + - `Z` - Z stepper driver + - `E` - Extruder stepper driver + - Commands + - `0` - Current off + - `1` - Current on + - `+` - Single step + - `-` - Single step oposite direction + - `NNN` - Value sereval steps + - `?` - Read register + - Subcommands for read register + - `mres` - Micro step resolution. More information in datasheet '5.5.2 CHOPCONF – Chopper Configuration' + - `step` - Step + - `mscnt` - Microstep counter. More information in datasheet '5.5 Motor Driver Registers' + - `mscuract` - Actual microstep current for motor. More information in datasheet '5.5 Motor Driver Registers' + - `wave` - Microstep linearity compensation curve + - `!` - Set register + - Subcommands for set register + - `mres` - Micro step resolution + - `step` - Step + - `wave` - Microstep linearity compensation curve + - Values for set register + - `0, 180 --> 250` - Off + - `0.9 --> 1.25` - Valid values (recommended is 1.1) + - `@` - Home calibrate axis + + Examples: + + D2130E?wave + + Print extruder microstep linearity compensation curve + + D2130E!wave0 + + Disable extruder linearity compensation curve, (sine curve is used) + + D2130E!wave220 + + (sin(x))^1.1 extruder microstep compensation curve used + + Notes: + For more information see https://www.trinamic.com/fileadmin/assets/Products/ICs_Documents/TMC2130_datasheet.pdf + * + */ case 2130: dcode_2130(); break; From cdc6beaf6f1abd58146e4fc44092c1fe679c898b Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Wed, 4 Dec 2019 12:25:33 +0100 Subject: [PATCH 083/180] Added M910 -> M918 --- Firmware/Marlin_main.cpp | 110 ++++++++++++++++++++++----------------- 1 file changed, 63 insertions(+), 47 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 7181b7303..248ce989b 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -8072,7 +8072,9 @@ Sigma_Exit: #ifdef TMC2130_SERVICE_CODES_M910_M918 /*! - ### M910 - TMC2130 init G32: Undock Z Probe sled + ### M910 - TMC2130 init M910: TMC2130 init + Not active in default, only if `TMC2130_SERVICE_CODES_M910_M918` is defined in source code. + */ ----------------------------------------------- case 910: { @@ -8081,8 +8083,16 @@ Sigma_Exit: break; /*! - ### M911 - Set TMC2130 holding currents G32: Undock Z Probe sled - */ ------------------------------------------------- + ### M911 - Set TMC2130 holding currents M911: Set TMC2130 holding currents + Not active in default, only if `TMC2130_SERVICE_CODES_M910_M918` is defined in source code. + + M911 [ X | Y | Z | E ] + + - `X` - X stepper driver holding current value + - `Y` - Y stepper driver holding current value + - `Z` - Z stepper driver holding current value + - `E` - Extruder stepper driver holding current value + */ ------------------------------------------------- case 911: { if (code_seen('X')) tmc2130_set_current_h(0, code_value()); @@ -8093,7 +8103,16 @@ Sigma_Exit: break; /*! - ### M912 - Set TMC2130 running currents G32: Undock Z Probe sled + ### M912 - Set TMC2130 running currents M912: Set TMC2130 running currents + Not active in default, only if `TMC2130_SERVICE_CODES_M910_M918` is defined in source code. + + M912 [ X | Y | Z | E ] + + + - `X` - X stepper driver running current value + - `Y` - Y stepper driver running current value + - `Z` - Z stepper driver running current value + - `E` - Extruder stepper driver running current value */ ----------------------------------------------- case 912: { @@ -8105,7 +8124,9 @@ Sigma_Exit: break; /*! - ### M913 - Print TMC2130 currents G32: Undock Z Probe sled + ### M913 - Print TMC2130 currents M913: Print TMC2130 currents + Not active in default, only if `TMC2130_SERVICE_CODES_M910_M918` is defined in source code. + Shows TMC2130 currents. */ ----------------------------- case 913: { @@ -8114,7 +8135,8 @@ Sigma_Exit: break; /*! - ### M914 - Set TMC2130 normal mode G32: Undock Z Probe sled + ### M914 - Set TMC2130 normal mode M914: Set TMC2130 normal mode + Not active in default, only if `TMC2130_SERVICE_CODES_M910_M918` is defined in source code. */ ------------------------------ case 914: { @@ -8125,7 +8147,8 @@ Sigma_Exit: break; /*! - ### M915 - Set TMC2130 silent mode G32: Undock Z Probe sled + ### M915 - Set TMC2130 silent mode M915: Set TMC2130 silent mode + Not active in default, only if `TMC2130_SERVICE_CODES_M910_M918` is defined in source code. */ ------------------------------ case 915: { @@ -8136,7 +8159,16 @@ Sigma_Exit: break; /*! - ### M916 - Set TMC2130 Stallguard sensitivity threshold G32: Undock Z Probe sled + ### M916 - Set TMC2130 Stallguard sensitivity threshold M916: Set TMC2130 Stallguard sensitivity threshold + Not active in default, only if `TMC2130_SERVICE_CODES_M910_M918` is defined in source code. + + M916 [ X | Y | Z | E ] + + + - `X` - X stepper driver stallguard sensitivity threshold value + - `Y` - Y stepper driver stallguard sensitivity threshold value + - `Z` - Z stepper driver stallguard sensitivity threshold value + - `E` - Extruder stepper driver stallguard sensitivity threshold value */ ------------------------------------------------------- case 916: { @@ -8150,7 +8182,16 @@ Sigma_Exit: break; /*! - ### M917 - Set TMC2130 PWM amplitude offset (pwm_ampl) G32: Undock Z Probe sled + ### M917 - Set TMC2130 PWM amplitude offset (pwm_ampl) M917: Set TMC2130 PWM amplitude offset (pwm_ampl) + Not active in default, only if `TMC2130_SERVICE_CODES_M910_M918` is defined in source code. + + M917 [ X | Y | Z | E ] + + + - `X` - X stepper driver PWM amplitude offset value + - `Y` - Y stepper driver PWM amplitude offset value + - `Z` - Z stepper driver PWM amplitude offset value + - `E` - Extruder stepper driver PWM amplitude offset value */ -------------------------------------------------------------- case 917: { @@ -8162,7 +8203,16 @@ Sigma_Exit: break; /*! - ### M918 - Set TMC2130 PWM amplitude gradient (pwm_grad) G32: Undock Z Probe sled + ### M918 - Set TMC2130 PWM amplitude gradient (pwm_grad) M918: Set TMC2130 PWM amplitude gradient (pwm_grad) + Not active in default, only if `TMC2130_SERVICE_CODES_M910_M918` is defined in source code. + + M918 [ X | Y | Z | E ] + + + - `X` - X stepper driver PWM amplitude gradient value + - `Y` - Y stepper driver PWM amplitude gradient value + - `Z` - Z stepper driver PWM amplitude gradient value + - `E` - Extruder stepper driver PWM amplitude gradient value */ ------------------------------------------------------------- case 918: { @@ -8794,45 +8844,11 @@ Sigma_Exit: }break; #ifdef TMC2130 - //! ### D2130 - TMC2130 Trinamic stepper controller - // --------------------------- - - - /*! - - - D2130[subcommand][value] - - - : - - '0' current off - - '1' current on - - '+' single step - - * value sereval steps - - '-' dtto oposite direction - - '?' read register - - * "mres" - - * "step" - - * "mscnt" - - * "mscuract" - - * "wave" - - '!' set register - - * "mres" - - * "step" - - * "wave" - - '@' home calibrate axis - - Example: - - D2130E?wave ... print extruder microstep linearity compensation curve - - D2130E!wave0 ... disable extruder linearity compensation curve, (sine curve is used) - - D2130E!wave220 ... (sin(x))^1.1 extruder microstep compensation curve used - */ /*! * - ### D2130 - Trinamic stepper controller D2130: Trinamic stepper controller - Unsing G28 without any paramters will perfom on the Prusa i3 printers home AND mesh bed leveling, while the default G-code G28 is just homeing the printer + ### D2130 - Trinamic stepper controller D2130: Trinamic stepper controller + + @todo Please review by owner of the code. RepRap Wiki Gcode needs to be updated after review of owner as well. D2130 [ Axis | Command | Subcommand | Value ] From fb3c65b3dcbc100b80f2d295b729498ca6d25be1 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Wed, 4 Dec 2019 12:38:43 +0100 Subject: [PATCH 084/180] fixed links to RR Wiki --- Firmware/Marlin_main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 248ce989b..b27dfed74 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -8182,7 +8182,7 @@ Sigma_Exit: break; /*! - ### M917 - Set TMC2130 PWM amplitude offset (pwm_ampl) M917: Set TMC2130 PWM amplitude offset (pwm_ampl) + ### M917 - Set TMC2130 PWM amplitude offset (pwm_ampl) M917: Set TMC2130 PWM amplitude offset (pwm_ampl) Not active in default, only if `TMC2130_SERVICE_CODES_M910_M918` is defined in source code. M917 [ X | Y | Z | E ] @@ -8203,7 +8203,7 @@ Sigma_Exit: break; /*! - ### M918 - Set TMC2130 PWM amplitude gradient (pwm_grad) M918: Set TMC2130 PWM amplitude gradient (pwm_grad) + ### M918 - Set TMC2130 PWM amplitude gradient (pwm_grad) M918: Set TMC2130 PWM amplitude gradient (pwm_grad) Not active in default, only if `TMC2130_SERVICE_CODES_M910_M918` is defined in source code. M918 [ X | Y | Z | E ] From f7bfca30612e0da9519fdced7bcd397a72f4af94 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Wed, 4 Dec 2019 13:39:56 +0100 Subject: [PATCH 085/180] Fix merge issues --- Firmware/Marlin_main.cpp | 40 ++++++---------------------------------- 1 file changed, 6 insertions(+), 34 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 22229b477..3a3270841 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -5569,14 +5569,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) card.openFile(strchr_pointer + 4,true); break; -<<<<<<< HEAD /*! ### M24 - Start SD print M24: Start/resume SD print */ ---------------------------------- -======= - //! ### M24 - Start/resume SD print - // ---------------------------------- ->>>>>>> upstream/MK3 case 24: if (isPrintPaused) lcd_resume_print(); @@ -5588,14 +5583,6 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; -<<<<<<< HEAD - /*! - ### M25 - Pause SD print M25: Pause SD print - */ ---------------------------------- - case 25: - card.pauseSDPrint(); - break; - /*! ### M26 - Set SD index M26: Set SD position Set position in SD card file to index in bytes. @@ -5605,13 +5592,6 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) - `S` - Index in bytes */ ---------------------------------- -======= - //! ### M26 S\ - Set SD index - //! Set position in SD card file to index in bytes. - //! This command is expected to be called after M23 and before M24. - //! Otherwise effect of this command is undefined. - // ---------------------------------- ->>>>>>> upstream/MK3 case 26: if(card.cardOK && code_seen('S')) { long index = code_value_long(); @@ -7759,17 +7739,16 @@ Sigma_Exit: break; #endif //FILAMENTCHANGEENABLE -<<<<<<< HEAD /*! ### M601 - Pause print M601: Pause print */ ------------------------------- -======= - //! ### M25 - Pause SD print - //! ### M601 - Pause print - //! ### M125 - Pause print (TODO: not implemented) - // ------------------------------- + /*! + ### M125 - Pause print (TODO: not implemented) + */ ------------------------------- + /*! + ### M25 - Pause SD print M25: Pause SD print + */ ---------------------------------- case 25: ->>>>>>> upstream/MK3 case 601: { if (!isPrintPaused) @@ -7790,18 +7769,11 @@ Sigma_Exit: } break; -<<<<<<< HEAD /*! ### M603 - Stop print M603: Stop print */ ------------------------------- - case 603: { - lcd_print_stop(); -======= - //! ### M603 - Stop print - // ------------------------------- case 603: { Stop(); ->>>>>>> upstream/MK3 } break; From 0cafd103787c405f7995cca01b3d014047d543bd Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Wed, 4 Dec 2019 13:43:19 +0100 Subject: [PATCH 086/180] minor fix --- Firmware/Marlin_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 3a3270841..90aff701b 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -7746,7 +7746,7 @@ Sigma_Exit: ### M125 - Pause print (TODO: not implemented) */ ------------------------------- /*! - ### M25 - Pause SD print M25: Pause SD print + ### M25 - Pause SD print M25: Pause SD print */ ---------------------------------- case 25: case 601: From 17e23693ebda55452d3560a0e2e8428afc6afac3 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Wed, 4 Dec 2019 14:21:43 +0100 Subject: [PATCH 087/180] Fixed stuipid copy paste error --- Firmware/Dcodes.cpp | 2 +- Firmware/Marlin_main.cpp | 243 +++++++++++++++++++-------------------- 2 files changed, 122 insertions(+), 123 deletions(-) diff --git a/Firmware/Dcodes.cpp b/Firmware/Dcodes.cpp index 9649d62bb..0a5142629 100644 --- a/Firmware/Dcodes.cpp +++ b/Firmware/Dcodes.cpp @@ -111,7 +111,7 @@ void print_mem(uint32_t address, uint16_t count, uint8_t type, uint8_t countperl - `X` - Data * */ - void dcode_3() +void dcode_3() { DBG(_N("D3 - Read/Write EEPROM\n")); uint16_t address = 0x0000; //default 0x0000 diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 90aff701b..c8dfcd098 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3906,7 +3906,7 @@ eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,0xFFFF); - `E` - The amount to extrude between the starting point and ending point - `F` - The feedrate per minute of the move between the starting point and ending point (if supplied) - */ -------------------------------------- + */ case 0: // G0 -> G1 case 1: // G1 if(Stopped == false) { @@ -4132,7 +4132,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) - `E` - The amount to extrude between the starting point and ending point - `F` - The feedrate per minute of the move between the starting point and ending point (if supplied) - */ ------------------------------ + */ case 2: if(Stopped == false) { get_arc_coordinates(); @@ -4161,7 +4161,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) - `P` - Time to wait, in milliseconds - `S` - Time to wait, in seconds - */ ------------------------------- + */ case 4: codenum = 0; if(code_seen('P')) codenum = code_value(); // milliseconds to wait @@ -4187,7 +4187,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) G10 - */ ------------------------------ + */ case 10: #if EXTRUDERS > 1 retracted_swap[active_extruder]=(code_seen('S') && code_value_long() == 1); // checks for swap retract argument @@ -4205,7 +4205,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) G11 - */ ----------------------------- + */ case 11: #if EXTRUDERS > 1 retract(false,retracted_swap[active_extruder]); @@ -4230,7 +4230,6 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) - `W` - Suppress mesh bed leveling - `C` - Calibrate X and Y origin (home) - Only on MK3/s */ - // ------------------------------ case 28: { long home_x_value = 0; @@ -4267,7 +4266,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code. See `G81` - */ -------------------------------- + */ case 29: { #if Z_MIN_PIN == -1 @@ -4415,7 +4414,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G30 - Single Z Probe G30: Single Z-Probe In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code. - */ ------------------------------------ + */ case 30: { st_synchronize(); @@ -4442,7 +4441,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G31 - Dock the sled G31: Dock Z Probe sled In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code. - */ --------------------------- + */ case 31: dock_sled(true); break; @@ -4451,7 +4450,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G32 - Undock the sled G32: Undock Z Probe sled In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code. - */ ---------------------------- + */ case 32: dock_sled(false); break; @@ -4462,7 +4461,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G30 - Single Z Probe G30: Single Z-Probe - */ ---------------------------- + */ case 30: { st_synchronize(); @@ -4486,7 +4485,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) G75 - */ --------------------------------------------- + */ case 75: { for (int i = 40; i <= 110; i++) @@ -4517,7 +4516,6 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) echo PINDA temperature -- Z shift (mm): 0.--- ``` */ - ------------------------------------------------ case 76: { #ifdef PINDA_THERMISTOR @@ -4794,7 +4792,6 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) - `F` - Front Bed Level correct value in um. - `B` - Back Bed Level correct value in um. */ - // ----------------------------------- /* * Probes a grid and produces a mesh to compensate for variable bed height @@ -5229,7 +5226,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) G81 - */ ----------------------------------------- + */ case 81: if (mbl.active) { SERIAL_PROTOCOLPGM("Num X,Y: "); @@ -5257,7 +5254,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) WARNING! USE WITH CAUTION! If you'll try to probe where is no leveling pad, nasty things can happen! In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code. - */ ----------------------------------------- + */ case 82: SERIAL_PROTOCOLLNPGM("Finding bed "); int l_feedmultiply = setup_for_endstop_move(); @@ -5271,7 +5268,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G83: Babystep in Z and store to EEPROM - Not active G83: Babystep in Z and store to EEPROM In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code. - */ ----------------------------------------- + */ case 83: { int babystepz = code_seen('S') ? code_value() : 0; @@ -5297,7 +5294,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G84: UNDO Babystep Z (move Z axis back) - Not active G84: UNDO Babystep Z (move Z axis back) In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code. - */ ----------------------------------------- + */ case 84: babystepsTodoZsubtract(babystepLoadZ); // babystepLoadZ = 0; @@ -5306,7 +5303,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G85: Pick best babystep - Not active M0: Stop or Unconditional stop - */ --------------------------------------------------------------- + */ case 0: // M0 - Unconditional stop - Wait for user button press on LCD case 1: // M1 - Conditional stop - Wait for user button press on LCD { @@ -5522,8 +5519,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; - //! ### M17 - Enable axes M17: Enable/Power all stepper motors - // --------------------------------- + /*! + ### M17 - Enable axes M17: Enable/Power all stepper motors + */ case 17: LCD_MESSAGERPGM(_i("No move."));////MSG_NO_MOVE enable_x(); @@ -5538,7 +5536,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### M20 - SD Card file list M20: List SD card - */ ----------------------------------- + */ case 20: SERIAL_PROTOCOLLNRPGM(_N("Begin file list"));////MSG_BEGIN_FILE_LIST card.ls(); @@ -5547,21 +5545,21 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### M21 - Init SD card M21: Initialize SD card - */ ------------------------------------ + */ case 21: card.initsd(); break; /*! ### M22 - Release SD card M22: Release SD card - */ ----------------------------------- + */ case 22: card.release(); break; /*! ### M23 - Select file M23: Select SD file - */ ----------------------------------- + */ case 23: starpos = (strchr(strchr_pointer + 4,'*')); if(starpos!=NULL) @@ -5571,7 +5569,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### M24 - Start SD print M24: Start/resume SD print - */ ---------------------------------- + */ case 24: if (isPrintPaused) lcd_resume_print(); @@ -5591,7 +5589,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) M26 [ S ] - `S` - Index in bytes - */ ---------------------------------- + */ case 26: if(card.cardOK && code_seen('S')) { long index = code_value_long(); @@ -5604,14 +5602,14 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### M27 - Get SD status M27: Report SD print status - */ ---------------------------------- + */ case 27: card.getStatus(); break; /*! ### M28 - Start SD write M28: Begin write to SD card - */ --------------------------------- + */ case 28: starpos = (strchr(strchr_pointer + 4,'*')); if(starpos != NULL){ @@ -5624,7 +5622,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### M29 - Stop SD write M29: Stop writing to SD card Currently has no effect. - */ ------------------------------------- + */ case 29: //processed in write to file routine above //card,saving = false; @@ -5632,7 +5630,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### M30 - Delete file M30: Delete a file on the SD card - */ ---------------------------------- + */ case 30: if (card.cardOK){ card.closefile(); @@ -5649,7 +5647,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### M32 - Select file and start SD print M32: Select file and start SD print @todo What are the parameters P and S for in M32? - */ ------------------------------------ + */ case 32: { if(card.sdprinting) { @@ -5686,8 +5684,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } } break; - /*! ### M982 - Start SD logging M928: Start SD logging - */ --------------------------------- + /*! + ### M982 - Start SD logging M928: Start SD logging + */ case 928: starpos = (strchr(strchr_pointer + 5,'*')); if(starpos != NULL){ @@ -5702,7 +5701,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### M31 - Report current print time M31: Output time since last M109 or SD card start to serial - */ -------------------------------------------------- + */ case 31: //M31 take time since the start of the SD print or an M109 command { stoptime=_millis(); @@ -5721,7 +5720,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### M42 - Set pin state M42: Switch I/O pin - */ ----------------------------- + */ case 42: if (code_seen('S')) { @@ -5753,7 +5752,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### M44 - Reset the bed skew and offset calibration M44: Reset the bed skew and offset calibration - */ -------------------------------------------------------------------- + */ case 44: // M44: Prusa3D: Reset the bed skew and offset calibration. // Reset the baby step value and the baby step applied flag. @@ -5773,7 +5772,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) M45 [ V ] - `V` - Verbosity level 1, 10 and 20 (low, mid, high). Only when SUPPORT_VERBOSITY is defined. - */ ------------------------------------------------------ + */ case 45: // M45: Prusa3D: bed skew and offset with manual Z up { int8_t verbosity_level = 0; @@ -5792,7 +5791,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### M46 - Show the assigned IP address M46: Show the assigned IP address. - */ ---------------------------------------------------- + */ /* case 46: { @@ -5818,7 +5817,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### M47 - Show end stops dialog on the display M47: Show end stops dialog on the display - */ ---------------------------------------------------- + */ case 47: KEEPALIVE_STATE(PAUSED_FOR_USER); @@ -6150,7 +6149,7 @@ Sigma_Exit: M104 [ S ] - `S` - Target temperature - */ ----------------------------------------- + */ case 104: // M104 { uint8_t extruder; @@ -6166,14 +6165,14 @@ Sigma_Exit: /*! ### M112 - Emergency stop M112: Full (Emergency) Stop - */ ----------------------------------------- + */ case 112: kill(_n(""), 3); break; /*! ### M140 - Set bed temperature M140: Set Bed Temperature (Fast) - */ ----------------------------------------- + */ case 140: if (code_seen('S')) setTargetBed(code_value()); break; @@ -6194,7 +6193,7 @@ Sigma_Exit: ok T:20.2 /0.0 B:19.1 /0.0 T0:20.2 /0.0 @:0 B@:0 P:19.8 A:26.4 - */ ----------------------------------------- + */ case 105: { uint8_t extruder; @@ -6302,7 +6301,7 @@ Sigma_Exit: Command always waits for both cool down and heat up. If no parameters are supplied waits for previously set extruder temperature. - */ ------------------------------------------------- + */ case 109: { uint8_t extruder; @@ -6417,7 +6416,7 @@ Sigma_Exit: /*! ### M106 - Set fan speed M106: Fan On - */ ------------------------------------------- + */ case 106: // M106 Sxxx Fan On S 0 .. 255 if (code_seen('S')){ fanSpeed=constrain(code_value(),0,255); @@ -6429,7 +6428,7 @@ Sigma_Exit: /*! ### M107 - Fan off M107: Fan Off - */ ------------------------------- + */ case 107: fanSpeed = 0; break; @@ -6439,7 +6438,7 @@ Sigma_Exit: /*! ### M80 - Turn on the Power Supply M80: ATX Power On - */ ------------------------------- + */ case 80: SET_OUTPUT(PS_ON_PIN); //GND WRITE(PS_ON_PIN, PS_ON_AWAKE); @@ -6460,7 +6459,7 @@ Sigma_Exit: /*! ### M81 - Turn off Power Supply M81: ATX Power Off - */ -------------------------------------- + */ case 81: disable_heater(); st_synchronize(); @@ -6485,7 +6484,7 @@ Sigma_Exit: /*! ### M82 - Set E axis to absolute mode M82: Set extruder to absolute mode Makes the extruder interpret extrusion as absolute positions. - */ --------------------------------------- + */ case 82: axis_relative_modes[3] = false; break; @@ -6493,7 +6492,7 @@ Sigma_Exit: /*! ### M83 - Set E axis to relative mode M83: Set extruder to relative mode Makes the extruder interpret extrusion values as relative positions. - */ --------------------------------------- + */ case 83: axis_relative_modes[3] = true; break; @@ -6555,7 +6554,7 @@ Sigma_Exit: /*! ### M85 - Set max inactive time M85: Set Inactivity Shutdown Timer Set Inactivity Shutdown Timer with parameter S. "M85 S0" will disable the inactivity shutdown time (default) - */ --------------------------------------- + */ case 85: // M85 if(code_seen('S')) { max_inactive_time = code_value() * 1000; @@ -6592,7 +6591,7 @@ Sigma_Exit: - `Y` - Steps per unit for the Y drive - `Z` - Steps per unit for the Z drive - `E` - Steps per unit for the extruder drive(s) - */ --------------------------------------- + */ case 92: for(int8_t i=0; i < NUM_AXIS; i++) { @@ -6622,7 +6621,7 @@ Sigma_Exit: M110 [ N ] - `N` - Line number - */ --------------------------------------- + */ case 110: if (code_seen('N')) gcode_LastN = code_value_long(); @@ -6635,7 +6634,7 @@ Sigma_Exit: M113 [ S ] - `S` - Seconds Default is 2 seconds between "busy" messages - */ ------------------------------------------ + */ case 113: if (code_seen('S')) { host_keepalive_interval = (uint8_t)code_value_short(); @@ -6699,7 +6698,7 @@ Sigma_Exit: /*! ### M114 - Get current position M114: Get Current Position - */ ------------------------------------- + */ case 114: gcode_M114(); break; @@ -6717,14 +6716,14 @@ Sigma_Exit: /*! ### M120 - Enable endstops M120: Enable endstop detection - */ ---------------------------------------- + */ case 120: enable_endstops(false) ; break; /*! ### M121 - Disable endstops M121: Disable endstop detection - */ ---------------------------------------- + */ case 121: enable_endstops(true) ; break; @@ -6732,7 +6731,7 @@ Sigma_Exit: /*! ### M119 - Get endstop states M119: Get Endstop Status Returns the current state of the configured X, Y, Z endstops. Takes into account any 'inverted endstop' settings, so one can confirm that the machine is interpreting the endstops correctly. - */ ---------------------------------------- + */ case 119: SERIAL_PROTOCOLRPGM(_N("Reporting endstop status"));////MSG_M119_REPORT SERIAL_PROTOCOLLN(""); @@ -6798,7 +6797,7 @@ Sigma_Exit: /*! ### M150 - Set RGB(W) Color M150: Set LED color In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code by defining BLINKM and its dependencies. - */ ------------------------------------------- + */ case 150: { byte red; @@ -6821,7 +6820,7 @@ Sigma_Exit: - `D` - Diameter in mm - `T` - Number of extruder (MMUs) - */ ---------------------------------------- + */ case 200: // M200 D set filament diameter and set E axis units to cubic millimeters (use S0 to set back to millimeters). { @@ -6863,7 +6862,7 @@ Sigma_Exit: /*! ### M201 - Set Print Max Acceleration M201: Set max printing acceleration - */ ------------------------------------------- + */ case 201: for (int8_t i = 0; i < NUM_AXIS; i++) { @@ -6899,7 +6898,7 @@ Sigma_Exit: /*! ### M203 - Set Max Feedrate M203: Set maximum feedrate - */ --------------------------------------- + */ case 203: // M203 max feedrate mm/sec for (int8_t i = 0; i < NUM_AXIS; i++) { @@ -6926,7 +6925,7 @@ Sigma_Exit: /*! ### M204 - Acceleration settings M204: Set default acceleration - */ ------------------------------------------ + */ /*! Supporting old format: M204 [ S | T ] @@ -6967,7 +6966,7 @@ Sigma_Exit: /*! ### M205 - Set advanced settings M205: Advanced settings - */ --------------------------------------------- + */ /*! Set some advanced settings related to movement. M205 [ S | T | B | X | Y | Z | E ] @@ -7002,7 +7001,7 @@ Sigma_Exit: - `X` - X axis offset - `Y` - Y axis offset - `Z` - Z axis offset - */ ---------------------------------------------- + */ case 206: for(int8_t i=0; i < 3; i++) { @@ -7019,7 +7018,7 @@ Sigma_Exit: - `S` - positive length to retract, in mm - `F` - retraction feedrate, in mm/min - `Z` - additional zlift/hop - */ -------------------------------------------------- + */ case 207: //M207 - set retract length S[positive mm] F[feedrate mm/min] Z[additional zlift/hop] { if(code_seen('S')) @@ -7043,7 +7042,7 @@ Sigma_Exit: - `S` - positive length surplus to the M207 Snnn, in mm - `F` - feedrate, in mm/sec - */ -------------------------------------------- + */ case 208: // M208 - set retract recover length S[positive mm surplus to the M207 S*] F[feedrate mm/min] { if(code_seen('S')) @@ -7064,7 +7063,7 @@ Sigma_Exit: - `S` - 1=true or 0=false This boolean value S 1=true or 0=false enables automatic retract detect if the slicer did not support G10/G11: every normal extrude-only move will be classified as retract depending on the direction. - */ --------------------------------------------- + */ case 209: // M209 - S<1=true/0=false> enable automatic retract detect if the slicer did not support G10/11: every normal extrude-only move will be classified as retract depending on the direction. { if(code_seen('S')) @@ -7109,7 +7108,7 @@ Sigma_Exit: /*! ### M218 - Set hotend offset M218: Set Hotend Offset In Prusa Firmware this G-code is only active if `EXTRUDERS` is higher then 1 in the source code. On Original i3 Prusa MK2/s MK2.5/s MK3/s it is not active. - */ ---------------------------------------- + */ case 218: // M218 - set hotend offset (in mm), T X Y { uint8_t extruder; @@ -7146,7 +7145,7 @@ Sigma_Exit: - `S` - Speed factor override percentage (0..100 or higher) - `R` - Restore previous speed factor - */ ----------------------------------------------- + */ case 220: // M220 S- set speed factor override percentage { if (code_seen('B')) //backup current speed factor @@ -7171,7 +7170,7 @@ Sigma_Exit: - `S` - Extrude factor override percentage (0..100 or higher), default 100% - `T` - Extruder drive number (Prusa Firmware only), default 0 if not set. - */ ---------------------------------------------------- + */ case 221: // M221 S- set extrude factor override percentage { if(code_seen('S')) @@ -7203,7 +7202,7 @@ Sigma_Exit: - `S` - pin state Wait until the specified pin reaches the state required - */ ------------------------------------------ + */ case 226: // M226 P S- Wait until the specified pin reaches the state required { if(code_seen('P')){ @@ -7261,7 +7260,7 @@ Sigma_Exit: /*! ### M280 - Set/Get servo position M280: Set servo position In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code. - */ -------------------------------------------- + */ case 280: // M280 - set servo position absolute. P: servo index, S: angle or microseconds { int servo_index = -1; @@ -7310,7 +7309,7 @@ Sigma_Exit: - `P` - duration in milliseconds In Prusa Firmware the defaults are `100Hz` and `1000ms`, so that `M300` without parameters will beep for a second. - */ ----------------------- + */ case 300: // M300 { int beepS = code_seen('S') ? code_value() : 110; @@ -7344,7 +7343,7 @@ Sigma_Exit: Sets Proportional (P), Integral (I) and Derivative (D) values for hot end. See also PID Tuning. - */ --------------------------------------- + */ case 301: { if(code_seen('P')) cs.Kp = code_value(); @@ -7386,7 +7385,7 @@ Sigma_Exit: Sets Proportional (P), Integral (I) and Derivative (D) values for bed. See also PID Tuning. - */ -------------------------------------- + */ case 304: { if(code_seen('P')) cs.bedKp = code_value(); @@ -7412,7 +7411,7 @@ Sigma_Exit: In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code. You need to define `CHDK` and assign a `PHOTOGRAPH_PIN` to bea ble to use it. - */ -------------------------------------------- + */ case 240: // M240 Triggers a camera by emulating a Canon RC-1 : http://www.doc-diy.net/photo/rc-1_hacked/ { #ifdef CHDK @@ -7454,7 +7453,7 @@ Sigma_Exit: - `S` - Cold extrude minimum temperature This tells the printer to allow movement of the extruder motor above a certain temperature, or if disabled, to allow extruder movement when the hotend is below a safe printing temperature. - */ ------------------------------------------------------------------- + */ case 302: { float temp = .0; @@ -7474,7 +7473,7 @@ Sigma_Exit: - `C` - Cycles, default `5` PID Tuning refers to a control algorithm used in some repraps to tune heating behavior for hot ends and heated beds. This command generates Proportional (Kp), Integral (Ki), and Derivative (Kd) values for the hotend or bed (`E-1`). Send the appropriate code and wait for the output to update the firmware. - */ ------------------------------------- + */ case 303: { float temp = 150.0; @@ -7493,7 +7492,7 @@ Sigma_Exit: ### M400 - Wait for all moves to finish M400: Wait for current moves to finish Finishes all current moves and and thus clears the buffer. - */ ----------------------------------------- + */ case 400: { st_synchronize(); @@ -7511,7 +7510,7 @@ Sigma_Exit: Currently three different materials are needed (default, flex and PVA). And storing this information for different load/unload profiles etc. in the future firmware does not have to wait for "ok" from MMU. - */ ---------------------------------------------- + */ case 403: { // currently three different materials are needed (default, flex and PVA) @@ -7532,7 +7531,7 @@ Sigma_Exit: ### M500 - Store settings in EEPROM M500: Store parameters in non-volatile storage Save current parameters to EEPROM, SD card or other non-volatile storage. - */ ----------------------------------------- + */ case 500: { Config_StoreSettings(); @@ -7543,7 +7542,7 @@ Sigma_Exit: ### M501 - Read settings from EEPROM M501: Read parameters from EEPROM Set the active parameters to those stored in the EEPROM, SD card or other non-volatile storage. This is useful to revert parameters after experimenting with them. - */ ---------------------------------------- + */ case 501: { Config_RetrieveSettings(); @@ -7554,7 +7553,7 @@ Sigma_Exit: ### M502 - Revert all settings to factory default M502: Restore Default Settings This command resets all tunable parameters to their default values, as set in the firmware's configuration files. This doesn't reset any parameters stored in the EEPROM, so it must be followed with M500 to reboot with default settings. - */ ------------------------------------------------- + */ case 502: { Config_ResetDefault(); @@ -7565,7 +7564,7 @@ Sigma_Exit: ### M503 - Repport all settings currently in memory M503: Report Current Settings This command asks the firmware to reply with the current print settings as set in memory. Settings will differ from EEPROM contents if changed since the last load / save. The reply output includes the G-Code commands to produce each setting. For example, Steps-Per-Unit values are displayed as an M92 command. - */ ------------------------------------------------- + */ case 503: { Config_PrintSettings(); @@ -7577,7 +7576,7 @@ Sigma_Exit: Resets the language to English. Only on Original Prusa i3 MK2.5/s and MK3/s with multiple languages. - */ ------------------------------------------------ + */ case 509: { lang_reset(); @@ -7591,7 +7590,7 @@ Sigma_Exit: ### M540 - Abort print on endstop hit (enable/disable) M540 in Marlin: Enable/Disable "Stop SD Print on Endstop Hit" In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code. You must define `ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED`. - */ ----------------------------------------------------- + */ case 540: { if(code_seen('S')) abort_on_endstop_hit = code_value() > 0; @@ -7609,7 +7608,7 @@ Sigma_Exit: Sets the Z-probe Z offset. This offset is used to determine the actual Z position of the nozzle when using a probe to home Z with G28. This value may also be used by G81 (Prusa) / G29 (Marlin) to apply correction to the Z position. This value represents the distance from nozzle to the bed surface at the point where the probe is triggered. This value will be negative for typical switch probes, inductive probes, and setups where the nozzle makes a circuit with a raised metal contact. This setting will be greater than zero on machines where the nozzle itself is used as the probe, pressing down on the bed to press a switch. (This is a common setup on delta machines.) - */ ----------------------------------------------------- + */ #ifdef CUSTOM_M_CODE_SET_Z_PROBE_OFFSET case CUSTOM_M_CODE_SET_Z_PROBE_OFFSET: { @@ -7663,7 +7662,7 @@ Sigma_Exit: Initiates Filament change, it is also used during Filament Runout Sensor process. If the `M600` is triggered under 25mm it will do a Z-lift of 25mm to prevent a filament blob. - */ -------------------------------------- + */ case 600: //Pause for filament change X[pos] Y[pos] Z[relative lift] E[initial retract] L[later retract distance for removal] { st_synchronize(); @@ -7741,13 +7740,13 @@ Sigma_Exit: /*! ### M601 - Pause print M601: Pause print - */ ------------------------------- + */ /*! ### M125 - Pause print (TODO: not implemented) - */ ------------------------------- + */ /*! ### M25 - Pause SD print M25: Pause SD print - */ ---------------------------------- + */ case 25: case 601: { @@ -7762,7 +7761,7 @@ Sigma_Exit: /*! ### M602 - Resume print M602: Resume print - */ ------------------------------- + */ case 602: { if (isPrintPaused) lcd_resume_print(); @@ -7771,7 +7770,7 @@ Sigma_Exit: /*! ### M603 - Stop print M603: Stop print - */ ------------------------------- + */ case 603: { Stop(); } @@ -7786,7 +7785,7 @@ Sigma_Exit: - `S` - Target temperature Wait for PINDA thermistor to reach target temperature - */ -------------------------------------------------------------- + */ case 860: { int set_target_pinda = 0; @@ -7843,7 +7842,7 @@ Sigma_Exit: - `I` - Table index Set compensation ustep value `S` for compensation table index `I`. - */ ----------------------------------------------------------- + */ case 861: if (code_seen('?')) { // ? - Print out current EEPROM offset values uint8_t cal_status = calibration_status_pinda(); @@ -7950,7 +7949,7 @@ Sigma_Exit: - MK3S (302) - MK3SMMU2S (20302) - */ ---------------------------------------------- + */ case 862: // M862: print checking float nDummy; uint8_t nCommand; @@ -8022,7 +8021,7 @@ Sigma_Exit: - `W` - Width - `H` - Height - `D` - Diameter Set ratio from WH/D - */ ---------------------------------------------- + */ case 900: gcode_M900(); break; @@ -8042,7 +8041,7 @@ Sigma_Exit: - `S` - ?? @todo What are `B` and `S` in M907? - */ --------------------------------------------------------------- + */ case 907: { #ifdef TMC2130 @@ -8079,7 +8078,7 @@ Sigma_Exit: /*! ### M908 - Control digital trimpot directly M908: Control digital trimpot directly In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code. - */ --------------------------------------------------------- + */ case 908: { #if defined(DIGIPOTSS_PIN) && DIGIPOTSS_PIN > -1 @@ -8097,7 +8096,7 @@ Sigma_Exit: ### M910 - TMC2130 init M910: TMC2130 init Not active in default, only if `TMC2130_SERVICE_CODES_M910_M918` is defined in source code. - */ ----------------------------------------------- + */ case 910: { tmc2130_init(); @@ -8114,7 +8113,7 @@ Sigma_Exit: - `Y` - Y stepper driver holding current value - `Z` - Z stepper driver holding current value - `E` - Extruder stepper driver holding current value - */ ------------------------------------------------- + */ case 911: { if (code_seen('X')) tmc2130_set_current_h(0, code_value()); @@ -8135,7 +8134,7 @@ Sigma_Exit: - `Y` - Y stepper driver running current value - `Z` - Z stepper driver running current value - `E` - Extruder stepper driver running current value - */ ----------------------------------------------- + */ case 912: { if (code_seen('X')) tmc2130_set_current_r(0, code_value()); @@ -8149,7 +8148,7 @@ Sigma_Exit: ### M913 - Print TMC2130 currents M913: Print TMC2130 currents Not active in default, only if `TMC2130_SERVICE_CODES_M910_M918` is defined in source code. Shows TMC2130 currents. - */ ----------------------------- + */ case 913: { tmc2130_print_currents(); @@ -8159,7 +8158,7 @@ Sigma_Exit: /*! ### M914 - Set TMC2130 normal mode M914: Set TMC2130 normal mode Not active in default, only if `TMC2130_SERVICE_CODES_M910_M918` is defined in source code. - */ ------------------------------ + */ case 914: { tmc2130_mode = TMC2130_MODE_NORMAL; @@ -8171,7 +8170,7 @@ Sigma_Exit: /*! ### M915 - Set TMC2130 silent mode M915: Set TMC2130 silent mode Not active in default, only if `TMC2130_SERVICE_CODES_M910_M918` is defined in source code. - */ ------------------------------ + */ case 915: { tmc2130_mode = TMC2130_MODE_SILENT; @@ -8191,7 +8190,7 @@ Sigma_Exit: - `Y` - Y stepper driver stallguard sensitivity threshold value - `Z` - Z stepper driver stallguard sensitivity threshold value - `E` - Extruder stepper driver stallguard sensitivity threshold value - */ ------------------------------------------------------- + */ case 916: { if (code_seen('X')) tmc2130_sg_thr[X_AXIS] = code_value(); @@ -8214,7 +8213,7 @@ Sigma_Exit: - `Y` - Y stepper driver PWM amplitude offset value - `Z` - Z stepper driver PWM amplitude offset value - `E` - Extruder stepper driver PWM amplitude offset value - */ -------------------------------------------------------------- + */ case 917: { if (code_seen('X')) tmc2130_set_pwm_ampl(0, code_value()); @@ -8235,7 +8234,7 @@ Sigma_Exit: - `Y` - Y stepper driver PWM amplitude gradient value - `Z` - Z stepper driver PWM amplitude gradient value - `E` - Extruder stepper driver PWM amplitude gradient value - */ ------------------------------------------------------------- + */ case 918: { if (code_seen('X')) tmc2130_set_pwm_grad(0, code_value()); @@ -8250,7 +8249,7 @@ Sigma_Exit: /*! ### M350 - Set microstepping mode M350: Set microstepping mode Warning: Steps per unit remains unchanged. S code sets stepping mode for all drivers. - */ --------------------------------------------------- + */ case 350: { #ifdef TMC2130 @@ -8300,7 +8299,7 @@ Sigma_Exit: Toggle MS1 MS2 pins directly, S# determines MS1 or MS2, X# sets the pin high/low. M351 [B<0|1>] [E<0|1>] S<1|2> [X<0|1>] [Y<0|1>] [Z<0|1>] - */ ----------------------------------- + */ case 351: { #if defined(X_MS1_PIN) && X_MS1_PIN > -1 @@ -8323,7 +8322,7 @@ Sigma_Exit: /*! ### M701 - Load filament M701: Load filament - */ ------------------------- + */ case 701: { if (mmu_enabled && code_seen('E')) @@ -8340,7 +8339,7 @@ Sigma_Exit: - `U` - Unload all filaments used in current print - `C` - Unload just current filament - without any parameters unload all filaments - */ ------------------------ + */ case 702: { #ifdef SNMM @@ -8365,7 +8364,7 @@ Sigma_Exit: /*! ### M999 - Restart after being stopped M999: Restart after being stopped by error - */ ------------------------------------ + */ case 999: Stopped = false; lcd_reset_alert_level(); @@ -8374,7 +8373,7 @@ Sigma_Exit: break; /*! #### End of M-Commands - */ ------------------------------------ + */ default: printf_P(PSTR("Unknown M code: %s \n"), cmdbuffer + bufindr + CMDHDRSIZE); } From 0b9123ce24a31f9247cc0af2282ede488dd8b641 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Thu, 5 Dec 2019 15:18:24 +0100 Subject: [PATCH 088/180] Fix Live K, allow "Advance K" to be translated --- Firmware/menu.h | 2 -- Firmware/messages.c | 3 +++ Firmware/messages.h | 3 +++ Firmware/ultralcd.cpp | 6 +++--- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Firmware/menu.h b/Firmware/menu.h index 2ab0c3659..88363359b 100755 --- a/Firmware/menu.h +++ b/Firmware/menu.h @@ -132,8 +132,6 @@ extern const char menu_fmt_int3[]; extern const char menu_fmt_float31[]; extern const char menu_fmt_float13[]; -extern const char menu_fmt_float13off[]; - extern void menu_draw_float31(const char* str, float val); diff --git a/Firmware/messages.c b/Firmware/messages.c index bb2e9510a..3c2fc9bb1 100644 --- a/Firmware/messages.c +++ b/Firmware/messages.c @@ -131,6 +131,9 @@ const char MSG_MAGNETS_COMP[] PROGMEM_I1 = ISTR("Magnets comp."); //// const char MSG_FS_ACTION[] PROGMEM_I1 = ISTR("FS Action"); //// const char MSG_FS_CONTINUE[] PROGMEM_I1 = ISTR("Cont."); //// const char MSG_FS_PAUSE[] PROGMEM_I1 = ISTR("Pause"); //// +#ifdef LA_LIVE_K +const char MSG_ADVANCE_K[] PROGMEM_I1 = ISTR("Advance K:"); //// +#endif //not internationalized messages const char MSG_SD_WORKDIR_FAIL[] PROGMEM_N1 = "workDir open failed"; //// diff --git a/Firmware/messages.h b/Firmware/messages.h index 60a4cc1c1..ec3ab96ec 100644 --- a/Firmware/messages.h +++ b/Firmware/messages.h @@ -131,6 +131,9 @@ extern const char MSG_MAGNETS_COMP[]; extern const char MSG_FS_ACTION[]; extern const char MSG_FS_CONTINUE[]; extern const char MSG_FS_PAUSE[]; +#ifdef LA_LIVE_K +extern const char MSG_ADVANCE_K[]; +#endif //not internationalized messages extern const char MSG_BROWNOUT_RESET[]; diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index ddfab61f0..9de5ec95b 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -7065,14 +7065,14 @@ static void lcd_colorprint_change() { #ifdef LA_LIVE_K // @wavexx: looks like there's no generic float editing function in menu.cpp so we // redefine our custom handling functions to mimick other tunables -#define MSG_ADVANCE_K PSTR("Advance K:") +const char menu_fmt_float13off[] PROGMEM = "%c%-13.13S%6.6S"; static void lcd_advance_draw_K(char chr, float val) { if (val <= 0) - lcd_printf_P(menu_fmt_float13off, chr, MSG_ADVANCE_K, " [off]"); + lcd_printf_P(menu_fmt_float13off, chr, _T(MSG_ADVANCE_K), _T(MSG_OFF)); else - lcd_printf_P(menu_fmt_float13, chr, MSG_ADVANCE_K, val); + lcd_printf_P(menu_fmt_float13, chr, _T(MSG_ADVANCE_K), val); } static void lcd_advance_edit_K(void) From 28b66bc909744cbbe1a11328cfe5c262a726aa4a Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Sun, 15 Dec 2019 17:27:15 +0100 Subject: [PATCH 089/180] Update to prepare for new prusa3d/PF-build-env Fixed a bug in Arduino user preferences --- PF-build.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/PF-build.sh b/PF-build.sh index 984df8a58..9cbedd549 100755 --- a/PF-build.sh +++ b/PF-build.sh @@ -56,7 +56,7 @@ # Some may argue that this is only used by a script, BUT as soon someone accidentally or on purpose starts Arduino IDE # it will use the default Arduino IDE folders and so can corrupt the build environment. # -# Version: 1.0.6-Build_10 +# Version: 1.0.6-Build_12 # Change log: # 12 Jan 2019, 3d-gussner, Fixed "compiler.c.elf.flags=-w -Os -Wl,-u,vfprintf -lprintf_flt -lm -Wl,--gc-sections" in 'platform.txt' # 16 Jan 2019, 3d-gussner, Build_2, Added development check to modify 'Configuration.h' to prevent unwanted LCD messages that Firmware is unknown @@ -114,7 +114,9 @@ # 26 Jul 2019, 3d-gussner, Change JSON repository to prusa3d after PR https://github.com/prusa3d/Arduino_Boards/pull/1 was merged # 23 Sep 2019, 3d-gussner, Prepare PF-build.sh for comming Prusa3d/Arduino_Boards version 1.0.2 Pull Request # 17 Oct 2019, 3d-gussner, Changed folder and check file names to have seperated build enviroments depening on Arduino IDE version and -# board-versions. +# board-versions. +# 15 Dec 2019, 3d-gussner, Prepare for switch to Prusa3d/PF-build-env repository +# 15 Dec 2019, 3d-gussner, Fix Audrino user preferences for the chosen board. #### Start check if OSTYPE is supported OS_FOUND=$( command -v uname) @@ -219,7 +221,8 @@ BOARD_VERSION="1.0.2" BOARD_URL="https://raw.githubusercontent.com/prusa3d/Arduino_Boards/master/IDE_Board_Manager/package_prusa3d_index.json" BOARD_FILENAME="prusa3dboards" BOARD_FILE_URL="https://raw.githubusercontent.com/prusa3d/Arduino_Boards/master/IDE_Board_Manager/prusa3dboards-1.0.2.tar.bz2" -PF_BUILD_FILE_URL="https://github.com/3d-gussner/PF-build-env/releases/download/$BUILD_ENV/PF-build-env-$BUILD_ENV.zip" +PF_BUILD_FILE_URL="https://github.com/3d-gussner/PF-build-env-1/releases/download/$BUILD_ENV-WinLin/PF-build-env-WinLin-$BUILD_ENV.zip" +#PF_BUILD_FILE_URL="https://github.com/prusa3d/PF-build-env/releases/download/$BUILD_ENV-WinLin/PF-build-env-WinLin-$BUILD_ENV.zip" LIB="PrusaLibrary" SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )" @@ -321,7 +324,7 @@ if [ ! -e ../PF-build-env-$BUILD_ENV/Preferences-$ARDUINO_ENV-$BOARD_VERSION-$TA echo "update.check" sed -i 's/update.check = true/update.check = false/g' ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/lib/preferences.txt echo "board" - sed -i 's/board = uno/board = $BOARD/g' ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/lib/preferences.txt + sed -i "s/board = uno/board = $BOARD/g" ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/lib/preferences.txt echo "editor.linenumbers" sed -i 's/editor.linenumbers = false/editor.linenumbers = true/g' ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor/lib/preferences.txt echo "boardsmanager.additional.urls" @@ -364,7 +367,7 @@ if [[ ! -d "../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$P fi # Download and extract Prusa Firmware specific library files -if [ ! -f "PF-build-env-$BUILD_ENV.zip" ]; then +if [ ! -f "PF-build-env-WinLin-$BUILD_ENV.zip" ]; then echo "$(tput setaf 6)Downloading Prusa Firmware build environment...$(tput setaf 2)" sleep 2 wget $PF_BUILD_FILE_URL || exit 11 @@ -373,7 +376,7 @@ fi if [ ! -e "../PF-build-env-$BUILD_ENV/PF-build-env-$BUILD_ENV-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor.txt" ]; then echo "$(tput setaf 6)Unzipping Prusa Firmware build environment...$(tput setaf 2)" sleep 2 - unzip -o PF-build-env-$BUILD_ENV.zip -d ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor || exit 12 + unzip -o PF-build-env-WinLin-$BUILD_ENV.zip -d ../PF-build-env-$BUILD_ENV/$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor || exit 12 echo "# PF-build-env-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor-$BUILD_ENV" >> ../PF-build-env-$BUILD_ENV/PF-build-env-$BUILD_ENV-$ARDUINO_ENV-$BOARD_VERSION-$TARGET_OS-$Processor.txt echo "$(tput sgr0)" fi From 0cc68228f8c7b00ec99693e6da4bd6cfa7b1a524 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sat, 14 Dec 2019 18:05:08 +0100 Subject: [PATCH 090/180] Unretract when resuming a paused print --- Firmware/Marlin.h | 1 + Firmware/Marlin_main.cpp | 4 ---- Firmware/ultralcd.cpp | 4 ++-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index 7dedc8a4b..ad1407ae3 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -308,6 +308,7 @@ extern float max_pos[3]; extern bool axis_known_position[3]; extern int fanSpeed; extern int8_t lcd_change_fil_state; +extern float default_retraction; #ifdef TMC2130 void homeaxis(int axis, uint8_t cnt = 1, uint8_t* pstep = 0); diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 4970091ea..3327f8f8e 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -9571,10 +9571,6 @@ void long_pause() //long pause print // Stop heaters setAllTargetHotends(0); - //retract - current_position[E_AXIS] -= default_retraction; - plan_buffer_line_curposXYZE(400, active_extruder); - //lift z current_position[Z_AXIS] += Z_PAUSE_LIFT; if (current_position[Z_AXIS] > Z_MAX_POS) current_position[Z_AXIS] = Z_MAX_POS; diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 5d0abeac9..d29e40617 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -1662,7 +1662,7 @@ void lcd_return_to_status() //! @brief Pause print, disable nozzle heater, move to park position void lcd_pause_print() { - stop_and_save_print_to_ram(0.0,0.0); + stop_and_save_print_to_ram(0.0, -default_retraction); lcd_return_to_status(); isPrintPaused = true; if (LcdCommands::Idle == lcd_commands_type) @@ -6771,7 +6771,7 @@ void lcd_resume_print() if (fan_error_selftest()) return; //abort if error persists isPrintPaused = false; - restore_print_from_ram_and_continue(0.0); + restore_print_from_ram_and_continue(default_retraction); pause_time += (_millis() - start_pause_print); //accumulate time when print is paused for correct statistics calculation refresh_cmd_timeout(); SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_RESUMED); //resume octoprint From 46c06f7eee5c289fa5abda658c7e55c5e80f09a9 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Tue, 17 Dec 2019 14:05:39 +0100 Subject: [PATCH 091/180] Updated it to use Arduino_Boards v1.0.3 and linked everything to prusa3d repositories --- PF-build.sh | 18 +++++++++++------- README.md | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/PF-build.sh b/PF-build.sh index 9cbedd549..8f1fa2478 100755 --- a/PF-build.sh +++ b/PF-build.sh @@ -56,7 +56,7 @@ # Some may argue that this is only used by a script, BUT as soon someone accidentally or on purpose starts Arduino IDE # it will use the default Arduino IDE folders and so can corrupt the build environment. # -# Version: 1.0.6-Build_12 +# Version: 1.0.6-Build_13 # Change log: # 12 Jan 2019, 3d-gussner, Fixed "compiler.c.elf.flags=-w -Os -Wl,-u,vfprintf -lprintf_flt -lm -Wl,--gc-sections" in 'platform.txt' # 16 Jan 2019, 3d-gussner, Build_2, Added development check to modify 'Configuration.h' to prevent unwanted LCD messages that Firmware is unknown @@ -117,6 +117,7 @@ # board-versions. # 15 Dec 2019, 3d-gussner, Prepare for switch to Prusa3d/PF-build-env repository # 15 Dec 2019, 3d-gussner, Fix Audrino user preferences for the chosen board. +# 17 Dec 2019, 3d-gussner, Fix "timer0_fract = 0" warning by using Arduino_boards v1.0.3 #### Start check if OSTYPE is supported OS_FOUND=$( command -v uname) @@ -209,20 +210,22 @@ if ! type python > /dev/null; then fi fi -#### End prepare bash environment +#### End prepare bash / Linux environment #### Set build environment ARDUINO_ENV="1.8.5" BUILD_ENV="1.0.6" BOARD="prusa_einsy_rambo" -BOARD_PACKAGE_NAME="PrusaResearchRambo" -BOARD_VERSION="1.0.2" +BOARD_PACKAGE_NAME="PrusaResearch" +BOARD_VERSION="1.0.3" +#BOARD_URL="https://raw.githubusercontent.com/3d-gussner/Arduino_Boards/Prusa_Merge_v1.0.3/IDE_Board_Manager/package_prusa3d_index.json" BOARD_URL="https://raw.githubusercontent.com/prusa3d/Arduino_Boards/master/IDE_Board_Manager/package_prusa3d_index.json" BOARD_FILENAME="prusa3dboards" -BOARD_FILE_URL="https://raw.githubusercontent.com/prusa3d/Arduino_Boards/master/IDE_Board_Manager/prusa3dboards-1.0.2.tar.bz2" -PF_BUILD_FILE_URL="https://github.com/3d-gussner/PF-build-env-1/releases/download/$BUILD_ENV-WinLin/PF-build-env-WinLin-$BUILD_ENV.zip" -#PF_BUILD_FILE_URL="https://github.com/prusa3d/PF-build-env/releases/download/$BUILD_ENV-WinLin/PF-build-env-WinLin-$BUILD_ENV.zip" +#BOARD_FILE_URL="https://raw.githubusercontent.com/3d-gussner/Arduino_Boards/Prusa_Merge_v1.0.3/IDE_Board_Manager/prusa3dboards-1.0.3.tar.bz2" +BOARD_FILE_URL="https://raw.githubusercontent.com/prusa3d/Arduino_Boards/master/IDE_Board_Manager/prusa3dboards-1.0.3.tar.bz2" +#PF_BUILD_FILE_URL="https://github.com/3d-gussner/PF-build-env-1/releases/download/$BUILD_ENV-WinLin/PF-build-env-WinLin-$BUILD_ENV.zip" +PF_BUILD_FILE_URL="https://github.com/prusa3d/PF-build-env/releases/download/$BUILD_ENV-WinLin/PF-build-env-WinLin-$BUILD_ENV.zip" LIB="PrusaLibrary" SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )" @@ -236,6 +239,7 @@ echo "Ardunio IDE :" $ARDUINO_ENV echo "Build env :" $BUILD_ENV echo "Board :" $BOARD echo "Package name:" $BOARD_PACKAGE_NAME +echo "Board v. :" $BOARD_VERSION echo "Specific Lib:" $LIB echo "" diff --git a/README.md b/README.md index 782ed6f7d..6edbe0127 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ _Note: Multi language build is not supported._ * Open Arduino and navigate to File -> Preferences -> Settings * To the text field `"Additional Boards Manager URLSs"` add `https://raw.githubusercontent.com/prusa3d/Arduino_Boards/master/IDE_Board_Manager/package_prusa3d_index.json` -* Open Board manager (`Tools->Board->Board manager`), and install `Prusa Research AVR MK3 RAMBo EINSy board` +* Open Board manager (`Tools->Board->Board manager`), and install `Prusa Research AVR Boards by Prusa Research` **c.** Modify compiler flags in `platform.txt` file From 7b29ce29b45c0bef41bfe604c43014ba88c2c139 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sat, 21 Dec 2019 22:48:30 +0100 Subject: [PATCH 092/180] Add a Linear Advance 1.0->1.5 compatibility layer Allow existing gcode using LA10 to transparently take advantage of LA15 by using a simple linear conversion function based on experimental results with the MK3 implementation of linear advance. Autodetect LA10 values based on the first M900 instruction contained in the print. In order to support printing mixed files without resetting the printer we also reset the autodetection status when starting a new SD print and/or when explicitly disabling LA. Since we cannot reliably detect whether a new print is started when printing via USB, also reset the detection status when homing in G28, which is generally performed once at each print. Note that this doesn't clear the previous K value, it only allows a subsequent M900 to provide LA10 values when printed after a LA15 file. --- Firmware/Configuration_adv.h | 1 + Firmware/Marlin_main.cpp | 29 +++++++++++++++++++++++--- Firmware/la10compat.cpp | 40 ++++++++++++++++++++++++++++++++++++ Firmware/la10compat.h | 39 +++++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 Firmware/la10compat.cpp create mode 100644 Firmware/la10compat.h diff --git a/Firmware/Configuration_adv.h b/Firmware/Configuration_adv.h index 7f25f07d5..d25b345c3 100644 --- a/Firmware/Configuration_adv.h +++ b/Firmware/Configuration_adv.h @@ -287,6 +287,7 @@ #ifdef LIN_ADVANCE #define LIN_ADVANCE_K 0 // Unit: mm compression per 1mm/s extruder speed + //#define LA_NOCOMPAT // Disable Linear Advance 1.0 compatibility //#define LA_LIVE_K // Allow adjusting K in the Tune menu //#define LA_DEBUG // If enabled, this will generate debug information output over USB. //#define LA_DEBUG_LOGIC // @wavexx: setup logic channels for isr debugging diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 816763ac1..8959bdd31 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -83,6 +83,9 @@ #include "Dcodes.h" #include "AutoDeplete.h" +#ifndef LA_NOCOMPAT +#include "la10compat.h" +#endif #ifdef SWSPI #include "swspi.h" @@ -2068,12 +2071,23 @@ static float probe_pt(float x, float y, float z_before) { */ inline void gcode_M900() { st_synchronize(); - + const float newK = code_seen('K') ? code_value_float() : -1; +#ifdef LA_NOCOMPAT if (newK >= 0 && newK < 10) - extruder_advance_K = newK; + extruder_advance_K = newK; else - SERIAL_ECHOLNPGM("K out of allowed range!"); + SERIAL_ECHOLNPGM("K out of allowed range!"); +#else + if (newK == 0) { + la10c_reset(); + extruder_advance_K = 0; + } + else if(newK > 0) + extruder_advance_K = la10c_value(newK); + else + SERIAL_ECHOLNPGM("K out of allowed range!"); +#endif SERIAL_ECHO_START; SERIAL_ECHOPGM("Advance K="); @@ -4136,6 +4150,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) // -------------------------------------------- case 28: { +#ifndef LA_NOCOMPAT + la10c_reset(); +#endif long home_x_value = 0; long home_y_value = 0; long home_z_value = 0; @@ -5372,6 +5389,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) else { failstats_reset_print(); +#ifndef LA_NOCOMPAT + la10c_reset(); +#endif card.startFileprint(); starttime=_millis(); } @@ -5465,6 +5485,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) if(code_seen('S')) if(strchr_pointerLA15 conversion +// +// When the current mode is UNKNOWN autodetection is active and any K<10 +// will set the mode to LA15, LA10 is set otherwise. When LA10 +// compatbility mode is active the K factor is converted to a LA15 +// equivalent (that is, the return value is always a LA15 value). +// +// Once the interpretation mode has been set it is kept until the mode +// is explicitly reset. This is done to handle transparent fallback for +// old firmware revisions in combination with the following gcode +// sequence: +// +// M900 K0.01 ; set LA15 value (interpreted by any firmware) +// M900 K10 ; set LA10 value (ignored by LA15 firmware) +// +// A LA15 firmware without this module will only parse the first +// correctly, rejecting the second. A LA10 FW will parse both, but keep +// the last value. Since the LA15 value, if present, corresponds to the +// truth value, the compatibility stub needs to "lock" onto the first +// seen value for the current print. +// +// The mode needs to be carefully reset for each print in order for +// diffent versions of M900 to be interpreted independently. + +#pragma once + +enum __attribute__((packed)) LA10C_MODE +{ + LA10C_UNKNOWN = 0, + LA10C_LA15 = 1, + LA10C_LA10 = 2 +}; + +// Explicitly set/reset the interpretation mode for la10c_value() +void la10c_mode_change(LA10C_MODE mode); +static inline void la10c_reset() { la10c_mode_change(LA10C_UNKNOWN); } + +// Return a LA15 K value according to the supplied value and mode +float la10c_value(float k); From a31319888c3d6660fc7ecd9869a6e5b2488339fc Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Mon, 23 Dec 2019 19:06:13 +0100 Subject: [PATCH 093/180] Fix fan_check_error check in usb print resume Also check for fan_check_error == EFCE_OK in addition to EFCE_FIXED. Reorganize the check in order to fix both #if[n]def FANCHECK cases, as similarly done in the SDSUPPORT case a few lines below. --- Firmware/ultralcd.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 5d0abeac9..588cb2480 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -6910,10 +6910,15 @@ static void lcd_main_menu() } + if(isPrintPaused && saved_printing_type == PRINTING_TYPE_USB) + { #ifdef FANCHECK - if((fan_check_error == EFCE_FIXED) && (saved_printing_type == PRINTING_TYPE_USB)) - MENU_ITEM_SUBMENU_P(_i("Resume print"), lcd_resume_print);////MSG_RESUME_PRINT + if((fan_check_error == EFCE_FIXED) || (fan_check_error == EFCE_OK)) + MENU_ITEM_SUBMENU_P(_i("Resume print"), lcd_resume_print);////MSG_RESUME_PRINT +#else + MENU_ITEM_SUBMENU_P(_i("Resume print"), lcd_resume_print);////MSG_RESUME_PRINT #endif + } #ifdef SDSUPPORT if (card.cardOK || lcd_commands_type == LcdCommands::Layer1Cal) From 301d64042bcb1a68744da60ccda02d549b37b578 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Fri, 27 Dec 2019 19:29:02 +0100 Subject: [PATCH 094/180] Set fsensor_watch_runout earlier to prevent re-entry Do not set/clear fsensor_watch_runout within fsensor_oq_meassure_start which is used outside of fsensor_update where it could have a different starting value. Set it within fsensor_stop_and_save_print to immediately prevent re-entry. --- Firmware/fsensor.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index 1c28d025f..b9b1f0685 100755 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -124,14 +124,16 @@ unsigned long nIRsensorLastTime; void fsensor_stop_and_save_print(void) { printf_P(PSTR("fsensor_stop_and_save_print\n")); - stop_and_save_print_to_ram(0, 0); //XYZE - no change + stop_and_save_print_to_ram(0, 0); + fsensor_watch_runout = false; } void fsensor_restore_print_and_continue(void) { printf_P(PSTR("fsensor_restore_print_and_continue\n")); + fsensor_watch_runout = true; fsensor_err_cnt = 0; - restore_print_from_ram_and_continue(0); //XYZ = orig, E - no change + restore_print_from_ram_and_continue(0); } // fsensor_checkpoint_print cuts the current print job at the current position, @@ -379,7 +381,6 @@ void fsensor_oq_meassure_start(uint8_t skip) fsensor_oq_sh_sum = 0; pat9125_update(); pat9125_y = 0; - fsensor_watch_runout = false; fsensor_oq_meassure = true; } @@ -391,7 +392,6 @@ void fsensor_oq_meassure_stop(void) printf_P(_N(" st_sum=%u yd_sum=%u er_sum=%u er_max=%hhu\n"), fsensor_oq_st_sum, fsensor_oq_yd_sum, fsensor_oq_er_sum, fsensor_oq_er_max); printf_P(_N(" yd_min=%u yd_max=%u yd_avg=%u sh_avg=%u\n"), fsensor_oq_yd_min, fsensor_oq_yd_max, (uint16_t)((uint32_t)fsensor_oq_yd_sum * fsensor_chunk_len / fsensor_oq_st_sum), (uint16_t)(fsensor_oq_sh_sum / fsensor_oq_samples)); fsensor_oq_meassure = false; - fsensor_watch_runout = true; fsensor_err_cnt = 0; } @@ -578,12 +578,13 @@ void fsensor_update(void) #ifdef PAT9125 if (fsensor_enabled && fsensor_watch_runout && (fsensor_err_cnt > FSENSOR_ERR_MAX)) { + fsensor_stop_and_save_print(); + bool autoload_enabled_tmp = fsensor_autoload_enabled; fsensor_autoload_enabled = false; bool oq_meassure_enabled_tmp = fsensor_oq_meassure_enabled; fsensor_oq_meassure_enabled = true; - fsensor_stop_and_save_print(); fsensor_err_cnt = 0; fsensor_oq_meassure_start(0); From fe4c00fb8a8ff32fcafecb2a730e432a7f065607 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Fri, 27 Dec 2019 19:35:08 +0100 Subject: [PATCH 095/180] Lift the extruder when checking for the filament This avoids leaving marks on the print --- Firmware/fsensor.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index b9b1f0685..02f7d572b 100755 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -585,6 +585,11 @@ void fsensor_update(void) bool oq_meassure_enabled_tmp = fsensor_oq_meassure_enabled; fsensor_oq_meassure_enabled = true; + // move the nozzle away while checking the filament + current_position[Z_AXIS] += 0.8; + if(current_position[Z_AXIS] > Z_MAX_POS) current_position[Z_AXIS] = Z_MAX_POS; + plan_buffer_line_curposXYZE(max_feedrate[Z_AXIS], active_extruder); + st_synchronize(); fsensor_err_cnt = 0; fsensor_oq_meassure_start(0); From 97170ed68dbfd5660f28f2f286d94bafee74d939 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Fri, 27 Dec 2019 19:37:20 +0100 Subject: [PATCH 096/180] Do not call process_commands() within fsensor_update() Plan moves directly to reduce the required stack size. --- Firmware/fsensor.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index 02f7d572b..f9875fa6e 100755 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -591,20 +591,15 @@ void fsensor_update(void) plan_buffer_line_curposXYZE(max_feedrate[Z_AXIS], active_extruder); st_synchronize(); + // check the filament in isolation fsensor_err_cnt = 0; fsensor_oq_meassure_start(0); - - enquecommand_front_P((PSTR("G1 E-3 F200"))); - process_commands(); - KEEPALIVE_STATE(IN_HANDLER); - cmdqueue_pop_front(); - st_synchronize(); - - enquecommand_front_P((PSTR("G1 E3 F200"))); - process_commands(); - KEEPALIVE_STATE(IN_HANDLER); - cmdqueue_pop_front(); - st_synchronize(); + float e_tmp = current_position[E_AXIS]; + current_position[E_AXIS] -= 3; + plan_buffer_line_curposXYZE(200/60, active_extruder); + current_position[E_AXIS] = e_tmp; + plan_buffer_line_curposXYZE(200/60, active_extruder); + st_synchronize(); uint8_t err_cnt = fsensor_err_cnt; fsensor_oq_meassure_stop(); From bd80ee88a0f0c8d5a354f7c81a8551d9ee297f5d Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sat, 28 Dec 2019 18:50:42 +0100 Subject: [PATCH 097/180] Set the IN_HANDLER busy state while checking the filament --- Firmware/fsensor.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index f9875fa6e..0113317eb 100755 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -579,6 +579,7 @@ void fsensor_update(void) if (fsensor_enabled && fsensor_watch_runout && (fsensor_err_cnt > FSENSOR_ERR_MAX)) { fsensor_stop_and_save_print(); + KEEPALIVE_STATE(IN_HANDLER); bool autoload_enabled_tmp = fsensor_autoload_enabled; fsensor_autoload_enabled = false; From 186f8816000f0c8632fe3c8cfe0aac8c0b13d4b1 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 29 Dec 2019 22:08:44 +0100 Subject: [PATCH 098/180] Avoid calling fsensor_update() one level earlier Move the common checks between filament sensors out of fsensor_update(). Disable the runout check if a saved state is already present (this check was missing in the PAT9125 variant) as this is currently not supported. Note that the CHECK_FSENSOR looks completely redundant besides e_active(). --- Firmware/Marlin_main.cpp | 3 ++- Firmware/fsensor.cpp | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 4970091ea..fc395900a 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -8606,7 +8606,8 @@ if(0) #ifdef PAT9125 fsensor_autoload_check_stop(); #endif //PAT9125 - fsensor_update(); + if (fsensor_enabled && !saved_printing) + fsensor_update(); } } } diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index 0113317eb..a7dbce979 100755 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -576,7 +576,7 @@ void fsensor_enque_M600(){ void fsensor_update(void) { #ifdef PAT9125 - if (fsensor_enabled && fsensor_watch_runout && (fsensor_err_cnt > FSENSOR_ERR_MAX)) + if (fsensor_watch_runout && (fsensor_err_cnt > FSENSOR_ERR_MAX)) { fsensor_stop_and_save_print(); KEEPALIVE_STATE(IN_HANDLER); @@ -621,7 +621,7 @@ void fsensor_update(void) fsensor_enque_M600(); } #else //PAT9125 - if (CHECK_FSENSOR && fsensor_enabled && ir_sensor_detected) + if (CHECK_FSENSOR && ir_sensor_detected) { if(digitalRead(IR_SENSOR_PIN)) { // IR_SENSOR_PIN ~ H From f5d382f9f4d77b32f1779099cc7fad1f1277d7e9 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sat, 28 Dec 2019 20:35:04 +0100 Subject: [PATCH 099/180] Remove useless st_synchronize calls when unparking --- Firmware/Marlin_main.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 4970091ea..994fba7bb 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -10312,12 +10312,10 @@ void restore_print_from_ram_and_continue(float e_move) //first move print head in XY to the saved position: plan_buffer_line(saved_pos[X_AXIS], saved_pos[Y_AXIS], current_position[Z_AXIS], saved_pos[E_AXIS] - e_move, homing_feedrate[Z_AXIS]/13, active_extruder); - st_synchronize(); //then move Z plan_buffer_line(saved_pos[X_AXIS], saved_pos[Y_AXIS], saved_pos[Z_AXIS], saved_pos[E_AXIS] - e_move, homing_feedrate[Z_AXIS]/13, active_extruder); - st_synchronize(); //and finaly unretract (35mm/s) - plan_buffer_line(saved_pos[X_AXIS], saved_pos[Y_AXIS], saved_pos[Z_AXIS], saved_pos[E_AXIS], 35, active_extruder); + plan_buffer_line(saved_pos[X_AXIS], saved_pos[Y_AXIS], saved_pos[Z_AXIS], saved_pos[E_AXIS], FILAMENTCHANGE_RFEED, active_extruder); st_synchronize(); #ifdef FANCHECK From d78636c308c0285fe2773d404c64811ecfea19a9 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 29 Dec 2019 23:25:16 +0100 Subject: [PATCH 100/180] Do not synchronize on M900 Since the advance factor is computed per-segment in LA15, there's no need to stop the planner. Allow changing K freely at each segment. This allows varying quality factors for different filling roles, see: https://github.com/supermerill/Slic3r/issues/108 During pause/resume/crashdetect or powerpanic K might temporarily be out of sync when used this way. If this becomes an issue, we might need to store K for each block, as done for the feedrate. --- Firmware/Marlin_main.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 8959bdd31..9a0977ab3 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -2070,8 +2070,6 @@ static float probe_pt(float x, float y, float z_before) { * K Set advance K factor */ inline void gcode_M900() { - st_synchronize(); - const float newK = code_seen('K') ? code_value_float() : -1; #ifdef LA_NOCOMPAT if (newK >= 0 && newK < 10) From fd0ed1f0eac44b5564110ce8db2d632dad13c66f Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Mon, 30 Dec 2019 11:32:27 +0100 Subject: [PATCH 101/180] Move LA reset from G28 to G80, do not reset on 0 In preparation for #2161, use MBL (G80) as a "new print" boundary instead of just re-homing to ensure the reset is issued only once for each print. Similarly, do not reset the autodetection when LA is disabled via M900 K0. This can/will be used during a print if different quality settings are used for different filling roles. --- Firmware/Marlin_main.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 9a0977ab3..97fbdf7f7 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -2078,7 +2078,6 @@ inline void gcode_M900() { SERIAL_ECHOLNPGM("K out of allowed range!"); #else if (newK == 0) { - la10c_reset(); extruder_advance_K = 0; } else if(newK > 0) @@ -4148,9 +4147,6 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) // -------------------------------------------- case 28: { -#ifndef LA_NOCOMPAT - la10c_reset(); -#endif long home_x_value = 0; long home_y_value = 0; long home_z_value = 0; @@ -4674,6 +4670,11 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) case_G80: { mesh_bed_leveling_flag = true; +#ifndef LA_NOCOMPAT + // When printing via USB there's no clear boundary between prints. Abuse MBL to indicate + // the beginning of a new print, allowing a new autodetected setting just after G80. + la10c_reset(); +#endif #ifndef PINDA_THERMISTOR static bool run = false; // thermistor-less PINDA temperature compensation is running #endif // ndef PINDA_THERMISTOR From 57be14fca6d791a550be515fc1c074d11296dcbd Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sat, 28 Dec 2019 20:26:19 +0100 Subject: [PATCH 102/180] Complete all pending moves before restoring a saved print --- Firmware/mmu.cpp | 1 + Firmware/ultralcd.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Firmware/mmu.cpp b/Firmware/mmu.cpp index 2bb2afa76..bc369fd53 100755 --- a/Firmware/mmu.cpp +++ b/Firmware/mmu.cpp @@ -1589,6 +1589,7 @@ void mmu_continue_loading(bool blocking) if (blocking) { marlin_wait_for_click(); + st_synchronize(); restore_print_from_ram_and_continue(0); state = Ls::Retry; } diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 5d0abeac9..f5b73d3ed 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -6764,12 +6764,13 @@ static bool fan_error_selftest() void lcd_resume_print() { lcd_return_to_status(); - lcd_reset_alert_level(); - lcd_setstatuspgm(_T(MSG_RESUMING_PRINT)); lcd_reset_alert_level(); //for fan speed error - if (fan_error_selftest()) return; //abort if error persists + lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS)); + st_synchronize(); + + lcd_setstatuspgm(_T(MSG_RESUMING_PRINT)); isPrintPaused = false; restore_print_from_ram_and_continue(0.0); pause_time += (_millis() - start_pause_print); //accumulate time when print is paused for correct statistics calculation From 86696156af0a17cfea873e01e7cf81d9f0a3e5a2 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Mon, 30 Dec 2019 13:17:12 +0100 Subject: [PATCH 103/180] Improve K error checking, allow to manually reset the version Properly check K independently for each version by delegating it to la10c_value() Handle -1 as a special case to allow manual reset. --- Firmware/Marlin_main.cpp | 17 +++++++++++------ Firmware/la10compat.cpp | 12 ++++++++++-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 97fbdf7f7..71e952a58 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -2070,20 +2070,25 @@ static float probe_pt(float x, float y, float z_before) { * K Set advance K factor */ inline void gcode_M900() { - const float newK = code_seen('K') ? code_value_float() : -1; + float newK = code_seen('K') ? code_value_float() : -2; #ifdef LA_NOCOMPAT if (newK >= 0 && newK < 10) extruder_advance_K = newK; else SERIAL_ECHOLNPGM("K out of allowed range!"); #else - if (newK == 0) { + if (newK == 0) extruder_advance_K = 0; - } - else if(newK > 0) - extruder_advance_K = la10c_value(newK); + else if (newK == -1) + la10c_reset(); else - SERIAL_ECHOLNPGM("K out of allowed range!"); + { + newK = la10c_value(newK); + if (newK < 0) + SERIAL_ECHOLNPGM("K out of allowed range!"); + else + extruder_advance_K = newK; + } #endif SERIAL_ECHO_START; diff --git a/Firmware/la10compat.cpp b/Firmware/la10compat.cpp index 41c3a8e6f..d54e5acea 100644 --- a/Firmware/la10compat.cpp +++ b/Firmware/la10compat.cpp @@ -31,10 +31,18 @@ static float la10c_convert(float k) float la10c_value(float k) { if(la10c_mode == LA10C_UNKNOWN) + { + // do not autodetect until a valid value is seen + if(k == 0) + return 0; + else if(k < 0) + return -1; + la10c_mode_change(k < 10? LA10C_LA15: LA10C_LA10); + } if(la10c_mode == LA10C_LA15) - return k; + return (k >= 0 && k < 10? k: -1); else - return la10c_convert(k); + return (k >= 0? la10c_convert(k): -1); } From 5660fcffb08841742103e67f32eb3cd3da30ae23 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Mon, 30 Dec 2019 14:49:07 +0100 Subject: [PATCH 104/180] Do not enqueue a E/Z moves unless requested Do not unconditionally enqueue a Z move if no move has been requested. Since Z is calculated using the absolute current (saved) position and scheduled for later execution, the queue order becomes relevant. --- Firmware/Marlin_main.cpp | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 3327f8f8e..c8e142c47 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -10238,23 +10238,29 @@ void stop_and_save_print_to_ram(float z_move, float e_move) // move away from the print. char buf[48]; - // First unretract (relative extrusion) - if(!saved_extruder_relative_mode){ - enquecommand(PSTR("M83"), true); - } - //retract 45mm/s - // A single sprintf may not be faster, but is definitely 20B shorter - // than a sequence of commands building the string piece by piece - // A snprintf would have been a safer call, but since it is not used - // in the whole program, its implementation would bring more bytes to the total size - // The behavior of dtostrf 8,3 should be roughly the same as %-0.3 - sprintf_P(buf, PSTR("G1 E%-0.3f F2700"), e_move); - enquecommand(buf, false); + if(e_move) + { + // First unretract (relative extrusion) + if(!saved_extruder_relative_mode){ + enquecommand(PSTR("M83"), true); + } + //retract 45mm/s + // A single sprintf may not be faster, but is definitely 20B shorter + // than a sequence of commands building the string piece by piece + // A snprintf would have been a safer call, but since it is not used + // in the whole program, its implementation would bring more bytes to the total size + // The behavior of dtostrf 8,3 should be roughly the same as %-0.3 + sprintf_P(buf, PSTR("G1 E%-0.3f F2700"), e_move); + enquecommand(buf, false); + } + + if(z_move) + { + // Then lift Z axis + sprintf_P(buf, PSTR("G1 Z%-0.3f F%-0.3f"), saved_pos[Z_AXIS] + z_move, homing_feedrate[Z_AXIS]); + enquecommand(buf, false); + } - // Then lift Z axis - sprintf_P(buf, PSTR("G1 Z%-0.3f F%-0.3f"), saved_pos[Z_AXIS] + z_move, homing_feedrate[Z_AXIS]); - // At this point the command queue is empty. - enquecommand(buf, false); // If this call is invoked from the main Arduino loop() function, let the caller know that the command // in the command queue is not the original command, but a new one, so it should not be removed from the queue. repeatcommand_front(); From f8a0d5d7737476f13c0699b1b9a879df4eddd78a Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Tue, 7 Jan 2020 19:51:30 +0200 Subject: [PATCH 105/180] Fix lcd_print_stop function --- Firmware/Marlin_main.cpp | 29 ++++++++++++----------- Firmware/ultralcd.cpp | 50 ++++++++++++++++++++++++++++++---------- 2 files changed, 53 insertions(+), 26 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 507a8f83e..62bfb68da 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -4692,13 +4692,13 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) // We don't know where we are! HOME! // Push the commands to the front of the message queue in the reverse order! // There shall be always enough space reserved for these commands. - if (lcd_commands_type != LcdCommands::StopPrint) { + // if (lcd_commands_type != LcdCommands::StopPrint) { repeatcommand_front(); // repeat G80 with all its parameters enquecommand_front_P((PSTR("G28 W0"))); - } - else { - mesh_bed_leveling_flag = false; - } + // } + // else { + // mesh_bed_leveling_flag = false; + // } break; } @@ -4728,23 +4728,23 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) #ifndef PINDA_THERMISTOR if (run == false && temp_cal_active == true && calibration_status_pinda() == true && target_temperature_bed >= 50) { - if (lcd_commands_type != LcdCommands::StopPrint) { + // if (lcd_commands_type != LcdCommands::StopPrint) { temp_compensation_start(); run = true; repeatcommand_front(); // repeat G80 with all its parameters enquecommand_front_P((PSTR("G28 W0"))); - } - else { - mesh_bed_leveling_flag = false; - } + // } + // else { + // mesh_bed_leveling_flag = false; + // } break; } run = false; #endif //PINDA_THERMISTOR - if (lcd_commands_type == LcdCommands::StopPrint) { - mesh_bed_leveling_flag = false; - break; - } + // if (lcd_commands_type == LcdCommands::StopPrint) { + // mesh_bed_leveling_flag = false; + // break; + // } // Save custom message state, set a new custom message state to display: Calibrating point 9. CustomMsg custom_message_type_old = custom_message_type; unsigned int custom_message_state_old = custom_message_state; @@ -8948,6 +8948,7 @@ static void wait_for_heater(long codenum, uint8_t extruder) { residencyStart = -1; /* continue to loop until we have reached the target temp _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */ + cancel_heatup = false; while ((!cancel_heatup) && ((residencyStart == -1) || (residencyStart >= 0 && (((unsigned int)(_millis() - residencyStart)) < (TEMP_RESIDENCY_TIME * 1000UL))))) { #else diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index d988e5488..d8b3e817b 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -250,7 +250,9 @@ static void fil_unload_menu(); static void lcd_disable_farm_mode(); static void lcd_set_fan_check(); static void lcd_cutter_enabled(); +#ifdef SNMM static char snmm_stop_print_menu(); +#endif //SNMM #ifdef SDCARD_SORT_ALPHA static void lcd_sort_type_set(); #endif @@ -1056,7 +1058,7 @@ static void lcd_status_screen() } if (current_click - && (lcd_commands_type != LcdCommands::StopPrint) //click is aborted unless stop print finishes + // && (lcd_commands_type != LcdCommands::StopPrint) //click is aborted unless stop print finishes && ( menu_block_entering_on_serious_errors == SERIOUS_ERR_NONE ) // or a serious error blocks entering the menu ) { @@ -1466,7 +1468,7 @@ void lcd_commands() } #endif // not SNMM - +/* if (lcd_commands_type == LcdCommands::StopPrint) /// stop print { @@ -1558,6 +1560,7 @@ void lcd_commands() lcd_commands_step = 7; } } +*/ if (lcd_commands_type == LcdCommands::FarmModeConfirm) /// farm mode confirm { @@ -6051,7 +6054,7 @@ void bowden_menu() { } } -//#ifdef SNMM +#ifdef SNMM static char snmm_stop_print_menu() { //menu for choosing which filaments will be unloaded in stop print lcd_clear(); @@ -6102,6 +6105,8 @@ static char snmm_stop_print_menu() { //menu for choosing which filaments will be } +#endif //SNMM + //! @brief Select one of numbered items //! //! Create list of items with header. Header can not be selected. @@ -7320,7 +7325,6 @@ void lcd_print_stop() // Clear any saved printing state cancel_saved_printing(); - cancel_heatup = true; // Abort the planner/queue/sd planner_abort_hard(); @@ -7331,19 +7335,41 @@ void lcd_print_stop() CRITICAL_SECTION_END; +#ifdef MESH_BED_LEVELING + mbl.active = false; //also prevents undoing the mbl compensation a second time in the second planner_abort_hard() +#endif + lcd_setstatuspgm(_T(MSG_PRINT_ABORTED)); stoptime = _millis(); unsigned long t = (stoptime - starttime - pause_time) / 1000; //time in s pause_time = 0; save_statistics(total_filament_used, t); - lcd_return_to_status(); - lcd_ignore_click(true); - lcd_commands_step = 0; - lcd_commands_type = LcdCommands::StopPrint; - // Turn off the print fan - SET_OUTPUT(FAN_PIN); - WRITE(FAN_PIN, 0); - fanSpeed = 0; + + lcd_commands_step = 0; + lcd_commands_type = LcdCommands::Idle; + + lcd_cooldown(); //turns off heaters and fan; goes to status screen. + cancel_heatup = true; //unroll temperature wait loop stack. + + current_position[Z_AXIS] += 10; //lift Z. + plan_buffer_line_curposXYZE(manual_feedrate[Z_AXIS] / 60, active_extruder); + + if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS]) //if axis are homed, move to parked position. + { + current_position[X_AXIS] = X_CANCEL_POS; + current_position[Y_AXIS] = Y_CANCEL_POS; + plan_buffer_line_curposXYZE(manual_feedrate[0] / 60, active_extruder); + } + st_synchronize(); + + if (mmu_enabled) extr_unload(); //M702 C + + finishAndDisableSteppers(); //M84 + + lcd_setstatuspgm(_T(WELCOME_MSG)); + custom_message_type = CustomMsg::Status; + + planner_abort_hard(); //needs to be done since plan_buffer_line resets waiting_inside_plan_buffer_line_print_aborted to false. Also copies current to destination. } void lcd_sdcard_stop() From 4422fc29f8c020347133e63b3fab67b4fd2cbe18 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Tue, 7 Jan 2020 20:42:21 +0200 Subject: [PATCH 106/180] Set XYZ to absolute and E to relative --- Firmware/ultralcd.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index d8b3e817b..44e9b4371 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -7370,6 +7370,11 @@ void lcd_print_stop() custom_message_type = CustomMsg::Status; planner_abort_hard(); //needs to be done since plan_buffer_line resets waiting_inside_plan_buffer_line_print_aborted to false. Also copies current to destination. + + axis_relative_modes[X_AXIS] = false; + axis_relative_modes[Y_AXIS] = false; + axis_relative_modes[Z_AXIS] = false; + axis_relative_modes[E_AXIS] = true; } void lcd_sdcard_stop() From 1996fc79409789d09dcc4c8bb21b4732df920679 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Tue, 7 Jan 2020 20:43:56 +0200 Subject: [PATCH 107/180] Remove commented-out code --- Firmware/Marlin_main.cpp | 26 +++-------- Firmware/ultralcd.cpp | 94 ---------------------------------------- 2 files changed, 6 insertions(+), 114 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 62bfb68da..94dd7dba4 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -4692,13 +4692,8 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) // We don't know where we are! HOME! // Push the commands to the front of the message queue in the reverse order! // There shall be always enough space reserved for these commands. - // if (lcd_commands_type != LcdCommands::StopPrint) { - repeatcommand_front(); // repeat G80 with all its parameters - enquecommand_front_P((PSTR("G28 W0"))); - // } - // else { - // mesh_bed_leveling_flag = false; - // } + repeatcommand_front(); // repeat G80 with all its parameters + enquecommand_front_P((PSTR("G28 W0"))); break; } @@ -4728,23 +4723,14 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) #ifndef PINDA_THERMISTOR if (run == false && temp_cal_active == true && calibration_status_pinda() == true && target_temperature_bed >= 50) { - // if (lcd_commands_type != LcdCommands::StopPrint) { - temp_compensation_start(); - run = true; - repeatcommand_front(); // repeat G80 with all its parameters - enquecommand_front_P((PSTR("G28 W0"))); - // } - // else { - // mesh_bed_leveling_flag = false; - // } + temp_compensation_start(); + run = true; + repeatcommand_front(); // repeat G80 with all its parameters + enquecommand_front_P((PSTR("G28 W0"))); break; } run = false; #endif //PINDA_THERMISTOR - // if (lcd_commands_type == LcdCommands::StopPrint) { - // mesh_bed_leveling_flag = false; - // break; - // } // Save custom message state, set a new custom message state to display: Calibrating point 9. CustomMsg custom_message_type_old = custom_message_type; unsigned int custom_message_state_old = custom_message_state; diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 44e9b4371..75d233620 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -1058,7 +1058,6 @@ static void lcd_status_screen() } if (current_click - // && (lcd_commands_type != LcdCommands::StopPrint) //click is aborted unless stop print finishes && ( menu_block_entering_on_serious_errors == SERIOUS_ERR_NONE ) // or a serious error blocks entering the menu ) { @@ -1468,99 +1467,6 @@ void lcd_commands() } #endif // not SNMM -/* - if (lcd_commands_type == LcdCommands::StopPrint) /// stop print - { - - - if (lcd_commands_step == 0) - { - lcd_commands_step = 6; - } - - if (lcd_commands_step == 1 && !blocks_queued()) - { - lcd_commands_step = 0; - lcd_commands_type = LcdCommands::Idle; - lcd_setstatuspgm(_T(WELCOME_MSG)); - custom_message_type = CustomMsg::Status; - isPrintPaused = false; - } - if (lcd_commands_step == 2 && !blocks_queued()) - { - setTargetBed(0); - enquecommand_P(PSTR("M104 S0")); //set hotend temp to 0 - - manage_heater(); - lcd_setstatuspgm(_T(WELCOME_MSG)); - cancel_heatup = false; - lcd_commands_step = 1; - } - if (lcd_commands_step == 3 && !blocks_queued()) - { - // M84: Disable steppers. - enquecommand_P(PSTR("M84")); - autotempShutdown(); - lcd_commands_step = 2; - } - if (lcd_commands_step == 4 && !blocks_queued()) - { - lcd_setstatuspgm(_T(MSG_PLEASE_WAIT)); - // G90: Absolute positioning. - enquecommand_P(PSTR("G90")); - // M83: Set extruder to relative mode. - enquecommand_P(PSTR("M83")); - #ifdef X_CANCEL_POS - enquecommand_P(PSTR("G1 X" STRINGIFY(X_CANCEL_POS) " Y" STRINGIFY(Y_CANCEL_POS) " E0 F7000")); - #else - enquecommand_P(PSTR("G1 X50 Y" STRINGIFY(Y_MAX_POS) " E0 F7000")); - #endif - lcd_ignore_click(false); - if (mmu_enabled) - lcd_commands_step = 8; - else - lcd_commands_step = 3; - } - if (lcd_commands_step == 5 && !blocks_queued()) - { - lcd_setstatuspgm(_T(MSG_PRINT_ABORTED)); - // G91: Set to relative positioning. - enquecommand_P(PSTR("G91")); - // Lift up. - enquecommand_P(PSTR("G1 Z15 F1500")); - if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS]) lcd_commands_step = 4; - else lcd_commands_step = 3; - } - if (lcd_commands_step == 6 && !blocks_queued()) - { - lcd_setstatuspgm(_T(MSG_PRINT_ABORTED)); - cancel_heatup = true; - setTargetBed(0); - if (mmu_enabled) - setAllTargetHotends(0); - manage_heater(); - custom_message_type = CustomMsg::FilamentLoading; - lcd_commands_step = 5; - } - if (lcd_commands_step == 7 && !blocks_queued()) - { - if (mmu_enabled) - enquecommand_P(PSTR("M702 C")); //current - else - switch(snmm_stop_print_menu()) - { - case 0: enquecommand_P(PSTR("M702")); break;//all - case 1: enquecommand_P(PSTR("M702 U")); break; //used - case 2: enquecommand_P(PSTR("M702 C")); break; //current - default: enquecommand_P(PSTR("M702")); break; - } - lcd_commands_step = 3; - } - if (lcd_commands_step == 8 && !blocks_queued()) { //step 8 is here for delay (going to next step after execution of all gcodes from step 4) - lcd_commands_step = 7; - } - } -*/ if (lcd_commands_type == LcdCommands::FarmModeConfirm) /// farm mode confirm { From d9e52835260b5780f076551ca35c1c4cb3eb5453 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Tue, 7 Jan 2020 21:02:13 +0200 Subject: [PATCH 108/180] Fix pause->stop->PrintFromSD scenario --- Firmware/ultralcd.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 75d233620..75031f46b 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -7281,6 +7281,8 @@ void lcd_print_stop() axis_relative_modes[Y_AXIS] = false; axis_relative_modes[Z_AXIS] = false; axis_relative_modes[E_AXIS] = true; + + isPrintPaused = false; //clear isPrintPaused flag to allow starting next print after pause->stop scenario. } void lcd_sdcard_stop() From bab756699f182a1733e62b2d59926bb09f8a9152 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 14 Jan 2020 20:24:14 +0100 Subject: [PATCH 109/180] Fix incorrect usage of plan_set_e_position() in G92 E* To maintain an accurate step count (which is required for correct position recovery), any call to plan_set_position&co needs to be done synchronously and from a halted state. However, G92 E* is currently special-cased to skip the sync (likely to avoid the associated performance cost), causing an incorrect E step count and position to be set. This breaks absolute position recovery, miscalculation of the LA factor and possibly other weird issues. We rewrite the handling of G92 to always sync but still special-case the frequent "G92 E0" for performance by using a free bit in the block flags. To avoid a sync, we relay the request for reset first to the planner which clears its internal state and then relays the request to the final stepper isr. --- Firmware/Marlin_main.cpp | 63 ++++++++++++++++++++++++++++++---------- Firmware/planner.cpp | 35 ++++++++++++++++++++++ Firmware/planner.h | 5 ++++ Firmware/stepper.cpp | 4 +++ 4 files changed, 91 insertions(+), 16 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 72a24312c..1cea6c59d 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3356,6 +3356,49 @@ static void gcode_PRUSA_BadRAMBoFanTest(){ #endif } + +// G92 - Set current position to coordinates given +static void gcode_G92() +{ + bool codes[NUM_AXIS]; + float values[NUM_AXIS]; + + // Check which axes need to be set + for(uint8_t i = 0; i < NUM_AXIS; ++i) + { + codes[i] = code_seen(axis_codes[i]); + if(codes[i]) + values[i] = code_value(); + } + + if((codes[E_AXIS] && values[E_AXIS] == 0) && + (!codes[X_AXIS] && !codes[Y_AXIS] && !codes[Z_AXIS])) + { + // As a special optimization, when _just_ clearing the E position + // we schedule a flag asynchronously along with the next block to + // reset the starting E position instead of stopping the planner + current_position[E_AXIS] = 0; + plan_reset_next_e(); + } + else + { + // In any other case we're forced to synchronize + st_synchronize(); + for(uint8_t i = 0; i < 3; ++i) + { + if(codes[i]) + current_position[i] = values[i] + cs.add_homing[i]; + } + if(codes[E_AXIS]) + current_position[E_AXIS] = values[E_AXIS]; + + // Set all at once + plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], + current_position[Z_AXIS], current_position[E_AXIS]); + } +} + + #ifdef BACKLASH_X extern uint8_t st_backlash_x; #endif //BACKLASH_X @@ -5217,22 +5260,10 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) //! ### G92 - Set position // ----------------------------- - case 92: - if(!code_seen(axis_codes[E_AXIS])) - st_synchronize(); - for(int8_t i=0; i < NUM_AXIS; i++) { - if(code_seen(axis_codes[i])) { - if(i == E_AXIS) { - current_position[i] = code_value(); - plan_set_e_position(current_position[E_AXIS]); - } - else { - current_position[i] = code_value()+cs.add_homing[i]; - plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); - } - } - } - break; + case 92: { + gcode_G92(); + } + break; //! ### G98 - Activate farm mode diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index f5270d4a2..8c26cef9b 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -130,6 +130,10 @@ float extruder_advance_K = LIN_ADVANCE_K; float position_float[NUM_AXIS]; #endif +// Request the next block to start at zero E count +static bool plan_reset_next_e_queue; +static bool plan_reset_next_e_sched; + // Returns the index of the next block in the ring buffer // NOTE: Removed modulo (%) operator, which uses an expensive divide and multiplication. static inline int8_t next_block_index(int8_t block_index) { @@ -441,6 +445,8 @@ void plan_init() { previous_speed[2] = 0.0; previous_speed[3] = 0.0; previous_nominal_speed = 0.0; + plan_reset_next_e_queue = false; + plan_reset_next_e_sched = false; } @@ -658,6 +664,9 @@ void planner_abort_hard() previous_speed[2] = 0.0; previous_speed[3] = 0.0; + plan_reset_next_e_queue = false; + plan_reset_next_e_sched = false; + // Relay to planner wait routine, that the current line shall be canceled. waiting_inside_plan_buffer_line_print_aborted = true; } @@ -721,6 +730,20 @@ void plan_buffer_line(float x, float y, float z, const float &e, float feed_rate // Save the global feedrate at scheduling time block->gcode_feedrate = feedrate; + // Reset the starting E position when requested + if (plan_reset_next_e_queue) + { + position[E_AXIS] = 0; +#ifdef LIN_ADVANCE + position_float[E_AXIS] = 0; +#endif + + // the block might still be discarded later, but we need to ensure the lower-level + // count_position is also reset correctly for consistent results! + plan_reset_next_e_queue = false; + plan_reset_next_e_sched = true; + } + #ifdef ENABLE_AUTO_BED_LEVELING apply_rotation_xyz(plan_bed_level_matrix, x, y, z); #endif // ENABLE_AUTO_BED_LEVELING @@ -1165,6 +1188,13 @@ Having the real displacement of the head, we can calculate the total movement le // Reset the block flag. block->flag = 0; + if (plan_reset_next_e_sched) + { + // finally propagate a pending reset + block->flag |= BLOCK_FLAG_E_RESET; + plan_reset_next_e_sched = false; + } + // Initial limit on the segment entry velocity. float vmax_junction; @@ -1367,6 +1397,11 @@ void plan_set_e_position(const float &e) st_set_e_position(position[E_AXIS]); } +void plan_reset_next_e() +{ + plan_reset_next_e_queue = true; +} + #ifdef PREVENT_DANGEROUS_EXTRUDE void set_extrude_min_temp(float temp) { diff --git a/Firmware/planner.h b/Firmware/planner.h index 8cb3218c1..23509acfc 100644 --- a/Firmware/planner.h +++ b/Firmware/planner.h @@ -44,6 +44,8 @@ enum BlockFlag { // than 32767, therefore the DDA algorithm may run with 16bit resolution only. // In addition, the stepper routine will not do any end stop checking for higher performance. BLOCK_FLAG_DDA_LOWRES = 8, + // Block starts with Zeroed E counter + BLOCK_FLAG_E_RESET = 16, }; union dda_isteps_t @@ -168,6 +170,9 @@ void plan_set_position(float x, float y, float z, const float &e); void plan_set_z_position(const float &z); void plan_set_e_position(const float &e); +// Reset the E position to zero at the start of the next segment +void plan_reset_next_e(); + extern bool e_active(); void check_axes_activity(); diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index ff17c845c..74625a633 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -362,6 +362,10 @@ FORCE_INLINE void stepper_next_block() LA_phase = -1; #endif + if (current_block->flag & BLOCK_FLAG_E_RESET) { + count_position[E_AXIS] = 0; + } + if (current_block->flag & BLOCK_FLAG_DDA_LOWRES) { counter_x.lo = -(current_block->step_event_count.lo >> 1); counter_y.lo = counter_x.lo; From 4a4d7976d1f935eb6974830b36a1f7a36fab6ec1 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 15 Jan 2020 15:30:48 +0200 Subject: [PATCH 110/180] Fix PRUSA typo --- Firmware/Marlin_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 957d2cd73..5e6eeb9d5 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3731,7 +3731,7 @@ void process_commands() Set of internal PRUSA commands #### Usage - P RUSA [ Ping | PRN | FAN | fn | thx | uvlo | MMURES | RESET | fv | M28 | SN | Fir | Rev | Lang | Lz | Beat | FR ] + PRUSA [ Ping | PRN | FAN | fn | thx | uvlo | MMURES | RESET | fv | M28 | SN | Fir | Rev | Lang | Lz | Beat | FR ] #### Parameters - `Ping` From 8449136520ced2c07068290f564617ac95f74635 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 15 Jan 2020 15:31:14 +0200 Subject: [PATCH 111/180] Separate M117 from the TMC2130 commands --- Firmware/Marlin_main.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 5e6eeb9d5..5dabe7741 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3599,16 +3599,7 @@ void process_commands() --------------------------------------------------------------------------------- ### M117 - Display Message M117: Display Message This causes the given message to be shown in the status line on an attached LCD. - - It is also used by internal to display status messages on LCD. - Here the internal status messages: - Only on MK3/s (TMC2130) - - CRASH DETECTED - - CRASH RECOVER - - CRASH_CANCEL - - TMC_SET_WAVE - - TMC_SET_STEP - - TMC_SET_CHOP + It is processed early as to allow printing messages that contain G, M, N or T. */ if (code_seen("M117")) { //moved to highest priority place to be able to to print strings which includes "G", "PRUSA" and "^" starpos = (strchr(strchr_pointer + 5, '*')); @@ -3618,6 +3609,19 @@ void process_commands() } #ifdef TMC2130 + /*! + --------------------------------------------------------------------------------- + ### Special internal commands + These are used by internal functions to process certain actions in the right order. Some of these are also usable by the user. + They are processed early as the commands are complex (strings). + These are only available on the MK3(S) as these require TMC2130 drivers: + - CRASH DETECTED + - CRASH RECOVER + - CRASH_CANCEL + - TMC_SET_WAVE + - TMC_SET_STEP + - TMC_SET_CHOP + */ else if (strncmp_P(CMDBUFFER_CURRENT_STRING, PSTR("CRASH_"), 6) == 0) { From 7ea00a7efd9156b61467367a584e8edaa0f56140 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 15 Jan 2020 15:31:28 +0200 Subject: [PATCH 112/180] Fix typo in page description --- Firmware/Marlin_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 5dabe7741..dd34d1de6 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3548,7 +3548,7 @@ extern uint8_t st_backlash_y; //! _This is a list of currently implemented G Codes in Prusa firmware (dynamically generated from doxygen)._ /** -They are shown in order of appierence in the code. +They are shown in order of appearance in the code. There are reasons why some G Codes aren't in numerical order. */ From 7118007efe18b6a37c5488259ae605a3df1cf092 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 15 Jan 2020 15:52:56 +0200 Subject: [PATCH 113/180] Adjustments --- Firmware/Marlin_main.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index dd34d1de6..cdbb8cedf 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3945,7 +3945,7 @@ eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,0xFFFF); --------------------------------------------------------------------------------- # G Codes ### G0, G1 - Coordinated movement X Y Z E G0 & G1: Move - In Prusa Frimware G0 and G1 are the same. + In Prusa Firmware G0 and G1 are the same. #### Usage G0 [ X | Y | Z | E | F | S ] @@ -4171,6 +4171,8 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G2, G3 - Controlled Arc Move G2 & G3: Controlled Arc Move + These commands don't propperly work with MBL enabled. The compensation only happens at the end of the move, so avoid long arcs. + #### Usage G2 [ X | Y | I | E | F ] (Clockwise Arc) @@ -4270,7 +4272,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G28 - Home all Axis one at a time G28: Move to Origin (Home) - Unsing `G28` without any paramters will perfom on the Prusa i3 printers home AND mesh bed leveling, while `G28 W` will just home the printer + Using `G28` without any parameters will perfom home of all Axis AND mesh bed leveling, while `G28 W` will just home the printer. #### Usage G28 [ X | Y | Z | W | C ] @@ -4279,7 +4281,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) - `X` - Flag to go back to the X axis origin - `Y` - Flag to go back to the Y axis origin - `Z` - Flag to go back to the Z axis origin - - `W` - Suppress mesh bed leveling + - `W` - Suppress mesh bed leveling if `X`, `Y` or `Z` are not provided - `C` - Calibrate X and Y origin (home) - Only on MK3/s */ case 28: @@ -4513,6 +4515,8 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G30 - Single Z Probe G30: Single Z-Probe + Sensor must be over the bed. + The maximum travel distance before an error is triggered is 10mm. */ case 30: { From 4cf4720a15ae093c25547c930b4f96ed547d6ff7 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 15 Jan 2020 17:27:54 +0200 Subject: [PATCH 114/180] Even more formatting fixes --- Firmware/Marlin_main.cpp | 239 ++++++++++++++++++++++----------------- 1 file changed, 138 insertions(+), 101 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index cdbb8cedf..2b8d81de6 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -4236,11 +4236,6 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G10 - Retract G10: Retract Retracts filament according to settings of `M207` - - #### Usage - - G10 - */ case 10: #if EXTRUDERS > 1 @@ -4255,10 +4250,6 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G11 - Retract recover G11: Unretract Unretracts/recovers filament according to settings of `M208` - #### Usage - - G11 - */ case 11: #if EXTRUDERS > 1 @@ -4537,10 +4528,6 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G75 - Print temperature interpolation G75: Print temperature interpolation Show/print PINDA temperature interpolating. - #### Usage - - G75 - */ case 75: { @@ -4556,11 +4543,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) The PINDAv2 sensor has a built-in thermistor which has the advantage that the calibration can be done once for all materials. The Original i3 Prusa MK2/s uses PINDAv1 and this calibration improves the temperature drift, but not as good as the PINDAv2. - - #### Usage - - G76 - + #### Example ``` @@ -4839,10 +4822,10 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) #### Parameters - `N` - Number of mesh points on x axis. Default is 3. Valid values are 3 and 7. - `R` - Probe retries. Default 3 max. 10 - - `V` - Verbosity level 1=low, 10=mid, 20=high. It can be only used if firmware has been compiled with SUPPORT_VERBOSITY active. + - `V` - Verbosity level 1=low, 10=mid, 20=high. It only can be used if the firmware has been compiled with SUPPORT_VERBOSITY active. Using the following parameters enables additional "manual" bed leveling correction. Valid values are -100 microns to 100 microns. - #### Additional Parameters + #### Additional Parameters - `L` - Left Bed Level correct value in um. - `R` - Right Bed Level correct value in um. - `F` - Front Bed Level correct value in um. @@ -4850,7 +4833,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) */ /* - * Probes a grid and produces a mesh to compensate for variable bed height + * Probes a grid and produces a mesh to compensate for variable bed height * The S0 report the points as below * +----> X-axis * | @@ -5269,11 +5252,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G81 - Mesh bed leveling status G81: Mesh bed leveling status Prints mesh bed leveling status and bed profile if activated. - #### Usage - - G81 - - */ + */ case 81: if (mbl.active) { SERIAL_PROTOCOLPGM("Num X,Y: "); @@ -5394,11 +5373,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G90 - Switch off relative mode G90: Set to Absolute Positioning - #### Usage - - G90 - - All coordinates from now on are absolute relative to the origin of the machine. + All coordinates from now on are absolute relative to the origin of the machine. E axis is also switched to absolute mode. */ case 90: { for(uint8_t i = 0; i != NUM_AXIS; ++i) @@ -5408,11 +5383,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G91 - Switch on relative mode G91: Set to Relative Positioning - #### Usage - - G91 - - All coordinates from now on are relative to the last position. + All coordinates from now on are relative to the last position. E axis is also switched to relative mode. */ case 91: { for(uint8_t i = 0; i != NUM_AXIS; ++i) @@ -5422,7 +5393,13 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G92 - Set position G92: Set Position - #### Usage + + It is used for setting the current position of each axis. The parameters are always absolute to the origin. + If a parameter is omitted, that axis will not be affected. + If `X`, `Y`, or `Z` axis are specified, the move afterwards might stutter because of Mesh Bed Leveling. `E` axis is not affected if the target position is 0 (`G92 E0`). + A G92 without coordinates will reset all axes to zero on some firmware. This is not the case for Prusa-Firmware! + + #### Usage G92 [ X | Y | Z | E ] @@ -5432,9 +5409,6 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) - `Z` - new Z axis position - `E` - new extruder position - Allows programming of absolute zero point, by reseting the current position to the values specified. This would set the machine's X coordinate to 10, and the extrude coordinate to 90. No physical motion will occur. - - A G92 without coordinates will reset all axes to zero on some firmware. */ case 92: { gcode_G92(); @@ -5445,11 +5419,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G98 - Activate farm mode G98: Activate farm mode Enable Prusa-specific Farm functions and g-code. - #### Usage - - G98 - - See Internal Prusa commands + See Internal Prusa commands. */ case 98: farm_mode = 1; @@ -5463,10 +5433,6 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G99 - Deactivate farm mode G99: Deactivate farm mode Disables Prusa-specific Farm functions and g-code. - #### Usage - - G99 - */ case 99: farm_mode = 0; @@ -5561,7 +5527,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; /*! - ### M17 - Enable axes M17: Enable/Power all stepper motors + ### M17 - Enable all axis M17: Enable/Power all stepper motors */ case 17: LCD_MESSAGERPGM(_i("No move."));////MSG_NO_MOVE @@ -5600,6 +5566,10 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### M23 - Select file M23: Select SD file + #### Usage + + M23 [filename] + */ case 23: starpos = (strchr(strchr_pointer + 4,'*')); @@ -5630,9 +5600,12 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) Set position in SD card file to index in bytes. This command is expected to be called after M23 and before M24. Otherwise effect of this command is undefined. - M26 [ S ] - - - `S` - Index in bytes + #### Usage + + M26 [ S ] + + #### Parameters + - `S` - Index in bytes */ case 26: if(card.cardOK && code_seen('S')) { @@ -5665,7 +5638,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; /*! ### M29 - Stop SD write M29: Stop writing to SD card - Currently has no effect. + Stops writing to the SD file signaling the end of the uploaded file. It is processed very early and it's not written to the card. */ case 29: //processed in write to file routine above @@ -5673,7 +5646,11 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; /*! - ### M30 - Delete file M30: Delete a file on the SD card + ### M30 - Delete file M30: Delete a file on the SD card + #### Usage + + M30 [filename] + */ case 30: if (card.cardOK){ @@ -5732,7 +5709,11 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; /*! - ### M982 - Start SD logging M928: Start SD logging + ### M928 - Start SD logging M928: Start SD logging + #### Usage + + M928 [filename] + */ case 928: starpos = (strchr(strchr_pointer + 5,'*')); @@ -5767,6 +5748,14 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### M42 - Set pin state M42: Switch I/O pin + #### Usage + + M42 [ P | S ] + + #### Parameters + - `P` - Pin number. + - `S` - Pin value. If the pin is analog, values are from 0 to 255. If the pin is digital, values are from 0 to 1. + */ case 42: if (code_seen('S')) @@ -5816,9 +5805,12 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### M45 - Bed skew and offset with manual Z up M45: Bed skew and offset with manual Z up - - M45 [ V ] - - `V` - Verbosity level 1, 10 and 20 (low, mid, high). Only when SUPPORT_VERBOSITY is defined. + #### Usage + + M45 [ V ] + #### Parameters + - `V` - Verbosity level 1, 10 and 20 (low, mid, high). Only when SUPPORT_VERBOSITY is defined. Optional. + - `Z` - If it is provided, only Z calibration will run. Otherwise full calibration is executed. */ case 45: // M45: Prusa3D: bed skew and offset with manual Z up { @@ -5915,18 +5907,21 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### M48 - Z-Probe repeatability measurement function M48: Measure Z-Probe repeatability - This function assumes the bed has been homed. Specifically, that a G28 command as been issued prior to invoking the M48 Z-Probe repeatability measurement function. Any information generated by a prior G29 Bed leveling command will be lost and need to be regenerated. + This function assumes the bed has been homed. Specifically, that a G28 command as been issued prior to invoking the M48 Z-Probe repeatability measurement function. Any information generated by a prior G29 Bed leveling command will be lost and needs to be regenerated. The number of samples will default to 10 if not specified. You can use upper or lower case letters for any of the options EXCEPT n. n must be in lower case because Marlin uses a capital N for its communication protocol and will get horribly confused if you send it a capital N. + @todo Why would you check for both uppercase and lowercase? Seems wasteful. + #### Usage + M48 [ n | X | Y | V | L ] + + #### Parameters - `n` - Number of samples. Valid values 4-50 - `X` - X position for samples - `Y` - Y position for samples - `V` - Verbose level. Valid values 1-4 - `L` - Legs of movementprior to doing probe. Valid values 1-15 - - */ case 48: // M48 Z-Probe repeatability { @@ -6168,14 +6163,15 @@ Sigma_Exit: /*! ### M73 - Set/get print progress M73: Set/Get build percentage - Prusa firmware just shows percent done and time remaining. - + #### Usage + M73 [ P | R | Q | S ] - - - `P` - Percent in normal mode - - `R` - Time remaining in normal mode - - `Q` - Percent in silent mode - - `S` - Time in silent mode + + #### Parameters + - `P` - Percent in normal mode + - `R` - Time remaining in normal mode + - `Q` - Percent in silent mode + - `S` - Time in silent mode */ case 73: //M73 show percent done and time remaining if(code_seen('P')) print_percent_done_normal = code_value(); @@ -6192,9 +6188,11 @@ Sigma_Exit: /*! ### M104 - Set hotend temperature M104: Set Extruder Temperature - + #### Usage + M104 [ S ] - + + #### Parameters - `S` - Target temperature */ case 104: // M104 @@ -6212,6 +6210,7 @@ Sigma_Exit: /*! ### M112 - Emergency stop M112: Full (Emergency) Stop + It is processed much earlier as to bypass the cmdqueue. */ case 112: kill(MSG_M112_KILL, 3); @@ -6219,6 +6218,12 @@ Sigma_Exit: /*! ### M140 - Set bed temperature M140: Set Bed Temperature (Fast) + #### Usage + + M140 [ S ] + + #### Parameters + - `S` - Target temperature */ case 140: if (code_seen('S')) setTargetBed(code_value()); @@ -6233,7 +6238,7 @@ Sigma_Exit: - `Tx:` - x Tool (actual / target) - `@:` - Hotend power - `B@:` - Bed power - - `P:` - PINDAv2 actual (only MK2.5/s and MK3.5/s) + - `P:` - PINDAv2 actual (only MK2.5/s and MK3/s) - `A:` - Ambient actual (only MK3/s) _Example:_ @@ -6338,7 +6343,10 @@ Sigma_Exit: /*! ### M109 - Wait for extruder temperature M109: Set Extruder Temperature and Wait - Parameters (not mandatory): + #### Usage + + M104 [ B | R | S ] + #### Parameters (not mandatory) - `S` - Set extruder temperature - `R` - Set extruder temperature @@ -6346,8 +6354,7 @@ Sigma_Exit: Parameters S and R are treated identically. Command always waits for both cool down and heat up. - If no parameters are supplied waits for previously - set extruder temperature. + If no parameters are supplied waits for previously set extruder temperature. */ case 109: { @@ -6400,7 +6407,11 @@ Sigma_Exit: /*! ### M190 - Wait for bed temperature M190: Wait for bed temperature to reach target temp - Parameters (not mandatory): + #### Usage + + M190 [ R | S ] + + #### Parameters (not mandatory) - `S` - Set extruder temperature and wait for heating - `R` - Set extruder temperature and wait for heating or cooling @@ -6463,6 +6474,12 @@ Sigma_Exit: /*! ### M106 - Set fan speed M106: Fan On + #### Usage + + M106 [ S ] + + #### Parameters + - `S` - Specifies the duty cycle of the print fan. Allowed values are 0-255. If it's omitted, a value of 255 is used. */ case 106: // M106 Sxxx Fan On S 0 .. 255 if (code_seen('S')){ @@ -6485,6 +6502,7 @@ Sigma_Exit: /*! ### M80 - Turn on the Power Supply M80: ATX Power On + Only works if the firmware is compiled with PS_ON_PIN defined. */ case 80: SET_OUTPUT(PS_ON_PIN); //GND @@ -6505,6 +6523,7 @@ Sigma_Exit: /*! ### M81 - Turn off Power Supply M81: ATX Power Off + Only works if the firmware is compiled with PS_ON_PIN defined. */ case 81: disable_heater(); @@ -6546,10 +6565,10 @@ Sigma_Exit: /*! ### M84 - Disable steppers M84: Stop idle hold - This command can be used to set the stepper inactivity timeout (`S`) or to disable steppers (`X`,`Y`,`Z`,`E`) + This command can be used without any additional parameters. In that case all steppers are disabled. - _This command can be used without any additional parameters._ + The file completeness check uses this parameter to detect an incomplete file. It has to be present at the end of a file with no parameters. M84 [ S | X | Y | Z | E ] @@ -6557,7 +6576,7 @@ Sigma_Exit: - `X` - X axsis - `Y` - Y axis - `Z` - Z axis - - `E` - Exruder drive(s) + - `E` - Exruder ### M18 - Disable steppers M18: Disable all stepper motors Equal to M84 (compatibility) @@ -6600,7 +6619,12 @@ Sigma_Exit: /*! ### M85 - Set max inactive time M85: Set Inactivity Shutdown Timer - Set Inactivity Shutdown Timer with parameter S. "M85 S0" will disable the inactivity shutdown time (default) + #### Usage + + M85 [ S ] + + #### Parameters + - `S` - specifies the time in seconds. If a value of 0 is specified, the timer is disabled. */ case 85: // M85 if(code_seen('S')) { @@ -6610,15 +6634,14 @@ Sigma_Exit: #ifdef SAFETYTIMER /*! - ### M86 - Set safety timer expiration time M86: Set Safety Timer expiration time - Sets the safety timer expiration time in seconds. - + ### M86 - Set safety timer expiration time M86: Set Safety Timer expiration time When safety timer expires, heatbed and nozzle target temperatures are set to zero. + #### Usage M86 [ S ] - - `S` - Seconds Setting it to 0 will disable safety timer. - + #### Parameters + - `S` - specifies the time in seconds. If a value of 0 is specified, the timer is disabled. */ case 86: if (code_seen('S')) { @@ -6631,13 +6654,15 @@ Sigma_Exit: /*! ### M92 Set Axis steps-per-unit M92: Set axis_steps_per_unit Allows programming of steps per unit (usually mm) for motor drives. These values are reset to firmware defaults on power on, unless saved to EEPROM if available (M500 in Marlin) - + #### Usage + M92 [ X | Y | Z | E ] - - `X` - Steps per unit for the X drive - - `Y` - Steps per unit for the Y drive - - `Z` - Steps per unit for the Z drive - - `E` - Steps per unit for the extruder drive(s) + #### Parameters + - `X` - Steps per unit for the X drive + - `Y` - Steps per unit for the Y drive + - `Z` - Steps per unit for the Z drive + - `E` - Steps per unit for the extruder drive */ case 92: for(int8_t i=0; i < NUM_AXIS; i++) @@ -6664,10 +6689,12 @@ Sigma_Exit: /*! ### M110 - Set Line number M110: Set Current Line Number Sets the line number in G-code - + #### Usage + M110 [ N ] - - `N` - Line number + #### Parameters + - `N` - Line number */ case 110: if (code_seen('N')) @@ -6676,11 +6703,13 @@ Sigma_Exit: /*! ### M113 - Get or set host keep-alive interval M113: Host Keepalive - During some lengthy processes, such as G29, Marlin may appear to the host to have “gone away.” The “host keepalive” feature will send messages to the host when Marlin is busy or waiting for user response so the host won’t try to reconnect. + During some lengthy processes, such as G29, Marlin may appear to the host to have “gone away.” The “host keepalive” feature will send messages to the host when Marlin is busy or waiting for user response so the host won’t try to reconnect (or disconnect). + #### Usage M113 [ S ] - - `S` - Seconds Default is 2 seconds between "busy" messages + #### Parameters + - `S` - Seconds. Default is 2 seconds between "busy" messages */ case 113: if (code_seen('S')) { @@ -6697,13 +6726,6 @@ Sigma_Exit: /*! ### M115 - Firmware info M115: Get Firmware Version and Capabilities Print the firmware info and capabilities - - M115 [ V | U ] - - - V - Report current installed firmware version - - U - Firmware version provided by G-code to be compared to current one. - - Without any arguments, prints Prusa firmware version number, machine type, extruder count and UUID. `M115 U` Checks the firmware version provided. If the firmware version provided by the U code is higher than the currently running firmware, it will pause the print for 30s and ask the user to upgrade the firmware. @@ -6720,6 +6742,13 @@ Sigma_Exit: `M115 U3.8.2-RC1` results on LCD display for 30s or user interaction: `New firmware version available: 3.8.2-RC1 Please upgrade.` + #### Usage + + M115 [ V | U ] + + #### Parameters + - V - Report current installed firmware version + - U - Firmware version provided by G-code to be compared to current one. */ case 115: // M115 if (code_seen('V')) { @@ -6844,6 +6873,14 @@ Sigma_Exit: /*! ### M150 - Set RGB(W) Color M150: Set LED color In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code by defining BLINKM and its dependencies. + #### Usage + + M150 [ R | U | B ] + + #### Parameters + - `R` - Red color value + - `U` - Green color value. It is NOT `G`! + - `B` - Blue color value */ case 150: { From cabfc37f157b278b021c8978acac59951d2f4856 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 15 Jan 2020 20:17:26 +0200 Subject: [PATCH 115/180] The other changes --- Firmware/Marlin_main.cpp | 709 +++++++++++++++++++++------------------ 1 file changed, 384 insertions(+), 325 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 2b8d81de6..671fc40c2 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -6899,9 +6899,11 @@ Sigma_Exit: /*! ### M200 - Set filament diameter M200: Set filament diameter - + #### Usage + M200 [ D | T ] + #### Parameters - `D` - Diameter in mm - `T` - Number of extruder (MMUs) */ @@ -6946,6 +6948,7 @@ Sigma_Exit: /*! ### M201 - Set Print Max Acceleration M201: Set max printing acceleration + For each axis individually. */ case 201: for (int8_t i = 0; i < NUM_AXIS; i++) @@ -6982,6 +6985,7 @@ Sigma_Exit: /*! ### M203 - Set Max Feedrate M203: Set maximum feedrate + For each axis individually. */ case 203: // M203 max feedrate mm/sec for (int8_t i = 0; i < NUM_AXIS; i++) @@ -7009,16 +7013,20 @@ Sigma_Exit: /*! ### M204 - Acceleration settings M204: Set default acceleration - */ - /*! Supporting old format: + #### Usage + Old format: - M204 [ S | T ] - - `S` - normal moves + M204 [ S | T ] + New format: + + M204 [ P | R | T ] + + #### Parameters + Old format: + - `S` - normal moves - `T` - filmanent only moves - and new format: - - M204 [ P | R | T ] + New format: - `P` - printing moves - `R` - filmanent only moves - `T` - travel moves (as of now T is ignored) @@ -7041,7 +7049,9 @@ Sigma_Exit: cs.retract_acceleration = code_value(); if(code_seen('T')) { // Interpret the T value as the travel acceleration in the new Marlin format. - //FIXME Prusa3D firmware currently does not support travel acceleration value independent from the extruding acceleration value. + /*! + @todo Prusa3D firmware currently does not support travel acceleration value independent from the extruding acceleration value. + */ // travel_acceleration = code_value(); } } @@ -7050,11 +7060,12 @@ Sigma_Exit: /*! ### M205 - Set advanced settings M205: Advanced settings - */ - /*! Set some advanced settings related to movement. - - M205 [ S | T | B | X | Y | Z | E ] + Set some advanced settings related to movement. + #### Usage + M205 [ S | T | B | X | Y | Z | E ] + + #### Parameters - `S` - Minimum feedrate for print moves (unit/s) - `T` - Minimum feedrate for travel moves (units/s) - `B` - Minimum segment time (us) @@ -7079,9 +7090,11 @@ Sigma_Exit: /*! ### M206 - Set additional homing offsets M206: Offset axes + #### Usage - M206 [ X | Y | Z] + M206 [ X | Y | Z ] + #### Parameters - `X` - X axis offset - `Y` - Y axis offset - `Z` - Z axis offset @@ -7096,9 +7109,11 @@ Sigma_Exit: /*! ### M207 - Set firmware retraction M207: Set retract length - - M207 [ S | F | Z] + #### Usage + M207 [ S | F | Z ] + + #### Parameters - `S` - positive length to retract, in mm - `F` - retraction feedrate, in mm/min - `Z` - additional zlift/hop @@ -7121,9 +7136,11 @@ Sigma_Exit: /*! ### M208 - Set retract recover length M208: Set unretract length - - M208 [ S | F ] + #### Usage + M208 [ S | F ] + + #### Parameters - `S` - positive length surplus to the M207 Snnn, in mm - `F` - feedrate, in mm/sec */ @@ -7141,12 +7158,13 @@ Sigma_Exit: /*! ### M209 - Enable/disable automatict retract M209: Enable automatic retract - - M209 [ S ] - - - `S` - 1=true or 0=false - This boolean value S 1=true or 0=false enables automatic retract detect if the slicer did not support G10/G11: every normal extrude-only move will be classified as retract depending on the direction. + #### Usage + + M209 [ S ] + + #### Parameters + - `S` - 1=true or 0=false */ case 209: // M209 - S<1=true/0=false> enable automatic retract detect if the slicer did not support G10/11: every normal extrude-only move will be classified as retract depending on the direction. { @@ -7192,6 +7210,13 @@ Sigma_Exit: /*! ### M218 - Set hotend offset M218: Set Hotend Offset In Prusa Firmware this G-code is only active if `EXTRUDERS` is higher then 1 in the source code. On Original i3 Prusa MK2/s MK2.5/s MK3/s it is not active. + #### Usage + + M218 [ X | Y ] + + #### Parameters + - `X` - X offset + - `Y` - Y offset */ case 218: // M218 - set hotend offset (in mm), T X Y { @@ -7222,13 +7247,14 @@ Sigma_Exit: /*! ### M220 Set feedrate percentage M220: Set speed factor override percentage - - M220 [ B | S | R ] - - - `B` - Backup current speed factor - - `S` - Speed factor override percentage (0..100 or higher) - - `R` - Restore previous speed factor - + #### Usage + + M220 [ B | S | R ] + + #### Parameters + - `B` - Backup current speed factor + - `S` - Speed factor override percentage (0..100 or higher) + - `R` - Restore previous speed factor */ case 220: // M220 S- set speed factor override percentage { @@ -7248,12 +7274,13 @@ Sigma_Exit: /*! ### M221 - Set extrude factor override percentage M221: Set extrude factor override percentage - - M221 [ S | T ] - - - `S` - Extrude factor override percentage (0..100 or higher), default 100% - - `T` - Extruder drive number (Prusa Firmware only), default 0 if not set. - + #### Usage + + M221 [ S | T ] + + #### Parameters + - `S` - Extrude factor override percentage (0..100 or higher), default 100% + - `T` - Extruder drive number (Prusa Firmware only), default 0 if not set. */ case 221: // M221 S- set extrude factor override percentage { @@ -7279,13 +7306,14 @@ Sigma_Exit: /*! ### M226 - Wait for Pin state M226: Wait for pin state - - M226 [ P | S ] - - - `P` - pin number - - `S` - pin state - Wait until the specified pin reaches the state required + #### Usage + + M226 [ P | S ] + + #### Parameters + - `P` - pin number + - `S` - pin state */ case 226: // M226 P S- Wait until the specified pin reaches the state required { @@ -7344,6 +7372,13 @@ Sigma_Exit: /*! ### M280 - Set/Get servo position M280: Set servo position In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code. + #### Usage + + M280 [ P | S ] + + #### Parameters + - `P` - Servo index (id) + - `S` - Target position */ case 280: // M280 - set servo position absolute. P: servo index, S: angle or microseconds { @@ -7386,13 +7421,14 @@ Sigma_Exit: /*! ### M300 - Play tone M300: Play beep sound - - M300 [ S | P ] - - - `S` - frequency in Hz - - `P` - duration in milliseconds - In Prusa Firmware the defaults are `100Hz` and `1000ms`, so that `M300` without parameters will beep for a second. + #### Usage + + M300 [ S | P ] + + #### Parameters + - `S` - frequency in Hz. Not all firmware versions support this parameter + - `P` - duration in milliseconds */ case 300: // M300 { @@ -7416,17 +7452,17 @@ Sigma_Exit: /*! ### M301 - Set hotend PID M301: Set PID parameters - - M301 [ P | I | D | C ] - - - `P` - proportional (Kp) - - `I` - integral (Ki) - - `D` - derivative (Kd) - - `C` - heating power=Kc*(e_speed0) - Sets Proportional (P), Integral (I) and Derivative (D) values for hot end. - - See also PID Tuning. + See also PID Tuning. + #### Usage + + M301 [ P | I | D | C ] + + #### Parameters + - `P` - proportional (Kp) + - `I` - integral (Ki) + - `D` - derivative (Kd) + - `C` - heating power=Kc*(e_speed0) */ case 301: { @@ -7459,16 +7495,16 @@ Sigma_Exit: /*! ### M304 - Set bed PID M304: Set PID parameters - Bed - - M304 [ P | I | D ] - - - `P` - proportional (Kp) - - `I` - integral (Ki) - - `D` - derivative (Kd) - Sets Proportional (P), Integral (I) and Derivative (D) values for bed. - - See also PID Tuning. + See also PID Tuning. + #### Usage + + M304 [ P | I | D ] + + #### Parameters + - `P` - proportional (Kp) + - `I` - integral (Ki) + - `D` - derivative (Kd) */ case 304: { @@ -7494,7 +7530,7 @@ Sigma_Exit: In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code. - You need to define `CHDK` and assign a `PHOTOGRAPH_PIN` to bea ble to use it. + You need to (re)define and assign `CHDK` or `PHOTOGRAPH_PIN` the correct pin number to be able to use the feature. */ case 240: // M240 Triggers a camera by emulating a Canon RC-1 : http://www.doc-diy.net/photo/rc-1_hacked/ { @@ -7505,9 +7541,7 @@ Sigma_Exit: chdkHigh = _millis(); chdkActive = true; - #else - - #if defined(PHOTOGRAPH_PIN) && PHOTOGRAPH_PIN > -1 + #elif defined(PHOTOGRAPH_PIN) && PHOTOGRAPH_PIN > -1 const uint8_t NUM_PULSES=16; const float PULSE_LENGTH=0.01524; for(int i=0; i < NUM_PULSES; i++) { @@ -7524,19 +7558,19 @@ Sigma_Exit: _delay_ms(PULSE_LENGTH); } #endif - #endif //chdk end if } break; #ifdef PREVENT_DANGEROUS_EXTRUDE /*! ### M302 - Allow cold extrude, or set minimum extrude temperature M302: Allow cold extrudes - - M302 [ S ] - - - `S` - Cold extrude minimum temperature - - This tells the printer to allow movement of the extruder motor above a certain temperature, or if disabled, to allow extruder movement when the hotend is below a safe printing temperature. + This tells the printer to allow movement of the extruder motor above a certain temperature, or if disabled, to allow extruder movement when the hotend is below a safe printing temperature. + #### Usage + + M302 [ S ] + + #### Parameters + - `S` - Cold extrude minimum temperature */ case 302: { @@ -7549,14 +7583,15 @@ Sigma_Exit: /*! ### M303 - PID autotune M303: Run PID tuning - - M303 [ E | S | C ] - - - `E` - Extruder, default `E0`. - - `S` - Target temperature, default `210°C` - - `C` - Cycles, default `5` + PID Tuning refers to a control algorithm used in some repraps to tune heating behavior for hot ends and heated beds. This command generates Proportional (Kp), Integral (Ki), and Derivative (Kd) values for the hotend or bed. Send the appropriate code and wait for the output to update the firmware values. + #### Usage - PID Tuning refers to a control algorithm used in some repraps to tune heating behavior for hot ends and heated beds. This command generates Proportional (Kp), Integral (Ki), and Derivative (Kd) values for the hotend or bed (`E-1`). Send the appropriate code and wait for the output to update the firmware. + M303 [ E | S | C ] + + #### Parameters + - `E` - Extruder, default `E0`. Use `E-1` to calibrate the bed PID + - `S` - Target temperature, default `210°C` for hotend, 70 for bed + - `C` - Cycles, default `5` */ case 303: { @@ -7574,8 +7609,8 @@ Sigma_Exit: /*! ### M400 - Wait for all moves to finish M400: Wait for current moves to finish - - Finishes all current moves and and thus clears the buffer. + Finishes all current moves and and thus clears the buffer. + Equivalent to `G4` with no parameters. */ case 400: { @@ -7585,15 +7620,15 @@ Sigma_Exit: /*! ### M403 - Set filament type (material) for particular extruder and notify the MMU M403 - Set filament type (material) for particular extruder and notify the MMU - - M403 [ E | F ] - - - `E` - Extruder number - - `F` - Filament type - - Currently three different materials are needed (default, flex and PVA). - - And storing this information for different load/unload profiles etc. in the future firmware does not have to wait for "ok" from MMU. + Currently three different materials are needed (default, flex and PVA). + And storing this information for different load/unload profiles etc. in the future firmware does not have to wait for "ok" from MMU. + #### Usage + + M403 [ E | F ] + + #### Parameters + - `E` - Extruder number. 0-indexed. + - `F` - Filament type */ case 403: { @@ -7613,8 +7648,7 @@ Sigma_Exit: /*! ### M500 - Store settings in EEPROM M500: Store parameters in non-volatile storage - - Save current parameters to EEPROM, SD card or other non-volatile storage. + Save current parameters to EEPROM. */ case 500: { @@ -7624,8 +7658,7 @@ Sigma_Exit: /*! ### M501 - Read settings from EEPROM M501: Read parameters from EEPROM - - Set the active parameters to those stored in the EEPROM, SD card or other non-volatile storage. This is useful to revert parameters after experimenting with them. + Set the active parameters to those stored in the EEPROM. This is useful to revert parameters after experimenting with them. */ case 501: { @@ -7635,8 +7668,7 @@ Sigma_Exit: /*! ### M502 - Revert all settings to factory default M502: Restore Default Settings - - This command resets all tunable parameters to their default values, as set in the firmware's configuration files. This doesn't reset any parameters stored in the EEPROM, so it must be followed with M500 to reboot with default settings. + This command resets all tunable parameters to their default values, as set in the firmware's configuration files. This doesn't reset any parameters stored in the EEPROM, so it must be followed by M500 to write the default settings. */ case 502: { @@ -7646,7 +7678,6 @@ Sigma_Exit: /*! ### M503 - Repport all settings currently in memory M503: Report Current Settings - This command asks the firmware to reply with the current print settings as set in memory. Settings will differ from EEPROM contents if changed since the last load / save. The reply output includes the G-Code commands to produce each setting. For example, Steps-Per-Unit values are displayed as an M92 command. */ case 503: @@ -7657,7 +7688,6 @@ Sigma_Exit: /*! ### M509 - Force language selection M509: Force language selection - Resets the language to English. Only on Original Prusa i3 MK2.5/s and MK3/s with multiple languages. */ @@ -7672,8 +7702,13 @@ Sigma_Exit: /*! ### M540 - Abort print on endstop hit (enable/disable) M540 in Marlin: Enable/Disable "Stop SD Print on Endstop Hit" - In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code. You must define `ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED`. + #### Usage + + M540 [ S ] + + #### Parameters + - `S` - disabled=0, enabled=1 */ case 540: { @@ -7684,14 +7719,14 @@ Sigma_Exit: /*! ### M851 - Set Z-Probe Offset M851: Set Z-Probe Offset" - - M4861 [ Z ] - - - `Z` - Z offset probe to nozzle. - - Sets the Z-probe Z offset. This offset is used to determine the actual Z position of the nozzle when using a probe to home Z with G28. This value may also be used by G81 (Prusa) / G29 (Marlin) to apply correction to the Z position. - + Sets the Z-probe Z offset. This offset is used to determine the actual Z position of the nozzle when using a probe to home Z with G28. This value may also be used by G81 (Prusa) / G29 (Marlin) to apply correction to the Z position. This value represents the distance from nozzle to the bed surface at the point where the probe is triggered. This value will be negative for typical switch probes, inductive probes, and setups where the nozzle makes a circuit with a raised metal contact. This setting will be greater than zero on machines where the nozzle itself is used as the probe, pressing down on the bed to press a switch. (This is a common setup on delta machines.) + #### Usage + + M851 [ Z ] + + #### Parameters + - `Z` - Z offset probe to nozzle. */ #ifdef CUSTOM_M_CODE_SET_Z_PROBE_OFFSET case CUSTOM_M_CODE_SET_Z_PROBE_OFFSET: @@ -7733,19 +7768,18 @@ Sigma_Exit: /*! ### M600 - Initiate Filament change procedure M600: Filament change pause - - M600 [ X | Y | Z | E | L | AUTO ] - - - `X` - X position, default 211 - - `Y` - Y position, default 0 - - `Z` - relative lift Z, default 2. - - `E` - initial retract, default -2 - - `L` - later retract distance for removal, default -80 - - `AUTO` - Automatically (only with MMU) - - Initiates Filament change, it is also used during Filament Runout Sensor process. - + Initiates Filament change, it is also used during Filament Runout Sensor process. If the `M600` is triggered under 25mm it will do a Z-lift of 25mm to prevent a filament blob. + #### Usage + + M600 [ X | Y | Z | E | L | AUTO ] + + - `X` - X position, default 211 + - `Y` - Y position, default 0 + - `Z` - relative lift Z, default 2. + - `E` - initial retract, default -2 + - `L` - later retract distance for removal, default -80 + - `AUTO` - Automatically (only with MMU) */ case 600: //Pause for filament change X[pos] Y[pos] Z[relative lift] E[initial retract] L[later retract distance for removal] { @@ -7863,12 +7897,13 @@ Sigma_Exit: #ifdef PINDA_THERMISTOR /*! ### M860 - Wait for extruder temperature (PINDA) M860 Wait for Probe Temperature - - M860 [ S ] - - - `S` - Target temperature - Wait for PINDA thermistor to reach target temperature + #### Usage + + M860 [ S ] + + #### Parameters + - `S` - Target temperature */ case 860: { @@ -7916,16 +7951,17 @@ Sigma_Exit: /*! ### M861 - Set/Get PINDA temperature compensation offsets M861 Set Probe Thermal Compensation - + Set compensation ustep value `S` for compensation table index `I`. + #### Usage + M861 [ ? | ! | Z | S | I ] - - - `?` - Print current EEPROM offset values - - `!` - Set factory default values - - `Z` - Set all values to 0 (effectively disabling PINDA temperature compensation) - - `S` - Microsteps - - `I` - Table index - - Set compensation ustep value `S` for compensation table index `I`. + + #### Parameters + - `?` - Print current EEPROM offset values + - `!` - Set factory default values + - `Z` - Set all values to 0 (effectively disabling PINDA temperature compensation) + - `S` - Microsteps + - `I` - Table index */ case 861: if (code_seen('?')) { // ? - Print out current EEPROM offset values @@ -8097,14 +8133,16 @@ Sigma_Exit: /*! ### M900 - Set Linear advance options M900 Set Linear Advance Scaling Factors Sets the advance extrusion factors for Linear Advance. If any of the R, W, H, or D parameters are set to zero the ratio will be computed dynamically during printing. - - M900 [ K | R | W | H | D] - - - `K` - Advance K factor - - `R` - Set ratio directly (overrides WH/D) - - `W` - Width - - `H` - Height - - `D` - Diameter Set ratio from WH/D + #### Usage + + M900 [ K | R | W | H | D] + + #### Parameters + - `K` - Advance K factor + - `R` - Set ratio directly (overrides WH/D) + - `W` - Width + - `H` - Height + - `D` - Diameter Set ratio from WH/D */ case 900: gcode_M900(); @@ -8114,17 +8152,17 @@ Sigma_Exit: /*! ### M907 - Set digital trimpot motor current in mA using axis codes M907: Set digital trimpot motor Set digital trimpot motor current using axis codes (X, Y, Z, E, B, S). + #### Usage + + M907 [ X | Y | Z | E | B | S ] - M907 [ X | Y | Z | E | B | S ] - - - `X` - X motor driver - - `Y` - Y motor driver - - `Z` - Z motor driver - - `E` - Extruder motor driver - - `B` - ?? - - `S` - ?? - - @todo What are `B` and `S` in M907? + #### Parameters + - `X` - X motor driver + - `Y` - Y motor driver + - `Z` - Z motor driver + - `E` - Extruder motor driver + - `B` - Second Extruder motor driver + - `S` - All motors */ case 907: { @@ -8161,7 +8199,14 @@ Sigma_Exit: /*! ### M908 - Control digital trimpot directly M908: Control digital trimpot directly - In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code. + In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code. Not usable on Prusa printers. + #### Usage + + M908 [ P | S ] + + #### Parameters + - `P` - channel + - `S` - current */ case 908: { @@ -8190,13 +8235,15 @@ Sigma_Exit: /*! ### M911 - Set TMC2130 holding currents M911: Set TMC2130 holding currents Not active in default, only if `TMC2130_SERVICE_CODES_M910_M918` is defined in source code. - - M911 [ X | Y | Z | E ] - - - `X` - X stepper driver holding current value - - `Y` - Y stepper driver holding current value - - `Z` - Z stepper driver holding current value - - `E` - Extruder stepper driver holding current value + #### Usage + + M911 [ X | Y | Z | E ] + + #### Parameters + - `X` - X stepper driver holding current value + - `Y` - Y stepper driver holding current value + - `Z` - Z stepper driver holding current value + - `E` - Extruder stepper driver holding current value */ case 911: { @@ -8210,14 +8257,15 @@ Sigma_Exit: /*! ### M912 - Set TMC2130 running currents M912: Set TMC2130 running currents Not active in default, only if `TMC2130_SERVICE_CODES_M910_M918` is defined in source code. - - M912 [ X | Y | Z | E ] - - - - `X` - X stepper driver running current value - - `Y` - Y stepper driver running current value - - `Z` - Z stepper driver running current value - - `E` - Extruder stepper driver running current value + #### Usage + + M912 [ X | Y | Z | E ] + + #### Parameters + - `X` - X stepper driver running current value + - `Y` - Y stepper driver running current value + - `Z` - Z stepper driver running current value + - `E` - Extruder stepper driver running current value */ case 912: { @@ -8266,14 +8314,15 @@ Sigma_Exit: /*! ### M916 - Set TMC2130 Stallguard sensitivity threshold M916: Set TMC2130 Stallguard sensitivity threshold Not active in default, only if `TMC2130_SERVICE_CODES_M910_M918` is defined in source code. - - M916 [ X | Y | Z | E ] - - - - `X` - X stepper driver stallguard sensitivity threshold value - - `Y` - Y stepper driver stallguard sensitivity threshold value - - `Z` - Z stepper driver stallguard sensitivity threshold value - - `E` - Extruder stepper driver stallguard sensitivity threshold value + #### Usage + + M916 [ X | Y | Z | E ] + + #### Parameters + - `X` - X stepper driver stallguard sensitivity threshold value + - `Y` - Y stepper driver stallguard sensitivity threshold value + - `Z` - Z stepper driver stallguard sensitivity threshold value + - `E` - Extruder stepper driver stallguard sensitivity threshold value */ case 916: { @@ -8289,14 +8338,15 @@ Sigma_Exit: /*! ### M917 - Set TMC2130 PWM amplitude offset (pwm_ampl) M917: Set TMC2130 PWM amplitude offset (pwm_ampl) Not active in default, only if `TMC2130_SERVICE_CODES_M910_M918` is defined in source code. - - M917 [ X | Y | Z | E ] - - - - `X` - X stepper driver PWM amplitude offset value - - `Y` - Y stepper driver PWM amplitude offset value - - `Z` - Z stepper driver PWM amplitude offset value - - `E` - Extruder stepper driver PWM amplitude offset value + #### Usage + + M917 [ X | Y | Z | E ] + + #### Parameters + - `X` - X stepper driver PWM amplitude offset value + - `Y` - Y stepper driver PWM amplitude offset value + - `Z` - Z stepper driver PWM amplitude offset value + - `E` - Extruder stepper driver PWM amplitude offset value */ case 917: { @@ -8310,14 +8360,15 @@ Sigma_Exit: /*! ### M918 - Set TMC2130 PWM amplitude gradient (pwm_grad) M918: Set TMC2130 PWM amplitude gradient (pwm_grad) Not active in default, only if `TMC2130_SERVICE_CODES_M910_M918` is defined in source code. - - M918 [ X | Y | Z | E ] - - - - `X` - X stepper driver PWM amplitude gradient value - - `Y` - Y stepper driver PWM amplitude gradient value - - `Z` - Z stepper driver PWM amplitude gradient value - - `E` - Extruder stepper driver PWM amplitude gradient value + #### Usage + + M918 [ X | Y | Z | E ] + + #### Parameters + - `X` - X stepper driver PWM amplitude gradient value + - `Y` - Y stepper driver PWM amplitude gradient value + - `Z` - Z stepper driver PWM amplitude gradient value + - `E` - Extruder stepper driver PWM amplitude gradient value */ case 918: { @@ -8332,7 +8383,21 @@ Sigma_Exit: /*! ### M350 - Set microstepping mode M350: Set microstepping mode - Warning: Steps per unit remains unchanged. S code sets stepping mode for all drivers. + Printers with TMC2130 drivers have `X`, `Y`, `Z` and `E` as options. The steps-per-unit value is updated accordingly. Not all resolutions are valid! + Printers without TMC2130 drivers also have `B` and `S` options. In this case, the steps-per-unit value in not changed! + #### Usage + + M350 [ X | Y | Z | E | B | S ] + + #### Parameters + - `X` - X new resolution + - `Y` - Y new resolution + - `Z` - Z new resolution + - `E` - E new resolution + + Only valid for MK2.5(S) or printers without TMC2130 drivers + - `B` - Second extruder new resolution + - `S` - All axis new resolution */ case 350: { @@ -8380,9 +8445,18 @@ Sigma_Exit: /*! ### M351 - Toggle Microstep Pins M351: Toggle MS1 MS2 pins directly - Toggle MS1 MS2 pins directly, S# determines MS1 or MS2, X# sets the pin high/low. + Toggle MS1 MS2 pins directly. + #### Usage - M351 [B<0|1>] [E<0|1>] S<1|2> [X<0|1>] [Y<0|1>] [Z<0|1>] + M351 [B<0|1>] [E<0|1>] S<1|2> [X<0|1>] [Y<0|1>] [Z<0|1>] + + #### Parameters + - `X` - Update X axis + - `Y` - Update Y axis + - `Z` - Update Z axis + - `E` - Update E axis + - `S` - which MSx pin to toggle + - `B` - new pin value */ case 351: { @@ -8417,12 +8491,14 @@ Sigma_Exit: /*! ### M702 - Unload filament G32: Undock Z Probe sled - - M702 [ U | C] - - - `U` - Unload all filaments used in current print - - `C` - Unload just current filament - - without any parameters unload all filaments + #### Usage + + M702 [ U | C ] + + #### Parameters + - `U` - Unload all filaments used in current print + - `C` - Unload just current filament + - without any parameters unload all filaments */ case 702: { @@ -8448,6 +8524,7 @@ Sigma_Exit: /*! ### M999 - Restart after being stopped M999: Restart after being stopped by error + Usually doesn't work. */ case 999: Stopped = false; @@ -8466,19 +8543,16 @@ Sigma_Exit: } } // end if(code_seen('M')) (end of M codes) - - //! ----------------------------------------------------------------------------------------- - //! # T Codes - //! - //! T - select extruder in case of multi extruder printer - //! select filament in case of MMU_V2 - //! if extruder is "?", open menu to let the user select extruder/filament - //! - //! For MMU_V2: - //! @n T Gcode to extrude at least 38.10 mm at feedrate 19.02 mm/s must follow immediately to load to extruder wheels. - //! @n T? Gcode to extrude shouldn't have to follow, load to extruder wheels is done automatically - //! @n Tx Same as T?, except nozzle doesn't have to be preheated. Tc must be placed after extruder nozzle is preheated to finish filament load. - //! @n Tc Load to nozzle after filament was prepared by Tc and extruder nozzle is already heated. + /*! + ----------------------------------------------------------------------------------------- + # T Codes + T - select extruder in case of multi extruder printer. select filament in case of MMU_V2. + #### For MMU_V2: + T Gcode to extrude at least 38.10 mm at feedrate 19.02 mm/s must follow immediately to load to extruder wheels. + @n T? Gcode to extrude shouldn't have to follow, load to extruder wheels is done automatically + @n Tx Same as T?, except nozzle doesn't have to be preheated. Tc must be placed after extruder nozzle is preheated to finish filament load. + @n Tc Load to nozzle after filament was prepared by Tc and extruder nozzle is already heated. + */ else if(code_seen('T')) { int index; @@ -8669,25 +8743,20 @@ Sigma_Exit: { /*! - * ### D-1 - Endless Loop D-1: Endless Loop - - D-1 - - * */ case -1: dcode__1(); break; #ifdef DEBUG_DCODES /*! - * ### D0 - Reset D0: Reset - - D0 [ B ] - - - `B` - Bootloader - * + #### Usage + + D0 [ B ] + + #### Parameters + - `B` - Bootloader */ case 0: dcode_0(); break; @@ -8704,16 +8773,16 @@ Sigma_Exit: dcode_1(); break; /*! - * ### D2 - Read/Write RAM D3: Read/Write RAM This command can be used without any additional parameters. It will read the entire RAM. - - D3 [ A | C | X ] - - - `A` - Address (0x0000-0x1fff) - - `C` - Count (0x0001-0x2000) - - `X` - Data - * + #### Usage + + D3 [ A | C | X ] + + #### Parameters + - `A` - Address (0x0000-0x1fff) + - `C` - Count (0x0001-0x2000) + - `X` - Data */ case 2: dcode_2(); break; @@ -8721,16 +8790,16 @@ Sigma_Exit: #ifdef DEBUG_DCODE3 /*! - * ### D3 - Read/Write EEPROM D3: Read/Write EEPROM This command can be used without any additional parameters. It will read the entire eeprom. - - D3 [ A | C | X ] - - - `A` - Address (0x0000-0x0fff) - - `C` - Count (0x0001-0x1000) - - `X` - Data - * + #### Usage + + D3 [ A | C | X ] + + #### Parameters + - `A` - Address (0x0000-0x0fff) + - `C` - Count (0x0001-0x1000) + - `X` - Data */ case 3: dcode_3(); break; @@ -8738,17 +8807,17 @@ Sigma_Exit: #ifdef DEBUG_DCODES /*! - * - ### D4 - Read/Write PIN D4: Read/Write PIN + ### D4 - Read/Write PIN D4: Read/Write PIN To read the digital value of a pin you need only to define the pin number. - - D4 [ P | F | V ] - - - `P` - Pin (0-255) - - `F` - Function in/out (0/1) - - `V` - Value (0/1) - * + #### Usage + + D4 [ P | F | V ] + + #### Parameters + - `P` - Pin (0-255) + - `F` - Function in/out (0/1) + - `V` - Value (0/1) */ case 4: dcode_4(); break; @@ -8756,17 +8825,17 @@ Sigma_Exit: #ifdef DEBUG_DCODE5 /*! - * ### D5 - Read/Write FLASH D5: Read/Write Flash This command can be used without any additional parameters. It will read the 1kb FLASH. - - D3 [ A | C | X | E ] - - - `A` - Address (0x00000-0x3ffff) - - `C` - Count (0x0001-0x2000) - - `X` - Data - - `E` - Erase - * + #### Usage + + D3 [ A | C | X | E ] + + #### Parameters + - `A` - Address (0x00000-0x3ffff) + - `C` - Count (0x0001-0x2000) + - `X` - Data + - `E` - Erase */ case 5: dcode_5(); break; @@ -8775,87 +8844,76 @@ Sigma_Exit: #ifdef DEBUG_DCODES /*! - * ### D6 - Read/Write external FLASH D6: Read/Write external Flash - Reserved - * - */ + */ case 6: dcode_6(); break; /*! - * ### D7 - Read/Write Bootloader D7: Read/Write Bootloader - Reserved - * - */ + */ case 7: dcode_7(); break; /*! - * ### D8 - Read/Write PINDA D8: Read/Write PINDA - - D8 [ ? | ! | P | Z ] - - - `?` - Read PINDA temperature shift values - - `!` - Reset PINDA temperature shift values to default - - `P` - Pinda temperature [C] - - `Z` - Z Offset [mm] - * + #### Usage + + D8 [ ? | ! | P | Z ] + + #### Parameters + - `?` - Read PINDA temperature shift values + - `!` - Reset PINDA temperature shift values to default + - `P` - Pinda temperature [C] + - `Z` - Z Offset [mm] */ case 8: dcode_8(); break; /*! - * ### D9 - Read ADC D9: Read ADC - - D9 [ I | V ] - - - `I` - ADC channel index - - `0` - Heater 0 temperature - - `1` - Heater 1 temperature - - `2` - Bed temperature - - `3` - PINDA temperature - - `4` - PWR voltage - - `5` - Ambient temperature - - `6` - BED voltage - - `V` Value to be written as simulated - * + #### Usage + + D9 [ I | V ] + + #### Parameters + - `I` - ADC channel index + - `0` - Heater 0 temperature + - `1` - Heater 1 temperature + - `2` - Bed temperature + - `3` - PINDA temperature + - `4` - PWR voltage + - `5` - Ambient temperature + - `6` - BED voltage + - `V` Value to be written as simulated */ case 9: dcode_9(); break; /*! - * ### D10 - Set XYZ calibration = OK D10: Set XYZ calibration = OK - - * */ case 10: dcode_10(); break; /*! - * ### D12 - Time D12: Time - Writes the actual time in the log file. - * */ #endif //DEBUG_DCODES #ifdef HEATBED_ANALYSIS /*! - * ### D80 - Bed check D80: Bed check This command will log data to SD card file "mesh.txt". - - D80 [ E | F | G | H | I | J ] - + #### Usage + + D80 [ E | F | G | H | I | J ] + + #### Parameters - `E` - Dimension X (default 40) - `F` - Dimention Y (default 40) - `G` - Points X (default 40) @@ -8888,12 +8946,13 @@ Sigma_Exit: }break; /*! - * ### D81 - Bed analysis D80: Bed analysis This command will log data to SD card file "wldsd.txt". - - D81 [ E | F | G | H | I | J ] - + #### Usage + + D81 [ E | F | G | H | I | J ] + + #### Parameters - `E` - Dimension X (default 40) - `F` - Dimention Y (default 40) - `G` - Points X (default 40) @@ -8925,7 +8984,6 @@ Sigma_Exit: #ifdef DEBUG_DCODES /*! - * ### D106 - Print measured fan speed for different pwm values D106: Print measured fan speed for different pwm values */ case 106: @@ -8943,13 +9001,14 @@ Sigma_Exit: #ifdef TMC2130 /*! - * ### D2130 - Trinamic stepper controller D2130: Trinamic stepper controller - @todo Please review by owner of the code. RepRap Wiki Gcode needs to be updated after review of owner as well. - - D2130 [ Axis | Command | Subcommand | Value ] - + + #### Usage + + D2130 [ Axis | Command | Subcommand | Value ] + + #### Parameters - Axis - `X` - X stepper driver - `Y` - Y stepper driver @@ -9004,18 +9063,18 @@ Sigma_Exit: #if (defined (FILAMENT_SENSOR) && defined(PAT9125)) /*! - * ### D9125 - PAT9125 filament sensor D9125: PAT9125 filament sensor - - D9125 [ ? | ! | R | X | Y | L ] - - - `?` - Print values - - `!` - Print values - - `R` - Resolution. Not active in code - - `X` - X values - - `Y` - Y values - - `L` - Activate filament sensor log - * + #### Usage + + D9125 [ ? | ! | R | X | Y | L ] + + #### Parameters + - `?` - Print values + - `!` - Print values + - `R` - Resolution. Not active in code + - `X` - X values + - `Y` - Y values + - `L` - Activate filament sensor log */ case 9125: dcode_9125(); break; From aac66d4a4b853db540ace3a5f83fb97e07ee1ec4 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 15 Jan 2020 22:21:23 +0200 Subject: [PATCH 116/180] Add missing quote --- Firmware/Marlin_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 35a540f6d..60aa0d294 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -5327,7 +5327,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; /*! - ### G85: Pick best babystep - Not active G85: Pick best babystep In Prusa Firmware this G-code is deactivated by default, must be turned on in the source code. */ case 85: From ea51696a688d496b9865a2ef45d9008457e227c2 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 15 Jan 2020 22:30:43 +0200 Subject: [PATCH 117/180] Merge Special sections as requested --- Firmware/Marlin_main.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 60aa0d294..6090867fe 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3600,16 +3600,7 @@ void process_commands() ### M117 - Display Message M117: Display Message This causes the given message to be shown in the status line on an attached LCD. It is processed early as to allow printing messages that contain G, M, N or T. - */ - if (code_seen("M117")) { //moved to highest priority place to be able to to print strings which includes "G", "PRUSA" and "^" - starpos = (strchr(strchr_pointer + 5, '*')); - if (starpos != NULL) - *(starpos) = '\0'; - lcd_setstatus(strchr_pointer + 5); - } - -#ifdef TMC2130 - /*! + --------------------------------------------------------------------------------- ### Special internal commands These are used by internal functions to process certain actions in the right order. Some of these are also usable by the user. @@ -3621,7 +3612,15 @@ void process_commands() - TMC_SET_WAVE - TMC_SET_STEP - TMC_SET_CHOP - */ + */ + if (code_seen("M117")) { //moved to highest priority place to be able to to print strings which includes "G", "PRUSA" and "^" + starpos = (strchr(strchr_pointer + 5, '*')); + if (starpos != NULL) + *(starpos) = '\0'; + lcd_setstatus(strchr_pointer + 5); + } + +#ifdef TMC2130 else if (strncmp_P(CMDBUFFER_CURRENT_STRING, PSTR("CRASH_"), 6) == 0) { From 622319f86c82fa35b477c3ed6369748595415477 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 15 Jan 2020 22:30:53 +0200 Subject: [PATCH 118/180] Add missing LF --- Firmware/Marlin_main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 6090867fe..2f07fe67b 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -6344,6 +6344,7 @@ Sigma_Exit: #### Usage M104 [ B | R | S ] + #### Parameters (not mandatory) - `S` - Set extruder temperature From 47ddc2e9025ab6e9cdd5a8baa7010156b426782b Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 15 Jan 2020 22:35:34 +0200 Subject: [PATCH 119/180] M204 - better old_new separation --- Firmware/Marlin_main.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 2f07fe67b..0f2f6c183 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -7012,20 +7012,22 @@ Sigma_Exit: /*! ### M204 - Acceleration settings M204: Set default acceleration - #### Usage - Old format: + + #### Old format: + ##### Usage - M204 [ S | T ] - New format: - - M204 [ P | R | T ] - - #### Parameters - Old format: + M204 [ S | T ] + + ##### Parameters - `S` - normal moves - `T` - filmanent only moves - New format: + #### New format: + ##### Usage + + M204 [ P | R | T ] + + ##### Parameters - `P` - printing moves - `R` - filmanent only moves - `T` - travel moves (as of now T is ignored) From d676542229c01927ff7a6ff7b4df3a7f92a33320 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 15 Jan 2020 22:38:00 +0200 Subject: [PATCH 120/180] Revert code changes --- Firmware/Marlin_main.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 0f2f6c183..1898f0fc0 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -7542,7 +7542,9 @@ Sigma_Exit: chdkHigh = _millis(); chdkActive = true; - #elif defined(PHOTOGRAPH_PIN) && PHOTOGRAPH_PIN > -1 + #else + + #if defined(PHOTOGRAPH_PIN) && PHOTOGRAPH_PIN > -1 const uint8_t NUM_PULSES=16; const float PULSE_LENGTH=0.01524; for(int i=0; i < NUM_PULSES; i++) { @@ -7559,6 +7561,7 @@ Sigma_Exit: _delay_ms(PULSE_LENGTH); } #endif + #endif //chdk end if } break; #ifdef PREVENT_DANGEROUS_EXTRUDE From 6a1eb63a52b4cce52d41e1e4aa76f4f4e7600014 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 15 Jan 2020 22:41:02 +0200 Subject: [PATCH 121/180] Add @todo to M999 --- Firmware/Marlin_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 1898f0fc0..411edc545 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -8528,7 +8528,7 @@ Sigma_Exit: /*! ### M999 - Restart after being stopped M999: Restart after being stopped by error - Usually doesn't work. + @todo Usually doesn't work. Should be fixed or removed. Most of the time, if `Stopped` it set, the print fails and is unrecoverable. */ case 999: Stopped = false; From ccd3885d84e953cf3f87655656d16532b1fe0654 Mon Sep 17 00:00:00 2001 From: leptun Date: Wed, 15 Jan 2020 23:01:09 +0200 Subject: [PATCH 122/180] rephrase G28 W --- Firmware/Marlin_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 411edc545..6c52e34c0 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -4262,7 +4262,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! ### G28 - Home all Axis one at a time G28: Move to Origin (Home) - Using `G28` without any parameters will perfom home of all Axis AND mesh bed leveling, while `G28 W` will just home the printer. + Using `G28` without any parameters will perfom homing of all axis AND mesh bed leveling, while `G28 W` will just home all axis (no mesh bed leveling). #### Usage G28 [ X | Y | Z | W | C ] From 1d17a372508e8a8dedafa46a1f2fea71fd99133a Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Thu, 16 Jan 2020 09:15:44 +0200 Subject: [PATCH 123/180] all axis -> all axes --- Firmware/Marlin_main.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 6c52e34c0..211384f9d 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3429,7 +3429,7 @@ extern uint8_t st_backlash_y; //!@n G4 - Dwell S or P //!@n G10 - retract filament according to settings of M207 //!@n G11 - retract recover filament according to settings of M208 -//!@n G28 - Home all Axis +//!@n G28 - Home all Axes //!@n G29 - Detailed Z-Probe, probes the bed at 3 or more points. Will fail if you haven't homed yet. //!@n G30 - Single Z Probe, probes bed at current XY location. //!@n G31 - Dock sled (Z_PROBE_SLED only) @@ -4261,8 +4261,8 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) /*! - ### G28 - Home all Axis one at a time G28: Move to Origin (Home) - Using `G28` without any parameters will perfom homing of all axis AND mesh bed leveling, while `G28 W` will just home all axis (no mesh bed leveling). + ### G28 - Home all Axes one at a time G28: Move to Origin (Home) + Using `G28` without any parameters will perfom homing of all axes AND mesh bed leveling, while `G28 W` will just home all axes (no mesh bed leveling). #### Usage G28 [ X | Y | Z | W | C ] @@ -5525,7 +5525,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; /*! - ### M17 - Enable all axis M17: Enable/Power all stepper motors + ### M17 - Enable all axes M17: Enable/Power all stepper motors */ case 17: LCD_MESSAGERPGM(_i("No move."));////MSG_NO_MOVE @@ -6572,7 +6572,7 @@ Sigma_Exit: M84 [ S | X | Y | Z | E ] - `S` - Seconds - - `X` - X axsis + - `X` - X axis - `Y` - Y axis - `Z` - Z axis - `E` - Exruder @@ -6865,7 +6865,7 @@ Sigma_Exit: SERIAL_PROTOCOLLN(""); #endif break; - //TODO: update for all axis, use for loop + //!@todo update for all axes, use for loop #ifdef BLINKM @@ -8401,7 +8401,7 @@ Sigma_Exit: Only valid for MK2.5(S) or printers without TMC2130 drivers - `B` - Second extruder new resolution - - `S` - All axis new resolution + - `S` - All axes new resolution */ case 350: { From 95a2ad533d4cb5b3d61bc989b6681247bf3c72c3 Mon Sep 17 00:00:00 2001 From: DRracer Date: Thu, 16 Jan 2020 16:03:34 +0100 Subject: [PATCH 124/180] Version changed (3.9.0 build 3175) --- Firmware/Configuration.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/Configuration.h b/Firmware/Configuration.h index e11790e35..2f2ea7d8e 100644 --- a/Firmware/Configuration.h +++ b/Firmware/Configuration.h @@ -16,8 +16,8 @@ extern uint16_t nPrinterType; extern PGM_P sPrinterName; // Firmware version -#define FW_VERSION "3.8.1" -#define FW_COMMIT_NR 2869 +#define FW_VERSION "3.9.0" +#define FW_COMMIT_NR 3175 // FW_VERSION_UNKNOWN means this is an unofficial build. // The firmware should only be checked into github with this symbol. #define FW_DEV_VERSION FW_VERSION_UNKNOWN From e6ba9e633c9eaeea7eef5d9ba876c380503dd19a Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Tue, 21 Jan 2020 14:50:53 +0200 Subject: [PATCH 125/180] Adjusted hotend, bed and Ambient mintemp values --- Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h | 8 ++++---- Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h b/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h index 400d098ff..a2c0c3d8e 100644 --- a/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h @@ -151,8 +151,8 @@ // this value is litlebit higher that real limit, because ambient termistor is on the board and is temperated from it, // temperature inside the case is around 31C for ambient temperature 25C, when the printer is powered on long time and idle // the real limit is 15C (same as MINTEMP limit), this is because 15C is end of scale for both used thermistors (bed, heater) -#define MINTEMP_MINAMBIENT 25 -#define MINTEMP_MINAMBIENT_RAW 978 +#define MINTEMP_MINAMBIENT 10 +#define MINTEMP_MINAMBIENT_RAW 1002 #define DEBUG_DCODE3 @@ -282,14 +282,14 @@ *------------------------------------*/ // Mintemps -#define HEATER_0_MINTEMP 15 +#define HEATER_0_MINTEMP 10 #define HEATER_1_MINTEMP 5 #define HEATER_2_MINTEMP 5 #define HEATER_MINTEMP_DELAY 15000 // [ms] ! if changed, check maximal allowed value @ ShortTimer #if HEATER_MINTEMP_DELAY>USHRT_MAX #error "Check maximal allowed value @ ShortTimer (see HEATER_MINTEMP_DELAY definition)" #endif -#define BED_MINTEMP 15 +#define BED_MINTEMP 10 #define BED_MINTEMP_DELAY 50000 // [ms] ! if changed, check maximal allowed value @ ShortTimer #if BED_MINTEMP_DELAY>USHRT_MAX #error "Check maximal allowed value @ ShortTimer (see BED_MINTEMP_DELAY definition)" diff --git a/Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h b/Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h index 48ed91392..1c92bfbc0 100644 --- a/Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h @@ -153,8 +153,8 @@ // this value is litlebit higher that real limit, because ambient termistor is on the board and is temperated from it, // temperature inside the case is around 31C for ambient temperature 25C, when the printer is powered on long time and idle // the real limit is 15C (same as MINTEMP limit), this is because 15C is end of scale for both used thermistors (bed, heater) -#define MINTEMP_MINAMBIENT 25 -#define MINTEMP_MINAMBIENT_RAW 978 +#define MINTEMP_MINAMBIENT 10 +#define MINTEMP_MINAMBIENT_RAW 1002 #define DEBUG_DCODE3 @@ -284,14 +284,14 @@ *------------------------------------*/ // Mintemps -#define HEATER_0_MINTEMP 15 +#define HEATER_0_MINTEMP 10 #define HEATER_1_MINTEMP 5 #define HEATER_2_MINTEMP 5 #define HEATER_MINTEMP_DELAY 15000 // [ms] ! if changed, check maximal allowed value @ ShortTimer #if HEATER_MINTEMP_DELAY>USHRT_MAX #error "Check maximal allowed value @ ShortTimer (see HEATER_MINTEMP_DELAY definition)" #endif -#define BED_MINTEMP 15 +#define BED_MINTEMP 10 #define BED_MINTEMP_DELAY 50000 // [ms] ! if changed, check maximal allowed value @ ShortTimer #if BED_MINTEMP_DELAY>USHRT_MAX #error "Check maximal allowed value @ ShortTimer (see BED_MINTEMP_DELAY definition)" From 67decb466d478c487dfa6192f8f8cafb787faf06 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 21 Jan 2020 16:24:19 +0100 Subject: [PATCH 126/180] Avoid another call to st_get_position_mm current_position is already filled by planner_abort_hard. --- Firmware/Marlin_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 211384f9d..a3cf6440a 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -10549,7 +10549,7 @@ void uvlo_() planner_abort_hard(); // Store the current extruder position. - eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION_E), st_get_position_mm(E_AXIS)); + eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION_E), current_position[E_AXIS]); eeprom_update_byte((uint8_t*)EEPROM_UVLO_E_ABS, axis_relative_modes[3]?0:1); // Clean the input command queue. cmdqueue_reset(); From e8f05d06684a6c8818b11fba334bbb36d2e8fcf5 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 21 Jan 2020 16:26:16 +0100 Subject: [PATCH 127/180] Heat both nozzle/bed together while recovering a print --- Firmware/Marlin_main.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index a3cf6440a..267bbe587 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -10777,10 +10777,13 @@ void recover_print(uint8_t automatic) { // Home X and Y axes. Homing just X and Y shall not touch the babystep and the world2machine transformation status. enquecommand_P(PSTR("G28 X Y")); // Set the target bed and nozzle temperatures and wait. - sprintf_P(cmd, PSTR("M109 S%d"), target_temperature[active_extruder]); + sprintf_P(cmd, PSTR("M104 S%d"), target_temperature[active_extruder]); enquecommand(cmd); sprintf_P(cmd, PSTR("M190 S%d"), target_temperature_bed); enquecommand(cmd); + sprintf_P(cmd, PSTR("M109 S%d"), target_temperature[active_extruder]); + enquecommand(cmd); + enquecommand_P(PSTR("M83")); //E axis relative mode //enquecommand_P(PSTR("G1 E5 F120")); //Extrude some filament to stabilize pessure // If not automatically recoreverd (long power loss), extrude extra filament to stabilize From 84376301228aaaa0e2f02a0ab1c960a32af9f271 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 21 Jan 2020 16:29:12 +0100 Subject: [PATCH 128/180] Inhibit serial processing in uvlo_ Do not process serial commands when re-enabling the global isr. While printing via USB and a power panic is triggered, *any* extra command should be ignored. Abuse the "saved_printing" variable to inhibit serial processing. --- Firmware/Marlin_main.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 267bbe587..9777aa269 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -10551,15 +10551,18 @@ void uvlo_() // Store the current extruder position. eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION_E), current_position[E_AXIS]); eeprom_update_byte((uint8_t*)EEPROM_UVLO_E_ABS, axis_relative_modes[3]?0:1); - // Clean the input command queue. + + // Clean the input command queue, inhibit serial processing using saved_printing cmdqueue_reset(); card.sdprinting = false; -// card.closefile(); - // Enable stepper driver interrupt to move Z axis. - // This should be fine as the planner and command queues are empty and the SD card printing is disabled. - //FIXME one may want to disable serial lines at this point of time to avoid interfering with the command queue, - // though it should not happen that the command queue is touched as the plan_buffer_line always succeed without blocking. - sei(); +// card.closefile(); + saved_printing = true; + + // Enable stepper driver interrupt to move Z axis. This should be fine as the planner and + // command queues are empty, SD card printing is disabled, usb is inhibited. + sei(); + + // retract plan_buffer_line( current_position[X_AXIS], current_position[Y_AXIS], From 9ac80f73f2cc4d1d206c370ebef7bf74526137d6 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 21 Jan 2020 16:34:09 +0100 Subject: [PATCH 129/180] Remove an useless/duplicate Z move Likely a result of a merge --- Firmware/Marlin_main.cpp | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 9777aa269..674fff8dd 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -10563,37 +10563,26 @@ void uvlo_() sei(); // retract - plan_buffer_line( - current_position[X_AXIS], - current_position[Y_AXIS], - current_position[Z_AXIS], - current_position[E_AXIS] - default_retraction, - 95, active_extruder); - - st_synchronize(); - disable_e0(); - - plan_buffer_line( - current_position[X_AXIS], - current_position[Y_AXIS], - current_position[Z_AXIS] + UVLO_Z_AXIS_SHIFT + float((1024 - z_microsteps + 7) >> 4) / cs.axis_steps_per_unit[Z_AXIS], - current_position[E_AXIS] - default_retraction, - 40, active_extruder); + plan_buffer_line(current_position[X_AXIS], + current_position[Y_AXIS], + current_position[Z_AXIS], + current_position[E_AXIS] - default_retraction, + 95, active_extruder); st_synchronize(); disable_e0(); - plan_buffer_line( - current_position[X_AXIS], - current_position[Y_AXIS], - current_position[Z_AXIS] + UVLO_Z_AXIS_SHIFT + float((1024 - z_microsteps + 7) >> 4) / cs.axis_steps_per_unit[Z_AXIS], - current_position[E_AXIS] - default_retraction, - 40, active_extruder); + // Move Z up and to the next 0th full step. + plan_buffer_line(current_position[X_AXIS], + current_position[Y_AXIS], + current_position[Z_AXIS] + UVLO_Z_AXIS_SHIFT + float((1024 - z_microsteps + 7) >> 4) / cs.axis_steps_per_unit[Z_AXIS], + current_position[E_AXIS] - default_retraction, + 40, active_extruder); st_synchronize(); + disable_z(); - disable_e0(); - // Move Z up to the next 0th full step. // Write the file position. eeprom_update_dword((uint32_t*)(EEPROM_FILE_POSITION), sd_position); + // Store the mesh bed leveling offsets. This is 2*7*7=98 bytes, which takes 98*3.4us=333us in worst case. for (int8_t mesh_point = 0; mesh_point < MESH_NUM_X_POINTS * MESH_NUM_Y_POINTS; ++ mesh_point) { uint8_t ix = mesh_point % MESH_NUM_X_POINTS; // from 0 to MESH_NUM_X_POINTS - 1 From 4c8f1e8b892f335ec14b39244e26ed3e53e01753 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 21 Jan 2020 16:36:34 +0100 Subject: [PATCH 130/180] Use eeprom_update_word instead of EEPROM_save_B --- Firmware/Marlin_main.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 674fff8dd..eb7a179ff 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -10509,7 +10509,6 @@ void uvlo_() tmc2130_set_current_r(E_AXIS, 20); #endif //TMC2130 - // Indicate that the interrupt has been triggered. // SERIAL_ECHOLNPGM("UVLO"); @@ -10591,17 +10590,19 @@ void uvlo_() int16_t v = mbl.active ? int16_t(floor(mbl.z_values[iy][ix] * 1000.f + 0.5f)) : 0; eeprom_update_word((uint16_t*)(EEPROM_UVLO_MESH_BED_LEVELING_FULL +2*mesh_point), *reinterpret_cast(&v)); } - // Read out the current Z motor microstep counter. This will be later used + + // Write the current Z motor microstep counter. This will be later used // for reaching the zero full step before powering off. eeprom_update_word((uint16_t*)(EEPROM_UVLO_Z_MICROSTEPS), z_microsteps); - // Store the current position. + // Store the current position. eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0), current_position[X_AXIS]); eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4), current_position[Y_AXIS]); eeprom_update_float((float*)EEPROM_UVLO_CURRENT_POSITION_Z , current_position[Z_AXIS]); + // Store the current feed rate, temperatures, fan speed and extruder multipliers (flow rates) eeprom_update_word((uint16_t*)EEPROM_UVLO_FEEDRATE, feedrate_bckp); - EEPROM_save_B(EEPROM_UVLO_FEEDMULTIPLY, &feedmultiply); + eeprom_update_word((uint16_t*)EEPROM_UVLO_FEEDMULTIPLY, feedmultiply); eeprom_update_byte((uint8_t*)EEPROM_UVLO_TARGET_HOTEND, target_temperature[active_extruder]); eeprom_update_byte((uint8_t*)EEPROM_UVLO_TARGET_BED, target_temperature_bed); eeprom_update_byte((uint8_t*)EEPROM_UVLO_FAN_SPEED, fanSpeed); @@ -10897,7 +10898,7 @@ void restore_print_from_eeprom() { fan_speed_rec = eeprom_read_byte((uint8_t*)EEPROM_UVLO_FAN_SPEED); feedrate_rec = eeprom_read_word((uint16_t*)EEPROM_UVLO_FEEDRATE); - EEPROM_read_B(EEPROM_UVLO_FEEDMULTIPLY, &feedmultiply_rec); + feedmultiply_rec = eeprom_read_word((uint16_t*)EEPROM_UVLO_FEEDMULTIPLY); SERIAL_ECHOPGM("Feedrate:"); MYSERIAL.print(feedrate_rec); SERIAL_ECHOPGM(", feedmultiply:"); From 7f3d4a8491acabbbb139a41e4c5bff7e4dad9d3f Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 21 Jan 2020 16:39:39 +0100 Subject: [PATCH 131/180] Restore the last E axis position correctly after powerpanic - Initially restore the last E position from the eeprom in any case, not just when using absolute mode (although unnecessary: since it will be reset later), fixing a possible unitialized position and crash during recovery (thanks to @leptun) - Remove useless extra calls to put the extruder in relative mode: the extruder already starts in relative mode and is later switched to absolute. - Replace incorrect calls to STRINGIFY with sprintf_P - Retract after pressure has been restored in uvlo_tiny, to be consistent with a regular uvlo (remove the bogus double unretract as a result). - Set the real E position prior to the panic *after* the retraction, using the now-fixed G92. --- Firmware/Marlin_main.cpp | 41 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index eb7a179ff..61ab10310 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -10778,12 +10778,15 @@ void recover_print(uint8_t automatic) { enquecommand(cmd); enquecommand_P(PSTR("M83")); //E axis relative mode - //enquecommand_P(PSTR("G1 E5 F120")); //Extrude some filament to stabilize pessure - // If not automatically recoreverd (long power loss), extrude extra filament to stabilize - if(automatic == 0){ - enquecommand_P(PSTR("G1 E5 F120")); //Extrude some filament to stabilize pessure - } - enquecommand_P(PSTR("G1 E" STRINGIFY(-default_retraction)" F480")); + + // If not automatically recoreverd (long power loss) + if(automatic == 0){ + //Extrude some filament to stabilize the pressure + enquecommand_P(PSTR("G1 E5 F120")); + // Retract to be consistent with a short pause + sprintf_P(cmd, PSTR("G1 E%-0.3f F2700"), default_retraction); + enquecommand(cmd); + } printf_P(_N("After waiting for temp:\nCurrent pos X_AXIS:%.3f\nCurrent pos Y_AXIS:%.3f\n"), current_position[X_AXIS], current_position[Y_AXIS]); @@ -10794,7 +10797,6 @@ void recover_print(uint8_t automatic) { void recover_machine_state_after_power_panic(bool bTiny) { - char cmd[30]; // 1) Recover the logical cordinates at the time of the power panic. // The logical XY coordinates are needed to recover the machine Z coordinate corrected by the mesh bed leveling. current_position[X_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0)); @@ -10829,12 +10831,9 @@ void recover_machine_state_after_power_panic(bool bTiny) UVLO_Z_AXIS_SHIFT + float((1024 - eeprom_read_word((uint16_t*)(EEPROM_UVLO_Z_MICROSTEPS)) + 7) >> 4) / cs.axis_steps_per_unit[Z_AXIS]; } - if (eeprom_read_byte((uint8_t*)EEPROM_UVLO_E_ABS)) { - current_position[E_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION_E)); - sprintf_P(cmd, PSTR("G92 E")); - dtostrf(current_position[E_AXIS], 6, 3, cmd + strlen(cmd)); - enquecommand(cmd); - } + + // Recover last E axis position + current_position[E_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION_E)); memcpy(destination, current_position, sizeof(destination)); @@ -10929,8 +10928,6 @@ void restore_print_from_eeprom() { uint32_t position = eeprom_read_dword((uint32_t*)(EEPROM_FILE_POSITION)); SERIAL_ECHOPGM("Position read from eeprom:"); MYSERIAL.println(position); - // E axis relative mode. - enquecommand_P(PSTR("M83")); // Move to the XY print position in logical coordinates, where the print has been killed. strcpy_P(cmd, PSTR("G1 X")); strcat(cmd, ftostr32(eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0)))); strcat_P(cmd, PSTR(" Y")); strcat(cmd, ftostr32(eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4)))); @@ -10942,16 +10939,20 @@ void restore_print_from_eeprom() { strcpy_P(cmd, PSTR("G1 Z")); strcat(cmd, ftostr32(eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION_Z)))); enquecommand(cmd); // Unretract. - enquecommand_P(PSTR("G1 E" STRINGIFY(2*default_retraction)" F480")); + sprintf_P(cmd, PSTR("G1 E%0.3f F2700"), default_retraction); + enquecommand(cmd); + // Recover final E axis position and mode + float pos_e = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION_E)); + sprintf_P(cmd, PSTR("G92 E")); + dtostrf(pos_e, 6, 3, cmd + strlen(cmd)); + enquecommand(cmd); + if (eeprom_read_byte((uint8_t*)EEPROM_UVLO_E_ABS)) + enquecommand_P(PSTR("M82")); //E axis abslute mode // Set the feedrates saved at the power panic. sprintf_P(cmd, PSTR("G1 F%d"), feedrate_rec); enquecommand(cmd); sprintf_P(cmd, PSTR("M220 S%d"), feedmultiply_rec); enquecommand(cmd); - if (eeprom_read_byte((uint8_t*)EEPROM_UVLO_E_ABS)) - { - enquecommand_P(PSTR("M82")); //E axis abslute mode - } // Set the fan speed saved at the power panic. strcpy_P(cmd, PSTR("M106 S")); strcat(cmd, itostr3(int(fan_speed_rec))); From 73527d6069c5a4b6d75d8150887640c0ec2f4f6f Mon Sep 17 00:00:00 2001 From: MRprusa3d Date: Wed, 22 Jan 2020 04:45:13 +0100 Subject: [PATCH 132/180] selfTest workflow optimalization --- Firmware/ultralcd.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 5d291f35c..38471b814 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -7541,26 +7541,24 @@ bool lcd_selftest() int _progress = 0; bool _result = true; bool _swapped_fan = false; +#if IR_SENSOR_ANALOG + bool bAction; + bAction=lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Is the filament unloaded?"),false,true); + if(!bAction) + return(false); +#endif //IR_SENSOR_ANALOG lcd_wait_for_cool_down(); lcd_clear(); lcd_set_cursor(0, 0); lcd_puts_P(_i("Self test start "));////MSG_SELFTEST_START c=20 #ifdef TMC2130 FORCE_HIGH_POWER_START; #endif // TMC2130 -#if !IR_SENSOR_ANALOG _delay(2000); -#endif //!IR_SENSOR_ANALOG FORCE_BL_ON_START; _delay(2000); KEEPALIVE_STATE(IN_HANDLER); -#if IR_SENSOR_ANALOG - bool bAction; - bAction=lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Is filament unloaded?"),false,true); - if(!bAction) - return(false); -#endif //IR_SENSOR_ANALOG _progress = lcd_selftest_screen(TestScreen::ExtruderFan, _progress, 3, true, 2000); #if (defined(FANCHECK) && defined(TACH_0)) From 4055977a95fde87d7d78763e02c5838e9c48bbf0 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Sat, 25 Jan 2020 11:41:27 +0200 Subject: [PATCH 133/180] Do not clear axis known position when Z is set to silent Also removed unused (forgotten) variable. --- Firmware/Marlin_main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 211384f9d..70cbd6d7a 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -11563,7 +11563,7 @@ if(!(bEnableForce_z||eeprom_read_byte((uint8_t*)EEPROM_SILENT))) void disable_force_z() { - uint16_t z_microsteps=0; + // uint16_t z_microsteps=0; if(!bEnableForce_z) return; // motor already disabled (may be ;-p ) @@ -11576,7 +11576,7 @@ void disable_force_z() tmc2130_init(true); #endif // TMC2130 - axis_known_position[Z_AXIS]=false; + // axis_known_position[Z_AXIS]=false; } From 53101819701f010cb215e5b50cbfb026084fa870 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 22 Jan 2020 19:39:55 +0100 Subject: [PATCH 134/180] Cancel a recovering print when using the LCD "Stop" Also clear the UVLO flag when using lcd_print_stop. This prevents an aborted print which has been cancelled while unparking (just prior to recover) to come back again at the next startup. --- Firmware/Marlin_main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 61ab10310..67b85b94d 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -11249,6 +11249,7 @@ void restore_print_from_ram_and_continue(float e_move) // Cancel the state related to a currently saved print void cancel_saved_printing() { + eeprom_update_byte((uint8_t*)EEPROM_UVLO, 0); saved_target[0] = SAVED_TARGET_UNSET; saved_printing_type = PRINTING_TYPE_NONE; saved_printing = false; From ec8b5aaa341cbfd02bf952ba16f36a50a902e816 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 26 Jan 2020 14:01:18 +0100 Subject: [PATCH 135/180] Do not attempt to "zero-phase" the microstep counter If the motors are off-phase, this is more likely to "bump" them to an incorrect/reverse full-step, doing worse. We need to ensure the motors are already positioned on a fullstep during power panic instead. Remove the PSU_DELTA exception: Z _always_ needs to be powered here. --- Firmware/Marlin_main.cpp | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 67b85b94d..f5bccffe0 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1327,29 +1327,12 @@ void setup() SET_OUTPUT(CONTROLLERFAN_PIN); //Set pin used for driver cooling fan #endif - setup_homepin(); -#ifdef TMC2130 - - if (1) { - // try to run to zero phase before powering the Z motor. - // Move in negative direction - WRITE(Z_DIR_PIN,INVERT_Z_DIR); - // Round the current micro-micro steps to micro steps. - for (uint16_t phase = (tmc2130_rd_MSCNT(Z_AXIS) + 8) >> 4; phase > 0; -- phase) { - // Until the phase counter is reset to zero. - WRITE(Z_STEP_PIN, !INVERT_Z_STEP_PIN); - _delay(2); - WRITE(Z_STEP_PIN, INVERT_Z_STEP_PIN); - _delay(2); - } - } -#endif //TMC2130 - -#if defined(Z_AXIS_ALWAYS_ON) && !defined(PSU_Delta) - enable_z(); +#if defined(Z_AXIS_ALWAYS_ON) + enable_z(); #endif + farm_mode = eeprom_read_byte((uint8_t*)EEPROM_FARM_MODE); EEPROM_read_B(EEPROM_FARM_NUMBER, &farm_no); if ((farm_mode == 0xFF && farm_no == 0) || (farm_no == static_cast(0xFFFF))) farm_mode = false; //if farm_mode has not been stored to eeprom yet and farm number is set to zero or EEPROM is fresh, deactivate farm mode From ec5cbf73b90070fa9ce58cfc9628dd72f8cb03ea Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 26 Jan 2020 14:24:53 +0100 Subject: [PATCH 136/180] During PP keep the watchdog waiting for longer When the printer is connected to a USB host during a PP (and the host does not lose power), the rambo can linger for longer, sometimes for long enough to recover the print state. Drain some more power. --- Firmware/Marlin_main.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index f5bccffe0..b3b0376ca 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -10625,10 +10625,11 @@ void uvlo_() plan_buffer_line_curposXYZE(500, active_extruder); st_synchronize(); #endif -wdt_enable(WDTO_500MS); -WRITE(BEEPER,HIGH); -while(1) - ; + + // burn all that residual power + wdt_enable(WDTO_1S); + WRITE(BEEPER,HIGH); + while(1); } @@ -10672,10 +10673,10 @@ eeprom_update_byte((uint8_t*)EEPROM_UVLO,2); // Increment power failure counter eeprom_update_byte((uint8_t*)EEPROM_POWER_COUNT, eeprom_read_byte((uint8_t*)EEPROM_POWER_COUNT) + 1); eeprom_update_word((uint16_t*)EEPROM_POWER_COUNT_TOT, eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT) + 1); -wdt_enable(WDTO_500MS); -WRITE(BEEPER,HIGH); -while(1) - ; + // burn all that residual power + wdt_enable(WDTO_1S); + WRITE(BEEPER,HIGH); + while(1); } #endif //UVLO_SUPPORT From 0702e0de6e1cc22a3c8af6d0d40f35e23564a2b6 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 26 Jan 2020 17:12:27 +0100 Subject: [PATCH 137/180] Use world2machine instead of repeating code --- Firmware/planner.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index 8c26cef9b..197b3d9f9 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -1345,14 +1345,7 @@ void plan_set_position(float x, float y, float z, const float &e) apply_rotation_xyz(plan_bed_level_matrix, x, y, z); #endif // ENABLE_AUTO_BED_LEVELING - // Apply the machine correction matrix. - if (world2machine_correction_mode != WORLD2MACHINE_CORRECTION_NONE) - { - float tmpx = x; - float tmpy = y; - x = world2machine_rotation_and_skew[0][0] * tmpx + world2machine_rotation_and_skew[0][1] * tmpy + world2machine_shift[0]; - y = world2machine_rotation_and_skew[1][0] * tmpx + world2machine_rotation_and_skew[1][1] * tmpy + world2machine_shift[1]; - } + world2machine(x, y); position[X_AXIS] = lround(x*cs.axis_steps_per_unit[X_AXIS]); position[Y_AXIS] = lround(y*cs.axis_steps_per_unit[Y_AXIS]); From 11a0e95f60313f6162d6b94e0d0cc31395aeb825 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 26 Jan 2020 17:16:15 +0100 Subject: [PATCH 138/180] Re-enable the code that moves the extruder during PP There is frequently plenty of power left during a PP. Take advantage of it by moving the extruder to either side of the axis to detach completely the nozzle from the print. Re-enable Z during this move to avoid losing the current step. --- Firmware/Marlin_main.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index b3b0376ca..3fdff1a91 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -10617,18 +10617,17 @@ void uvlo_() // Increment power failure counter eeprom_update_byte((uint8_t*)EEPROM_POWER_COUNT, eeprom_read_byte((uint8_t*)EEPROM_POWER_COUNT) + 1); eeprom_update_word((uint16_t*)EEPROM_POWER_COUNT_TOT, eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT) + 1); - printf_P(_N("UVLO - end %d\n"), _millis() - time_start); -#if 0 - // Move the print head to the side of the print until all the power stored in the power supply capacitors is depleted. + printf_P(_N("UVLO - end %d\n"), _millis() - time_start); + WRITE(BEEPER,HIGH); + + // All is set: with all the juice left, try to move extruder away to detach the nozzle completely from the print + enable_z(); current_position[X_AXIS] = (current_position[X_AXIS] < 0.5f * (X_MIN_POS + X_MAX_POS)) ? X_MIN_POS : X_MAX_POS; plan_buffer_line_curposXYZE(500, active_extruder); st_synchronize(); -#endif - // burn all that residual power wdt_enable(WDTO_1S); - WRITE(BEEPER,HIGH); while(1); } From eb2ca78167fbec4ded3731a00f9cad921adbea39 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 26 Jan 2020 17:35:50 +0100 Subject: [PATCH 139/180] Rewrite uvlo handling for accurate Z re/positioning - In both uvlo_ and uvlo_tiny, calculate Z usteps properly and adjust the Z position to a true fullstep before disabling the motor. This avoids shifs during recovery. - In uvlo_tiny, instead of moving up indefinitely, adjust Z just once using the smallest move possible (new def UVLO_TINY_Z_AXIS_SHIFT) - Perform all the uvlo/recovery processing in physical coordinates and MBL off: there should be no automatic Z movement! - Disable heaters in both handlers to conserve more power. - Add timing information to uvlo_tiny too. - During recovery, to switch between physical and logical positioning introduce a new "PRUSA MBL" gcode as most of the procedure is enqueued, and no existing gcode was available. --- Firmware/Marlin.h | 5 +- Firmware/Marlin_main.cpp | 256 ++++++++++-------- Firmware/eeprom.h | 4 +- .../variants/1_75mm_MK3-EINSy10a-E3Dv6full.h | 4 + .../variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h | 6 +- 5 files changed, 158 insertions(+), 117 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index 19e5df57b..58b3351de 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -445,9 +445,8 @@ void setup_uvlo_interrupt(); void setup_fan_interrupt(); #endif -//extern void recover_machine_state_after_power_panic(); -extern void recover_machine_state_after_power_panic(bool bTiny); -extern void restore_print_from_eeprom(); +extern bool recover_machine_state_after_power_panic(); +extern void restore_print_from_eeprom(bool mbl_was_active); extern void position_menu(); extern void print_world_coordinates(); diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 3fdff1a91..c2439d743 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3838,6 +3838,17 @@ void process_commands() } else if(code_seen("FR")) { // PRUSA FR // Factory full reset factory_reset(0); + } else if(code_seen("MBL")) { // PRUSA MBL + // Change the MBL status without changing the logical Z position. + if(code_seen("V")) { + bool value = code_value_short(); + st_synchronize(); + if(value != mbl.active) { + mbl.active = value; + // Use plan_set_z_position to reset the physical values + plan_set_z_position(current_position[Z_AXIS]); + } + } //-// /* @@ -10492,15 +10503,11 @@ void uvlo_() tmc2130_set_current_r(E_AXIS, 20); #endif //TMC2130 - // Indicate that the interrupt has been triggered. - // SERIAL_ECHOLNPGM("UVLO"); - - // Read out the current Z motor microstep counter. This will be later used - // for reaching the zero full step before powering off. - uint16_t z_microsteps = 0; -#ifdef TMC2130 - z_microsteps = tmc2130_rd_MSCNT(Z_TMC2130_CS); -#endif //TMC2130 + // Stop all heaters + uint8_t saved_target_temperature_bed = target_temperature_bed; + uint8_t saved_target_temperature_ext = target_temperature[active_extruder]; + setAllTargetHotends(0); + setTargetBed(0); // Calculate the file position, from which to resume this print. long sd_position = sdpos_atomic; //atomic sd position of last command added in queue @@ -10525,40 +10532,52 @@ void uvlo_() feedrate_bckp = feedrate; } + // From this point on and up to the print recovery, Z should not move during X/Y travels and + // should be controlled precisely. Reset the MBL status before planner_abort_hard in order to + // get the physical Z for further manipulation. + bool mbl_was_active = mbl.active; + mbl.active = false; + // After this call, the planner queue is emptied and the current_position is set to a current logical coordinate. // The logical coordinate will likely differ from the machine coordinate if the skew calibration and mesh bed leveling // are in action. planner_abort_hard(); - // Store the current extruder position. + // Store the print logical Z position, which we need to recover (a slight error here would be + // recovered on the next Gcode instruction, while a physical location error would not) + float logical_z = current_position[Z_AXIS]; + if(mbl_was_active) logical_z -= mbl.get_z(st_get_position_mm(X_AXIS), st_get_position_mm(Y_AXIS)); + eeprom_update_float((float*)EEPROM_UVLO_CURRENT_POSITION_Z, logical_z); + + // Store the print E position before we lose track eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION_E), current_position[E_AXIS]); eeprom_update_byte((uint8_t*)EEPROM_UVLO_E_ABS, axis_relative_modes[3]?0:1); // Clean the input command queue, inhibit serial processing using saved_printing cmdqueue_reset(); card.sdprinting = false; -// card.closefile(); saved_printing = true; // Enable stepper driver interrupt to move Z axis. This should be fine as the planner and // command queues are empty, SD card printing is disabled, usb is inhibited. sei(); - // retract - plan_buffer_line(current_position[X_AXIS], - current_position[Y_AXIS], - current_position[Z_AXIS], - current_position[E_AXIS] - default_retraction, - 95, active_extruder); + // Retract + current_position[E_AXIS] -= default_retraction; + plan_buffer_line_curposXYZE(95, active_extruder); st_synchronize(); disable_e0(); - // Move Z up and to the next 0th full step. - plan_buffer_line(current_position[X_AXIS], - current_position[Y_AXIS], - current_position[Z_AXIS] + UVLO_Z_AXIS_SHIFT + float((1024 - z_microsteps + 7) >> 4) / cs.axis_steps_per_unit[Z_AXIS], - current_position[E_AXIS] - default_retraction, - 40, active_extruder); + // Read out the current Z motor microstep counter to move the axis up towards + // a full step before powering off. NOTE: we need to ensure to schedule more + // than "dropsegments" steps in order to move (this is always the case here + // due to UVLO_Z_AXIS_SHIFT being used) + uint16_t z_res = tmc2130_get_res(Z_AXIS); + uint16_t z_microsteps = tmc2130_rd_MSCNT(Z_AXIS); + current_position[Z_AXIS] += float(1024 - z_microsteps) + / (z_res * cs.axis_steps_per_unit[Z_AXIS]) + + UVLO_Z_AXIS_SHIFT; + plan_buffer_line_curposXYZE(homing_feedrate[Z_AXIS]/60, active_extruder); st_synchronize(); disable_z(); @@ -10570,24 +10589,24 @@ void uvlo_() uint8_t ix = mesh_point % MESH_NUM_X_POINTS; // from 0 to MESH_NUM_X_POINTS - 1 uint8_t iy = mesh_point / MESH_NUM_X_POINTS; // Scale the z value to 1u resolution. - int16_t v = mbl.active ? int16_t(floor(mbl.z_values[iy][ix] * 1000.f + 0.5f)) : 0; + int16_t v = mbl_was_active ? int16_t(floor(mbl.z_values[iy][ix] * 1000.f + 0.5f)) : 0; eeprom_update_word((uint16_t*)(EEPROM_UVLO_MESH_BED_LEVELING_FULL +2*mesh_point), *reinterpret_cast(&v)); } - // Write the current Z motor microstep counter. This will be later used - // for reaching the zero full step before powering off. + // Write the _final_ Z position and motor microstep counter (unused). + eeprom_update_float((float*)EEPROM_UVLO_TINY_CURRENT_POSITION_Z, current_position[Z_AXIS]); + z_microsteps = tmc2130_rd_MSCNT(Z_AXIS); eeprom_update_word((uint16_t*)(EEPROM_UVLO_Z_MICROSTEPS), z_microsteps); // Store the current position. eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0), current_position[X_AXIS]); eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4), current_position[Y_AXIS]); - eeprom_update_float((float*)EEPROM_UVLO_CURRENT_POSITION_Z , current_position[Z_AXIS]); // Store the current feed rate, temperatures, fan speed and extruder multipliers (flow rates) eeprom_update_word((uint16_t*)EEPROM_UVLO_FEEDRATE, feedrate_bckp); eeprom_update_word((uint16_t*)EEPROM_UVLO_FEEDMULTIPLY, feedmultiply); - eeprom_update_byte((uint8_t*)EEPROM_UVLO_TARGET_HOTEND, target_temperature[active_extruder]); - eeprom_update_byte((uint8_t*)EEPROM_UVLO_TARGET_BED, target_temperature_bed); + eeprom_update_byte((uint8_t*)EEPROM_UVLO_TARGET_HOTEND, saved_target_temperature_ext); + eeprom_update_byte((uint8_t*)EEPROM_UVLO_TARGET_BED, saved_target_temperature_bed); eeprom_update_byte((uint8_t*)EEPROM_UVLO_FAN_SPEED, fanSpeed); eeprom_update_float((float*)(EEPROM_EXTRUDER_MULTIPLIER_0), extruder_multiplier[0]); #if EXTRUDERS > 1 @@ -10611,9 +10630,6 @@ void uvlo_() // Finaly store the "power outage" flag. if(sd_print) eeprom_update_byte((uint8_t*)EEPROM_UVLO, 1); - st_synchronize(); - printf_P(_N("stps%d\n"), tmc2130_rd_MSCNT(Z_AXIS)); - // Increment power failure counter eeprom_update_byte((uint8_t*)EEPROM_POWER_COUNT, eeprom_read_byte((uint8_t*)EEPROM_POWER_COUNT) + 1); eeprom_update_word((uint16_t*)EEPROM_POWER_COUNT_TOT, eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT) + 1); @@ -10634,44 +10650,68 @@ void uvlo_() void uvlo_tiny() { -uint16_t z_microsteps=0; + unsigned long time_start = _millis(); + + // Conserve power as soon as possible. + disable_x(); + disable_y(); + disable_e0(); -// Conserve power as soon as possible. -disable_x(); -disable_y(); -disable_e0(); - #ifdef TMC2130 -tmc2130_set_current_h(Z_AXIS, 20); -tmc2130_set_current_r(Z_AXIS, 20); + tmc2130_set_current_h(Z_AXIS, 20); + tmc2130_set_current_r(Z_AXIS, 20); #endif //TMC2130 -// Read out the current Z motor microstep counter -#ifdef TMC2130 -z_microsteps=tmc2130_rd_MSCNT(Z_TMC2130_CS); -#endif //TMC2130 -planner_abort_hard(); + // Stop all heaters + setAllTargetHotends(0); + setTargetBed(0); -//save current position only in case, where the printer is moving on Z axis, which is only when EEPROM_UVLO is 1 -//EEPROM_UVLO is 1 after normal uvlo or after recover_print(), when the extruder is moving on Z axis after rehome -if(eeprom_read_byte((uint8_t*)EEPROM_UVLO)!=2){ - eeprom_update_float((float*)(EEPROM_UVLO_TINY_CURRENT_POSITION_Z), current_position[Z_AXIS]); - eeprom_update_word((uint16_t*)(EEPROM_UVLO_TINY_Z_MICROSTEPS),z_microsteps); -} + // When power is interrupted on the _first_ recovery an attempt can be made to raise the + // extruder, causing the Z position to change. Similarly, when recovering, the Z position is + // lowered. In such cases we cannot just save Z, we need to re-align the steppers to a fullstep. + // Disable MBL (if not already) to work with physical coordinates. + mbl.active = false; + planner_abort_hard(); -//after multiple power panics current Z axis is unknow -//in this case we set EEPROM_UVLO_TINY_CURRENT_POSITION_Z to last know position which is EEPROM_UVLO_CURRENT_POSITION_Z -if(eeprom_read_float((float*)EEPROM_UVLO_TINY_CURRENT_POSITION_Z) < 0.001f){ - eeprom_update_float((float*)(EEPROM_UVLO_TINY_CURRENT_POSITION_Z), eeprom_read_float((float*)EEPROM_UVLO_CURRENT_POSITION_Z)); - eeprom_update_word((uint16_t*)(EEPROM_UVLO_TINY_Z_MICROSTEPS), eeprom_read_word((uint16_t*)EEPROM_UVLO_Z_MICROSTEPS)); -} + // Allow for small roundoffs to be ignored + if(abs(current_position[Z_AXIS] - eeprom_read_float((float*)(EEPROM_UVLO_TINY_CURRENT_POSITION_Z))) >= 1.f/cs.axis_steps_per_unit[Z_AXIS]) + { + // Clean the input command queue, inhibit serial processing using saved_printing + cmdqueue_reset(); + card.sdprinting = false; + saved_printing = true; -// Finaly store the "power outage" flag. -eeprom_update_byte((uint8_t*)EEPROM_UVLO,2); + // Enable stepper driver interrupt to move Z axis. This should be fine as the planner and + // command queues are empty, SD card printing is disabled, usb is inhibited. + sei(); + + // The axis was moved: adjust Z as done on a regular UVLO. + uint16_t z_res = tmc2130_get_res(Z_AXIS); + uint16_t z_microsteps = tmc2130_rd_MSCNT(Z_AXIS); + current_position[Z_AXIS] += float(1024 - z_microsteps) + / (z_res * cs.axis_steps_per_unit[Z_AXIS]) + + UVLO_TINY_Z_AXIS_SHIFT; + plan_buffer_line_curposXYZE(homing_feedrate[Z_AXIS]/60, active_extruder); + st_synchronize(); + disable_z(); + + // Update Z position + eeprom_update_float((float*)(EEPROM_UVLO_TINY_CURRENT_POSITION_Z), current_position[Z_AXIS]); + + // Update the _final_ Z motor microstep counter (unused). + z_microsteps = tmc2130_rd_MSCNT(Z_AXIS); + eeprom_update_word((uint16_t*)(EEPROM_UVLO_Z_MICROSTEPS), z_microsteps); + } + + // Update the the "power outage" flag. + eeprom_update_byte((uint8_t*)EEPROM_UVLO,2); + + // Increment power failure counter + eeprom_update_byte((uint8_t*)EEPROM_POWER_COUNT, eeprom_read_byte((uint8_t*)EEPROM_POWER_COUNT) + 1); + eeprom_update_word((uint16_t*)EEPROM_POWER_COUNT_TOT, eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT) + 1); + + printf_P(_N("UVLO_TINY - end %d\n"), _millis() - time_start); -// Increment power failure counter -eeprom_update_byte((uint8_t*)EEPROM_POWER_COUNT, eeprom_read_byte((uint8_t*)EEPROM_POWER_COUNT) + 1); -eeprom_update_word((uint16_t*)EEPROM_POWER_COUNT_TOT, eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT) + 1); // burn all that residual power wdt_enable(WDTO_1S); WRITE(BEEPER,HIGH); @@ -10744,13 +10784,16 @@ void recover_print(uint8_t automatic) { lcd_update(2); lcd_setstatuspgm(_i("Recovering print "));////MSG_RECOVERING_PRINT c=20 r=1 - bool bTiny=(eeprom_read_byte((uint8_t*)EEPROM_UVLO)==2); - recover_machine_state_after_power_panic(bTiny); //recover position, temperatures and extrude_multipliers - // Lift the print head, so one may remove the excess priming material. - if(!bTiny&&(current_position[Z_AXIS]<25)) - enquecommand_P(PSTR("G1 Z25 F800")); + // Recover position, temperatures and extrude_multipliers + bool mbl_was_active = recover_machine_state_after_power_panic(); - // Home X and Y axes. Homing just X and Y shall not touch the babystep and the world2machine transformation status. + // Attempt to lift the print head on the first recovery, so one may remove the excess priming material. + bool raise_z = (eeprom_read_byte((uint8_t*)EEPROM_UVLO) == 1); + if(raise_z && (current_position[Z_AXIS]<25)) + enquecommand_P(PSTR("G1 Z25 F800")); + + // Home X and Y axes. Homing just X and Y shall not touch the babystep and the world2machine + // transformation status. G28 will not touch Z when MBL is off. enquecommand_P(PSTR("G28 X Y")); // Set the target bed and nozzle temperatures and wait. sprintf_P(cmd, PSTR("M104 S%d"), target_temperature[active_extruder]); @@ -10774,19 +10817,19 @@ void recover_print(uint8_t automatic) { printf_P(_N("After waiting for temp:\nCurrent pos X_AXIS:%.3f\nCurrent pos Y_AXIS:%.3f\n"), current_position[X_AXIS], current_position[Y_AXIS]); // Restart the print. - restore_print_from_eeprom(); + restore_print_from_eeprom(mbl_was_active); printf_P(_N("Current pos Z_AXIS:%.3f\nCurrent pos E_AXIS:%.3f\n"), current_position[Z_AXIS], current_position[E_AXIS]); } -void recover_machine_state_after_power_panic(bool bTiny) +bool recover_machine_state_after_power_panic() { - // 1) Recover the logical cordinates at the time of the power panic. - // The logical XY coordinates are needed to recover the machine Z coordinate corrected by the mesh bed leveling. - current_position[X_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0)); - current_position[Y_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4)); + // 1) Preset some dummy values for the XY axes + current_position[X_AXIS] = 0; + current_position[Y_AXIS] = 0; - // 2) Restore the mesh bed leveling offsets. This is 2*7*7=98 bytes, which takes 98*3.4us=333us in worst case. - mbl.active = false; + // 2) Restore the mesh bed leveling offsets, but not the MBL status. + // This is 2*7*7=98 bytes, which takes 98*3.4us=333us in worst case. + bool mbl_was_active = false; for (int8_t mesh_point = 0; mesh_point < MESH_NUM_X_POINTS * MESH_NUM_Y_POINTS; ++ mesh_point) { uint8_t ix = mesh_point % MESH_NUM_X_POINTS; // from 0 to MESH_NUM_X_POINTS - 1 uint8_t iy = mesh_point / MESH_NUM_X_POINTS; @@ -10794,26 +10837,13 @@ void recover_machine_state_after_power_panic(bool bTiny) int16_t v; eeprom_read_block(&v, (void*)(EEPROM_UVLO_MESH_BED_LEVELING_FULL+2*mesh_point), 2); if (v != 0) - mbl.active = true; + mbl_was_active = true; mbl.z_values[iy][ix] = float(v) * 0.001f; } - // Recover the logical coordinate of the Z axis at the time of the power panic. + // Recover the physical coordinate of the Z axis at the time of the power panic. // The current position after power panic is moved to the next closest 0th full step. - if(bTiny){ - current_position[Z_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_TINY_CURRENT_POSITION_Z)) - + float((1024 - eeprom_read_word((uint16_t*)(EEPROM_UVLO_TINY_Z_MICROSTEPS)) - + 7) >> 4) / cs.axis_steps_per_unit[Z_AXIS]; - - //after multiple power panics the print is slightly in the air so get it little bit down. - //Not exactly sure why is this happening, but it has something to do with bed leveling and world2machine coordinates - current_position[Z_AXIS] -= 0.4*mbl.get_z(current_position[X_AXIS], current_position[Y_AXIS]); - } - else{ - current_position[Z_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION_Z)) + - UVLO_Z_AXIS_SHIFT + float((1024 - eeprom_read_word((uint16_t*)(EEPROM_UVLO_Z_MICROSTEPS)) - + 7) >> 4) / cs.axis_steps_per_unit[Z_AXIS]; - } + current_position[Z_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_TINY_CURRENT_POSITION_Z)); // Recover last E axis position current_position[E_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION_E)); @@ -10832,17 +10862,13 @@ void recover_machine_state_after_power_panic(bool bTiny) // The baby stepping value is used to reset the physical Z axis when rehoming the Z axis. babystep_load(); - // 5) Set the physical positions from the logical positions using the world2machine transformation and the active bed leveling. + // 5) Set the physical positions from the logical positions using the world2machine transformation + // This is only done to inizialize Z/E axes with physical locations, since X/Y are unknown. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); - // 6) Power up the motors, mark their positions as known. - //FIXME Verfiy, whether the X and Y axes should be powered up here, as they will later be re-homed anyway. - axis_known_position[X_AXIS] = true; enable_x(); - axis_known_position[Y_AXIS] = true; enable_y(); - axis_known_position[Z_AXIS] = true; enable_z(); - - SERIAL_ECHOPGM("recover_machine_state_after_power_panic, initial "); - print_physical_coordinates(); + // 6) Power up the Z motors, mark their positions as known. + axis_known_position[Z_AXIS] = true; + enable_z(); // 7) Recover the target temperatures. target_temperature[active_extruder] = eeprom_read_byte((uint8_t*)EEPROM_UVLO_TARGET_HOTEND); @@ -10867,9 +10893,11 @@ void recover_machine_state_after_power_panic(bool bTiny) #ifdef LIN_ADVANCE extruder_advance_K = eeprom_read_float((float*)EEPROM_UVLO_LA_K); #endif + + return mbl_was_active; } -void restore_print_from_eeprom() { +void restore_print_from_eeprom(bool mbl_was_active) { int feedrate_rec; int feedmultiply_rec; uint8_t fan_speed_rec; @@ -10910,17 +10938,23 @@ void restore_print_from_eeprom() { enquecommand(cmd); uint32_t position = eeprom_read_dword((uint32_t*)(EEPROM_FILE_POSITION)); SERIAL_ECHOPGM("Position read from eeprom:"); - MYSERIAL.println(position); - // Move to the XY print position in logical coordinates, where the print has been killed. - strcpy_P(cmd, PSTR("G1 X")); strcat(cmd, ftostr32(eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0)))); - strcat_P(cmd, PSTR(" Y")); strcat(cmd, ftostr32(eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4)))); - strcat_P(cmd, PSTR(" F2000")); + MYSERIAL.println(position); + + // Move to the XY print position in logical coordinates, where the print has been killed, but + // without shifting Z along the way. This requires performing the move without mbl. + sprintf_P(cmd, PSTR("G1 X%f Y%f F2000"), + eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0)), + eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4))); enquecommand(cmd); - //moving on Z axis ahead, set EEPROM_UVLO to 1, so normal uvlo can fire - eeprom_update_byte((uint8_t*)EEPROM_UVLO,1); - // Move the Z axis down to the print, in logical coordinates. - strcpy_P(cmd, PSTR("G1 Z")); strcat(cmd, ftostr32(eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION_Z)))); + + // Enable MBL and switch to logical positioning + if (mbl_was_active) + enquecommand_P(PSTR("PRUSA MBL V1")); + + // Move the Z axis down to the print, in logical coordinates. + sprintf_P(cmd, PSTR("G1 Z%f"), eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION_Z))); enquecommand(cmd); + // Unretract. sprintf_P(cmd, PSTR("G1 E%0.3f F2700"), default_retraction); enquecommand(cmd); diff --git a/Firmware/eeprom.h b/Firmware/eeprom.h index 5a9d7d813..c50dc94e5 100644 --- a/Firmware/eeprom.h +++ b/Firmware/eeprom.h @@ -79,7 +79,7 @@ static_assert(sizeof(Sheets) == EEPROM_SHEETS_SIZEOF, "Sizeof(Sheets) is not EEP #define EEPROM_FAN_CHECK_ENABLED (EEPROM_UVLO_FAN_SPEED - 1) #define EEPROM_UVLO_MESH_BED_LEVELING (EEPROM_FAN_CHECK_ENABLED - 9*2) -#define EEPROM_UVLO_Z_MICROSTEPS (EEPROM_UVLO_MESH_BED_LEVELING - 2) +#define EEPROM_UVLO_Z_MICROSTEPS (EEPROM_UVLO_MESH_BED_LEVELING - 2) // uint16_t (could be removed) #define EEPROM_UVLO_E_ABS (EEPROM_UVLO_Z_MICROSTEPS - 1) #define EEPROM_UVLO_CURRENT_POSITION_E (EEPROM_UVLO_E_ABS - 4) //float for current position in E @@ -167,7 +167,7 @@ static_assert(sizeof(Sheets) == EEPROM_SHEETS_SIZEOF, "Sizeof(Sheets) is not EEP // #define EEPROM_UVLO_TINY_CURRENT_POSITION_Z (EEPROM_EXTRUDEMULTIPLY-4) // float -#define EEPROM_UVLO_TINY_Z_MICROSTEPS (EEPROM_UVLO_TINY_CURRENT_POSITION_Z-2) // uint16 +#define EEPROM_UVLO_TINY_Z_MICROSTEPS (EEPROM_UVLO_TINY_CURRENT_POSITION_Z-2) // uint16 (unused) // Sound Mode //#define EEPROM_SOUND_MODE (EEPROM_EXTRUDEMULTIPLY-1) // uint8 diff --git a/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h b/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h index 400d098ff..53bfb4bf9 100644 --- a/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h @@ -618,6 +618,10 @@ // The following example, 12 * (4 * 16 / 400) = 12 * 0.16mm = 1.92mm. //#define UVLO_Z_AXIS_SHIFT 1.92 #define UVLO_Z_AXIS_SHIFT 0.64 +// When powered off during PP recovery, the Z axis position can still be re-adjusted. In this case +// we just need to shift to the nearest fullstep, but we need a move which is at least +// "dropsegments" steps long. All the above rules still need to apply. +#define UVLO_TINY_Z_AXIS_SHIFT 0.16 // If power panic occured, and the current temperature is higher then target temperature before interrupt minus this offset, print will be recovered automatically. #define AUTOMATIC_UVLO_BED_TEMP_OFFSET 5 diff --git a/Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h b/Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h index 48ed91392..253fe0ec8 100644 --- a/Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h @@ -620,7 +620,11 @@ // The following example, 12 * (4 * 16 / 400) = 12 * 0.16mm = 1.92mm. //#define UVLO_Z_AXIS_SHIFT 1.92 #define UVLO_Z_AXIS_SHIFT 0.64 -// If power panic occured, and the current temperature is higher then target temperature before interrupt minus this offset, print will be recovered automatically. +// When powered off during PP recovery, the Z axis position can still be re-adjusted. In this case +// we just need to shift to the nearest fullstep, but we need a move which is at least +// "dropsegments" steps long. All the above rules still need to apply. +#define UVLO_TINY_Z_AXIS_SHIFT 0.16 +// If power panic occured, and the current temperature is higher then target temperature before interrupt minus this offset, print will be recovered automatically. #define AUTOMATIC_UVLO_BED_TEMP_OFFSET 5 #define HEATBED_V2 From 50a9fe003a5524cfae0023b605c96577831d2a1b Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Mon, 27 Jan 2020 11:08:28 +0100 Subject: [PATCH 140/180] Bump the unparking speed to 50mm/s (same as M600 recovery) --- Firmware/Marlin_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index c2439d743..1d7821947 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -10942,7 +10942,7 @@ void restore_print_from_eeprom(bool mbl_was_active) { // Move to the XY print position in logical coordinates, where the print has been killed, but // without shifting Z along the way. This requires performing the move without mbl. - sprintf_P(cmd, PSTR("G1 X%f Y%f F2000"), + sprintf_P(cmd, PSTR("G1 X%f Y%f F3000"), eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0)), eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4))); enquecommand(cmd); From 5d8857371132b311c76d07c19be548a73281b8f0 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Mon, 27 Jan 2020 14:59:18 +0100 Subject: [PATCH 141/180] Save/restore hotend temperatures above 255C in PowerPanic Use 2 bytes to store extruder temperature during UVLO. Re-use the storage of EEPROM_UVLO_TINY_Z_MICROSTEPS which has been freed by previous changes. Fixes #2303 --- Firmware/Marlin_main.cpp | 6 +++--- Firmware/eeprom.h | 10 ++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 1d7821947..a204f9f0b 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -10505,7 +10505,7 @@ void uvlo_() // Stop all heaters uint8_t saved_target_temperature_bed = target_temperature_bed; - uint8_t saved_target_temperature_ext = target_temperature[active_extruder]; + uint16_t saved_target_temperature_ext = target_temperature[active_extruder]; setAllTargetHotends(0); setTargetBed(0); @@ -10605,7 +10605,7 @@ void uvlo_() // Store the current feed rate, temperatures, fan speed and extruder multipliers (flow rates) eeprom_update_word((uint16_t*)EEPROM_UVLO_FEEDRATE, feedrate_bckp); eeprom_update_word((uint16_t*)EEPROM_UVLO_FEEDMULTIPLY, feedmultiply); - eeprom_update_byte((uint8_t*)EEPROM_UVLO_TARGET_HOTEND, saved_target_temperature_ext); + eeprom_update_word((uint16_t*)EEPROM_UVLO_TARGET_HOTEND, saved_target_temperature_ext); eeprom_update_byte((uint8_t*)EEPROM_UVLO_TARGET_BED, saved_target_temperature_bed); eeprom_update_byte((uint8_t*)EEPROM_UVLO_FAN_SPEED, fanSpeed); eeprom_update_float((float*)(EEPROM_EXTRUDER_MULTIPLIER_0), extruder_multiplier[0]); @@ -10871,7 +10871,7 @@ bool recover_machine_state_after_power_panic() enable_z(); // 7) Recover the target temperatures. - target_temperature[active_extruder] = eeprom_read_byte((uint8_t*)EEPROM_UVLO_TARGET_HOTEND); + target_temperature[active_extruder] = eeprom_read_word((uint16_t*)EEPROM_UVLO_TARGET_HOTEND); target_temperature_bed = eeprom_read_byte((uint8_t*)EEPROM_UVLO_TARGET_BED); // 8) Recover extruder multipilers diff --git a/Firmware/eeprom.h b/Firmware/eeprom.h index c50dc94e5..f0544f395 100644 --- a/Firmware/eeprom.h +++ b/Firmware/eeprom.h @@ -72,8 +72,8 @@ static_assert(sizeof(Sheets) == EEPROM_SHEETS_SIZEOF, "Sizeof(Sheets) is not EEP #define EEPROM_FILENAME (EEPROM_UVLO_CURRENT_POSITION - 8) //8chars to store filename without extension #define EEPROM_FILE_POSITION (EEPROM_FILENAME - 4) //32 bit for uint32_t file position #define EEPROM_UVLO_CURRENT_POSITION_Z (EEPROM_FILE_POSITION - 4) //float for current position in Z -#define EEPROM_UVLO_TARGET_HOTEND (EEPROM_UVLO_CURRENT_POSITION_Z - 1) -#define EEPROM_UVLO_TARGET_BED (EEPROM_UVLO_TARGET_HOTEND - 1) +#define EEPROM_UVLO_UNUSED_001 (EEPROM_UVLO_CURRENT_POSITION_Z - 1) // uint8_t (unused) +#define EEPROM_UVLO_TARGET_BED (EEPROM_UVLO_UNUSED_001 - 1) #define EEPROM_UVLO_FEEDRATE (EEPROM_UVLO_TARGET_BED - 2) //uint16_t #define EEPROM_UVLO_FAN_SPEED (EEPROM_UVLO_FEEDRATE - 1) #define EEPROM_FAN_CHECK_ENABLED (EEPROM_UVLO_FAN_SPEED - 1) @@ -165,13 +165,11 @@ static_assert(sizeof(Sheets) == EEPROM_SHEETS_SIZEOF, "Sizeof(Sheets) is not EEP #define EEPROM_EXTRUDER_MULTIPLIER_2 (EEPROM_EXTRUDER_MULTIPLIER_1 - 4) //float #define EEPROM_EXTRUDEMULTIPLY (EEPROM_EXTRUDER_MULTIPLIER_2 - 2) // uint16 -// #define EEPROM_UVLO_TINY_CURRENT_POSITION_Z (EEPROM_EXTRUDEMULTIPLY-4) // float -#define EEPROM_UVLO_TINY_Z_MICROSTEPS (EEPROM_UVLO_TINY_CURRENT_POSITION_Z-2) // uint16 (unused) +#define EEPROM_UVLO_TARGET_HOTEND (EEPROM_UVLO_TINY_CURRENT_POSITION_Z-2) // uint16 // Sound Mode -//#define EEPROM_SOUND_MODE (EEPROM_EXTRUDEMULTIPLY-1) // uint8 -#define EEPROM_SOUND_MODE (EEPROM_UVLO_TINY_Z_MICROSTEPS-1) // uint8 +#define EEPROM_SOUND_MODE (EEPROM_UVLO_TARGET_HOTEND-1) // uint8 #define EEPROM_AUTO_DEPLETE (EEPROM_SOUND_MODE-1) //bool #define EEPROM_FSENS_OQ_MEASS_ENABLED (EEPROM_AUTO_DEPLETE - 1) //bool From 3da20db02404f3654631bf99d8c4d8aea0e8c709 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Mon, 27 Jan 2020 18:50:17 +0100 Subject: [PATCH 142/180] Really poweroff Z motors when PSU_Delta is defined enable/disable_z behave differently when PSU_Delta is defined. During powerpanic and kill however we do *really* need to save energy and poweroff the motors. Rename enable/disable_z as poweron/poweroff_z and define some aliases so that we can use the low-level function where needed. --- Firmware/Marlin.h | 35 +++++++++++++++++------------------ Firmware/Marlin_main.cpp | 8 ++++---- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index 58b3351de..a0b3c19b8 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -146,40 +146,39 @@ void manage_inactivity(bool ignore_stepper_queue=false); #if defined(Z_ENABLE_PIN) && Z_ENABLE_PIN > -1 #if defined(Z_AXIS_ALWAYS_ON) #ifdef Z_DUAL_STEPPER_DRIVERS - #define enable_z() { WRITE(Z_ENABLE_PIN, Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN, Z_ENABLE_ON); } - #define disable_z() { WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN,!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; } + #define poweron_z() { WRITE(Z_ENABLE_PIN, Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN, Z_ENABLE_ON); } + #define poweroff_z() { WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN,!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; } #else - #define enable_z() WRITE(Z_ENABLE_PIN, Z_ENABLE_ON) - #define disable_z() {} + #define poweron_z() WRITE(Z_ENABLE_PIN, Z_ENABLE_ON) + #define poweroff_z() {} #endif #else #ifdef Z_DUAL_STEPPER_DRIVERS - #define enable_z() { WRITE(Z_ENABLE_PIN, Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN, Z_ENABLE_ON); } - #define disable_z() { WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN,!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; } + #define poweron_z() { WRITE(Z_ENABLE_PIN, Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN, Z_ENABLE_ON); } + #define poweroff_z() { WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN,!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; } #else - #define enable_z() WRITE(Z_ENABLE_PIN, Z_ENABLE_ON) - #define disable_z() { WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; } + #define poweron_z() WRITE(Z_ENABLE_PIN, Z_ENABLE_ON) + #define poweroff_z() { WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; } #endif #endif #else - #define enable_z() {} - #define disable_z() {} + #define poweron_z() {} + #define poweroff_z() {} #endif -#ifdef PSU_Delta +#ifndef PSU_Delta + #define enable_z() poweron_z() + #define disable_z() poweroff_z() +#else void init_force_z(); void check_force_z(); - #undef disable_z - #define disable_z() disable_force_z() - void disable_force_z(); - #undef enable_z - #define enable_z() enable_force_z() void enable_force_z(); + void disable_force_z(); + #define enable_z() enable_force_z() + #define disable_z() disable_force_z() #endif // PSU_Delta - - //#if defined(Z_ENABLE_PIN) && Z_ENABLE_PIN > -1 //#ifdef Z_DUAL_STEPPER_DRIVERS //#define enable_z() { WRITE(Z_ENABLE_PIN, Z_ENABLE_ON); WRITE(Z2_ENABLE_PIN, Z_ENABLE_ON); } diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index a204f9f0b..c80199a22 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -9595,7 +9595,7 @@ void kill(const char *full_screen_message, unsigned char id) disable_x(); // SERIAL_ECHOLNPGM("kill - disable Y"); disable_y(); - disable_z(); + poweroff_z(); disable_e0(); disable_e1(); disable_e2(); @@ -10579,7 +10579,7 @@ void uvlo_() + UVLO_Z_AXIS_SHIFT; plan_buffer_line_curposXYZE(homing_feedrate[Z_AXIS]/60, active_extruder); st_synchronize(); - disable_z(); + poweroff_z(); // Write the file position. eeprom_update_dword((uint32_t*)(EEPROM_FILE_POSITION), sd_position); @@ -10638,7 +10638,7 @@ void uvlo_() WRITE(BEEPER,HIGH); // All is set: with all the juice left, try to move extruder away to detach the nozzle completely from the print - enable_z(); + poweron_z(); current_position[X_AXIS] = (current_position[X_AXIS] < 0.5f * (X_MIN_POS + X_MAX_POS)) ? X_MIN_POS : X_MAX_POS; plan_buffer_line_curposXYZE(500, active_extruder); st_synchronize(); @@ -10693,7 +10693,7 @@ void uvlo_tiny() + UVLO_TINY_Z_AXIS_SHIFT; plan_buffer_line_curposXYZE(homing_feedrate[Z_AXIS]/60, active_extruder); st_synchronize(); - disable_z(); + poweroff_z(); // Update Z position eeprom_update_float((float*)(EEPROM_UVLO_TINY_CURRENT_POSITION_Z), current_position[Z_AXIS]); From 200cdde1af99ffc3d3c981f6d431cf0bc936ca2d Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 28 Jan 2020 21:50:12 +0100 Subject: [PATCH 143/180] Setup the UVLO interrupt later during initialization Do not allow uvlo_tiny() to trigger before the previous print has already been recovered. A quick repeated power failure could cause uvlo_tiny to overwrite the Z position before it has been correctly recovered. --- Firmware/Marlin_main.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index c80199a22..fbfb39f25 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1298,10 +1298,6 @@ void setup() st_init(); // Initialize stepper, this enables interrupts! -#ifdef UVLO_SUPPORT - setup_uvlo_interrupt(); -#endif //UVLO_SUPPORT - #ifdef TMC2130 tmc2130_mode = silentMode?TMC2130_MODE_SILENT:TMC2130_MODE_NORMAL; update_mode_profile(); @@ -1596,12 +1592,14 @@ void setup() lcd_update(2); lcd_setstatuspgm(_T(WELCOME_MSG)); } - } - - } + + // Only arm the uvlo interrupt _after_ a recovering print has been initialized and + // the entire state machine initialized. + setup_uvlo_interrupt(); #endif //UVLO_SUPPORT + fCheckModeInit(); fSetMmuMode(mmu_enabled); KEEPALIVE_STATE(NOT_BUSY); From b46dc59fad9bf26534ac8e9d40e17c4404b2362d Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 29 Jan 2020 16:06:54 +0100 Subject: [PATCH 144/180] Refuse to start a print if power is lost before arming uvlo If power has been lost during startup already a falling edge would be skipped, causing the print to continue and lose its state without being able to save again. Check for a low line after arming the interrupt and simply wait for reset. --- Firmware/Marlin_main.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index fbfb39f25..5eb8d48b2 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -10480,6 +10480,14 @@ void serialecho_temperatures() { } #ifdef UVLO_SUPPORT +void uvlo_drain_reset() +{ + // burn all that residual power + wdt_enable(WDTO_1S); + WRITE(BEEPER,HIGH); + while(1); +} + void uvlo_() { @@ -10709,11 +10717,7 @@ void uvlo_tiny() eeprom_update_word((uint16_t*)EEPROM_POWER_COUNT_TOT, eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT) + 1); printf_P(_N("UVLO_TINY - end %d\n"), _millis() - time_start); - - // burn all that residual power - wdt_enable(WDTO_1S); - WRITE(BEEPER,HIGH); - while(1); + uvlo_drain_reset(); } #endif //UVLO_SUPPORT @@ -10760,12 +10764,19 @@ void setup_uvlo_interrupt() { DDRE &= ~(1 << 4); //input pin PORTE &= ~(1 << 4); //no internal pull-up - //sensing falling edge + // sensing falling edge EICRB |= (1 << 0); EICRB &= ~(1 << 1); - //enable INT4 interrupt + // enable INT4 interrupt EIMSK |= (1 << 4); + + // check if power was lost before we armed the interrupt + if(!(PINE & (1 << 4))) + { + SERIAL_ECHOLNPGM("INT4"); + uvlo_drain_reset(); + } } ISR(INT4_vect) { From 4fd913ddf3f7170456cbdf195c332a75f8f2012f Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 29 Jan 2020 17:45:47 +0200 Subject: [PATCH 145/180] Remove commented out code --- Firmware/Marlin_main.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 70cbd6d7a..1dc45eab5 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -11563,8 +11563,6 @@ if(!(bEnableForce_z||eeprom_read_byte((uint8_t*)EEPROM_SILENT))) void disable_force_z() { - // uint16_t z_microsteps=0; - if(!bEnableForce_z) return; // motor already disabled (may be ;-p ) bEnableForce_z=false; @@ -11575,8 +11573,6 @@ void disable_force_z() update_mode_profile(); tmc2130_init(true); #endif // TMC2130 - - // axis_known_position[Z_AXIS]=false; } From 2b46fdac2d0251041cb89f96ae16e7e19e17473c Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 29 Jan 2020 17:56:26 +0100 Subject: [PATCH 146/180] Only trigger a quick reset if there's a pending saved state Thanks to @leptun --- Firmware/Marlin_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 5eb8d48b2..169effb8d 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -10772,7 +10772,7 @@ void setup_uvlo_interrupt() { EIMSK |= (1 << 4); // check if power was lost before we armed the interrupt - if(!(PINE & (1 << 4))) + if(!(PINE & (1 << 4)) && eeprom_read_byte((uint8_t*)EEPROM_UVLO)) { SERIAL_ECHOLNPGM("INT4"); uvlo_drain_reset(); From 02d1525445b81002cc591738d69cbdb05988ee18 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 29 Jan 2020 21:08:56 +0100 Subject: [PATCH 147/180] Display "POWER PANIC DETECTED" when possible Both during early init and in uvlo_tiny, display "POWER PANIC DETECTED" if enough charge is left. This is not worth doing in regular uvlo_, as we want to give full priority to the X motor --- Firmware/Marlin_main.cpp | 2 ++ Firmware/messages.c | 1 + Firmware/messages.h | 1 + 3 files changed, 4 insertions(+) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 169effb8d..20a269af5 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -10485,6 +10485,8 @@ void uvlo_drain_reset() // burn all that residual power wdt_enable(WDTO_1S); WRITE(BEEPER,HIGH); + lcd_clear(); + lcd_puts_at_P(0, 1, MSG_POWERPANIC_DETECTED); while(1); } diff --git a/Firmware/messages.c b/Firmware/messages.c index 68bad5ffb..2b113673e 100644 --- a/Firmware/messages.c +++ b/Firmware/messages.c @@ -171,3 +171,4 @@ const char MSG_M112_KILL[] PROGMEM_N1 = "M112 called. Emergency Stop."; ////c=20 #ifdef LA_LIVE_K const char MSG_ADVANCE_K[] PROGMEM_N1 = "Advance K:"; ////c=13 #endif +const char MSG_POWERPANIC_DETECTED[] PROGMEM_N1 = "POWER PANIC DETECTED"; ////c=20 diff --git a/Firmware/messages.h b/Firmware/messages.h index 678524abb..7cc240d3b 100644 --- a/Firmware/messages.h +++ b/Firmware/messages.h @@ -170,6 +170,7 @@ extern const char MSG_FANCHECK_EXTRUDER[]; extern const char MSG_FANCHECK_PRINT[]; extern const char MSG_M112_KILL[]; extern const char MSG_ADVANCE_K[]; +extern const char MSG_POWERPANIC_DETECTED[]; #if defined(__cplusplus) } From a5198e32a3d041024fbf327d0e380bbd69543a5f Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 29 Jan 2020 22:44:19 +0200 Subject: [PATCH 148/180] Just keep the current state. ON or OFF. No switching allowed --- Firmware/heatbed_pwm.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Firmware/heatbed_pwm.cpp b/Firmware/heatbed_pwm.cpp index 1e467c4e8..612cf3c86 100755 --- a/Firmware/heatbed_pwm.cpp +++ b/Firmware/heatbed_pwm.cpp @@ -139,19 +139,15 @@ ISR(TIMER0_OVF_vect) // timer compare interrupt service routine break; case States::ONE: // state ONE - we'll either stay in ONE or change to FALL OCR0B = 255; + if (bedPWMDisabled) return; slowCounter += slowInc; // this does software timer_clk/256 or less - if (!bedPWMDisabled){ //disable heating as soon as possible - if( slowCounter < pwm ){ - return; - } - if( (soft_pwm_bed << 1) >= (255 - slowInc - 1) ){ //@@TODO simplify & explain - // if slowInc==2, soft_pwm == 251 will be the first to do short drops to zero. 252 will keep full heating - return; // want full duty for the next ONE cycle again - so keep on heating and just wait for the next timer ovf - } - } - else if (pwm > 200){ //if duty cycle is high and BED PWM is disabled keep heater on. Prevents overcooling + if( slowCounter < pwm ){ return; } + if( (soft_pwm_bed << 1) >= (255 - slowInc - 1) ){ //@@TODO simplify & explain + // if slowInc==2, soft_pwm == 251 will be the first to do short drops to zero. 252 will keep full heating + return; // want full duty for the next ONE cycle again - so keep on heating and just wait for the next timer ovf + } // otherwise moving towards FALL // @@TODO it looks like ONE_TO_FALL isn't necessary, there are no artefacts at all state = States::ONE;//_TO_FALL; From 755230e2e750880de393586946dfa0c26a15737c Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 29 Jan 2020 22:47:28 +0200 Subject: [PATCH 149/180] fix small mistake --- Firmware/heatbed_pwm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/heatbed_pwm.cpp b/Firmware/heatbed_pwm.cpp index 612cf3c86..4552bf966 100755 --- a/Firmware/heatbed_pwm.cpp +++ b/Firmware/heatbed_pwm.cpp @@ -95,7 +95,7 @@ ISR(TIMER0_OVF_vect) // timer compare interrupt service routine { switch(state){ case States::ZERO_START: - if (bedPWMDisabled) break; + if (bedPWMDisabled) return; pwm = soft_pwm_bed << 1;// expecting soft_pwm_bed to be 7bit! if( pwm != 0 ){ state = States::ZERO; // do nothing, let it tick once again after the 30Hz period From b86aafb56e2dd3b2ec162b7130ec28890ec908f4 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 29 Jan 2020 23:03:20 +0200 Subject: [PATCH 150/180] Documentation --- Firmware/heatbed_pwm.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Firmware/heatbed_pwm.cpp b/Firmware/heatbed_pwm.cpp index 4552bf966..e85515016 100755 --- a/Firmware/heatbed_pwm.cpp +++ b/Firmware/heatbed_pwm.cpp @@ -45,6 +45,12 @@ // If there are any change requirements in the future, the signal must be checked with an osciloscope again, // ad-hoc changes may completely screw things up! +// 2020-01-29 update: we are introducing a new option to the automaton that will allow us to force the output state +// to either full ON or OFF. This is so that interference during the MBL probing is minimal. +// To accomplish this goal we use bedPWMDisabled. It is only supposed to be used for brief periods of time as to +// not make the bed temperature too unstable. Also, careful consideration should be used when using this +// option as leaving this enabled will also keep the bed output in the state it stopped in. + ///! Definition off finite automaton states enum class States : uint8_t { ZERO_START = 0,///< entry point of the automaton - reads the soft_pwm_bed value for the next whole PWM cycle @@ -95,7 +101,7 @@ ISR(TIMER0_OVF_vect) // timer compare interrupt service routine { switch(state){ case States::ZERO_START: - if (bedPWMDisabled) return; + if (bedPWMDisabled) return; // stay in the OFF state and do not change the output pin pwm = soft_pwm_bed << 1;// expecting soft_pwm_bed to be 7bit! if( pwm != 0 ){ state = States::ZERO; // do nothing, let it tick once again after the 30Hz period @@ -139,7 +145,7 @@ ISR(TIMER0_OVF_vect) // timer compare interrupt service routine break; case States::ONE: // state ONE - we'll either stay in ONE or change to FALL OCR0B = 255; - if (bedPWMDisabled) return; + if (bedPWMDisabled) return; // stay in the ON state and do not change the output pin slowCounter += slowInc; // this does software timer_clk/256 or less if( slowCounter < pwm ){ return; From 8c2902a6605cacbc35232b3f6f1c49f9ca12a20f Mon Sep 17 00:00:00 2001 From: leptun Date: Wed, 2 Oct 2019 17:34:09 +0300 Subject: [PATCH 151/180] Revert "Mesh bed leveling testing" This reverts commit 28e812d91fe2b4633c9427abdf554e5a9449dd17. --- Firmware/Marlin_main.cpp | 10 +++++++--- Firmware/mesh_bed_calibration.cpp | 8 ++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index e14dd2e35..fbfb39f25 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -4973,7 +4973,11 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) z_offset_u = eeprom_read_word((uint16_t*)(EEPROM_BED_CALIBRATION_Z_JITTER + 2 * (ix + iy * 3 - 1))); } z0 = mbl.z_values[0][0] + *reinterpret_cast(&z_offset_u) * 0.01; - // printf_P(PSTR("Bed leveling, point: %d, calibration Z stored in eeprom: %d, calibration z: %f \n"), mesh_point, z_offset_u, z0); + #ifdef SUPPORT_VERBOSITY + if (verbosity_level >= 1) { + printf_P(PSTR("Bed leveling, point: %d, calibration Z stored in eeprom: %d, calibration z: %f \n"), mesh_point, z_offset_u, z0); + } + #endif // SUPPORT_VERBOSITY } // Move Z up to MESH_HOME_Z_SEARCH. @@ -5000,7 +5004,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]); #endif // SUPPORT_VERBOSITY - printf_P(PSTR("after clamping: [%f;%f]\n"), current_position[X_AXIS], current_position[Y_AXIS]); + //printf_P(PSTR("after clamping: [%f;%f]\n"), current_position[X_AXIS], current_position[Y_AXIS]); plan_buffer_line_curposXYZE(XY_AXIS_FEEDRATE, active_extruder); st_synchronize(); @@ -5011,7 +5015,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; } if (init_z_bckp - current_position[Z_AXIS] < 0.1f) { //broken cable or initial Z coordinate too low. Go to MESH_HOME_Z_SEARCH and repeat last step (z-probe) again to distinguish between these two cases. - printf_P(PSTR("Another attempt! Current Z position: %f\n"), current_position[Z_AXIS]); + //printf_P(PSTR("Another attempt! Current Z position: %f\n"), current_position[Z_AXIS]); current_position[Z_AXIS] = MESH_HOME_Z_SEARCH; plan_buffer_line_curposXYZE(Z_LIFT_FEEDRATE, active_extruder); st_synchronize(); diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index fed100e68..88cbc671a 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -991,7 +991,7 @@ inline bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, i update_current_position_z(); //printf_P(PSTR("Zs: %f, Z: %f, delta Z: %f"), z_bckp, current_position[Z_AXIS], (z_bckp - current_position[Z_AXIS])); if (abs(current_position[Z_AXIS] - z_bckp) < 0.025) { - printf_P(PSTR("PINDA triggered immediately, move Z higher and repeat measurement\n")); + //printf_P(PSTR("PINDA triggered immediately, move Z higher and repeat measurement\n")); current_position[Z_AXIS] += 0.5; go_to_current(homing_feedrate[Z_AXIS]/60); current_position[Z_AXIS] = minimum_z; @@ -1019,10 +1019,10 @@ inline bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, i float dz = i?abs(current_position[Z_AXIS] - (z / i)):0; z += current_position[Z_AXIS]; //printf_P(PSTR("Z[%d] = %d, dz=%d\n"), i, (int)(current_position[Z_AXIS] * 1000), (int)(dz * 1000)); - printf_P(PSTR("Z- measurement deviation from avg value %f um\n"), dz); + //printf_P(PSTR("Z- measurement deviation from avg value %f um\n"), dz); if (dz > 0.05) { //deviation > 50um if (high_deviation_occured == false) { //first occurence may be caused in some cases by mechanic resonance probably especially if printer is placed on unstable surface - printf_P(PSTR("high dev. first occurence\n")); + //printf_P(PSTR("high dev. first occurence\n")); delay_keep_alive(500); //damping //start measurement from the begining, but this time with higher movements in Z axis which should help to reduce mechanical resonance high_deviation_occured = true; @@ -1033,7 +1033,7 @@ inline bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, i goto error; } } - printf_P(PSTR("PINDA triggered at %f\n"), current_position[Z_AXIS]); + //printf_P(PSTR("PINDA triggered at %f\n"), current_position[Z_AXIS]); } current_position[Z_AXIS] = z; if (n_iter > 1) From 571906a494ac07d3450854b15b3068ecc5eb0655 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 28 Jan 2020 21:55:16 +0100 Subject: [PATCH 152/180] Do not update saved_target if there's no current_block There is a chance that current_block can be NULL despite the queue being non-empty. This can happen early after a block has been queued, but before the isr has picked it up for processing, and/or when the current block is at the last step and is being discarded. Check for current_block directly to avoid this race. --- Firmware/Marlin_main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 20a269af5..9d00d42bd 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -10529,7 +10529,7 @@ void uvlo_() // save the global state at planning time uint16_t feedrate_bckp; - if (blocks_queued()) + if (current_block) { memcpy(saved_target, current_block->gcode_target, sizeof(saved_target)); feedrate_bckp = current_block->gcode_feedrate; @@ -11129,7 +11129,7 @@ void stop_and_save_print_to_ram(float z_move, float e_move) #endif // save the global state at planning time - if (blocks_queued()) + if (current_block) { memcpy(saved_target, current_block->gcode_target, sizeof(saved_target)); saved_feedrate2 = current_block->gcode_feedrate; From 1db024f17af6ed22f7836ebb553f6b7fe5215227 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 28 Jan 2020 22:03:38 +0100 Subject: [PATCH 153/180] Always raise the extruder 25mm during power recovery Avoids oozed material (drooping more than ~1mm) to scrape and potentially detach the print. --- Firmware/Marlin_main.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 9d00d42bd..abd4c3685 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -10798,10 +10798,13 @@ void recover_print(uint8_t automatic) { // Recover position, temperatures and extrude_multipliers bool mbl_was_active = recover_machine_state_after_power_panic(); - // Attempt to lift the print head on the first recovery, so one may remove the excess priming material. - bool raise_z = (eeprom_read_byte((uint8_t*)EEPROM_UVLO) == 1); - if(raise_z && (current_position[Z_AXIS]<25)) - enquecommand_P(PSTR("G1 Z25 F800")); + // Lift the print head 25mm, first to avoid collisions with oozed material with the print, + // and second also so one may remove the excess priming material. + if(eeprom_read_byte((uint8_t*)EEPROM_UVLO) == 1) + { + sprintf_P(cmd, PSTR("G1 Z%.3f F800"), current_position[Z_AXIS] + 25); + enquecommand(cmd); + } // Home X and Y axes. Homing just X and Y shall not touch the babystep and the world2machine // transformation status. G28 will not touch Z when MBL is off. From 886c2fdc4ebf18c9ca175068525fa4218c5637e4 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Thu, 30 Jan 2020 17:24:32 +0200 Subject: [PATCH 154/180] Show correct fixed message --- Firmware/temperature.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index 175122548..7517978be 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -2003,6 +2003,8 @@ void check_max_temp() //! number of repeating the same state with consecutive step() calls //! used to slow down text switching struct alert_automaton_mintemp { + const char *m2; + alert_automaton_mintemp(const char *m2):m2(m2){} private: enum { ALERT_AUTOMATON_SPEED_DIV = 5 }; enum class States : uint8_t { Init = 0, TempAboveMintemp, ShowPleaseRestart, ShowMintemp }; @@ -2022,7 +2024,6 @@ public: //! @param current_temp current hotend/bed temperature (for computing simple hysteresis) //! @param mintemp minimal temperature including hysteresis to check current_temp against void step(float current_temp, float mintemp){ - static const char m2[] PROGMEM = "MINTEMP fixed"; static const char m1[] PROGMEM = "Please restart"; switch(state){ case States::Init: // initial state - check hysteresis @@ -2050,8 +2051,9 @@ public: } } }; - -static alert_automaton_mintemp alert_automaton_hotend, alert_automaton_bed; +static const char m2hotend[] PROGMEM = "MINTEMP HEATER fixed"; +static const char m2bed[] PROGMEM = "MINTEMP BED fixed"; +static alert_automaton_mintemp alert_automaton_hotend(m2hotend), alert_automaton_bed(m2bed); void check_min_temp_heater0() { From 84ecf96be50a3af450bff5d506962ef0a0158f57 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Fri, 31 Jan 2020 15:08:24 +0100 Subject: [PATCH 155/180] Do not clear last print fail stats prematurely M24 was always cleaning the last print failstats. But because M24 is used to restore a print after power failure (by setting the seek offset), it would also reset the stats incorrectly after resuming. Check for the file index position and reset the stats only when a print is started from the beginning of the file. Apply the same logic to M32 and similarly handle the LA10->15 conversion (do not re-apply the adjustment for a resumed print). --- Firmware/Marlin_main.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index cd4ee63f4..62f93fae5 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -5576,10 +5576,15 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) lcd_resume_print(); else { - failstats_reset_print(); + if (!card.get_sdpos()) + { + // A new print has started from scratch, reset stats + failstats_reset_print(); #ifndef LA_NOCOMPAT - la10c_reset(); + la10c_reset(); #endif + } + card.startFileprint(); starttime=_millis(); } @@ -5689,12 +5694,19 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) if(code_seen('S')) if(strchr_pointer Date: Fri, 31 Jan 2020 15:27:19 +0100 Subject: [PATCH 156/180] Fix copy paste issues D2 D5 Fixed copy paste --- Firmware/Dcodes.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/Dcodes.cpp b/Firmware/Dcodes.cpp index 0a5142629..ee62087d6 100644 --- a/Firmware/Dcodes.cpp +++ b/Firmware/Dcodes.cpp @@ -255,7 +255,7 @@ void dcode_1() ### D2 - Read/Write RAM D3: Read/Write RAM This command can be used without any additional parameters. It will read the entire RAM. - D3 [ A | C | X ] + D2 [ A | C | X ] - `A` - Address (0x0000-0x1fff) - `C` - Count (0x0001-0x2000) @@ -355,7 +355,7 @@ void dcode_4() ### D5 - Read/Write FLASH D5: Read/Write Flash This command can be used without any additional parameters. It will read the 1kb FLASH. - D3 [ A | C | X | E ] + D5 [ A | C | X | E ] - `A` - Address (0x00000-0x3ffff) - `C` - Count (0x0001-0x2000) From a355fdd00d8a3287144d09056c45df94b5043b72 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Fri, 31 Jan 2020 15:40:07 +0100 Subject: [PATCH 157/180] And another one sorry --- Firmware/Dcodes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Dcodes.cpp b/Firmware/Dcodes.cpp index ee62087d6..70ffe2c49 100644 --- a/Firmware/Dcodes.cpp +++ b/Firmware/Dcodes.cpp @@ -252,7 +252,7 @@ void dcode_1() /*! * - ### D2 - Read/Write RAM D3: Read/Write RAM + ### D2 - Read/Write RAM D2: Read/Write RAM This command can be used without any additional parameters. It will read the entire RAM. D2 [ A | C | X ] From 3bbc14382103e711f6b5b304e7522f25aeb85f28 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 2 Feb 2020 18:01:06 +0100 Subject: [PATCH 158/180] Fix build with LA_LIVE_K Do not check for LA_LIVE_K in messages.c (Configuration_adv.h is not included here). Rely on the linker to drop the symbol when LA_LIVE_K is disabled. --- Firmware/messages.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/Firmware/messages.c b/Firmware/messages.c index 2b113673e..4e229ba76 100644 --- a/Firmware/messages.c +++ b/Firmware/messages.c @@ -168,7 +168,5 @@ const char MSG_OCTOPRINT_CANCEL[] PROGMEM_N1 = "// action:cancel"; //// const char MSG_FANCHECK_EXTRUDER[] PROGMEM_N1 = "Err: EXTR. FAN ERROR"; ////c=20 const char MSG_FANCHECK_PRINT[] PROGMEM_N1 = "Err: PRINT FAN ERROR"; ////c=20 const char MSG_M112_KILL[] PROGMEM_N1 = "M112 called. Emergency Stop."; ////c=20 -#ifdef LA_LIVE_K const char MSG_ADVANCE_K[] PROGMEM_N1 = "Advance K:"; ////c=13 -#endif const char MSG_POWERPANIC_DETECTED[] PROGMEM_N1 = "POWER PANIC DETECTED"; ////c=20 From 47db75d5fda29dabf2f6b8749c3180677fb99ca5 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 2 Feb 2020 18:02:57 +0100 Subject: [PATCH 159/180] Fix overflow and infloop with LA15 and low step rates When calculating the advance tick interval, be sure to check for integer overflow. Very low step rates can result in values exceeding uint16_t causing premature LA tick delivery. An overflow resulting in zero would also block in an infinite loop within advance_spread(). Even though such rates are worthless in terms of compensation and often result in 0 extra ticks as well, do not disable LA for the block (as doing so would reset the count for short segments) and do not check for zero in multiple paces either. Saturate the interval instead, delaying any further tick to the next block. --- Firmware/planner.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index 197b3d9f9..57d7b89bb 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -1137,17 +1137,24 @@ Having the real displacement of the head, we can calculate the total movement le // still need to replicate the *exact* same step grouping policy (see below) float advance_speed = (extruder_advance_K * e_D_ratio * block->acceleration * cs.axis_steps_per_unit[E_AXIS]); if (advance_speed > MAX_STEP_FREQUENCY) advance_speed = MAX_STEP_FREQUENCY; - block->advance_rate = (F_CPU / 8.0) / advance_speed; - if (block->advance_rate > 20000) { - block->advance_rate = (block->advance_rate >> 2)&0x3fff; + float advance_rate = (F_CPU / 8.0) / advance_speed; + if (advance_speed > 20000) { + block->advance_rate = advance_rate * 4; block->advance_step_loops = 4; } - else if (block->advance_rate > 10000) { - block->advance_rate = (block->advance_rate >> 1)&0x7fff; + else if (advance_speed > 10000) { + block->advance_rate = advance_rate * 2; block->advance_step_loops = 2; } else + { + // never overflow the internal accumulator with very low rates + if (advance_rate < UINT16_MAX) + block->advance_rate = advance_rate; + else + block->advance_rate = UINT16_MAX; block->advance_step_loops = 1; + } #ifdef LA_DEBUG if (block->advance_step_loops > 2) From 4b85664b27abacbfe89ada22c2b54b0bd1abd526 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Mon, 3 Feb 2020 14:28:54 +0100 Subject: [PATCH 160/180] Raise default extruder jerk to 4.5 This should be the new default for LA1.5 for direct drive printers and newer PrusaSlicer profiles too (hopefully). --- Firmware/Configuration.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Configuration.h b/Firmware/Configuration.h index 2f2ea7d8e..694247fbd 100644 --- a/Firmware/Configuration.h +++ b/Firmware/Configuration.h @@ -424,7 +424,7 @@ your extruder heater takes 2 minutes to hit the target on heating. #define DEFAULT_XJERK 10 // (mm/sec) #define DEFAULT_YJERK 10 // (mm/sec) #define DEFAULT_ZJERK 0.4 // (mm/sec) -#define DEFAULT_EJERK 2.5 // (mm/sec) +#define DEFAULT_EJERK 4.5 // (mm/sec) //=========================================================================== //=============================Additional Features=========================== From 453f5dd8744383c2d1481228db91099037b103fe Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Mon, 3 Feb 2020 15:37:11 +0100 Subject: [PATCH 161/180] Adjust E-jerk in LA10 compatibility mode When upgrading K values of a LA1.0 print, also adjust E-jerk settings (<2) if permissible according to current accell limits. The same is also true when jerk is set mid-print via 'M205 E'. Existing values are always restored when switching to another compatibility mode. TODO: Since this is stateful, we will need to save the current print mode / acceleration and jerk in the eeprom for this to survive a power panic (see prusa3d#2456). --- Firmware/Marlin_main.cpp | 14 +++++++++++--- Firmware/la10compat.cpp | 42 +++++++++++++++++++++++++++++++++++++++- Firmware/la10compat.h | 9 ++++++++- 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index cd4ee63f4..92f3bd307 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -7075,9 +7075,17 @@ Sigma_Exit: if(code_seen('X')) cs.max_jerk[X_AXIS] = cs.max_jerk[Y_AXIS] = code_value(); if(code_seen('Y')) cs.max_jerk[Y_AXIS] = code_value(); if(code_seen('Z')) cs.max_jerk[Z_AXIS] = code_value(); - if(code_seen('E')) cs.max_jerk[E_AXIS] = code_value(); - if (cs.max_jerk[X_AXIS] > DEFAULT_XJERK) cs.max_jerk[X_AXIS] = DEFAULT_XJERK; - if (cs.max_jerk[Y_AXIS] > DEFAULT_YJERK) cs.max_jerk[Y_AXIS] = DEFAULT_YJERK; + if(code_seen('E')) + { + float e = code_value(); +#ifndef LA_NOCOMPAT + + e = la10c_jerk(e); +#endif + cs.max_jerk[E_AXIS] = e; + } + if (cs.max_jerk[X_AXIS] > DEFAULT_XJERK) cs.max_jerk[X_AXIS] = DEFAULT_XJERK; + if (cs.max_jerk[Y_AXIS] > DEFAULT_YJERK) cs.max_jerk[Y_AXIS] = DEFAULT_YJERK; } break; diff --git a/Firmware/la10compat.cpp b/Firmware/la10compat.cpp index d54e5acea..5b851bc34 100644 --- a/Firmware/la10compat.cpp +++ b/Firmware/la10compat.cpp @@ -2,13 +2,24 @@ #include "Marlin.h" -static LA10C_MODE la10c_mode = LA10C_UNKNOWN; +static LA10C_MODE la10c_mode = LA10C_UNKNOWN; // Current LA compatibility mode +static float la10c_orig_jerk = 0; // Unadjusted/saved e-jerk + + +LA10C_MODE la10c_mode_get() +{ + return la10c_mode; +} void la10c_mode_change(LA10C_MODE mode) { if(mode == la10c_mode) return; + // always restore to the last unadjusted E-jerk value + if(la10c_orig_jerk) + cs.max_jerk[E_AXIS] = la10c_orig_jerk; + SERIAL_ECHOPGM("LA10C: Linear Advance mode: "); switch(mode) { @@ -17,6 +28,9 @@ void la10c_mode_change(LA10C_MODE mode) case LA10C_LA10: SERIAL_ECHOLNPGM("1.0"); break; } la10c_mode = mode; + + // adjust the E-jerk if needed + cs.max_jerk[E_AXIS] = la10c_jerk(cs.max_jerk[E_AXIS]); } @@ -46,3 +60,29 @@ float la10c_value(float k) else return (k >= 0? la10c_convert(k): -1); } + + +float la10c_jerk(float j) +{ + la10c_orig_jerk = j; + + if(la10c_mode != LA10C_LA10) + return j; + + // check for a compatible range of values prior to convert (be sure that + // a higher E-jerk would still be compatible wrt the E accell range) + if(j < 4.5 && cs.max_acceleration_units_per_sq_second_normal[E_AXIS] < 2000) + return j; + + // bring low E-jerk values into equivalent LA 1.5 values by + // flattening the response in the (1-4.5) range using a piecewise + // function. Is it truly worth to preserve the difference between + // 1.5/2.5 E-jerk for LA1.0? Probably not, but we try nonetheless. + j = j < 1.0? j * 3.625: + j < 4.5? j * 0.25 + 3.375: + j; + + SERIAL_ECHOPGM("LA10C: Adjusted E-Jerk: "); + SERIAL_ECHOLN(j); + return j; +} diff --git a/Firmware/la10compat.h b/Firmware/la10compat.h index e6ffbc37b..5116eb278 100644 --- a/Firmware/la10compat.h +++ b/Firmware/la10compat.h @@ -5,6 +5,9 @@ // compatbility mode is active the K factor is converted to a LA15 // equivalent (that is, the return value is always a LA15 value). // +// E-jerk<2 is also bumped in LA10 mode to restore the the printing speed +// to values comparable to existing settings. +// // Once the interpretation mode has been set it is kept until the mode // is explicitly reset. This is done to handle transparent fallback for // old firmware revisions in combination with the following gcode @@ -31,9 +34,13 @@ enum __attribute__((packed)) LA10C_MODE LA10C_LA10 = 2 }; -// Explicitly set/reset the interpretation mode for la10c_value() +// Explicitly set/get/reset the interpretation mode for la10c_value() void la10c_mode_change(LA10C_MODE mode); +LA10C_MODE la10c_mode_get(); static inline void la10c_reset() { la10c_mode_change(LA10C_UNKNOWN); } // Return a LA15 K value according to the supplied value and mode float la10c_value(float k); + +// Return an updated LA15 E-jerk value according to the current mode +float la10c_jerk(float j); From 1f482adf557160f2417bb4e6235f460767740b07 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Mon, 3 Feb 2020 18:40:46 +0200 Subject: [PATCH 162/180] Improved lcd_menu_statistics() implementation --- Firmware/ultralcd.cpp | 50 ++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 38471b814..42848b781 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -2794,9 +2794,9 @@ static void lcd_LoadFilament() //! //! @code{.unparsed} //! |01234567890123456789| -//! |Filament used: | c=18 r=1 -//! | 00.00m | -//! |Print time: | c=18 r=1 +//! |Filament used: | c=19 r=1 +//! | 0000.00m | +//! |Print time: | c=19 r=1 //! | 00h 00m 00s | //! ---------------------- //! @endcode @@ -2805,29 +2805,30 @@ static void lcd_LoadFilament() //! //! @code{.unparsed} //! |01234567890123456789| -//! |Total filament : | c=18 r=1 -//! | 000.00 m | -//! |Total print time : | c=18 r=1 -//! | 00d :00h :00 m | +//! |Total filament: | c=19 r=1 +//! | 0000.00m | +//! |Total print time: | c=19 r=1 +//! | 00d 00h 00m | //! ---------------------- //! @endcode //! @todo Positioning of the messages and values on LCD aren't fixed to their exact place. This causes issues with translations. Translations missing for "d"days, "h"ours, "m"inutes", "s"seconds". void lcd_menu_statistics() { + lcd_timeoutToStatus.stop(); //infinite timeout if (IS_SD_PRINTING) { const float _met = ((float)total_filament_used) / (100000.f); const uint32_t _t = (_millis() - starttime) / 1000ul; - const int _h = _t / 3600; - const int _m = (_t - (_h * 3600ul)) / 60ul; - const int _s = _t - ((_h * 3600ul) + (_m * 60ul)); + const uint32_t _h = _t / 3600; + const uint8_t _m = (_t - (_h * 3600ul)) / 60ul; + const uint8_t _s = _t - ((_h * 3600ul) + (_m * 60ul)); - lcd_clear(); + lcd_home(); lcd_printf_P(_N( "%S:\n" - "%17.2fm \n" + "%18.2fm \n" "%S:\n" - "%2dh %02dm %02ds" + "%10ldh %02hhdm %02hhds" ), _i("Filament used"), _met, ////c=18 r=1 _i("Print time"), _h, _m, _s); ////c=18 r=1 @@ -2840,29 +2841,20 @@ void lcd_menu_statistics() uint8_t _hours, _minutes; uint32_t _days; float _filament_m = (float)_filament/100; -// int _filament_km = (_filament >= 100000) ? _filament / 100000 : 0; -// if (_filament_km > 0) _filament_m = _filament - (_filament_km * 100000); _days = _time / 1440; _hours = (_time - (_days * 1440)) / 60; _minutes = _time - ((_days * 1440) + (_hours * 60)); - lcd_clear(); + lcd_home(); lcd_printf_P(_N( "%S:\n" - "%17.2fm \n" + "%18.2fm \n" "%S:\n" - "%7ldd :%2hhdh :%02hhdm" - ), _i("Total filament"), _filament_m, _i("Total print time"), _days, _hours, _minutes); - KEEPALIVE_STATE(PAUSED_FOR_USER); - while (!lcd_clicked()) - { - manage_heater(); - manage_inactivity(true); - _delay(100); - } - KEEPALIVE_STATE(NOT_BUSY); - lcd_quick_feedback(); - menu_back(); + "%10ldd %02hhdh %02hhdm" + ), + _i("Total filament"), _filament_m, + _i("Total print time"), _days, _hours, _minutes); + menu_back_if_clicked_fb(); } } From 3ae5fa70cabc3f96c5093a07374458756977317f Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Mon, 3 Feb 2020 19:20:43 +0200 Subject: [PATCH 163/180] Fix comments --- Firmware/ultralcd.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 42848b781..cefd9b8c5 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -2830,8 +2830,8 @@ void lcd_menu_statistics() "%S:\n" "%10ldh %02hhdm %02hhds" ), - _i("Filament used"), _met, ////c=18 r=1 - _i("Print time"), _h, _m, _s); ////c=18 r=1 + _i("Filament used"), _met, ////c=19 r=1 + _i("Print time"), _h, _m, _s); ////c=19 r=1 menu_back_if_clicked_fb(); } else @@ -2852,8 +2852,8 @@ void lcd_menu_statistics() "%S:\n" "%10ldd %02hhdh %02hhdm" ), - _i("Total filament"), _filament_m, - _i("Total print time"), _days, _hours, _minutes); + _i("Total filament"), _filament_m, ////c=19 r=1 + _i("Total print time"), _days, _hours, _minutes); ////c=19 r=1 menu_back_if_clicked_fb(); } } From f23dd6bed4c1c5e6b1617723a0971dea1cfbb189 Mon Sep 17 00:00:00 2001 From: 3d-gussner <3d.gussner@gmail.com> Date: Tue, 4 Feb 2020 10:16:44 +0100 Subject: [PATCH 164/180] Hard reset to prusa3d/mk3 and added changes --- build.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index 907b1e037..d44a4d890 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,5 @@ #!/bin/bash -BUILD_ENV="1.0.6" +BUILD_ENV="1.0.6.1" SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )" if [ ! -d "build-env" ]; then @@ -8,7 +8,8 @@ fi cd build-env || exit 2 if [ ! -f "PF-build-env-Linux64-$BUILD_ENV.zip" ]; then - wget https://github.com/mkbel/PF-build-env/releases/download/$BUILD_ENV/PF-build-env-Linux64-$BUILD_ENV.zip || exit 3 + #wget https://github.com/3d-gussner/PF-build-env-1/releases/download/$BUILD_ENV-Linux64/PF-build-env-Linux64-$BUILD_ENV.zip || exit 3 + wget https://github.com/prusa3d/PF-build-env/releases/download/$BUILD_ENV-Linux64/PF-build-env-Linux64-$BUILD_ENV.zip || exit 3 fi if [ ! -d "../../PF-build-env-$BUILD_ENV" ]; then From f1ccfd481ac8f6c5a0bae3779ff73df060bc1c92 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Tue, 4 Feb 2020 17:30:44 +0200 Subject: [PATCH 165/180] HEATER -> HOTEND --- Firmware/temperature.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index 7517978be..54a782b01 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -2051,7 +2051,7 @@ public: } } }; -static const char m2hotend[] PROGMEM = "MINTEMP HEATER fixed"; +static const char m2hotend[] PROGMEM = "MINTEMP HOTEND fixed"; static const char m2bed[] PROGMEM = "MINTEMP BED fixed"; static alert_automaton_mintemp alert_automaton_hotend(m2hotend), alert_automaton_bed(m2bed); From e8ce5e140e98bb3de1b690bb6aed014a276acd41 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sat, 1 Jun 2019 22:06:55 +0200 Subject: [PATCH 166/180] FS: Detect runout earlier --- Firmware/fsensor.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index fce8f6fed..f4cb647a9 100755 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -19,7 +19,7 @@ //! @name Basic parameters //! @{ #define FSENSOR_CHUNK_LEN 0.64F //!< filament sensor chunk length 0.64mm -#define FSENSOR_ERR_MAX 17 //!< filament sensor maximum error count for runout detection +#define FSENSOR_ERR_MAX 9 //!< filament sensor maximum error count for runout detection //! @} //! @name Optical quality measurement parameters @@ -453,10 +453,7 @@ ISR(FSENSOR_INT_PIN_VECT) { if (pat9125_y < 0) { - if (fsensor_err_cnt) - fsensor_err_cnt += 2; - else - fsensor_err_cnt++; + fsensor_err_cnt++; } else if (pat9125_y > 0) { From 8fb8ff4bf43eb371217ba9b80b4ea64cf8f7cee0 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 2 Jun 2019 18:00:31 +0200 Subject: [PATCH 167/180] Include fsensor recovery stats in the last print stats --- Firmware/Marlin_main.cpp | 1 + Firmware/fsensor.cpp | 5 +++++ Firmware/fsensor.h | 1 + Firmware/ultralcd.cpp | 13 ++++++++----- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 43e3081fe..0a1e5439b 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -634,6 +634,7 @@ void crashdet_cancel() void failstats_reset_print() { + fsensor_softfail = 0; eeprom_update_byte((uint8_t *)EEPROM_CRASH_COUNT_X, 0); eeprom_update_byte((uint8_t *)EEPROM_CRASH_COUNT_Y, 0); eeprom_update_byte((uint8_t *)EEPROM_FERROR_COUNT, 0); diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index f4cb647a9..19c8b1f81 100755 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -83,6 +83,8 @@ uint8_t fsensor_autoload_c; uint32_t fsensor_autoload_last_millis; // uint8_t fsensor_autoload_sum; +// +uint8_t fsensor_softfail = 0; //! @} @@ -598,7 +600,10 @@ void fsensor_update(void) fsensor_oq_meassure_enabled = oq_meassure_enabled_tmp; if (!err) + { printf_P(PSTR("fsensor_err_cnt = 0\n")); + ++fsensor_softfail; + } else fsensor_enque_M600(); } diff --git a/Firmware/fsensor.h b/Firmware/fsensor.h index 5ed7f7fc8..fba131db3 100755 --- a/Firmware/fsensor.h +++ b/Firmware/fsensor.h @@ -14,6 +14,7 @@ extern bool fsensor_enabled; extern bool fsensor_not_responding; //enable/disable quality meassurement extern bool fsensor_oq_meassure_enabled; +extern uint8_t fsensor_softfail; //! @name save restore printing diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index cefd9b8c5..0461ff803 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -1796,11 +1796,14 @@ static void lcd_menu_fails_stats_print() uint8_t crashX = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_X); uint8_t crashY = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_Y); lcd_home(); - lcd_printf_P(failStatsFmt, - _i("Last print failures"), ////c=20 r=1 - _i("Power failures"), power, ////c=14 r=1 - _i("Filam. runouts"), filam, ////c=14 r=1 - _i("Crash"), crashX, crashY); ////c=7 r=1 + lcd_printf_P(PSTR("%S\n" + " %S %-3d\n" + " %S H %-3d S %-3d\n" + " %S X %-3d Y %-3d"), + _i("Last print failures"), + _i("Power failures"), power, + _i("Runouts"), filam, fsensor_softfail, + _i("Crash"), crashX, crashY); menu_back_if_clicked_fb(); } From ce74b746f14cf8ea54be925b154838cf0cb0de47 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Mon, 3 Jun 2019 17:31:19 +0200 Subject: [PATCH 168/180] FS: Trigger a runout with repeated soft-failures (clog?) --- Firmware/fsensor.cpp | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index 19c8b1f81..7daea8dac 100755 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -20,6 +20,9 @@ //! @{ #define FSENSOR_CHUNK_LEN 0.64F //!< filament sensor chunk length 0.64mm #define FSENSOR_ERR_MAX 9 //!< filament sensor maximum error count for runout detection + +#define FSENSOR_SOFTERR_CMAX 3 //!< number of contiguous soft failures before a triggering a runout +#define FSENSOR_SOFTERR_DELTA 30000 //!< maximum interval (ms) to consider soft failures contiguous //! @} //! @name Optical quality measurement parameters @@ -85,6 +88,8 @@ uint32_t fsensor_autoload_last_millis; uint8_t fsensor_autoload_sum; // uint8_t fsensor_softfail = 0; +uint8_t fsensor_softfail_ccnt = 0; +unsigned long fsensor_softfail_last = 0; //! @} @@ -596,16 +601,25 @@ void fsensor_update(void) err |= (fsensor_oq_yd_sum < (4 * FSENSOR_OQ_MIN_YD)); fsensor_restore_print_and_continue(); - fsensor_autoload_enabled = autoload_enabled_tmp; - fsensor_oq_meassure_enabled = oq_meassure_enabled_tmp; + fsensor_autoload_enabled = autoload_enabled_tmp; + fsensor_oq_meassure_enabled = oq_meassure_enabled_tmp; - if (!err) + unsigned long now = _millis(); + if (!err && (now - fsensor_softfail_last) > FSENSOR_SOFTERR_DELTA) + fsensor_softfail_ccnt = 0; + if (!err && fsensor_softfail_ccnt <= FSENSOR_SOFTERR_CMAX) { - printf_P(PSTR("fsensor_err_cnt = 0\n")); + printf_P(PSTR("fsensor_err_cnt = 0\n")); ++fsensor_softfail; - } - else - fsensor_enque_M600(); + ++fsensor_softfail_ccnt; + fsensor_softfail_last = now; + } + else + { + fsensor_softfail_ccnt = 0; + fsensor_softfail_last = 0; + fsensor_enque_M600(); + } } #else //PAT9125 if (CHECK_FSENSOR && ir_sensor_detected) From d47363d85a5a813e86af8458bacc0f4970904615 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 5 Feb 2020 14:23:41 +0100 Subject: [PATCH 169/180] Update the filament axis resolution when E resolution is changed The filament sensor "chunk lenght" needs to be updated every time the E axis resolution is changed in order to trigger at the same distance. Introduce a new function fsensor_set_axis_steps_per_unit() and use it consistent during init, in M92 and M350. --- Firmware/Marlin_main.cpp | 6 ++++-- Firmware/fsensor.cpp | 7 ++++++- Firmware/fsensor.h | 3 +++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 0a1e5439b..047b7082b 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -6673,7 +6673,7 @@ Sigma_Exit: { if(code_seen(axis_codes[i])) { - if(i == 3) { // E + if(i == E_AXIS) { // E float value = code_value(); if(value < 20.0) { float factor = cs.axis_steps_per_unit[i] / value; // increase e constants if M92 E14 is given for netfab. @@ -6682,6 +6682,7 @@ Sigma_Exit: axis_steps_per_sqr_second[i] *= factor; } cs.axis_steps_per_unit[i] = value; + fsensor_set_axis_steps_per_unit(value); } else { cs.axis_steps_per_unit[i] = code_value(); @@ -8429,7 +8430,6 @@ Sigma_Exit: res_valid |= (i == E_AXIS) && ((res_new == 64) || (res_new == 128)); // resolutions valid for E only if (res_valid) { - st_synchronize(); uint16_t res = tmc2130_get_res(i); tmc2130_set_res(i, res_new); @@ -8446,6 +8446,8 @@ Sigma_Exit: cs.axis_steps_per_unit[i] /= fac; position[i] /= fac; } + if (i == E_AXIS) + fsensor_set_axis_steps_per_unit(cs.axis_steps_per_unit[i]); } } } diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index 7daea8dac..297460d61 100755 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -149,6 +149,11 @@ void fsensor_checkpoint_print(void) restore_print_from_ram_and_continue(0); } +void fsensor_set_axis_steps_per_unit(float u) +{ + fsensor_chunk_len = (int16_t)(FSENSOR_CHUNK_LEN * u); +} + void fsensor_init(void) { #ifdef PAT9125 @@ -161,7 +166,7 @@ void fsensor_init(void) #ifdef PAT9125 uint8_t oq_meassure_enabled = eeprom_read_byte((uint8_t*)EEPROM_FSENS_OQ_MEASS_ENABLED); fsensor_oq_meassure_enabled = (oq_meassure_enabled == 1)?true:false; - fsensor_chunk_len = (int16_t)(FSENSOR_CHUNK_LEN * cs.axis_steps_per_unit[E_AXIS]); + fsensor_set_axis_steps_per_unit(cs.axis_steps_per_unit[E_AXIS]); if (!pat9125) { diff --git a/Firmware/fsensor.h b/Firmware/fsensor.h index fba131db3..0c791d412 100755 --- a/Firmware/fsensor.h +++ b/Firmware/fsensor.h @@ -29,6 +29,9 @@ extern void fsensor_checkpoint_print(void); //! initialize extern void fsensor_init(void); +//! update axis resolution +extern void fsensor_set_axis_steps_per_unit(float u); + //! @name enable/disable //! @{ extern bool fsensor_enable(bool bUpdateEEPROM=true); From 6fbd632c844c527bb0812e36bc03318097d54087 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 5 Feb 2020 15:17:19 +0100 Subject: [PATCH 170/180] Isolate all PAT9125-specific code, fix build on !MK3 variants - Hide all prototypes related to PAT9125 to force all callers to check for the proper sensor, since the handling differences are substantial - Remove unneeded lenght accounting from the stepper isr as as consequence. - Keep detailed soft failure counts for the MK3 on the "last print failures" status screen, but fix build on variants without a PAT9125 by fixing the lcd stats function. --- Firmware/Marlin_main.cpp | 8 +++++++- Firmware/fsensor.cpp | 32 ++++++++++++++++++++------------ Firmware/fsensor.h | 15 ++++++++++----- Firmware/stepper.cpp | 14 +++++++------- Firmware/ultralcd.cpp | 25 ++++++++++++++++++------- 5 files changed, 62 insertions(+), 32 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 047b7082b..1dcb89389 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -634,13 +634,15 @@ void crashdet_cancel() void failstats_reset_print() { - fsensor_softfail = 0; eeprom_update_byte((uint8_t *)EEPROM_CRASH_COUNT_X, 0); eeprom_update_byte((uint8_t *)EEPROM_CRASH_COUNT_Y, 0); eeprom_update_byte((uint8_t *)EEPROM_FERROR_COUNT, 0); eeprom_update_byte((uint8_t *)EEPROM_POWER_COUNT, 0); eeprom_update_byte((uint8_t *)EEPROM_MMU_FAIL, 0); eeprom_update_byte((uint8_t *)EEPROM_MMU_LOAD_FAIL, 0); +#if defined(FILAMENT_SENSOR) && defined(PAT9125) + fsensor_softfail = 0; +#endif } @@ -6682,7 +6684,9 @@ Sigma_Exit: axis_steps_per_sqr_second[i] *= factor; } cs.axis_steps_per_unit[i] = value; +#if defined(FILAMENT_SENSOR) && defined(PAT9125) fsensor_set_axis_steps_per_unit(value); +#endif } else { cs.axis_steps_per_unit[i] = code_value(); @@ -8446,8 +8450,10 @@ Sigma_Exit: cs.axis_steps_per_unit[i] /= fac; position[i] /= fac; } +#if defined(FILAMENT_SENSOR) && defined(PAT9125) if (i == E_AXIS) fsensor_set_axis_steps_per_unit(cs.axis_steps_per_unit[i]); +#endif } } } diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index 297460d61..c1f9f27b0 100755 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -47,25 +47,32 @@ const char ERRMSG_PAT9125_NOT_RESP[] PROGMEM = "PAT9125 not responding (%d)!\n"; #define FSENSOR_INT_PIN_PCMSK_BIT PCINT13 // PinChange Interrupt / PinChange Enable Mask @ PJ4 #define FSENSOR_INT_PIN_PCICR_BIT PCIE1 // PinChange Interrupt Enable / Flag @ PJ4 -//uint8_t fsensor_int_pin = FSENSOR_INT_PIN; -uint8_t fsensor_int_pin_old = 0; -int16_t fsensor_chunk_len = 0; - //! enabled = initialized and sampled every chunk event bool fsensor_enabled = true; //! runout watching is done in fsensor_update (called from main loop) bool fsensor_watch_runout = true; //! not responding - is set if any communication error occurred during initialization or readout bool fsensor_not_responding = false; + +#ifdef PAT9125 +uint8_t fsensor_int_pin_old = 0; +//! optical checking "chunk lenght" (already in steps) +int16_t fsensor_chunk_len = 0; //! enable/disable quality meassurement bool fsensor_oq_meassure_enabled = false; - //! number of errors, updated in ISR uint8_t fsensor_err_cnt = 0; //! variable for accumulating step count (updated callbacks from stepper and ISR) int16_t fsensor_st_cnt = 0; //! last dy value from pat9125 sensor (used in ISR) int16_t fsensor_dy_old = 0; +//! count of total sensor "soft" failures (filament status checks) +uint8_t fsensor_softfail = 0; +//! timestamp of last soft failure +unsigned long fsensor_softfail_last = 0; +//! count of soft failures within the configured time +uint8_t fsensor_softfail_ccnt = 0; +#endif //! log flag: 0=log disabled, 1=log enabled uint8_t fsensor_log = 1; @@ -78,6 +85,8 @@ uint8_t fsensor_log = 1; bool fsensor_autoload_enabled = true; //! autoload watching enable/disable flag bool fsensor_watch_autoload = false; + +#ifdef PAT9125 // uint16_t fsensor_autoload_y; // @@ -86,11 +95,8 @@ uint8_t fsensor_autoload_c; uint32_t fsensor_autoload_last_millis; // uint8_t fsensor_autoload_sum; -// -uint8_t fsensor_softfail = 0; -uint8_t fsensor_softfail_ccnt = 0; -unsigned long fsensor_softfail_last = 0; //! @} +#endif //! @name filament optical quality measurement variables @@ -136,7 +142,9 @@ void fsensor_restore_print_and_continue(void) { printf_P(PSTR("fsensor_restore_print_and_continue\n")); fsensor_watch_runout = true; +#ifdef PAT9125 fsensor_err_cnt = 0; +#endif restore_print_from_ram_and_continue(0); } @@ -368,6 +376,7 @@ bool fsensor_check_autoload(void) return false; } +#ifdef PAT9125 void fsensor_oq_meassure_set(bool State) { fsensor_oq_meassure_enabled = State; @@ -439,7 +448,7 @@ bool fsensor_oq_result(void) printf_P(_N("fsensor_oq_result %S\n"), (res?_OK:_NG)); return res; } -#ifdef PAT9125 + ISR(FSENSOR_INT_PIN_VECT) { if (mmu_enabled || ir_sensor_detected) return; @@ -538,8 +547,6 @@ void fsensor_setup_interrupt(void) PCICR |= bit(FSENSOR_INT_PIN_PCICR_BIT); // enable corresponding PinChangeInterrupt (set of pins) } -#endif //PAT9125 - void fsensor_st_block_chunk(int cnt) { if (!fsensor_enabled) return; @@ -551,6 +558,7 @@ void fsensor_st_block_chunk(int cnt) else {PIN_VAL(FSENSOR_INT_PIN, HIGH);} } } +#endif //PAT9125 //! Common code for enqueing M600 and supplemental codes into the command queue. diff --git a/Firmware/fsensor.h b/Firmware/fsensor.h index 0c791d412..373200dc8 100755 --- a/Firmware/fsensor.h +++ b/Firmware/fsensor.h @@ -6,16 +6,16 @@ #include "config.h" -//! minimum meassured chunk length in steps -extern int16_t fsensor_chunk_len; // enable/disable flag extern bool fsensor_enabled; // not responding flag extern bool fsensor_not_responding; -//enable/disable quality meassurement -extern bool fsensor_oq_meassure_enabled; +#ifdef PAT9125 +// optical checking "chunk lenght" (already in steps) +extern int16_t fsensor_chunk_len; +// count of soft failures extern uint8_t fsensor_softfail; - +#endif //! @name save restore printing //! @{ @@ -29,8 +29,10 @@ extern void fsensor_checkpoint_print(void); //! initialize extern void fsensor_init(void); +#ifdef PAT9125 //! update axis resolution extern void fsensor_set_axis_steps_per_unit(float u); +#endif //! @name enable/disable //! @{ @@ -56,8 +58,10 @@ extern void fsensor_autoload_check_stop(void); extern bool fsensor_check_autoload(void); //! @} +#ifdef PAT9125 //! @name optical quality measurement support //! @{ +extern bool fsensor_oq_meassure_enabled; extern void fsensor_oq_meassure_set(bool State); extern void fsensor_oq_meassure_start(uint8_t skip); extern void fsensor_oq_meassure_stop(void); @@ -74,6 +78,7 @@ extern void fsensor_st_block_chunk(int cnt); // to drain fsensor_st_cnt anyway at the beginning of the new block. #define fsensor_st_block_begin(rev) fsensor_st_block_chunk(0) //! @} +#endif //PAT9125 #if IR_SENSOR_ANALOG diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 74625a633..93b3d0397 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -36,9 +36,9 @@ #include "tmc2130.h" #endif //TMC2130 -#ifdef FILAMENT_SENSOR +#if defined(FILAMENT_SENSOR) && defined(PAT9125) #include "fsensor.h" -int fsensor_counter = 0; //counter for e-steps +int fsensor_counter; //counter for e-steps #endif //FILAMENT_SENSOR #include "mmu.h" @@ -421,9 +421,9 @@ FORCE_INLINE void stepper_next_block() #endif /* LIN_ADVANCE */ count_direction[E_AXIS] = 1; } -#ifdef FILAMENT_SENSOR - fsensor_counter = 0; - fsensor_st_block_begin(count_direction[E_AXIS] < 0); +#if defined(FILAMENT_SENSOR) && defined(PAT9125) + fsensor_counter = 0; + fsensor_st_block_begin(count_direction[E_AXIS] < 0); #endif //FILAMENT_SENSOR } else { @@ -973,13 +973,13 @@ FORCE_INLINE void advance_isr_scheduler() { WRITE_NC(E0_STEP_PIN, !INVERT_E_STEP_PIN); e_steps += (rev? 1: -1); WRITE_NC(E0_STEP_PIN, INVERT_E_STEP_PIN); -#ifdef FILAMENT_SENSOR +#if defined(FILAMENT_SENSOR) && defined(PAT9125) fsensor_counter += (rev? -1: 1); #endif } while(--max_ticks); -#ifdef FILAMENT_SENSOR +#if defined(FILAMENT_SENSOR) && defined(PAT9125) if (abs(fsensor_counter) >= fsensor_chunk_len) { fsensor_st_block_chunk(fsensor_counter); diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 0461ff803..fc39b1405 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -1796,14 +1796,23 @@ static void lcd_menu_fails_stats_print() uint8_t crashX = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_X); uint8_t crashY = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_Y); lcd_home(); +#ifndef PAT9125 + lcd_printf_P(failStatsFmt, + _i("Last print failures"), ////c=20 r=1 + _i("Power failures"), power, ////c=14 r=1 + _i("Filam. runouts"), filam, ////c=14 r=1 + _i("Crash"), crashX, crashY); ////c=7 r=1 +#else + // On the MK3 include detailed PAT9125 statistics about soft failures lcd_printf_P(PSTR("%S\n" - " %S %-3d\n" - " %S H %-3d S %-3d\n" - " %S X %-3d Y %-3d"), - _i("Last print failures"), - _i("Power failures"), power, - _i("Runouts"), filam, fsensor_softfail, - _i("Crash"), crashX, crashY); + " %-16.16S%-3d\n" + " %-7.7S H %-3d S %-3d\n" + " %-7.7S X %-3d Y %-3d"), + _i("Last print failures"), ////c=20 r=1 + _i("Power failures"), power, ////c=14 r=1 + _i("Runouts"), filam, fsensor_softfail, //c=7 r=1 + _i("Crash"), crashX, crashY); ////c=7 r=1 +#endif menu_back_if_clicked_fb(); } @@ -2234,10 +2243,12 @@ void lcd_set_filament_autoload() { fsensor_autoload_set(!fsensor_autoload_enabled); } +#if defined(FILAMENT_SENSOR) && defined(PAT9125) void lcd_set_filament_oq_meass() { fsensor_oq_meassure_set(!fsensor_oq_meassure_enabled); } +#endif FilamentAction eFilamentAction=FilamentAction::None; // must be initialized as 'non-autoLoad' From 5c4235b886b678335146bee4dca85ad7635ff497 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 5 Feb 2020 15:38:39 +0100 Subject: [PATCH 171/180] Correctly reset the PAT9125 filament counters When the error count is cleared, the cumulative deltas as well as the segment lenght which is kept inside the stepper isr need to be reset. Introduce a helper function fsensor_reset_err_cnt to clear all the required variables in one place which can be used in most cases (the only exceptions being quality measument). Introduce a new function st_reset_fsensor to also clear the segment lenght within the isr. --- Firmware/fsensor.cpp | 38 ++++++++++++++++++++++---------------- Firmware/stepper.cpp | 12 ++++++++++-- Firmware/stepper.h | 5 ++++- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index c1f9f27b0..3c42a3424 100755 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -138,12 +138,28 @@ void fsensor_stop_and_save_print(void) fsensor_watch_runout = false; } +#ifdef PAT9125 +// Reset all internal counters to zero, including stepper callbacks +void fsensor_reset_err_cnt() +{ + fsensor_err_cnt = 0; + pat9125_y = 0; + st_reset_fsensor(); +} + +void fsensor_set_axis_steps_per_unit(float u) +{ + fsensor_chunk_len = (int16_t)(FSENSOR_CHUNK_LEN * u); +} +#endif + + void fsensor_restore_print_and_continue(void) { printf_P(PSTR("fsensor_restore_print_and_continue\n")); fsensor_watch_runout = true; #ifdef PAT9125 - fsensor_err_cnt = 0; + fsensor_reset_err_cnt(); #endif restore_print_from_ram_and_continue(0); } @@ -157,11 +173,6 @@ void fsensor_checkpoint_print(void) restore_print_from_ram_and_continue(0); } -void fsensor_set_axis_steps_per_unit(float u) -{ - fsensor_chunk_len = (int16_t)(FSENSOR_CHUNK_LEN * u); -} - void fsensor_init(void) { #ifdef PAT9125 @@ -214,7 +225,7 @@ bool fsensor_enable(bool bUpdateEEPROM) fsensor_enabled = pat9125 ? true : false; fsensor_watch_runout = true; fsensor_oq_meassure = false; - fsensor_err_cnt = 0; + fsensor_reset_err_cnt(); fsensor_dy_old = 0; eeprom_update_byte((uint8_t*)EEPROM_FSENSOR, fsensor_enabled ? 0x01 : 0x00); FSensorStateMenu = fsensor_enabled ? 1 : 0; @@ -295,12 +306,11 @@ void fsensor_autoload_check_start(void) fsensor_autoload_last_millis = _millis(); fsensor_watch_runout = false; fsensor_watch_autoload = true; - fsensor_err_cnt = 0; } + void fsensor_autoload_check_stop(void) { - // puts_P(_N("fsensor_autoload_check_stop\n")); if (!fsensor_enabled) return; // puts_P(_N("fsensor_autoload_check_stop 1\n")); @@ -311,7 +321,7 @@ void fsensor_autoload_check_stop(void) fsensor_autoload_sum = 0; fsensor_watch_autoload = false; fsensor_watch_runout = true; - fsensor_err_cnt = 0; + fsensor_reset_err_cnt(); } #endif //PAT9125 @@ -410,7 +420,6 @@ void fsensor_oq_meassure_stop(void) printf_P(_N(" st_sum=%u yd_sum=%u er_sum=%u er_max=%hhu\n"), fsensor_oq_st_sum, fsensor_oq_yd_sum, fsensor_oq_er_sum, fsensor_oq_er_max); printf_P(_N(" yd_min=%u yd_max=%u yd_avg=%u sh_avg=%u\n"), fsensor_oq_yd_min, fsensor_oq_yd_max, (uint16_t)((uint32_t)fsensor_oq_yd_sum * fsensor_chunk_len / fsensor_oq_st_sum), (uint16_t)(fsensor_oq_sh_sum / fsensor_oq_samples)); fsensor_oq_meassure = false; - fsensor_err_cnt = 0; } const char _OK[] PROGMEM = "OK"; @@ -595,7 +604,7 @@ void fsensor_update(void) st_synchronize(); // check the filament in isolation - fsensor_err_cnt = 0; + fsensor_reset_err_cnt(); fsensor_oq_meassure_start(0); float e_tmp = current_position[E_AXIS]; current_position[E_AXIS] -= 3; @@ -603,13 +612,10 @@ void fsensor_update(void) current_position[E_AXIS] = e_tmp; plan_buffer_line_curposXYZE(200/60, active_extruder); st_synchronize(); - - uint8_t err_cnt = fsensor_err_cnt; fsensor_oq_meassure_stop(); bool err = false; - err |= (err_cnt > 1); - + err |= (fsensor_err_cnt > 1); err |= (fsensor_oq_er_sum > 2); err |= (fsensor_oq_yd_sum < (4 * FSENSOR_OQ_MIN_YD)); diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 93b3d0397..93e4ad8fa 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -1357,8 +1357,6 @@ void quickStop() } #ifdef BABYSTEPPING - - void babystep(const uint8_t axis,const bool direction) { //MUST ONLY BE CALLED BY A ISR, it depends on that no other ISR interrupts this @@ -1594,3 +1592,13 @@ void microstep_readings() #endif } #endif //TMC2130 + + +#if defined(FILAMENT_SENSOR) && defined(PAT9125) +void st_reset_fsensor() +{ + CRITICAL_SECTION_START; + fsensor_counter = 0; + CRITICAL_SECTION_END; +} +#endif //FILAMENT_SENSOR diff --git a/Firmware/stepper.h b/Firmware/stepper.h index 7c41743cd..7fdf426f3 100644 --- a/Firmware/stepper.h +++ b/Firmware/stepper.h @@ -92,7 +92,10 @@ void microstep_readings(); #ifdef BABYSTEPPING void babystep(const uint8_t axis,const bool direction); // perform a short step with a single stepper motor, outside of any convention #endif - +#if defined(FILAMENT_SENSOR) && defined(PAT9125) +// reset the internal filament sensor state +void st_reset_fsensor(); +#endif #endif From e84f82a6757ec3bfe3a9473b71f145775f631bae Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 5 Feb 2020 15:46:45 +0100 Subject: [PATCH 172/180] Rewrite filament sensor PAT9125 error handling Rewrite the logic behind the "chunking"/error count behind the PAT9125. Basic idea: check the _direction_ of movement returned by the optical sensor and compare it to the direction of the stepper. To avoid doing this continuosly (and because the optical sensor doesn't necessarily have the accuracy to track small distances), do so in chunks. Each time a chunk doesn't match the expected direction, increase the error count. Several improvements were done to the previous code: - Increase the chunk window: this ensures that a filament with poor response returns an usable direction, while also moving the average return values from the sensor in the middle of the 12 bits available for maximum effectiveness. - Since the returned values are more reliable, reduce the error count (1.25mm*4 = ~5mm before runout detection) - Track _both_ positive and negative movement, although only trigger errors during extrusion (necessary due to several assumptions made in the mmu/unloading code) - Do not reset the counters for each block: accumulate distances correctly, allowing detection of any block lenght. --- Firmware/config.h | 3 +- Firmware/fsensor.cpp | 104 +++++++++++++++++++++---------------------- Firmware/stepper.cpp | 1 - 3 files changed, 53 insertions(+), 55 deletions(-) diff --git a/Firmware/config.h b/Firmware/config.h index 241a2f20b..5c8f7cd98 100644 --- a/Firmware/config.h +++ b/Firmware/config.h @@ -34,7 +34,8 @@ //#define PAT9125_I2C_ADDR 0x79 //ID=HI //#define PAT9125_I2C_ADDR 0x73 //ID=NC #define PAT9125_XRES 0 -#define PAT9125_YRES 240 +#define PAT9125_YRES 240 // maximum resolution (5*X cpi) +#define PAT9124_YRES_MM (5*PAT9125_YRES/25.4) // counts per mm //SM4 configuration #define SM4_DEFDELAY 500 //default step delay [us] diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index 3c42a3424..ea171906f 100755 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -18,8 +18,8 @@ //! @name Basic parameters //! @{ -#define FSENSOR_CHUNK_LEN 0.64F //!< filament sensor chunk length 0.64mm -#define FSENSOR_ERR_MAX 9 //!< filament sensor maximum error count for runout detection +#define FSENSOR_CHUNK_LEN 1.25 //!< filament sensor chunk length (mm) +#define FSENSOR_ERR_MAX 4 //!< filament sensor maximum error/chunk count for runout detection #define FSENSOR_SOFTERR_CMAX 3 //!< number of contiguous soft failures before a triggering a runout #define FSENSOR_SOFTERR_DELTA 30000 //!< maximum interval (ms) to consider soft failures contiguous @@ -64,8 +64,6 @@ bool fsensor_oq_meassure_enabled = false; uint8_t fsensor_err_cnt = 0; //! variable for accumulating step count (updated callbacks from stepper and ISR) int16_t fsensor_st_cnt = 0; -//! last dy value from pat9125 sensor (used in ISR) -int16_t fsensor_dy_old = 0; //! count of total sensor "soft" failures (filament status checks) uint8_t fsensor_softfail = 0; //! timestamp of last soft failure @@ -226,7 +224,6 @@ bool fsensor_enable(bool bUpdateEEPROM) fsensor_watch_runout = true; fsensor_oq_meassure = false; fsensor_reset_err_cnt(); - fsensor_dy_old = 0; eeprom_update_byte((uint8_t*)EEPROM_FSENSOR, fsensor_enabled ? 0x01 : 0x00); FSensorStateMenu = fsensor_enabled ? 1 : 0; } @@ -477,53 +474,56 @@ ISR(FSENSOR_INT_PIN_VECT) fsensor_not_responding = true; printf_P(ERRMSG_PAT9125_NOT_RESP, 1); } + if (st_cnt != 0) - { //movement - if (st_cnt > 0) //positive movement - { - if (pat9125_y < 0) - { - fsensor_err_cnt++; - } - else if (pat9125_y > 0) - { - if (fsensor_err_cnt) - fsensor_err_cnt--; - } - else //(pat9125_y == 0) - if (((fsensor_dy_old <= 0) || (fsensor_err_cnt)) && (st_cnt > (fsensor_chunk_len >> 1))) - fsensor_err_cnt++; - if (fsensor_oq_meassure) - { - if (fsensor_oq_skipchunk) - { - fsensor_oq_skipchunk--; - fsensor_err_cnt = 0; - } - else - { - if (st_cnt == fsensor_chunk_len) - { - if (pat9125_y > 0) if (fsensor_oq_yd_min > pat9125_y) fsensor_oq_yd_min = (fsensor_oq_yd_min + pat9125_y) / 2; - if (pat9125_y >= 0) if (fsensor_oq_yd_max < pat9125_y) fsensor_oq_yd_max = (fsensor_oq_yd_max + pat9125_y) / 2; - } - fsensor_oq_samples++; - fsensor_oq_st_sum += st_cnt; - if (pat9125_y > 0) fsensor_oq_yd_sum += pat9125_y; - if (fsensor_err_cnt > old_err_cnt) - fsensor_oq_er_sum += (fsensor_err_cnt - old_err_cnt); - if (fsensor_oq_er_max < fsensor_err_cnt) - fsensor_oq_er_max = fsensor_err_cnt; - fsensor_oq_sh_sum += pat9125_s; - } - } - } - else //negative movement - { - } - } - else - { //no movement + { + // movement was planned, check for sensor movement + int8_t st_dir = st_cnt >= 0; + int8_t pat9125_dir = pat9125_y >= 0; + + if (pat9125_y == 0) + { + // no movement detected: increase error count only when extruding, since fast retracts + // cannot always be seen. We also need to ensure that no runout is generated while + // retracting as it's not currently handled everywhere + if (st_dir) ++fsensor_err_cnt; + } + else if (pat9125_dir != st_dir) + { + // detected direction opposite of motor movement + if (st_dir) ++fsensor_err_cnt; + } + else if (pat9125_dir == st_dir) + { + // direction agreeing with planned movement + if (fsensor_err_cnt) --fsensor_err_cnt; + } + + if (st_dir && fsensor_oq_meassure) + { + // extruding with quality assessment + if (fsensor_oq_skipchunk) + { + fsensor_oq_skipchunk--; + fsensor_err_cnt = 0; + } + else + { + if (st_cnt == fsensor_chunk_len) + { + if (pat9125_y > 0) if (fsensor_oq_yd_min > pat9125_y) fsensor_oq_yd_min = (fsensor_oq_yd_min + pat9125_y) / 2; + if (pat9125_y >= 0) if (fsensor_oq_yd_max < pat9125_y) fsensor_oq_yd_max = (fsensor_oq_yd_max + pat9125_y) / 2; + } + fsensor_oq_samples++; + fsensor_oq_st_sum += st_cnt; + if (pat9125_y > 0) fsensor_oq_yd_sum += pat9125_y; + if (fsensor_err_cnt > old_err_cnt) + fsensor_oq_er_sum += (fsensor_err_cnt - old_err_cnt); + if (fsensor_oq_er_max < fsensor_err_cnt) + fsensor_oq_er_max = fsensor_err_cnt; + fsensor_oq_sh_sum += pat9125_s; + } + } } #ifdef DEBUG_FSENSOR_LOG @@ -534,9 +534,7 @@ ISR(FSENSOR_INT_PIN_VECT) } #endif //DEBUG_FSENSOR_LOG - fsensor_dy_old = pat9125_y; pat9125_y = 0; - _lock = false; return; } diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 93e4ad8fa..6e0937cfd 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -422,7 +422,6 @@ FORCE_INLINE void stepper_next_block() count_direction[E_AXIS] = 1; } #if defined(FILAMENT_SENSOR) && defined(PAT9125) - fsensor_counter = 0; fsensor_st_block_begin(count_direction[E_AXIS] < 0); #endif //FILAMENT_SENSOR } From 1eddc40ed46cb74192e792ba2326e9ac174aa157 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 5 Feb 2020 22:05:04 +0100 Subject: [PATCH 173/180] Comment existing code --- Firmware/fsensor.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index ea171906f..2cf336a6e 100755 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -460,12 +460,17 @@ ISR(FSENSOR_INT_PIN_VECT) if (mmu_enabled || ir_sensor_detected) return; if (!((fsensor_int_pin_old ^ FSENSOR_INT_PIN_PIN_REG) & FSENSOR_INT_PIN_MASK)) return; fsensor_int_pin_old = FSENSOR_INT_PIN_PIN_REG; + + // prevent isr re-entry static bool _lock = false; if (_lock) return; _lock = true; + + // fetch fsensor_st_cnt atomically int st_cnt = fsensor_st_cnt; fsensor_st_cnt = 0; sei(); + uint8_t old_err_cnt = fsensor_err_cnt; uint8_t pat9125_res = fsensor_oq_meassure?pat9125_update():pat9125_update_y(); if (!pat9125_res) From 3af35844e11c95147befa708c3f75f7546ef90dd Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 5 Feb 2020 22:05:24 +0100 Subject: [PATCH 174/180] Remove redundant check (always trigger the fsensor isr) Since fsensor_st_block_chunk is already called on fsensor_chunk_size boundaries, there's no need to check a second time. --- Firmware/fsensor.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index 2cf336a6e..41d9a5065 100755 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -563,12 +563,10 @@ void fsensor_st_block_chunk(int cnt) { if (!fsensor_enabled) return; fsensor_st_cnt += cnt; - if (abs(fsensor_st_cnt) >= fsensor_chunk_len) - { -// !!! bit toggling (PINxn <- 1) (for PinChangeInterrupt) does not work for some MCU pins - if (PIN_GET(FSENSOR_INT_PIN)) {PIN_VAL(FSENSOR_INT_PIN, LOW);} - else {PIN_VAL(FSENSOR_INT_PIN, HIGH);} - } + + // !!! bit toggling (PINxn <- 1) (for PinChangeInterrupt) does not work for some MCU pins + if (PIN_GET(FSENSOR_INT_PIN)) {PIN_VAL(FSENSOR_INT_PIN, LOW);} + else {PIN_VAL(FSENSOR_INT_PIN, HIGH);} } #endif //PAT9125 From cdc17e8da1b88a6fd10fec6e7a875f3e5caf30c5 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 5 Feb 2020 22:06:56 +0100 Subject: [PATCH 175/180] Read all 12 bits correctly from PAT9125 DELTA_* registers Widen ucXL/ucYL/ucXYH types to 16 bits, since the following shifts will otherwise truncate the results. --- Firmware/pat9125.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Firmware/pat9125.c b/Firmware/pat9125.c index 7b7353dde..5b17345c2 100644 --- a/Firmware/pat9125.c +++ b/Firmware/pat9125.c @@ -183,9 +183,9 @@ uint8_t pat9125_update(void) if (pat9125_PID1 == 0xff) return 0; if (ucMotion & 0x80) { - uint8_t ucXL = pat9125_rd_reg(PAT9125_DELTA_XL); - uint8_t ucYL = pat9125_rd_reg(PAT9125_DELTA_YL); - uint8_t ucXYH = pat9125_rd_reg(PAT9125_DELTA_XYH); + uint16_t ucXL = pat9125_rd_reg(PAT9125_DELTA_XL); + uint16_t ucYL = pat9125_rd_reg(PAT9125_DELTA_YL); + uint16_t ucXYH = pat9125_rd_reg(PAT9125_DELTA_XYH); if (pat9125_PID1 == 0xff) return 0; int16_t iDX = ucXL | ((ucXYH << 4) & 0xf00); int16_t iDY = ucYL | ((ucXYH << 8) & 0xf00); @@ -207,8 +207,8 @@ uint8_t pat9125_update_y(void) if (pat9125_PID1 == 0xff) return 0; if (ucMotion & 0x80) { - uint8_t ucYL = pat9125_rd_reg(PAT9125_DELTA_YL); - uint8_t ucXYH = pat9125_rd_reg(PAT9125_DELTA_XYH); + uint16_t ucYL = pat9125_rd_reg(PAT9125_DELTA_YL); + uint16_t ucXYH = pat9125_rd_reg(PAT9125_DELTA_XYH); if (pat9125_PID1 == 0xff) return 0; int16_t iDY = ucYL | ((ucXYH << 8) & 0xf00); if (iDY & 0x800) iDY -= 4096; From 3be859ece951c6c4bdeb8ed112c7e14a439636d6 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Thu, 6 Feb 2020 13:48:23 +0100 Subject: [PATCH 176/180] FS: Improve reliability on speeds with poor optical tracking Depending on the filament surface and moving speed, the PAT9125 sensor can stop being able to track movement. In such cases, instead of triggering false errors and/or relying on previous states, read and use the exposure data off the sensor and increase error counts only for poorly exposed images instead, which is a good indicator of a far-away (or missing!) tracking surface. --- Firmware/fsensor.cpp | 23 +++++++++++++++++++---- Firmware/pat9125.c | 14 ++++---------- Firmware/pat9125.h | 6 +++--- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index 41d9a5065..9e7b2f6cf 100755 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -488,10 +488,25 @@ ISR(FSENSOR_INT_PIN_VECT) if (pat9125_y == 0) { - // no movement detected: increase error count only when extruding, since fast retracts - // cannot always be seen. We also need to ensure that no runout is generated while - // retracting as it's not currently handled everywhere - if (st_dir) ++fsensor_err_cnt; + if (st_dir) + { + // no movement detected: we might be within a blind sensor range, + // update the frame and shutter parameters we didn't earlier + if (!fsensor_oq_meassure) + pat9125_update_bs(); + + // increment the error count only if underexposed: filament likely missing + if ((pat9125_b < 80) && (pat9125_s > 10)) + { + // check for a dark frame (<30% avg brightness) with long exposure + ++fsensor_err_cnt; + } + else + { + // good frame, filament likely present + if(fsensor_err_cnt) --fsensor_err_cnt; + } + } } else if (pat9125_dir != st_dir) { diff --git a/Firmware/pat9125.c b/Firmware/pat9125.c index 5b17345c2..ae291c217 100644 --- a/Firmware/pat9125.c +++ b/Firmware/pat9125.c @@ -219,19 +219,13 @@ uint8_t pat9125_update_y(void) return 0; } -uint8_t pat9125_update_y2(void) +uint8_t pat9125_update_bs(void) { if ((pat9125_PID1 == 0x31) && (pat9125_PID2 == 0x91)) { - uint8_t ucMotion = pat9125_rd_reg(PAT9125_MOTION); - if (pat9125_PID1 == 0xff) return 0; //NOACK error - if (ucMotion & 0x80) - { - int8_t dy = pat9125_rd_reg(PAT9125_DELTA_YL); - if (pat9125_PID1 == 0xff) return 0; //NOACK error - pat9125_y -= dy; //negative number, because direction switching does not work - } - return 1; + pat9125_b = pat9125_rd_reg(PAT9125_FRAME); + pat9125_s = pat9125_rd_reg(PAT9125_SHUTTER); + if (pat9125_PID1 == 0xff) return 0; } return 0; } diff --git a/Firmware/pat9125.h b/Firmware/pat9125.h index 6d36a82e8..12f7fe949 100755 --- a/Firmware/pat9125.h +++ b/Firmware/pat9125.h @@ -19,9 +19,9 @@ extern uint8_t pat9125_b; extern uint8_t pat9125_s; extern uint8_t pat9125_init(void); -extern uint8_t pat9125_update(void); -extern uint8_t pat9125_update_y(void); -extern uint8_t pat9125_update_y2(void); +extern uint8_t pat9125_update(void); // update all sensor data +extern uint8_t pat9125_update_y(void); // update _y only +extern uint8_t pat9125_update_bs(void); // update _b/_s only #if defined(__cplusplus) From bd0544fe9e028ffb32d3696533340dc0319152b4 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Thu, 6 Feb 2020 14:44:43 +0100 Subject: [PATCH 177/180] FS: Use two different speeds when checking for runout When doing a PAT9125 "soft check", use two different speeds between retraction and extrusion. This increases the chances that we can track the surface. --- Firmware/fsensor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index 9e7b2f6cf..7f291d7a2 100755 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -624,7 +624,7 @@ void fsensor_update(void) fsensor_oq_meassure_start(0); float e_tmp = current_position[E_AXIS]; current_position[E_AXIS] -= 3; - plan_buffer_line_curposXYZE(200/60, active_extruder); + plan_buffer_line_curposXYZE(250/60, active_extruder); current_position[E_AXIS] = e_tmp; plan_buffer_line_curposXYZE(200/60, active_extruder); st_synchronize(); From 853bb79b6b4ac485537fd410f432229a9c45817f Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Thu, 6 Feb 2020 16:39:08 +0100 Subject: [PATCH 178/180] Return correct status from pat9125_update_bs --- Firmware/pat9125.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Firmware/pat9125.c b/Firmware/pat9125.c index ae291c217..de4693d29 100644 --- a/Firmware/pat9125.c +++ b/Firmware/pat9125.c @@ -226,6 +226,7 @@ uint8_t pat9125_update_bs(void) pat9125_b = pat9125_rd_reg(PAT9125_FRAME); pat9125_s = pat9125_rd_reg(PAT9125_SHUTTER); if (pat9125_PID1 == 0xff) return 0; + return 1; } return 0; } From 9e45b5d41e49ec6abe3b62263745ef741fca9167 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Thu, 6 Feb 2020 18:01:54 +0100 Subject: [PATCH 179/180] Improve PAT9125 filament / optical quality checks Tune the "soft" filament recheck to be more in-line with the latest changes. Relax the thresholds so that a poorly tracking filament that managed to trigger a recheck can still pass as long as /some/ motion is detected. Hide the unused fsensor_oq_result() behind the FSENSOR_QUALITY define, which is likely broken currently anyway. Cleanup and simplify all the OQ defines. --- Firmware/fsensor.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index 7f291d7a2..4894d29ce 100755 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -27,13 +27,10 @@ //! @name Optical quality measurement parameters //! @{ -#define FSENSOR_OQ_MAX_ES 6 //!< maximum error sum while loading (length ~64mm = 100chunks) -#define FSENSOR_OQ_MAX_EM 2 //!< maximum error counter value while loading -#define FSENSOR_OQ_MIN_YD 2 //!< minimum yd per chunk (applied to avg value) -#define FSENSOR_OQ_MAX_YD 200 //!< maximum yd per chunk (applied to avg value) -#define FSENSOR_OQ_MAX_PD 4 //!< maximum positive deviation (= yd_max/yd_avg) -#define FSENSOR_OQ_MAX_ND 5 //!< maximum negative deviation (= yd_avg/yd_min) -#define FSENSOR_OQ_MAX_SH 13 //!< maximum shutter value +#define FSENSOR_OQ_MAX_ES 2 //!< maximum sum of error blocks during filament recheck +#define FSENSOR_OQ_MIN_YD 2 //!< minimum yd sum during filament check (counts per inch) +#define FSENSOR_OQ_MIN_BR 80 //!< minimum brightness value +#define FSENSOR_OQ_MAX_SH 10 //!< maximum shutter value //! @} const char ERRMSG_PAT9125_NOT_RESP[] PROGMEM = "PAT9125 not responding (%d)!\n"; @@ -401,7 +398,7 @@ void fsensor_oq_meassure_start(uint8_t skip) fsensor_oq_yd_sum = 0; fsensor_oq_er_sum = 0; fsensor_oq_er_max = 0; - fsensor_oq_yd_min = FSENSOR_OQ_MAX_YD; + fsensor_oq_yd_min = INT16_MAX; fsensor_oq_yd_max = 0; fsensor_oq_sh_sum = 0; pat9125_update(); @@ -419,6 +416,7 @@ void fsensor_oq_meassure_stop(void) fsensor_oq_meassure = false; } +#ifdef FSENSOR_QUALITY const char _OK[] PROGMEM = "OK"; const char _NG[] PROGMEM = "NG!"; @@ -454,6 +452,7 @@ bool fsensor_oq_result(void) printf_P(_N("fsensor_oq_result %S\n"), (res?_OK:_NG)); return res; } +#endif //FSENSOR_QUALITY ISR(FSENSOR_INT_PIN_VECT) { @@ -496,7 +495,7 @@ ISR(FSENSOR_INT_PIN_VECT) pat9125_update_bs(); // increment the error count only if underexposed: filament likely missing - if ((pat9125_b < 80) && (pat9125_s > 10)) + if ((pat9125_b < FSENSOR_OQ_MIN_BR) && (pat9125_s > FSENSOR_OQ_MAX_SH)) { // check for a dark frame (<30% avg brightness) with long exposure ++fsensor_err_cnt; @@ -631,9 +630,9 @@ void fsensor_update(void) fsensor_oq_meassure_stop(); bool err = false; - err |= (fsensor_err_cnt > 1); - err |= (fsensor_oq_er_sum > 2); - err |= (fsensor_oq_yd_sum < (4 * FSENSOR_OQ_MIN_YD)); + err |= (fsensor_err_cnt > 0); // final error count is non-zero + err |= (fsensor_oq_er_sum > FSENSOR_OQ_MAX_ES); // total error count is above limit + err |= (fsensor_oq_yd_sum < FSENSOR_OQ_MIN_YD); // total measured distance is below limit fsensor_restore_print_and_continue(); fsensor_autoload_enabled = autoload_enabled_tmp; From 2e18a48b8778308e1ebf1782dbf95df51dff59fe Mon Sep 17 00:00:00 2001 From: DRracer Date: Mon, 17 Feb 2020 16:47:56 +0100 Subject: [PATCH 180/180] Version changed (3.9.0-RC1 build 3272) --- Firmware/Configuration.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/Configuration.h b/Firmware/Configuration.h index 694247fbd..98923ef4f 100644 --- a/Firmware/Configuration.h +++ b/Firmware/Configuration.h @@ -16,8 +16,8 @@ extern uint16_t nPrinterType; extern PGM_P sPrinterName; // Firmware version -#define FW_VERSION "3.9.0" -#define FW_COMMIT_NR 3175 +#define FW_VERSION "3.9.0-RC1" +#define FW_COMMIT_NR 3272 // FW_VERSION_UNKNOWN means this is an unofficial build. // The firmware should only be checked into github with this symbol. #define FW_DEV_VERSION FW_VERSION_UNKNOWN