From 8efe84d25d4d2f9b3910db475735aa0cd0931123 Mon Sep 17 00:00:00 2001 From: Rob Giseburt Date: Tue, 19 Nov 2019 13:02:57 -0600 Subject: [PATCH] Make dwell/spindle spin-up feedhold-aware --- g2core/stepper.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/g2core/stepper.cpp b/g2core/stepper.cpp index 93140694..4340d64e 100644 --- a/g2core/stepper.cpp +++ b/g2core/stepper.cpp @@ -74,12 +74,22 @@ exec_timer_type exec_timer; // triggers calculation of next+1 stepper se fwd_plan_timer_type fwd_plan_timer; // triggers planning of next block // SystickEvent for handling dwells (must be registered before it is active) -Motate::SysTickEvent dwell_systick_event {[&] { - if (spindle_speed_ramp_from_systick() && (--st_run.dwell_ticks_downcount == 0)) { - SysTickTimer.unregisterEvent(&dwell_systick_event); - _load_move(); // load the next move at the current interrupt level - } -}, nullptr}; +Motate::SysTickEvent dwell_systick_event{ + [&] { + // we're either in a dewll or a spindle speed ramp "dwell" + // in either case, if a feedhold comes in, we need to bail, and since the dwell *is* the motion + // move the state machine along from here + if (cm->hold_state == FEEDHOLD_SYNC) { + st_run.dwell_ticks_downcount = 1; // this'll decerement to zero shortly + cm->hold_state = FEEDHOLD_MOTION_STOPPED; + } + if (spindle_speed_ramp_from_systick() && (--st_run.dwell_ticks_downcount == 0)) { + st_run.dwell_ticks_downcount = 0; // in the case of stop==true, this is needed + SysTickTimer.unregisterEvent(&dwell_systick_event); + _load_move(); // load the next move at the current interrupt level + } + }, + nullptr}; /* Note on the above: It's a lambda function creating a closure function.