|
@@ -71,8 +71,7 @@ static dda_isteps_t
|
|
counter_z,
|
|
counter_z,
|
|
counter_e;
|
|
counter_e;
|
|
volatile dda_usteps_t step_events_completed; // The number of step events executed in the current block
|
|
volatile dda_usteps_t step_events_completed; // The number of step events executed in the current block
|
|
-static int32_t acceleration_time, deceleration_time;
|
|
|
|
-//static unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
|
|
|
|
|
|
+static uint32_t acceleration_time, deceleration_time;
|
|
static uint16_t acc_step_rate; // needed for deccelaration start point
|
|
static uint16_t acc_step_rate; // needed for deccelaration start point
|
|
static uint8_t step_loops;
|
|
static uint8_t step_loops;
|
|
static uint16_t OCR1A_nominal;
|
|
static uint16_t OCR1A_nominal;
|
|
@@ -234,7 +233,7 @@ void invert_z_endstop(bool endstop_invert)
|
|
// The trapezoid is the shape the speed curve over time. It starts at block->initial_rate, accelerates
|
|
// The trapezoid is the shape the speed curve over time. It starts at block->initial_rate, accelerates
|
|
// first block->accelerate_until step_events_completed, then keeps going at constant speed until
|
|
// first block->accelerate_until step_events_completed, then keeps going at constant speed until
|
|
// step_events_completed reaches block->decelerate_after after which it decelerates until the trapezoid generator is reset.
|
|
// step_events_completed reaches block->decelerate_after after which it decelerates until the trapezoid generator is reset.
|
|
-// The slope of acceleration is calculated with the leib ramp alghorithm.
|
|
|
|
|
|
+// The slope of acceleration is calculated using v = u + at where t is the accumulated timer values of the steps so far.
|
|
|
|
|
|
// "The Stepper Driver Interrupt" - This timer interrupt is the workhorse.
|
|
// "The Stepper Driver Interrupt" - This timer interrupt is the workhorse.
|
|
// It pops blocks from the block_buffer and executes them by pulsing the stepper pins appropriately.
|
|
// It pops blocks from the block_buffer and executes them by pulsing the stepper pins appropriately.
|
|
@@ -788,7 +787,7 @@ FORCE_INLINE void isr() {
|
|
// 25.12us for acceleration / deceleration.
|
|
// 25.12us for acceleration / deceleration.
|
|
{
|
|
{
|
|
//WRITE_NC(LOGIC_ANALYZER_CH1, true);
|
|
//WRITE_NC(LOGIC_ANALYZER_CH1, true);
|
|
- if (step_events_completed.wide <= (unsigned long int)current_block->accelerate_until) {
|
|
|
|
|
|
+ if (step_events_completed.wide <= current_block->accelerate_until) {
|
|
// v = t * a -> acc_step_rate = acceleration_time * current_block->acceleration_rate
|
|
// v = t * a -> acc_step_rate = acceleration_time * current_block->acceleration_rate
|
|
MultiU24X24toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate);
|
|
MultiU24X24toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate);
|
|
acc_step_rate += uint16_t(current_block->initial_rate);
|
|
acc_step_rate += uint16_t(current_block->initial_rate);
|
|
@@ -809,14 +808,21 @@ FORCE_INLINE void isr() {
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
}
|
|
}
|
|
- else if (step_events_completed.wide > (unsigned long int)current_block->decelerate_after) {
|
|
|
|
|
|
+ else if (step_events_completed.wide > current_block->decelerate_after) {
|
|
uint16_t step_rate;
|
|
uint16_t step_rate;
|
|
MultiU24X24toH16(step_rate, deceleration_time, current_block->acceleration_rate);
|
|
MultiU24X24toH16(step_rate, deceleration_time, current_block->acceleration_rate);
|
|
- step_rate = acc_step_rate - step_rate; // Decelerate from aceleration end point.
|
|
|
|
- if ((step_rate & 0x8000) || step_rate < uint16_t(current_block->final_rate)) {
|
|
|
|
- // Result is negative or too small.
|
|
|
|
- step_rate = uint16_t(current_block->final_rate);
|
|
|
|
|
|
+
|
|
|
|
+ if (step_rate > acc_step_rate) { // Check step_rate stays positive
|
|
|
|
+ step_rate = uint16_t(current_block->final_rate);
|
|
}
|
|
}
|
|
|
|
+ else {
|
|
|
|
+ step_rate = acc_step_rate - step_rate; // Decelerate from acceleration end point.
|
|
|
|
+
|
|
|
|
+ // lower limit
|
|
|
|
+ if (step_rate < current_block->final_rate)
|
|
|
|
+ step_rate = uint16_t(current_block->final_rate);
|
|
|
|
+ }
|
|
|
|
+
|
|
// Step_rate to timer interval.
|
|
// Step_rate to timer interval.
|
|
uint16_t timer = calc_timer(step_rate, step_loops);
|
|
uint16_t timer = calc_timer(step_rate, step_loops);
|
|
_NEXT_ISR(timer);
|
|
_NEXT_ISR(timer);
|
|
@@ -824,7 +830,7 @@ FORCE_INLINE void isr() {
|
|
|
|
|
|
#ifdef LIN_ADVANCE
|
|
#ifdef LIN_ADVANCE
|
|
if (current_block->use_advance_lead) {
|
|
if (current_block->use_advance_lead) {
|
|
- if (step_events_completed.wide <= (unsigned long int)current_block->decelerate_after + step_loops) {
|
|
|
|
|
|
+ if (step_events_completed.wide <= current_block->decelerate_after + step_loops) {
|
|
target_adv_steps = current_block->final_adv_steps;
|
|
target_adv_steps = current_block->final_adv_steps;
|
|
la_state = ADV_INIT | ADV_ACC_VARY;
|
|
la_state = ADV_INIT | ADV_ACC_VARY;
|
|
if (e_extruding && current_adv_steps < target_adv_steps)
|
|
if (e_extruding && current_adv_steps < target_adv_steps)
|