Merge pull request #4852 from esenapaj/Fix-for-advance-extrusion-algorithms

Fix for advance extrusion algorithms
This commit is contained in:
Scott Lahteine 2016-09-20 11:33:14 -05:00 committed by GitHub
commit ba94c89e21
2 changed files with 23 additions and 39 deletions

View file

@ -82,10 +82,10 @@ unsigned int Stepper::cleaning_buffer_counter = 0;
bool Stepper::locked_z2_motor = false; bool Stepper::locked_z2_motor = false;
#endif #endif
long Stepper::counter_X = 0, long Stepper::counter_X = 0,
Stepper::counter_Y = 0, Stepper::counter_Y = 0,
Stepper::counter_Z = 0, Stepper::counter_Z = 0,
Stepper::counter_E = 0; Stepper::counter_E = 0;
volatile uint32_t Stepper::step_events_completed = 0; // The number of step events executed in the current block volatile uint32_t Stepper::step_events_completed = 0; // The number of step events executed in the current block
@ -95,17 +95,17 @@ volatile uint32_t Stepper::step_events_completed = 0; // The number of step even
volatile unsigned char Stepper::eISR_Rate = 200; // Keep the ISR at a low rate until needed volatile unsigned char Stepper::eISR_Rate = 200; // Keep the ISR at a low rate until needed
#if ENABLED(LIN_ADVANCE) #if ENABLED(LIN_ADVANCE)
volatile int Stepper::e_steps[E_STEPPERS]; volatile long Stepper::e_steps[E_STEPPERS];
int Stepper::extruder_advance_k = LIN_ADVANCE_K, int Stepper::extruder_advance_k = LIN_ADVANCE_K,
Stepper::final_estep_rate, Stepper::final_estep_rate,
Stepper::current_estep_rate[E_STEPPERS], Stepper::current_estep_rate[E_STEPPERS],
Stepper::current_adv_steps[E_STEPPERS]; Stepper::current_adv_steps[E_STEPPERS];
#else #else
long Stepper::e_steps[E_STEPPERS], long Stepper::e_steps[E_STEPPERS],
Stepper::final_advance = 0, Stepper::final_advance = 0,
Stepper::old_advance = 0, Stepper::old_advance = 0,
Stepper::advance_rate, Stepper::advance_rate,
Stepper::advance; Stepper::advance;
#endif #endif
#endif #endif
@ -299,16 +299,14 @@ void Stepper::set_directions() {
SET_STEP_DIR(Z); // C SET_STEP_DIR(Z); // C
#endif #endif
#if DISABLED(ADVANCE) if (motor_direction(E_AXIS)) {
if (motor_direction(E_AXIS)) { REV_E_DIR();
REV_E_DIR(); count_direction[E_AXIS] = -1;
count_direction[E_AXIS] = -1; }
} else {
else { NORM_E_DIR();
NORM_E_DIR(); count_direction[E_AXIS] = 1;
count_direction[E_AXIS] = 1; }
}
#endif //!ADVANCE
} }
// "The Stepper Driver Interrupt" - This timer interrupt is the workhorse. // "The Stepper Driver Interrupt" - This timer interrupt is the workhorse.
@ -683,29 +681,15 @@ void Stepper::isr() {
old_OCR0A += eISR_Rate; old_OCR0A += eISR_Rate;
OCR0A = old_OCR0A; OCR0A = old_OCR0A;
#define SET_E_STEP_DIR(INDEX) \
E## INDEX ##_DIR_WRITE(e_steps[INDEX] <= 0 ? INVERT_E## INDEX ##_DIR : !INVERT_E## INDEX ##_DIR)
#define START_E_PULSE(INDEX) \ #define START_E_PULSE(INDEX) \
if (e_steps[INDEX]) E## INDEX ##_STEP_WRITE(INVERT_E_STEP_PIN) if (e_steps[INDEX]) E## INDEX ##_STEP_WRITE(!INVERT_E_STEP_PIN)
#define STOP_E_PULSE(INDEX) \ #define STOP_E_PULSE(INDEX) \
if (e_steps[INDEX]) { \ if (e_steps[INDEX]) { \
e_steps[INDEX] <= 0 ? ++e_steps[INDEX] : --e_steps[INDEX]; \ e_steps[INDEX] <= 0 ? ++e_steps[INDEX] : --e_steps[INDEX]; \
E## INDEX ##_STEP_WRITE(!INVERT_E_STEP_PIN); \ E## INDEX ##_STEP_WRITE(INVERT_E_STEP_PIN); \
} }
SET_E_STEP_DIR(0);
#if E_STEPPERS > 1
SET_E_STEP_DIR(1);
#if E_STEPPERS > 2
SET_E_STEP_DIR(2);
#if E_STEPPERS > 3
SET_E_STEP_DIR(3);
#endif
#endif
#endif
// Step all E steppers that have steps // Step all E steppers that have steps
for (uint8_t i = 0; i < step_loops; i++) { for (uint8_t i = 0; i < step_loops; i++) {

View file

@ -113,13 +113,13 @@ class Stepper {
static unsigned char old_OCR0A; static unsigned char old_OCR0A;
static volatile unsigned char eISR_Rate; static volatile unsigned char eISR_Rate;
#if ENABLED(LIN_ADVANCE) #if ENABLED(LIN_ADVANCE)
static volatile int e_steps[E_STEPPERS]; static volatile long e_steps[E_STEPPERS];
static int extruder_advance_k; static int extruder_advance_k;
static int final_estep_rate; static int final_estep_rate;
static int current_estep_rate[E_STEPPERS]; // Actual extruder speed [steps/s] static int current_estep_rate[E_STEPPERS]; // Actual extruder speed [steps/s]
static int current_adv_steps[E_STEPPERS]; // The amount of current added esteps due to advance. static int current_adv_steps[E_STEPPERS]; // The amount of current added esteps due to advance.
// i.e., the current amount of pressure applied // i.e., the current amount of pressure applied
// to the spring (=filament). // to the spring (=filament).
#else #else
static long e_steps[E_STEPPERS]; static long e_steps[E_STEPPERS];
static long advance_rate, advance, final_advance; static long advance_rate, advance, final_advance;