From 3857c7d88f1431b2cdaf02d93d4e1750dafd264f Mon Sep 17 00:00:00 2001 From: TheAntTeam Date: Sat, 12 Mar 2022 17:08:32 +0100 Subject: [PATCH 1/2] Using map of minimum speed in ramp increments'computations. --- FluidNC/src/Spindles/PWMSpindle.cpp | 12 ++++++------ FluidNC/src/Spindles/Spindle.h | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/FluidNC/src/Spindles/PWMSpindle.cpp b/FluidNC/src/Spindles/PWMSpindle.cpp index c627c441b..5971c78b9 100644 --- a/FluidNC/src/Spindles/PWMSpindle.cpp +++ b/FluidNC/src/Spindles/PWMSpindle.cpp @@ -57,10 +57,10 @@ namespace Spindles { _use_pwm_ramping = false; } else { // TODO: Do we want to deal with a min speed? - _ramp_up_dev_increment = mapSpeed(maxSpeed()) / (_spinup_ms / _ramp_interval); - _ramp_down_dev_increment = mapSpeed(maxSpeed()) / (_spindown_ms / _ramp_interval); - //log_info("PWM Ramping Maxspeed:" << maxSpeed() << " spinup incr:" << _ramp_up_dev_increment - //<< " spindown incr:" << _ramp_down_dev_increment); + _ramp_up_dev_increment = (mapSpeed(maxSpeed()) - mapSpeed(minSpeed())) / (_spinup_ms / _ramp_interval); + _ramp_down_dev_increment = (mapSpeed(maxSpeed()) - mapSpeed(minSpeed())) / (_spindown_ms / _ramp_interval); + // log_info("PWM Ramping Maxspeed:" << maxSpeed() << " spinup incr:" << _ramp_up_dev_increment + // << " spindown incr:" << _ramp_down_dev_increment); } } @@ -194,7 +194,7 @@ namespace Spindles { uint32_t next_duty = _current_duty; // this is the value that increments in this function bool spinup = (target_duty > _current_duty); - //log_info("Ramp duty from:" << _current_duty << " to:" << target_duty); + // log_info("Ramp duty from:" << _current_duty << " to:" << target_duty); while ((spinup && next_duty < target_duty) || (!spinup && (next_duty > target_duty))) { if (spinup) { @@ -210,7 +210,7 @@ namespace Spindles { next_duty = target_duty; } } - + set_output(next_duty); _current_duty = next_duty; if (next_duty == target_duty) { diff --git a/FluidNC/src/Spindles/Spindle.h b/FluidNC/src/Spindles/Spindle.h index eede1a3d0..78e947a60 100644 --- a/FluidNC/src/Spindles/Spindle.h +++ b/FluidNC/src/Spindles/Spindle.h @@ -30,6 +30,7 @@ namespace Spindles { bool _defaultedSpeeds; uint32_t offSpeed() { return _speeds[0].offset; } uint32_t maxSpeed() { return _speeds[_speeds.size() - 1].speed; } + uint32_t minSpeed() { return _speeds[0].speed; } uint32_t mapSpeed(SpindleSpeed speed); void setupSpeeds(uint32_t max_dev_speed); void shelfSpeeds(SpindleSpeed min, SpindleSpeed max); From 615a92db5e46b5fd7c6984b81ca30de55f52e309 Mon Sep 17 00:00:00 2001 From: TheAntTeam Date: Sat, 12 Mar 2022 21:53:37 +0100 Subject: [PATCH 2/2] Tentative fix of unwanted initial ramping. --- FluidNC/src/Spindles/PWMSpindle.cpp | 44 +++++++++++++++++------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/FluidNC/src/Spindles/PWMSpindle.cpp b/FluidNC/src/Spindles/PWMSpindle.cpp index 5971c78b9..e0ca913cc 100644 --- a/FluidNC/src/Spindles/PWMSpindle.cpp +++ b/FluidNC/src/Spindles/PWMSpindle.cpp @@ -190,33 +190,41 @@ namespace Spindles { void PWM::ramp_speed(uint32_t target_rpm) { // speed is given, but we need to work in dev_speed - uint32_t target_duty = mapSpeed(target_rpm); + uint32_t target_duty = mapSpeed(target_rpm); uint32_t next_duty = _current_duty; // this is the value that increments in this function + uint32_t min_duty = mapSpeed(_speeds[0].speed); bool spinup = (target_duty > _current_duty); // log_info("Ramp duty from:" << _current_duty << " to:" << target_duty); - while ((spinup && next_duty < target_duty) || (!spinup && (next_duty > target_duty))) { - if (spinup) { - if (next_duty + _ramp_up_dev_increment < target_duty) { - next_duty += _ramp_up_dev_increment; + if (next_duty < min_duty) { + set_output(min_duty); + _current_duty = min_duty; + // log_info("Force duty:" << _speeds[0].speed << " mapped:" << mapSpeed(_speeds[0].speed)); + return; + } else { + while ((spinup && next_duty < target_duty) || (!spinup && (next_duty > target_duty))) { + if (spinup) { + if (next_duty + _ramp_up_dev_increment < target_duty) { + next_duty += _ramp_up_dev_increment; + } else { + next_duty = target_duty; + } } else { - next_duty = target_duty; + if ((next_duty > _ramp_down_dev_increment) && (next_duty - _ramp_down_dev_increment > target_duty)) { // is is safe to subtract? + next_duty -= _ramp_down_dev_increment; + } else { + next_duty = target_duty; + } } - } else { - if ((next_duty > _ramp_down_dev_increment) && (next_duty - _ramp_down_dev_increment > target_duty)) { // is is safe to subtract? - next_duty -= _ramp_down_dev_increment; - } else { - next_duty = target_duty; + // log_info("Actual duty:" << next_duty << " to:" << target_duty); + set_output(next_duty); + _current_duty = next_duty; + if (next_duty == target_duty) { + return; } + delay_ms(_ramp_interval); } - - set_output(next_duty); - _current_duty = next_duty; - if (next_duty == target_duty) { - return; - } - delay_ms(_ramp_interval); } }