// 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;
// 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<<X_AXIS); }
if (target[Y_AXIS] < position[Y_AXIS]) { block->direction_bits |= (1<<Y_AXIS); }
else {
long acc_dist = estimate_acceleration_distance(0, block->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;
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
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;
#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
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.
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.
if (counter_e > 0) {
counter_e -= current_block->step_event_count;
if ((out_bits & (1<<E_AXIS)) != 0) { // - direction
- CRITICAL_SECTION_START;
e_steps--;
- CRITICAL_SECTION_END;
}
else {
- CRITICAL_SECTION_START;
e_steps++;
- CRITICAL_SECTION_END;
}
}
- // Do E steps + advance steps
- e_steps += ((advance >> 16) - old_advance);
- old_advance = advance >> 16;
#endif //ADVANCE
counter_x += current_block->steps_x;
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) {
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 {
// 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;) {
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);