From 0c262b03c28b0308c151f165e19084b0ed6858a2 Mon Sep 17 00:00:00 2001 From: Simen Svale Skogsrud Date: Tue, 25 Jan 2011 14:02:34 +0100 Subject: [PATCH] eliminated step down-counter in stepper.c --- stepper.c | 14 ++++++-------- stepper_plan.c | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/stepper.c b/stepper.c index 71b9453..87fce21 100644 --- a/stepper.c +++ b/stepper.c @@ -46,8 +46,7 @@ uint8_t out_bits; // The next stepping-bits to be output int32_t counter_x, counter_y, counter_z; // counter variables for the bresenham line tracer -uint32_t step_events_left; // The number of step events left to complete the current_block -uint32_t step_event_count; // The count of step events executed in the current block +uint32_t step_events_completed; // The count of step events executed in the current block volatile int busy; // TRUE when SIG_OUTPUT_COMPARE1A is being serviced. Used to avoid retriggering that handler. uint32_t cycles_per_step_event; // The number of machine cycles between each step event @@ -85,10 +84,10 @@ inline void trapezoid_generator_reset() { // current_block stays untouched by outside handlers for the duration of this function call. inline void trapezoid_generator_tick() { if (current_block) { - if (step_event_count < current_block->accelerate_until) { + if (step_events_completed < current_block->accelerate_until) { trapezoid_rate += current_block->rate_delta; set_step_events_per_minute(trapezoid_rate); - } else if (step_event_count > current_block->decelerate_after) { + } else if (step_events_completed > current_block->decelerate_after) { // NOTE: We will only reduce speed if the result will be > 0. This catches small // rounding errors that might leave steps hanging after the last trapezoid tick. if(current_block->rate_delta < trapezoid_rate) { @@ -143,8 +142,7 @@ SIGNAL(SIG_OUTPUT_COMPARE1A) counter_x = -(current_block->step_event_count >> 1); counter_y = counter_x; counter_z = counter_x; - step_events_left = current_block->step_event_count; - step_event_count = 0; + step_events_completed = 0; } else { DISABLE_STEPPER_DRIVER_INTERRUPT(); } @@ -168,8 +166,8 @@ SIGNAL(SIG_OUTPUT_COMPARE1A) counter_z -= current_block->step_event_count; } // If current block is finished, reset pointer - step_events_left -= 1; step_event_count += 1; - if (step_events_left <= 0) { + step_events_completed += 1; + if (step_events_completed >= current_block->step_event_count) { current_block = NULL; // move the block buffer tail to the next instruction block_buffer_tail = (block_buffer_tail + 1) % BLOCK_BUFFER_SIZE; diff --git a/stepper_plan.c b/stepper_plan.c index f9aa18c..3299f63 100644 --- a/stepper_plan.c +++ b/stepper_plan.c @@ -91,9 +91,9 @@ void calculate_trapezoid_for_block(struct Block *block, double entry_factor, dou // have to use intersection_distance() to calculate when to abort acceleration and start braking // in order to reach the final_rate exactly at the end of this block. if (plateau_steps < 0) { - plateau_steps = 0; accelerate_steps = ceil( intersection_distance(block->initial_rate, final_rate, acceleration_per_minute, block->step_event_count)); + plateau_steps = block->step_event_count-(2*accelerate_steps); } block->accelerate_until = accelerate_steps;