M221: use 256 for 100% flow internally for faster math

The flow rate is given as a percentage which is kept as
100 = 100% internally. But this means we must divide by 100 for
every movement which can be expensive.  Convert the value to
256 = 100% so the compiler can optimize the division to a
byte-shift.

Also, avoid the math altogether in the normal case where the
flow rate is already 100% and no change is required.

Note: This also requires an increase in the size of e_multiplier
to 16 bits so values >= 100% can be stored.  Previously flow
rates only up to 255% (2.5x) were supported which may have
surprised some users.  Now the flow rate can be as high as
10000% (100x), at least internally.
This commit is contained in:
Phil Hord 2016-07-01 15:32:51 -04:00 committed by Markus Hitter
parent 9b010e65ee
commit 51321910bc
3 changed files with 8 additions and 5 deletions

8
dda.c
View File

@ -111,7 +111,7 @@ void dda_init(void) {
if (startpoint.F == 0)
startpoint.F = next_target.target.F = SEARCH_FEEDRATE_Z;
if (startpoint.e_multiplier == 0)
startpoint.e_multiplier = next_target.target.e_multiplier = 100;
startpoint.e_multiplier = next_target.target.e_multiplier = 256;
}
/*! Distribute a new startpoint to DDA's internal structures without any movement.
@ -219,9 +219,11 @@ void dda_create(DDA *dda, TARGET *target) {
steps[E] = um_to_steps(target->axis[E], E);
// Apply extrusion multiplier.
if (target->e_multiplier != 256) {
steps[E] *= target->e_multiplier;
steps[E] += 50;
steps[E] /= 100;
steps[E] += 128;
steps[E] /= 256;
}
if ( ! target->e_relative) {
int32_t delta_steps;

2
dda.h
View File

@ -41,7 +41,7 @@ typedef struct {
axes_int32_t axis;
uint32_t F;
uint8_t e_multiplier;
uint16_t e_multiplier;
uint8_t e_relative :1; ///< bool: e axis relative? Overrides all_relative
} TARGET;

View File

@ -797,7 +797,8 @@ void process_gcode_command() {
//? --- M221: Control the extruders flow ---
if ( ! next_target.seen_S)
break;
next_target.target.e_multiplier = next_target.S;
// Scale 100% = 256
next_target.target.e_multiplier = (next_target.S * 64 + 12) / 25;
break;
#ifdef DEBUG