rework out_bits
This commit is contained in:
parent
6c27eaf864
commit
21ff773832
@ -46,7 +46,7 @@ block_t *current_block; // A pointer to the block currently being traced
|
||||
//static makes it impossible to be called from outside of this file by extern.!
|
||||
|
||||
// Variables used by The Stepper Driver Interrupt
|
||||
static unsigned char out_bits; // The next stepping-bits to be output
|
||||
static unsigned char out_bits = 0; // The next stepping-bits to be output
|
||||
static unsigned int cleaning_buffer_counter;
|
||||
|
||||
#ifdef Z_DUAL_ENDSTOPS
|
||||
@ -364,9 +364,58 @@ FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) {
|
||||
return timer;
|
||||
}
|
||||
|
||||
// set the stepper direction of each axis
|
||||
void set_stepper_direction() {
|
||||
|
||||
// Set the direction bits (X_AXIS=A_AXIS and Y_AXIS=B_AXIS for COREXY)
|
||||
if (TEST(out_bits, X_AXIS)) {
|
||||
X_APPLY_DIR(INVERT_X_DIR,0);
|
||||
count_direction[X_AXIS] = -1;
|
||||
}
|
||||
else {
|
||||
X_APPLY_DIR(!INVERT_X_DIR,0);
|
||||
count_direction[X_AXIS] = 1;
|
||||
}
|
||||
|
||||
if (TEST(out_bits, Y_AXIS)) {
|
||||
Y_APPLY_DIR(INVERT_Y_DIR,0);
|
||||
count_direction[Y_AXIS] = -1;
|
||||
}
|
||||
else {
|
||||
Y_APPLY_DIR(!INVERT_Y_DIR,0);
|
||||
count_direction[Y_AXIS] = 1;
|
||||
}
|
||||
|
||||
if (TEST(out_bits, Z_AXIS)) {
|
||||
Z_APPLY_DIR(INVERT_Z_DIR,0);
|
||||
count_direction[Z_AXIS] = -1;
|
||||
}
|
||||
else {
|
||||
Z_APPLY_DIR(!INVERT_Z_DIR,0);
|
||||
count_direction[Z_AXIS] = 1;
|
||||
}
|
||||
|
||||
#ifndef ADVANCE
|
||||
if (TEST(out_bits, E_AXIS)) {
|
||||
REV_E_DIR();
|
||||
count_direction[E_AXIS] = -1;
|
||||
}
|
||||
else {
|
||||
NORM_E_DIR();
|
||||
count_direction[E_AXIS] = 1;
|
||||
}
|
||||
#endif //!ADVANCE
|
||||
}
|
||||
|
||||
// Initializes the trapezoid generator from the current block. Called whenever a new
|
||||
// block begins.
|
||||
FORCE_INLINE void trapezoid_generator_reset() {
|
||||
|
||||
if (current_block->direction_bits != out_bits) {
|
||||
out_bits = current_block->direction_bits;
|
||||
set_stepper_direction();
|
||||
}
|
||||
|
||||
#ifdef ADVANCE
|
||||
advance = current_block->initial_advance;
|
||||
final_advance = current_block->final_advance;
|
||||
@ -439,27 +488,9 @@ ISR(TIMER1_COMPA_vect) {
|
||||
}
|
||||
|
||||
if (current_block != NULL) {
|
||||
// Set directions TO DO This should be done once during init of trapezoid. Endstops -> interrupt
|
||||
out_bits = current_block->direction_bits;
|
||||
|
||||
// Set the direction bits (X_AXIS=A_AXIS and Y_AXIS=B_AXIS for COREXY)
|
||||
if (TEST(out_bits, X_AXIS)) {
|
||||
X_APPLY_DIR(INVERT_X_DIR,0);
|
||||
count_direction[X_AXIS] = -1;
|
||||
}
|
||||
else {
|
||||
X_APPLY_DIR(!INVERT_X_DIR,0);
|
||||
count_direction[X_AXIS] = 1;
|
||||
}
|
||||
|
||||
if (TEST(out_bits, Y_AXIS)) {
|
||||
Y_APPLY_DIR(INVERT_Y_DIR,0);
|
||||
count_direction[Y_AXIS] = -1;
|
||||
}
|
||||
else {
|
||||
Y_APPLY_DIR(!INVERT_Y_DIR,0);
|
||||
count_direction[Y_AXIS] = 1;
|
||||
}
|
||||
// Check endstops
|
||||
if (check_endstops) {
|
||||
|
||||
#define _ENDSTOP(axis, minmax) axis ##_## minmax ##_endstop
|
||||
#define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN
|
||||
@ -478,9 +509,6 @@ ISR(TIMER1_COMPA_vect) {
|
||||
} \
|
||||
_OLD_ENDSTOP(axis, minmax) = _ENDSTOP(axis, minmax);
|
||||
|
||||
|
||||
// Check X and Y endstops
|
||||
if (check_endstops) {
|
||||
#ifdef COREXY
|
||||
// Head direction in -X axis for CoreXY bots.
|
||||
// If DeltaX == -DeltaY, the movement is only in Y axis
|
||||
@ -533,15 +561,7 @@ ISR(TIMER1_COMPA_vect) {
|
||||
#ifdef COREXY
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (TEST(out_bits, Z_AXIS)) { // -direction
|
||||
|
||||
Z_APPLY_DIR(INVERT_Z_DIR,0);
|
||||
count_direction[Z_AXIS] = -1;
|
||||
|
||||
if (check_endstops) {
|
||||
|
||||
if (TEST(out_bits, Z_AXIS)) { // z -direction
|
||||
#if HAS_Z_MIN
|
||||
|
||||
#ifdef Z_DUAL_ENDSTOPS
|
||||
@ -581,22 +601,12 @@ ISR(TIMER1_COMPA_vect) {
|
||||
{
|
||||
endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
|
||||
endstop_hit_bits |= BIT(Z_PROBE);
|
||||
|
||||
// if (z_probe_endstop && old_z_probe_endstop) SERIAL_ECHOLN("z_probe_endstop = true");
|
||||
}
|
||||
old_z_probe_endstop = z_probe_endstop;
|
||||
#endif
|
||||
|
||||
} // check_endstops
|
||||
|
||||
}
|
||||
else { // +direction
|
||||
|
||||
Z_APPLY_DIR(!INVERT_Z_DIR,0);
|
||||
count_direction[Z_AXIS] = 1;
|
||||
|
||||
if (check_endstops) {
|
||||
|
||||
else { // z +direction
|
||||
#if HAS_Z_MAX
|
||||
|
||||
#ifdef Z_DUAL_ENDSTOPS
|
||||
@ -644,21 +654,11 @@ ISR(TIMER1_COMPA_vect) {
|
||||
}
|
||||
old_z_probe_endstop = z_probe_endstop;
|
||||
#endif
|
||||
|
||||
} // check_endstops
|
||||
|
||||
} // +direction
|
||||
|
||||
#ifndef ADVANCE
|
||||
if (TEST(out_bits, E_AXIS)) { // -direction
|
||||
REV_E_DIR();
|
||||
count_direction[E_AXIS] = -1;
|
||||
}
|
||||
else { // +direction
|
||||
NORM_E_DIR();
|
||||
count_direction[E_AXIS] = 1;
|
||||
|
||||
}
|
||||
#endif //!ADVANCE
|
||||
|
||||
|
||||
|
||||
// Take multiple steps per interrupt (For high speed moves)
|
||||
for (int8_t i = 0; i < step_loops; i++) {
|
||||
@ -1073,6 +1073,8 @@ void st_init() {
|
||||
|
||||
enable_endstops(true); // Start with endstops active. After homing they can be disabled
|
||||
sei();
|
||||
|
||||
set_stepper_direction(); // Init directions to out_bits = 0
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user