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.!
|
//static makes it impossible to be called from outside of this file by extern.!
|
||||||
|
|
||||||
// Variables used by The Stepper Driver Interrupt
|
// 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;
|
static unsigned int cleaning_buffer_counter;
|
||||||
|
|
||||||
#ifdef Z_DUAL_ENDSTOPS
|
#ifdef Z_DUAL_ENDSTOPS
|
||||||
@ -364,9 +364,58 @@ FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) {
|
|||||||
return timer;
|
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
|
// Initializes the trapezoid generator from the current block. Called whenever a new
|
||||||
// block begins.
|
// block begins.
|
||||||
FORCE_INLINE void trapezoid_generator_reset() {
|
FORCE_INLINE void trapezoid_generator_reset() {
|
||||||
|
|
||||||
|
if (current_block->direction_bits != out_bits) {
|
||||||
|
out_bits = current_block->direction_bits;
|
||||||
|
set_stepper_direction();
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef ADVANCE
|
#ifdef ADVANCE
|
||||||
advance = current_block->initial_advance;
|
advance = current_block->initial_advance;
|
||||||
final_advance = current_block->final_advance;
|
final_advance = current_block->final_advance;
|
||||||
@ -439,27 +488,9 @@ ISR(TIMER1_COMPA_vect) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (current_block != NULL) {
|
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)
|
// Check endstops
|
||||||
if (TEST(out_bits, X_AXIS)) {
|
if (check_endstops) {
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define _ENDSTOP(axis, minmax) axis ##_## minmax ##_endstop
|
#define _ENDSTOP(axis, minmax) axis ##_## minmax ##_endstop
|
||||||
#define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN
|
#define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN
|
||||||
@ -478,9 +509,6 @@ ISR(TIMER1_COMPA_vect) {
|
|||||||
} \
|
} \
|
||||||
_OLD_ENDSTOP(axis, minmax) = _ENDSTOP(axis, minmax);
|
_OLD_ENDSTOP(axis, minmax) = _ENDSTOP(axis, minmax);
|
||||||
|
|
||||||
|
|
||||||
// Check X and Y endstops
|
|
||||||
if (check_endstops) {
|
|
||||||
#ifdef COREXY
|
#ifdef COREXY
|
||||||
// Head direction in -X axis for CoreXY bots.
|
// Head direction in -X axis for CoreXY bots.
|
||||||
// If DeltaX == -DeltaY, the movement is only in Y axis
|
// If DeltaX == -DeltaY, the movement is only in Y axis
|
||||||
@ -533,15 +561,7 @@ ISR(TIMER1_COMPA_vect) {
|
|||||||
#ifdef COREXY
|
#ifdef COREXY
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
if (TEST(out_bits, Z_AXIS)) { // z -direction
|
||||||
|
|
||||||
if (TEST(out_bits, Z_AXIS)) { // -direction
|
|
||||||
|
|
||||||
Z_APPLY_DIR(INVERT_Z_DIR,0);
|
|
||||||
count_direction[Z_AXIS] = -1;
|
|
||||||
|
|
||||||
if (check_endstops) {
|
|
||||||
|
|
||||||
#if HAS_Z_MIN
|
#if HAS_Z_MIN
|
||||||
|
|
||||||
#ifdef Z_DUAL_ENDSTOPS
|
#ifdef Z_DUAL_ENDSTOPS
|
||||||
@ -581,22 +601,12 @@ ISR(TIMER1_COMPA_vect) {
|
|||||||
{
|
{
|
||||||
endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
|
endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
|
||||||
endstop_hit_bits |= BIT(Z_PROBE);
|
endstop_hit_bits |= BIT(Z_PROBE);
|
||||||
|
// if (z_probe_endstop && old_z_probe_endstop) SERIAL_ECHOLN("z_probe_endstop = true");
|
||||||
// if (z_probe_endstop && old_z_probe_endstop) SERIAL_ECHOLN("z_probe_endstop = true");
|
|
||||||
}
|
}
|
||||||
old_z_probe_endstop = z_probe_endstop;
|
old_z_probe_endstop = z_probe_endstop;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // check_endstops
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else { // +direction
|
else { // z +direction
|
||||||
|
|
||||||
Z_APPLY_DIR(!INVERT_Z_DIR,0);
|
|
||||||
count_direction[Z_AXIS] = 1;
|
|
||||||
|
|
||||||
if (check_endstops) {
|
|
||||||
|
|
||||||
#if HAS_Z_MAX
|
#if HAS_Z_MAX
|
||||||
|
|
||||||
#ifdef Z_DUAL_ENDSTOPS
|
#ifdef Z_DUAL_ENDSTOPS
|
||||||
@ -644,21 +654,11 @@ ISR(TIMER1_COMPA_vect) {
|
|||||||
}
|
}
|
||||||
old_z_probe_endstop = z_probe_endstop;
|
old_z_probe_endstop = z_probe_endstop;
|
||||||
#endif
|
#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)
|
// Take multiple steps per interrupt (For high speed moves)
|
||||||
for (int8_t i = 0; i < step_loops; i++) {
|
for (int8_t i = 0; i < step_loops; i++) {
|
||||||
@ -989,12 +989,12 @@ void st_init() {
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (defined(Z_PROBE_PIN) && Z_PROBE_PIN >= 0) && defined(Z_PROBE_ENDSTOP) // Check for Z_PROBE_ENDSTOP so we don't pull a pin high unless it's to be used.
|
#if (defined(Z_PROBE_PIN) && Z_PROBE_PIN >= 0) && defined(Z_PROBE_ENDSTOP) // Check for Z_PROBE_ENDSTOP so we don't pull a pin high unless it's to be used.
|
||||||
SET_INPUT(Z_PROBE_PIN);
|
SET_INPUT(Z_PROBE_PIN);
|
||||||
#ifdef ENDSTOPPULLUP_ZPROBE
|
#ifdef ENDSTOPPULLUP_ZPROBE
|
||||||
WRITE(Z_PROBE_PIN,HIGH);
|
WRITE(Z_PROBE_PIN,HIGH);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define _STEP_INIT(AXIS) AXIS ##_STEP_INIT
|
#define _STEP_INIT(AXIS) AXIS ##_STEP_INIT
|
||||||
#define _WRITE_STEP(AXIS, HIGHLOW) AXIS ##_STEP_WRITE(HIGHLOW)
|
#define _WRITE_STEP(AXIS, HIGHLOW) AXIS ##_STEP_WRITE(HIGHLOW)
|
||||||
@ -1073,6 +1073,8 @@ void st_init() {
|
|||||||
|
|
||||||
enable_endstops(true); // Start with endstops active. After homing they can be disabled
|
enable_endstops(true); // Start with endstops active. After homing they can be disabled
|
||||||
sei();
|
sei();
|
||||||
|
|
||||||
|
set_stepper_direction(); // Init directions to out_bits = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user