cleaned up stepper.c
This commit is contained in:
parent
3a7ae13003
commit
c8f71cf033
27
stepper.c
27
stepper.c
@ -46,13 +46,14 @@ 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_completed; // The count of step events executed in the current block
|
uint32_t step_events_completed; // The number 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.
|
||||||
|
|
||||||
|
// Variables used by the trapezoid generation
|
||||||
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
|
||||||
uint32_t trapezoid_tick_cycle_counter; // The cycles since last trapezoid_tick used to generate ticks without
|
uint32_t trapezoid_tick_cycle_counter; // The cycles since last trapezoid_tick. Used to generate ticks at a steady
|
||||||
// allocating a separate timer
|
// pace without allocating a separate timer
|
||||||
uint32_t trapezoid_rate; // The current rate of step_events according to the trapezoid generator
|
uint32_t trapezoid_adjusted_rate; // The current rate of step_events according to the trapezoid generator
|
||||||
|
|
||||||
// Two trapezoids:
|
// Two trapezoids:
|
||||||
// __________________________
|
// __________________________
|
||||||
@ -67,16 +68,16 @@ uint32_t trapezoid_rate; // The current rate of step_events accord
|
|||||||
// time ----->
|
// time ----->
|
||||||
//
|
//
|
||||||
// The trapezoid is the shape the speed curve over time. It starts at block->initial_rate, accelerates by block->rate_delta
|
// The trapezoid is the shape the speed curve over time. It starts at block->initial_rate, accelerates by block->rate_delta
|
||||||
// during the first block->accelerate_until step_events then keeps going at constant speed until the step-evet count reaches
|
// during the first block->accelerate_until step_events_completed, then keeps going at constant speed until
|
||||||
// block->decelerate_after until the trapezoid generator is reset for the next block.
|
// step_events_completed reaches block->decelerate_after after which it decelerates until the trapezoid generator is reset.
|
||||||
// The slope of acceleration is always +/- block->rate_delta and is applied at a constant rate by trapezoid_generator_tick()
|
// The slope of acceleration is always +/- block->rate_delta and is applied at a constant rate by trapezoid_generator_tick()
|
||||||
// that is called ACCELERATION_TICKS_PER_SECOND times per second.
|
// that is called ACCELERATION_TICKS_PER_SECOND times per second.
|
||||||
|
|
||||||
// Initializes the trapezoid generator from the current block. Called whenever a new
|
// Initializes the trapezoid generator from the current block. Called whenever a new
|
||||||
// block begins.
|
// block begins.
|
||||||
inline void trapezoid_generator_reset() {
|
inline void trapezoid_generator_reset() {
|
||||||
trapezoid_rate = current_block->initial_rate;
|
trapezoid_adjusted_rate = current_block->initial_rate;
|
||||||
set_step_events_per_minute(trapezoid_rate);
|
set_step_events_per_minute(trapezoid_adjusted_rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is called ACCELERATION_TICKS_PER_SECOND times per second by the step_event
|
// This is called ACCELERATION_TICKS_PER_SECOND times per second by the step_event
|
||||||
@ -85,15 +86,15 @@ inline void trapezoid_generator_reset() {
|
|||||||
inline void trapezoid_generator_tick() {
|
inline void trapezoid_generator_tick() {
|
||||||
if (current_block) {
|
if (current_block) {
|
||||||
if (step_events_completed < current_block->accelerate_until) {
|
if (step_events_completed < current_block->accelerate_until) {
|
||||||
trapezoid_rate += current_block->rate_delta;
|
trapezoid_adjusted_rate += current_block->rate_delta;
|
||||||
set_step_events_per_minute(trapezoid_rate);
|
set_step_events_per_minute(trapezoid_adjusted_rate);
|
||||||
} else if (step_events_completed > 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_adjusted_rate) {
|
||||||
trapezoid_rate -= current_block->rate_delta;
|
trapezoid_adjusted_rate -= current_block->rate_delta;
|
||||||
}
|
}
|
||||||
set_step_events_per_minute(trapezoid_rate);
|
set_step_events_per_minute(trapezoid_adjusted_rate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user