Skip to content

Commit

Permalink
Use nominal rate for phase calculations
Browse files Browse the repository at this point in the history
The local interval calculated by advance_spread() might oscillate too
much in narrow intervals.
  • Loading branch information
wavexx committed Jul 12, 2020
1 parent f1efce7 commit c08f37d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Firmware/stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -883,11 +883,13 @@ FORCE_INLINE void isr() {
advance_spread(main_Rate);
if (LA_phase >= 0) {
if (step_loops == e_step_loops)
LA_phase = (eISR_Rate > main_Rate);
LA_phase = (current_block->advance_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));
auto adv_rate_n = fastdiv(current_block->advance_rate, step_loops);
auto main_rate_n = fastdiv(main_Rate, e_step_loops);
LA_phase = (adv_rate_n > main_rate_n);
}
}
}
Expand Down

0 comments on commit c08f37d

Please sign in to comment.