From af22e9cd38c9684bd64cc7307137abe9efbba6d0 Mon Sep 17 00:00:00 2001 From: Erik van der Zalm Date: Sun, 4 Dec 2011 19:54:07 +0100 Subject: [PATCH 1/3] Some advance modifications --- Marlin/Configuration.h | 4 ++-- Marlin/planner.cpp | 12 +++++++++--- Marlin/stepper.cpp | 43 +++++++++++++++++++++++++++++------------- 3 files changed, 41 insertions(+), 18 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 066e61005..08bf6ea9e 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -278,8 +278,8 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th #ifdef ADVANCE #define EXTRUDER_ADVANCE_K .3 - #define D_FILAMENT 1.7 - #define STEPS_MM_E 65 + #define D_FILAMENT 2.85 + #define STEPS_MM_E 836 #define EXTRUTION_AREA (0.25 * D_FILAMENT * D_FILAMENT * 3.14159) #define STEPS_PER_CUBIC_MM_E (axis_steps_per_unit[E_AXIS]/ EXTRUTION_AREA) diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp index 1674fcc7d..7a7a35db4 100644 --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@ -198,7 +198,6 @@ void calculate_trapezoid_for_block(block_t *block, float entry_factor, float exi // block->accelerate_until = accelerate_steps; // block->decelerate_after = accelerate_steps+plateau_steps; - CRITICAL_SECTION_START; // Fill variables used by the stepper in a critical section if(block->busy == false) { // Don't update variables if block is busy. block->accelerate_until = accelerate_steps; @@ -482,7 +481,7 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa // Bail if this is a zero-length block if (block->step_event_count <=dropsegments) { return; }; - // Compute direction bits for this block + // Compute direction bits for this block block->direction_bits = 0; if (target[X_AXIS] < position[X_AXIS]) { block->direction_bits |= (1<direction_bits |= (1<nominal_rate, block->acceleration_st); float advance = (STEPS_PER_CUBIC_MM_E * EXTRUDER_ADVANCE_K) * - (current_speed[E_AXIS] * current_speed[E_AXIS] * EXTRUTION_AREA * EXTRUTION_AREA / 3600.0)*65536; + (current_speed[E_AXIS] * current_speed[E_AXIS] * EXTRUTION_AREA * EXTRUTION_AREA)*256; block->advance = advance; if(acc_dist == 0) { block->advance_rate = 0; @@ -731,6 +730,13 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa block->advance_rate = advance / (float)acc_dist; } } + /* + SERIAL_ECHO_START; + SERIAL_ECHOPGM("advance :"); + SERIAL_ECHO(block->advance/256.0); + SERIAL_ECHOPGM("advance rate :"); + SERIAL_ECHOLN(block->advance_rate/256.0); + */ #endif // ADVANCE diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index 0eabc753d..bcad026fb 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -55,9 +55,9 @@ static long counter_x, // Counter variables for the bresenham line tracer volatile static unsigned long step_events_completed; // The number of step events executed in the current block #ifdef ADVANCE static long advance_rate, advance, final_advance = 0; - static short old_advance = 0; + static long old_advance = 0; #endif -static short e_steps; +static long e_steps; static unsigned char busy = false; // TRUE when SIG_OUTPUT_COMPARE1A is being serviced. Used to avoid retriggering that handler. static long acceleration_time, deceleration_time; //static unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate; @@ -253,6 +253,9 @@ FORCE_INLINE void trapezoid_generator_reset() { #ifdef ADVANCE advance = current_block->initial_advance; final_advance = current_block->final_advance; + // Do E steps + advance steps + e_steps += ((advance >>8) - old_advance); + old_advance = advance >>8; #endif deceleration_time = 0; // step_rate to timer interval @@ -260,6 +263,17 @@ FORCE_INLINE void trapezoid_generator_reset() { acceleration_time = calc_timer(acc_step_rate); OCR1A = acceleration_time; OCR1A_nominal = calc_timer(current_block->nominal_rate); + +// SERIAL_ECHO_START; +// SERIAL_ECHOPGM("advance :"); +// SERIAL_ECHO(current_block->advance/256.0); +// SERIAL_ECHOPGM("advance rate :"); +// SERIAL_ECHO(current_block->advance_rate/256.0); +// SERIAL_ECHOPGM("initial advance :"); +// SERIAL_ECHO(current_block->initial_advance/256.0); +// SERIAL_ECHOPGM("final advance :"); +// SERIAL_ECHOLN(current_block->final_advance/256.0); + } // "The Stepper Driver Interrupt" - This timer interrupt is the workhorse. @@ -382,6 +396,9 @@ ISR(TIMER1_COMPA_vect) count_direction[E_AXIS]=-1; } #endif //!ADVANCE + + + for(int8_t i=0; i < step_loops; i++) { // Take multiple steps per interrupt (For high speed moves) MSerial.checkRx(); // Check for serial chars. @@ -390,19 +407,12 @@ ISR(TIMER1_COMPA_vect) if (counter_e > 0) { counter_e -= current_block->step_event_count; if ((out_bits & (1<> 16) - old_advance); - old_advance = advance >> 16; #endif //ADVANCE counter_x += current_block->steps_x; @@ -461,6 +471,11 @@ ISR(TIMER1_COMPA_vect) for(int8_t i=0; i < step_loops; i++) { advance += advance_rate; } + //if(advance > current_block->advance) advance = current_block->advance; + // Do E steps + advance steps + e_steps += ((advance >>8) - old_advance); + old_advance = advance >>8; + #endif } else if (step_events_completed > current_block->decelerate_after) { @@ -485,8 +500,10 @@ ISR(TIMER1_COMPA_vect) for(int8_t i=0; i < step_loops; i++) { advance -= advance_rate; } - if(advance < final_advance) - advance = final_advance; + if(advance < final_advance) advance = final_advance; + // Do E steps + advance steps + e_steps += ((advance >>8) - old_advance); + old_advance = advance >>8; #endif //ADVANCE } else { @@ -507,7 +524,7 @@ ISR(TIMER1_COMPA_vect) // Timer 0 is shared with millies ISR(TIMER0_COMPA_vect) { - old_OCR0A += 25; // ~10kHz interrupt + old_OCR0A += 52; // ~10kHz interrupt (250000 / 26 = 9615kHz) OCR0A = old_OCR0A; // Set E direction (Depends on E direction + advance) for(unsigned char i=0; i<4;) { @@ -519,7 +536,7 @@ ISR(TIMER1_COMPA_vect) e_steps++; WRITE(E_STEP_PIN, HIGH); } - if (e_steps > 0) { + else if (e_steps > 0) { WRITE(E_DIR_PIN,!INVERT_E_DIR); e_steps--; WRITE(E_STEP_PIN, HIGH); From b99c49ec3b2f03e302926f5665dee7172df2deff Mon Sep 17 00:00:00 2001 From: Erik van der Zalm Date: Sun, 4 Dec 2011 20:17:21 +0100 Subject: [PATCH 2/3] Add option to only check endstop when homing --- Marlin/Configuration.h | 1 + Marlin/Marlin.pde | 5 ++ Marlin/stepper.cpp | 136 ++++++++++++++++++++++++----------------- Marlin/stepper.h | 2 + 4 files changed, 89 insertions(+), 55 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index f288aba97..e8b960f78 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -170,6 +170,7 @@ const bool Y_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. // For optos H21LOB set to true, for Mendel-Parts newer optos TCST2103 set to false +//#define ENDSTOPS_ONLY_FOR_HOMING // If defined the endstops will only be used for homing // For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1 #define X_ENABLE_ON 0 diff --git a/Marlin/Marlin.pde b/Marlin/Marlin.pde index 016702ee3..0a51b1edb 100644 --- a/Marlin/Marlin.pde +++ b/Marlin/Marlin.pde @@ -528,6 +528,8 @@ FORCE_INLINE void process_commands() saved_feedmultiply = feedmultiply; feedmultiply = 100; + enable_endstops(true); + for(int8_t i=0; i < NUM_AXIS; i++) { destination[i] = current_position[i]; } @@ -563,6 +565,9 @@ FORCE_INLINE void process_commands() HOMEAXIS(Z); current_position[2]=code_value()+add_homeing[2]; } + #ifdef ENDSTOPS_ONLY_FOR_HOMING + enable_endstops(false); + #endif feedrate = saved_feedrate; feedmultiply = saved_feedmultiply; diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index e25d179df..1f688ff90 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -79,6 +79,8 @@ static bool old_y_max_endstop=false; static bool old_z_min_endstop=false; static bool old_z_max_endstop=false; +static bool check_endstops = true; + volatile long count_position[NUM_AXIS] = { 0, 0, 0, 0}; volatile char count_direction[NUM_AXIS] = { 1, 1, 1, 1}; @@ -191,6 +193,11 @@ void endstops_hit_on_purpose() endstop_z_hit=false; } +void enable_endstops(bool check) +{ + check_endstops = check; +} + // __________________________ // /| |\ _________________ ^ // / | | \ /| |\ | @@ -309,82 +316,94 @@ ISR(TIMER1_COMPA_vect) if ((out_bits & (1< -1 - bool x_min_endstop=(READ(X_MIN_PIN) != X_ENDSTOPS_INVERTING); - if(x_min_endstop && old_x_min_endstop && (current_block->steps_x > 0)) { - endstops_trigsteps[X_AXIS] = count_position[X_AXIS]; - endstop_x_hit=true; - step_events_completed = current_block->step_event_count; - } - old_x_min_endstop = x_min_endstop; - #endif + if(check_endstops) { + #if X_MIN_PIN > -1 + bool x_min_endstop=(READ(X_MIN_PIN) != X_ENDSTOPS_INVERTING); + if(x_min_endstop && old_x_min_endstop && (current_block->steps_x > 0)) { + endstops_trigsteps[X_AXIS] = count_position[X_AXIS]; + endstop_x_hit=true; + step_events_completed = current_block->step_event_count; + } + old_x_min_endstop = x_min_endstop; + #endif + } } else { // +direction WRITE(X_DIR_PIN,!INVERT_X_DIR); count_direction[X_AXIS]=1; - #if X_MAX_PIN > -1 - bool x_max_endstop=(READ(X_MAX_PIN) != X_ENDSTOPS_INVERTING); - if(x_max_endstop && old_x_max_endstop && (current_block->steps_x > 0)){ - endstops_trigsteps[X_AXIS] = count_position[X_AXIS]; - endstop_x_hit=true; - step_events_completed = current_block->step_event_count; - } - old_x_max_endstop = x_max_endstop; - #endif + if(check_endstops) { + #if X_MAX_PIN > -1 + bool x_max_endstop=(READ(X_MAX_PIN) != X_ENDSTOPS_INVERTING); + if(x_max_endstop && old_x_max_endstop && (current_block->steps_x > 0)){ + endstops_trigsteps[X_AXIS] = count_position[X_AXIS]; + endstop_x_hit=true; + step_events_completed = current_block->step_event_count; + } + old_x_max_endstop = x_max_endstop; + #endif + } } if ((out_bits & (1< -1 - bool y_min_endstop=(READ(Y_MIN_PIN) != Y_ENDSTOPS_INVERTING); - if(y_min_endstop && old_y_min_endstop && (current_block->steps_y > 0)) { - endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS]; - endstop_y_hit=true; - step_events_completed = current_block->step_event_count; - } - old_y_min_endstop = y_min_endstop; - #endif + if(check_endstops) { + #if Y_MIN_PIN > -1 + bool y_min_endstop=(READ(Y_MIN_PIN) != Y_ENDSTOPS_INVERTING); + if(y_min_endstop && old_y_min_endstop && (current_block->steps_y > 0)) { + endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS]; + endstop_y_hit=true; + step_events_completed = current_block->step_event_count; + } + old_y_min_endstop = y_min_endstop; + #endif + } } else { // +direction WRITE(Y_DIR_PIN,!INVERT_Y_DIR); count_direction[Y_AXIS]=1; - #if Y_MAX_PIN > -1 - bool y_max_endstop=(READ(Y_MAX_PIN) != Y_ENDSTOPS_INVERTING); - if(y_max_endstop && old_y_max_endstop && (current_block->steps_y > 0)){ - endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS]; - endstop_y_hit=true; - step_events_completed = current_block->step_event_count; - } - old_y_max_endstop = y_max_endstop; - #endif + if(check_endstops) { + #if Y_MAX_PIN > -1 + bool y_max_endstop=(READ(Y_MAX_PIN) != Y_ENDSTOPS_INVERTING); + if(y_max_endstop && old_y_max_endstop && (current_block->steps_y > 0)){ + endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS]; + endstop_y_hit=true; + step_events_completed = current_block->step_event_count; + } + old_y_max_endstop = y_max_endstop; + #endif + } } if ((out_bits & (1< -1 - bool z_min_endstop=(READ(Z_MIN_PIN) != Z_ENDSTOPS_INVERTING); - if(z_min_endstop && old_z_min_endstop && (current_block->steps_z > 0)) { - endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; - endstop_z_hit=true; - step_events_completed = current_block->step_event_count; - } - old_z_min_endstop = z_min_endstop; - #endif + if(check_endstops) { + #if Z_MIN_PIN > -1 + bool z_min_endstop=(READ(Z_MIN_PIN) != Z_ENDSTOPS_INVERTING); + if(z_min_endstop && old_z_min_endstop && (current_block->steps_z > 0)) { + endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; + endstop_z_hit=true; + step_events_completed = current_block->step_event_count; + } + old_z_min_endstop = z_min_endstop; + #endif + } } else { // +direction WRITE(Z_DIR_PIN,!INVERT_Z_DIR); - count_direction[Z_AXIS]=1; - #if Z_MAX_PIN > -1 - bool z_max_endstop=(READ(Z_MAX_PIN) != Z_ENDSTOPS_INVERTING); - if(z_max_endstop && old_z_max_endstop && (current_block->steps_z > 0)) { - endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; - endstop_z_hit=true; - step_events_completed = current_block->step_event_count; - } - old_z_max_endstop = z_max_endstop; - #endif + count_direction[Z_AXIS]=1; + if(check_endstops) { + #if Z_MAX_PIN > -1 + bool z_max_endstop=(READ(Z_MAX_PIN) != Z_ENDSTOPS_INVERTING); + if(z_max_endstop && old_z_max_endstop && (current_block->steps_z > 0)) { + endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; + endstop_z_hit=true; + step_events_completed = current_block->step_event_count; + } + old_z_max_endstop = z_max_endstop; + #endif + } } #ifndef ADVANCE @@ -666,6 +685,13 @@ void st_init() e_steps = 0; TIMSK0 |= (1< Date: Sun, 4 Dec 2011 21:03:02 +0100 Subject: [PATCH 3/3] Update endstops only for homing. (use less resources when not used) --- Marlin/stepper.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index 1f688ff90..9cf8ddd17 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -87,7 +87,12 @@ volatile char count_direction[NUM_AXIS] = { 1, 1, 1, 1}; //=========================================================================== //=============================functions ============================ //=========================================================================== - + +#ifdef ENDSTOPS_ONLY_FOR_HOMING + #define CHECK_ENDSTOPS if(check_endstops) +#else + #define CHECK_ENDSTOPS +#endif // intRes = intIn1 * intIn2 >> 16 // uses: @@ -316,7 +321,8 @@ ISR(TIMER1_COMPA_vect) if ((out_bits & (1< -1 bool x_min_endstop=(READ(X_MIN_PIN) != X_ENDSTOPS_INVERTING); if(x_min_endstop && old_x_min_endstop && (current_block->steps_x > 0)) { @@ -331,7 +337,8 @@ ISR(TIMER1_COMPA_vect) else { // +direction WRITE(X_DIR_PIN,!INVERT_X_DIR); count_direction[X_AXIS]=1; - if(check_endstops) { + CHECK_ENDSTOPS + { #if X_MAX_PIN > -1 bool x_max_endstop=(READ(X_MAX_PIN) != X_ENDSTOPS_INVERTING); if(x_max_endstop && old_x_max_endstop && (current_block->steps_x > 0)){ @@ -347,7 +354,8 @@ ISR(TIMER1_COMPA_vect) if ((out_bits & (1< -1 bool y_min_endstop=(READ(Y_MIN_PIN) != Y_ENDSTOPS_INVERTING); if(y_min_endstop && old_y_min_endstop && (current_block->steps_y > 0)) { @@ -362,7 +370,8 @@ ISR(TIMER1_COMPA_vect) else { // +direction WRITE(Y_DIR_PIN,!INVERT_Y_DIR); count_direction[Y_AXIS]=1; - if(check_endstops) { + CHECK_ENDSTOPS + { #if Y_MAX_PIN > -1 bool y_max_endstop=(READ(Y_MAX_PIN) != Y_ENDSTOPS_INVERTING); if(y_max_endstop && old_y_max_endstop && (current_block->steps_y > 0)){ @@ -378,7 +387,8 @@ ISR(TIMER1_COMPA_vect) if ((out_bits & (1< -1 bool z_min_endstop=(READ(Z_MIN_PIN) != Z_ENDSTOPS_INVERTING); if(z_min_endstop && old_z_min_endstop && (current_block->steps_z > 0)) { @@ -393,7 +403,8 @@ ISR(TIMER1_COMPA_vect) else { // +direction WRITE(Z_DIR_PIN,!INVERT_Z_DIR); count_direction[Z_AXIS]=1; - if(check_endstops) { + CHECK_ENDSTOPS + { #if Z_MAX_PIN > -1 bool z_max_endstop=(READ(Z_MAX_PIN) != Z_ENDSTOPS_INVERTING); if(z_max_endstop && old_z_max_endstop && (current_block->steps_z > 0)) {