eliminated step down-counter in stepper.c
This commit is contained in:
parent
5977bd3748
commit
0c262b03c2
14
stepper.c
14
stepper.c
@ -46,8 +46,7 @@ uint8_t out_bits; // The next stepping-bits to be output
|
|||||||
int32_t counter_x,
|
int32_t counter_x,
|
||||||
counter_y,
|
counter_y,
|
||||||
counter_z; // counter variables for the bresenham line tracer
|
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_events_completed; // The count of step events executed in the current block
|
||||||
uint32_t step_event_count; // 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.
|
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
|
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.
|
// current_block stays untouched by outside handlers for the duration of this function call.
|
||||||
inline void trapezoid_generator_tick() {
|
inline void trapezoid_generator_tick() {
|
||||||
if (current_block) {
|
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;
|
trapezoid_rate += current_block->rate_delta;
|
||||||
set_step_events_per_minute(trapezoid_rate);
|
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
|
// 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.
|
// rounding errors that might leave steps hanging after the last trapezoid tick.
|
||||||
if(current_block->rate_delta < trapezoid_rate) {
|
if(current_block->rate_delta < trapezoid_rate) {
|
||||||
@ -143,8 +142,7 @@ SIGNAL(SIG_OUTPUT_COMPARE1A)
|
|||||||
counter_x = -(current_block->step_event_count >> 1);
|
counter_x = -(current_block->step_event_count >> 1);
|
||||||
counter_y = counter_x;
|
counter_y = counter_x;
|
||||||
counter_z = counter_x;
|
counter_z = counter_x;
|
||||||
step_events_left = current_block->step_event_count;
|
step_events_completed = 0;
|
||||||
step_event_count = 0;
|
|
||||||
} else {
|
} else {
|
||||||
DISABLE_STEPPER_DRIVER_INTERRUPT();
|
DISABLE_STEPPER_DRIVER_INTERRUPT();
|
||||||
}
|
}
|
||||||
@ -168,8 +166,8 @@ SIGNAL(SIG_OUTPUT_COMPARE1A)
|
|||||||
counter_z -= current_block->step_event_count;
|
counter_z -= current_block->step_event_count;
|
||||||
}
|
}
|
||||||
// If current block is finished, reset pointer
|
// If current block is finished, reset pointer
|
||||||
step_events_left -= 1; step_event_count += 1;
|
step_events_completed += 1;
|
||||||
if (step_events_left <= 0) {
|
if (step_events_completed >= current_block->step_event_count) {
|
||||||
current_block = NULL;
|
current_block = NULL;
|
||||||
// move the block buffer tail to the next instruction
|
// move the block buffer tail to the next instruction
|
||||||
block_buffer_tail = (block_buffer_tail + 1) % BLOCK_BUFFER_SIZE;
|
block_buffer_tail = (block_buffer_tail + 1) % BLOCK_BUFFER_SIZE;
|
||||||
|
@ -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
|
// 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.
|
// in order to reach the final_rate exactly at the end of this block.
|
||||||
if (plateau_steps < 0) {
|
if (plateau_steps < 0) {
|
||||||
plateau_steps = 0;
|
|
||||||
accelerate_steps = ceil(
|
accelerate_steps = ceil(
|
||||||
intersection_distance(block->initial_rate, final_rate, acceleration_per_minute, block->step_event_count));
|
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;
|
block->accelerate_until = accelerate_steps;
|
||||||
|
Loading…
Reference in New Issue
Block a user