Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using map of minimum speed in ramp increments' computations. #333

Open
wants to merge 2 commits into
base: BartsFixedIntervalRamp
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 31 additions & 23 deletions FluidNC/src/Spindles/PWMSpindle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
// 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);
}
}

Expand Down
1 change: 1 addition & 0 deletions FluidNC/src/Spindles/Spindle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down