Skip to content

Commit 2d39567

Browse files
authored
Merge branch 'MarlinFirmware:bugfix-2.1.x' into bf_ft_motion
2 parents 1e8b9d7 + a4382b4 commit 2d39567

File tree

8 files changed

+75
-49
lines changed

8 files changed

+75
-49
lines changed

Marlin/src/HAL/GD32_MFL/timers.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
extern uint32_t GetStepperTimerClkFreq();
4545

4646
// Timer prescaler calculations
47-
#define STEPPER_TIMER_PRESCALE (GetStepperTimerClkFreq() / STEPPER_TIMER_RATE) // Prescaler = 30
47+
#define STEPPER_TIMER_PRESCALE (GetStepperTimerClkFreq() / STEPPER_TIMER_RATE) // Prescaler = 30
4848
#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
49-
#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // Stepper timer ticks per µs
49+
#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // Stepper timer ticks per µs
5050
#define PULSE_TIMER_RATE STEPPER_TIMER_RATE
5151
#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
5252

@@ -57,7 +57,7 @@ extern uint32_t GetStepperTimerClkFreq();
5757
#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(MF_TIMER_STEP)
5858
#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(MF_TIMER_STEP)
5959
#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(MF_TIMER_STEP)
60-
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(MF_TIMER_TEMP)
60+
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(MF_TIMER_TEMP)
6161
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(MF_TIMER_TEMP)
6262

6363
extern void Step_Handler();

Marlin/src/gcode/feature/nonlinear/M592.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ void GcodeSuite::M592() {
4949
if (parser.seenval('A')) stepper.ne.A = parser.value_float();
5050
if (parser.seenval('B')) stepper.ne.B = parser.value_float();
5151
if (parser.seenval('C')) stepper.ne.C = parser.value_float();
52+
53+
#if ENABLED(SMOOTH_LIN_ADVANCE)
54+
stepper.ne_q30.A = _BV32(30) * (stepper.ne.A * planner.mm_per_step[E_AXIS_N(0)] * planner.mm_per_step[E_AXIS_N(0)]);
55+
stepper.ne_q30.B = _BV32(30) * (stepper.ne.B * planner.mm_per_step[E_AXIS_N(0)]);
56+
stepper.ne_q30.C = _BV32(30) * stepper.ne.C;
57+
#endif
5258
}
5359

5460
#endif // NONLINEAR_EXTRUSION

Marlin/src/inc/SanityCheck.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -868,8 +868,6 @@ static_assert(COUNT(arm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _L
868868
#error "SMOOTH_LIN_ADVANCE requires a 32-bit CPU."
869869
#elif ENABLED(S_CURVE_ACCELERATION)
870870
#error "SMOOTH_LIN_ADVANCE is not compatible with S_CURVE_ACCELERATION."
871-
#elif ENABLED(NONLINEAR_EXTRUSION)
872-
#error "SMOOTH_LIN_ADVANCE doesn't currently support NONLINEAR_EXTRUSION."
873871
#elif ENABLED(INPUT_SHAPING_E_SYNC) && NONE(INPUT_SHAPING_X, INPUT_SHAPING_Y)
874872
#error "INPUT_SHAPING_E_SYNC requires INPUT_SHAPING_X or INPUT_SHAPING_Y."
875873
#endif

Marlin/src/module/planner.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3252,6 +3252,10 @@ void Planner::refresh_acceleration_rates() {
32523252
void Planner::refresh_positioning() {
32533253
#if ENABLED(EDITABLE_STEPS_PER_UNIT)
32543254
LOOP_DISTINCT_AXES(i) mm_per_step[i] = 1.0f / settings.axis_steps_per_mm[i];
3255+
#if ALL(NONLINEAR_EXTRUSION, SMOOTH_LIN_ADVANCE)
3256+
stepper.ne_q30.A = _BV32(30) * (stepper.ne.A * mm_per_step[E_AXIS_N(0)] * mm_per_step[E_AXIS_N(0)]);
3257+
stepper.ne_q30.B = _BV32(30) * (stepper.ne.B * mm_per_step[E_AXIS_N(0)]);
3258+
#endif
32553259
#endif
32563260
set_position_mm(current_position);
32573261
refresh_acceleration_rates();

Marlin/src/module/planner.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,7 @@ class Planner {
531531
static void set_advance_k(const_float_t k, const uint8_t e=active_extruder) {
532532
UNUSED(e);
533533
extruder_advance_K[E_INDEX_N(e)] = k;
534-
#if ENABLED(SMOOTH_LIN_ADVANCE)
535-
extruder_advance_K_q27[E_INDEX_N(e)] = k * (1UL << 27);
536-
#endif
534+
TERN_(SMOOTH_LIN_ADVANCE, extruder_advance_K_q27[E_INDEX_N(e)] = k * _BV32(27));
537535
}
538536
static float get_advance_k(const uint8_t e=active_extruder) {
539537
UNUSED(e);

Marlin/src/module/stepper.cpp

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,16 @@ uint32_t Stepper::advance_divisor = 0,
257257

258258
#if ENABLED(NONLINEAR_EXTRUSION)
259259
ne_coeff_t Stepper::ne;
260-
ne_fix_t Stepper::ne_fix;
261-
int32_t Stepper::ne_edividend;
262-
uint32_t Stepper::ne_scale;
260+
#if NONLINEAR_EXTRUSION_Q24
261+
ne_q24_t Stepper::ne_q24;
262+
#else
263+
ne_q30_t Stepper::ne_q30;
264+
#endif
265+
// private:
266+
#if NONLINEAR_EXTRUSION_Q24
267+
int32_t Stepper::ne_edividend;
268+
uint32_t Stepper::ne_scale_q24;
269+
#endif
263270
#endif
264271

265272
#if HAS_ZV_SHAPING
@@ -2241,13 +2248,13 @@ hal_timer_t Stepper::calc_timer_interval(uint32_t step_rate) {
22412248
#endif // !CPU_32_BIT
22422249
}
22432250

2244-
#if ENABLED(NONLINEAR_EXTRUSION)
2245-
void Stepper::calc_nonlinear_e(uint32_t step_rate) {
2246-
const uint32_t velocity = ne_scale * step_rate; // Scale step_rate first so all intermediate values stay in range of 8.24 fixed point math
2247-
int32_t vd = (((((int64_t)ne_fix.A * velocity) >> 24) * velocity) >> 24) + (((int64_t)ne_fix.B * velocity) >> 24);
2248-
NOLESS(vd, 0);
2251+
#if NONLINEAR_EXTRUSION_Q24
2252+
void Stepper::calc_nonlinear_e(const uint32_t step_rate) {
2253+
const uint32_t velocity_q24 = ne_scale_q24 * step_rate; // Scale step_rate first so all intermediate values stay in range of 8.24 fixed point math
2254+
int32_t vd_q24 = (((((int64_t)ne_q24.A * velocity_q24) >> 24) * velocity_q24) >> 24) + (((int64_t)ne_q24.B * velocity_q24) >> 24);
2255+
NOLESS(vd_q24, 0);
22492256

2250-
advance_dividend.e = (uint64_t(ne_fix.C + vd) * ne_edividend) >> 24;
2257+
advance_dividend.e = (uint64_t(ne_q24.C + vd_q24) * ne_edividend) >> 24;
22512258
}
22522259
#endif
22532260

@@ -2463,9 +2470,7 @@ hal_timer_t Stepper::block_phase_isr() {
24632470
acceleration_time += interval;
24642471
deceleration_time = 0; // Reset since we're doing acceleration first.
24652472

2466-
#if ENABLED(NONLINEAR_EXTRUSION)
2467-
calc_nonlinear_e(acc_step_rate << oversampling_factor);
2468-
#endif
2473+
calc_nonlinear_e(acc_step_rate << oversampling_factor);
24692474

24702475
#if HAS_ROUGH_LIN_ADVANCE
24712476
if (la_active) {
@@ -2529,9 +2534,7 @@ hal_timer_t Stepper::block_phase_isr() {
25292534
interval = calc_multistep_timer_interval(step_rate << oversampling_factor);
25302535
deceleration_time += interval;
25312536

2532-
#if ENABLED(NONLINEAR_EXTRUSION)
2533-
calc_nonlinear_e(step_rate << oversampling_factor);
2534-
#endif
2537+
calc_nonlinear_e(step_rate << oversampling_factor);
25352538

25362539
#if HAS_ROUGH_LIN_ADVANCE
25372540
if (la_active) {
@@ -2584,9 +2587,7 @@ hal_timer_t Stepper::block_phase_isr() {
25842587
TERN_(SMOOTH_LIN_ADVANCE, curr_step_rate = current_block->nominal_rate;)
25852588
deceleration_time = ticks_nominal / 2;
25862589

2587-
#if ENABLED(NONLINEAR_EXTRUSION)
2588-
calc_nonlinear_e(current_block->nominal_rate << oversampling_factor);
2589-
#endif
2590+
calc_nonlinear_e(current_block->nominal_rate << oversampling_factor);
25902591

25912592
#if HAS_ROUGH_LIN_ADVANCE
25922593
if (la_active)
@@ -2836,18 +2837,18 @@ hal_timer_t Stepper::block_phase_isr() {
28362837
acc_step_rate = current_block->initial_rate;
28372838
#endif
28382839

2839-
#if ENABLED(NONLINEAR_EXTRUSION)
2840+
#if NONLINEAR_EXTRUSION_Q24
28402841
ne_edividend = advance_dividend.e;
28412842
const float scale = (float(ne_edividend) / advance_divisor) * planner.mm_per_step[E_AXIS_N(current_block->extruder)];
2842-
ne_scale = (1L << 24) * scale;
2843+
ne_scale_q24 = _BV32(24) * scale;
28432844
if (current_block->direction_bits.e && ANY_AXIS_MOVES(current_block)) {
2844-
ne_fix.A = (1L << 24) * ne.A;
2845-
ne_fix.B = (1L << 24) * ne.B;
2846-
ne_fix.C = (1L << 24) * ne.C;
2845+
ne_q24.A = _BV32(24) * ne.A;
2846+
ne_q24.B = _BV32(24) * ne.B;
2847+
ne_q24.C = _BV32(24) * ne.C;
28472848
}
28482849
else {
2849-
ne_fix.A = ne_fix.B = 0;
2850-
ne_fix.C = (1L << 24);
2850+
ne_q24.A = ne_q24.B = 0;
2851+
ne_q24.C = _BV32(24);
28512852
}
28522853
#endif
28532854

@@ -2856,9 +2857,7 @@ hal_timer_t Stepper::block_phase_isr() {
28562857
// Initialize ac/deceleration time as if half the time passed.
28572858
acceleration_time = deceleration_time = interval / 2;
28582859

2859-
#if ENABLED(NONLINEAR_EXTRUSION)
2860-
calc_nonlinear_e(current_block->initial_rate << oversampling_factor);
2861-
#endif
2860+
calc_nonlinear_e(current_block->initial_rate << oversampling_factor);
28622861

28632862
#if ENABLED(LIN_ADVANCE)
28642863
#if ENABLED(SMOOTH_LIN_ADVANCE)
@@ -2885,13 +2884,23 @@ hal_timer_t Stepper::block_phase_isr() {
28852884
uint32_t Stepper::extruder_advance_tau_ticks[DISTINCT_E],
28862885
Stepper::extruder_advance_alpha_q30[DISTINCT_E];
28872886

2888-
void Stepper::set_la_interval(const int32_t rate) {
2889-
if (rate == 0) {
2887+
void Stepper::set_la_interval(int32_t step_rate) {
2888+
if (step_rate == 0) {
28902889
la_interval = LA_ADV_NEVER;
28912890
}
28922891
else {
2893-
const bool forward_e = rate > 0;
2894-
la_interval = calc_timer_interval(uint32_t(ABS(rate)));
2892+
const bool forward_e = step_rate > 0;
2893+
2894+
#if ENABLED(NONLINEAR_EXTRUSION)
2895+
if (forward_e && ANY_AXIS_MOVES(current_block)) {
2896+
// Maximum polynomial value is just above 1, like 1.05..1.2, less than 2 anyway, so we can use 30 bits for fractional part
2897+
int32_t vd_q30 = ne_q30.A*step_rate*step_rate + ne_q30.B*step_rate;
2898+
NOLESS(vd_q30, 0);
2899+
step_rate = (int64_t(step_rate) * (ne_q30.C + vd_q30)) >> 30;
2900+
}
2901+
#endif
2902+
2903+
la_interval = calc_timer_interval(uint32_t(ABS(step_rate)));
28952904
if (forward_e != motor_direction(E_AXIS)) {
28962905
last_direction_bits.toggle(E_AXIS);
28972906
count_direction.e = -count_direction.e;

Marlin/src/module/stepper.h

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ constexpr ena_mask_t enable_overlap[] = {
147147
TERN0(INPUT_SHAPING_Z, _ISDMF[Z_AXIS] * _ISDASU[Z_AXIS]);
148148
#if defined(__AVR__) || !defined(ADAPTIVE_STEP_SMOOTHING)
149149
// min_step_isr_frequency is known at compile time on AVRs and any reduction in SRAM is welcome
150-
template<unsigned int INDEX=DISTINCT_AXES> constexpr float max_isr_rate() {
150+
template<int INDEX=DISTINCT_AXES> constexpr float max_isr_rate() {
151151
return _MAX(_ISDMF[ALIM(INDEX - 1, _ISDMF)] * _ISDASU[ALIM(INDEX - 1, _ISDASU)], max_isr_rate<INDEX - 1>());
152152
}
153153
template<> constexpr float max_isr_rate<0>() {
@@ -285,7 +285,12 @@ constexpr ena_mask_t enable_overlap[] = {
285285

286286
#if ENABLED(NONLINEAR_EXTRUSION)
287287
typedef struct { float A, B, C; void reset() { A = B = 0.0f; C = 1.0f; } } ne_coeff_t;
288-
typedef struct { int32_t A, B, C; } ne_fix_t;
288+
#if DISABLED(SMOOTH_LIN_ADVANCE)
289+
#define NONLINEAR_EXTRUSION_Q24 1
290+
typedef struct { int32_t A, B, C; } ne_q24_t;
291+
#else
292+
typedef struct { int32_t A, B, C; } ne_q30_t;
293+
#endif
289294
#endif
290295

291296
//
@@ -343,6 +348,11 @@ class Stepper {
343348

344349
#if ENABLED(NONLINEAR_EXTRUSION)
345350
static ne_coeff_t ne;
351+
#if NONLINEAR_EXTRUSION_Q24
352+
static ne_q24_t ne_q24;
353+
#else
354+
static ne_q30_t ne_q30;
355+
#endif
346356
#endif
347357

348358
#if ENABLED(ADAPTIVE_STEP_SMOOTHING_TOGGLE)
@@ -467,10 +477,9 @@ class Stepper {
467477
#endif
468478
#endif
469479

470-
#if ENABLED(NONLINEAR_EXTRUSION)
480+
#if NONLINEAR_EXTRUSION_Q24
471481
static int32_t ne_edividend;
472-
static uint32_t ne_scale;
473-
static ne_fix_t ne_fix;
482+
static uint32_t ne_scale_q24;
474483
#endif
475484

476485
#if ENABLED(BABYSTEPPING)
@@ -531,7 +540,7 @@ class Stepper {
531540
// The Linear advance ISR phase
532541
static void advance_isr();
533542
#if ENABLED(SMOOTH_LIN_ADVANCE)
534-
static void set_la_interval(const int32_t rate);
543+
static void set_la_interval(int32_t step_rate);
535544
static hal_timer_t smooth_lin_adv_isr();
536545
#endif
537546
#endif
@@ -738,8 +747,10 @@ class Stepper {
738747
// Evaluate axis motions and set bits in axis_did_move
739748
static void set_axis_moved_for_current_block();
740749

741-
#if ENABLED(NONLINEAR_EXTRUSION)
742-
static void calc_nonlinear_e(uint32_t step_rate);
750+
#if NONLINEAR_EXTRUSION_Q24
751+
static void calc_nonlinear_e(const uint32_t step_rate);
752+
#else
753+
static void calc_nonlinear_e(const uint32_t) {}
743754
#endif
744755

745756
#if ENABLED(S_CURVE_ACCELERATION)

README-PT-BR.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<a href="https://fosstodon.org/@marlinfirmware"><img alt="Siga MarlinFirmware no Mastodon" src="https://img.shields.io/mastodon/follow/109450200866020466?domain=https%3A%2F%2Ffosstodon.org&logoColor=%2300B&style=social"></a>
1515
</p>
1616

17-
Documentação adicional pode ser encontrada na [Página Inicial do Marlin](//marlinfw.org/).
17+
Documentação adicional pode ser encontrada na [Página Inicial do Marlin](//marlinfw.org/).
1818
Por favor, teste este firmware e nos avise se encontrar algum problema. Voluntários estão prontos para ajudar!
1919

2020
## Branch de Correções do Marlin 2.1

0 commit comments

Comments
 (0)