From 3bbc14382103e711f6b5b304e7522f25aeb85f28 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 2 Feb 2020 18:01:06 +0100 Subject: [PATCH 1/2] 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 2b113673..4e229ba7 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 2/2] 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 197b3d9f..57d7b89b 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)