|
@ -80,49 +80,46 @@ class Stepper { |
|
|
|
|
|
|
|
|
public: |
|
|
public: |
|
|
|
|
|
|
|
|
block_t* current_block = NULL; // A pointer to the block currently being traced
|
|
|
static block_t* current_block; // A pointer to the block currently being traced
|
|
|
|
|
|
|
|
|
#if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) |
|
|
#if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) |
|
|
bool abort_on_endstop_hit = false; |
|
|
static bool abort_on_endstop_hit; |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
#if ENABLED(Z_DUAL_ENDSTOPS) |
|
|
#if ENABLED(Z_DUAL_ENDSTOPS) |
|
|
bool performing_homing = false; |
|
|
static bool performing_homing; |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
#if ENABLED(ADVANCE) |
|
|
#if ENABLED(ADVANCE) |
|
|
long e_steps[4]; |
|
|
static long e_steps[4]; |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
|
|
|
|
|
|
unsigned char last_direction_bits = 0; // The next stepping-bits to be output
|
|
|
static unsigned char last_direction_bits; // The next stepping-bits to be output
|
|
|
unsigned int cleaning_buffer_counter = 0; |
|
|
static unsigned int cleaning_buffer_counter; |
|
|
|
|
|
|
|
|
#if ENABLED(Z_DUAL_ENDSTOPS) |
|
|
#if ENABLED(Z_DUAL_ENDSTOPS) |
|
|
bool locked_z_motor = false, |
|
|
static bool locked_z_motor, locked_z2_motor; |
|
|
locked_z2_motor = false; |
|
|
|
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
// Counter variables for the Bresenham line tracer
|
|
|
// Counter variables for the Bresenham line tracer
|
|
|
long counter_X = 0, counter_Y = 0, counter_Z = 0, counter_E = 0; |
|
|
static long counter_X, counter_Y, counter_Z, counter_E; |
|
|
volatile unsigned long step_events_completed = 0; // The number of step events executed in the current block
|
|
|
static volatile unsigned long step_events_completed; // The number of step events executed in the current block
|
|
|
|
|
|
|
|
|
#if ENABLED(ADVANCE) |
|
|
#if ENABLED(ADVANCE) |
|
|
unsigned char old_OCR0A; |
|
|
static unsigned char old_OCR0A; |
|
|
long advance_rate, advance, final_advance = 0; |
|
|
static long advance_rate, advance, old_advance, final_advance; |
|
|
long old_advance = 0; |
|
|
|
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
long acceleration_time, deceleration_time; |
|
|
static long acceleration_time, deceleration_time; |
|
|
//unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
|
|
|
//unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
|
|
|
unsigned short acc_step_rate; // needed for deceleration start point
|
|
|
static unsigned short acc_step_rate; // needed for deceleration start point
|
|
|
uint8_t step_loops; |
|
|
static uint8_t step_loops, step_loops_nominal; |
|
|
uint8_t step_loops_nominal; |
|
|
static unsigned short OCR1A_nominal; |
|
|
unsigned short OCR1A_nominal; |
|
|
|
|
|
|
|
|
|
|
|
volatile long endstops_trigsteps[3]; |
|
|
static volatile long endstops_trigsteps[3]; |
|
|
volatile long endstops_stepsTotal, endstops_stepsDone; |
|
|
static volatile long endstops_stepsTotal, endstops_stepsDone; |
|
|
|
|
|
|
|
|
#if HAS_MOTOR_CURRENT_PWM |
|
|
#if HAS_MOTOR_CURRENT_PWM |
|
|
#ifndef PWM_MOTOR_CURRENT |
|
|
#ifndef PWM_MOTOR_CURRENT |
|
@ -134,19 +131,19 @@ class Stepper { |
|
|
//
|
|
|
//
|
|
|
// Positions of stepper motors, in step units
|
|
|
// Positions of stepper motors, in step units
|
|
|
//
|
|
|
//
|
|
|
volatile long count_position[NUM_AXIS] = { 0 }; |
|
|
static volatile long count_position[NUM_AXIS]; |
|
|
|
|
|
|
|
|
//
|
|
|
//
|
|
|
// Current direction of stepper motors (+1 or -1)
|
|
|
// Current direction of stepper motors (+1 or -1)
|
|
|
//
|
|
|
//
|
|
|
volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1 }; |
|
|
static volatile signed char count_direction[NUM_AXIS]; |
|
|
|
|
|
|
|
|
public: |
|
|
public: |
|
|
|
|
|
|
|
|
//
|
|
|
//
|
|
|
// Constructor / initializer
|
|
|
// Constructor / initializer
|
|
|
//
|
|
|
//
|
|
|
Stepper() {}; |
|
|
Stepper() { }; |
|
|
|
|
|
|
|
|
//
|
|
|
//
|
|
|
// Initialize stepper hardware
|
|
|
// Initialize stepper hardware
|
|
@ -157,10 +154,10 @@ class Stepper { |
|
|
// Interrupt Service Routines
|
|
|
// Interrupt Service Routines
|
|
|
//
|
|
|
//
|
|
|
|
|
|
|
|
|
void isr(); |
|
|
static void isr(); |
|
|
|
|
|
|
|
|
#if ENABLED(ADVANCE) |
|
|
#if ENABLED(ADVANCE) |
|
|
void advance_isr(); |
|
|
static void advance_isr(); |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
//
|
|
|
//
|
|
@ -177,7 +174,7 @@ class Stepper { |
|
|
//
|
|
|
//
|
|
|
// Set direction bits for all steppers
|
|
|
// Set direction bits for all steppers
|
|
|
//
|
|
|
//
|
|
|
void set_directions(); |
|
|
static void set_directions(); |
|
|
|
|
|
|
|
|
//
|
|
|
//
|
|
|
// Get the position of a stepper, in steps
|
|
|
// Get the position of a stepper, in steps
|
|
@ -213,7 +210,7 @@ class Stepper { |
|
|
//
|
|
|
//
|
|
|
// The direction of a single motor
|
|
|
// The direction of a single motor
|
|
|
//
|
|
|
//
|
|
|
FORCE_INLINE bool motor_direction(AxisEnum axis) { return TEST(last_direction_bits, axis); } |
|
|
static FORCE_INLINE bool motor_direction(AxisEnum axis) { return TEST(last_direction_bits, axis); } |
|
|
|
|
|
|
|
|
#if HAS_DIGIPOTSS |
|
|
#if HAS_DIGIPOTSS |
|
|
void digitalPotWrite(int address, int value); |
|
|
void digitalPotWrite(int address, int value); |
|
@ -251,7 +248,7 @@ class Stepper { |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
|
|
|
|
|
|
FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) { |
|
|
static FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) { |
|
|
unsigned short timer; |
|
|
unsigned short timer; |
|
|
|
|
|
|
|
|
NOMORE(step_rate, MAX_STEP_FREQUENCY); |
|
|
NOMORE(step_rate, MAX_STEP_FREQUENCY); |
|
@ -283,13 +280,17 @@ class Stepper { |
|
|
timer = (unsigned short)pgm_read_word_near(table_address); |
|
|
timer = (unsigned short)pgm_read_word_near(table_address); |
|
|
timer -= (((unsigned short)pgm_read_word_near(table_address + 2) * (unsigned char)(step_rate & 0x0007)) >> 3); |
|
|
timer -= (((unsigned short)pgm_read_word_near(table_address + 2) * (unsigned char)(step_rate & 0x0007)) >> 3); |
|
|
} |
|
|
} |
|
|
if (timer < 100) { timer = 100; MYSERIAL.print(MSG_STEPPER_TOO_HIGH); MYSERIAL.println(step_rate); }//(20kHz this should never happen)
|
|
|
if (timer < 100) { // (20kHz - this should never happen)
|
|
|
|
|
|
timer = 100; |
|
|
|
|
|
MYSERIAL.print(MSG_STEPPER_TOO_HIGH); |
|
|
|
|
|
MYSERIAL.println(step_rate); |
|
|
|
|
|
} |
|
|
return timer; |
|
|
return timer; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 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.
|
|
|
FORCE_INLINE void trapezoid_generator_reset() { |
|
|
static FORCE_INLINE void trapezoid_generator_reset() { |
|
|
|
|
|
|
|
|
static int8_t last_extruder = -1; |
|
|
static int8_t last_extruder = -1; |
|
|
|
|
|
|
|
|