Seperate ENDSTOP_INVERTING for X Y and Z
Added simple endstop filter. Corrected M114 count display.
This commit is contained in:
parent
0db97b9c7f
commit
c0f8c9fd72
6 changed files with 62 additions and 18 deletions
|
@ -157,7 +157,9 @@
|
||||||
// Endstop Settings
|
// Endstop Settings
|
||||||
#define ENDSTOPPULLUPS // Comment this out (using // at the start of the line) to disable the endstop pullup resistors
|
#define ENDSTOPPULLUPS // Comment this out (using // at the start of the line) to disable the endstop pullup resistors
|
||||||
// The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins.
|
// The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins.
|
||||||
const bool ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops.
|
const bool X_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops.
|
||||||
|
const bool Y_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops.
|
||||||
|
const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops.
|
||||||
// For optos H21LOB set to true, for Mendel-Parts newer optos TCST2103 set to false
|
// For optos H21LOB set to true, for Mendel-Parts newer optos TCST2103 set to false
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -559,9 +559,16 @@ inline void process_commands()
|
||||||
if(!code_seen(axis_codes[E_AXIS]))
|
if(!code_seen(axis_codes[E_AXIS]))
|
||||||
st_synchronize();
|
st_synchronize();
|
||||||
for(int8_t i=0; i < NUM_AXIS; i++) {
|
for(int8_t i=0; i < NUM_AXIS; i++) {
|
||||||
if(code_seen(axis_codes[i])) current_position[i] = code_value();
|
if(code_seen(axis_codes[i])) {
|
||||||
|
current_position[i] = code_value();
|
||||||
|
if(i == E_AXIS) {
|
||||||
|
plan_set_e_position(current_position[E_AXIS]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -865,27 +872,27 @@ inline void process_commands()
|
||||||
case 119: // M119
|
case 119: // M119
|
||||||
#if (X_MIN_PIN > -1)
|
#if (X_MIN_PIN > -1)
|
||||||
SERIAL_PROTOCOLPGM("x_min:");
|
SERIAL_PROTOCOLPGM("x_min:");
|
||||||
SERIAL_PROTOCOL(((READ(X_MIN_PIN)^ENDSTOPS_INVERTING)?"H ":"L "));
|
SERIAL_PROTOCOL(((READ(X_MIN_PIN)^X_ENDSTOPS_INVERTING)?"H ":"L "));
|
||||||
#endif
|
#endif
|
||||||
#if (X_MAX_PIN > -1)
|
#if (X_MAX_PIN > -1)
|
||||||
SERIAL_PROTOCOLPGM("x_max:");
|
SERIAL_PROTOCOLPGM("x_max:");
|
||||||
SERIAL_PROTOCOL(((READ(X_MAX_PIN)^ENDSTOPS_INVERTING)?"H ":"L "));
|
SERIAL_PROTOCOL(((READ(X_MAX_PIN)^X_ENDSTOPS_INVERTING)?"H ":"L "));
|
||||||
#endif
|
#endif
|
||||||
#if (Y_MIN_PIN > -1)
|
#if (Y_MIN_PIN > -1)
|
||||||
SERIAL_PROTOCOLPGM("y_min:");
|
SERIAL_PROTOCOLPGM("y_min:");
|
||||||
SERIAL_PROTOCOL(((READ(Y_MIN_PIN)^ENDSTOPS_INVERTING)?"H ":"L "));
|
SERIAL_PROTOCOL(((READ(Y_MIN_PIN)^Y_ENDSTOPS_INVERTING)?"H ":"L "));
|
||||||
#endif
|
#endif
|
||||||
#if (Y_MAX_PIN > -1)
|
#if (Y_MAX_PIN > -1)
|
||||||
SERIAL_PROTOCOLPGM("y_max:");
|
SERIAL_PROTOCOLPGM("y_max:");
|
||||||
SERIAL_PROTOCOL(((READ(Y_MAX_PIN)^ENDSTOPS_INVERTING)?"H ":"L "));
|
SERIAL_PROTOCOL(((READ(Y_MAX_PIN)^Y_ENDSTOPS_INVERTING)?"H ":"L "));
|
||||||
#endif
|
#endif
|
||||||
#if (Z_MIN_PIN > -1)
|
#if (Z_MIN_PIN > -1)
|
||||||
SERIAL_PROTOCOLPGM("z_min:");
|
SERIAL_PROTOCOLPGM("z_min:");
|
||||||
SERIAL_PROTOCOL(((READ(Z_MIN_PIN)^ENDSTOPS_INVERTING)?"H ":"L "));
|
SERIAL_PROTOCOL(((READ(Z_MIN_PIN)^Z_ENDSTOPS_INVERTING)?"H ":"L "));
|
||||||
#endif
|
#endif
|
||||||
#if (Z_MAX_PIN > -1)
|
#if (Z_MAX_PIN > -1)
|
||||||
SERIAL_PROTOCOLPGM("z_max:");
|
SERIAL_PROTOCOLPGM("z_max:");
|
||||||
SERIAL_PROTOCOL(((READ(Z_MAX_PIN)^ENDSTOPS_INVERTING)?"H ":"L "));
|
SERIAL_PROTOCOL(((READ(Z_MAX_PIN)^Z_ENDSTOPS_INVERTING)?"H ":"L "));
|
||||||
#endif
|
#endif
|
||||||
SERIAL_PROTOCOLLN("");
|
SERIAL_PROTOCOLLN("");
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -762,7 +762,14 @@ void plan_set_position(const float &x, const float &y, const float &z, const flo
|
||||||
previous_speed[3] = 0.0;
|
previous_speed[3] = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void plan_set_e_position(const float &e)
|
||||||
|
{
|
||||||
|
position[E_AXIS] = lround(e*axis_steps_per_unit[E_AXIS]);
|
||||||
|
st_set_e_position(position[E_AXIS]);
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t movesplanned()
|
uint8_t movesplanned()
|
||||||
{
|
{
|
||||||
return (block_buffer_head-block_buffer_tail + BLOCK_BUFFER_SIZE) & (BLOCK_BUFFER_SIZE - 1);
|
return (block_buffer_head-block_buffer_tail + BLOCK_BUFFER_SIZE) & (BLOCK_BUFFER_SIZE - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa
|
||||||
|
|
||||||
// Set position. Used for G92 instructions.
|
// Set position. Used for G92 instructions.
|
||||||
void plan_set_position(const float &x, const float &y, const float &z, const float &e);
|
void plan_set_position(const float &x, const float &y, const float &z, const float &e);
|
||||||
|
void plan_set_e_position(const float &e);
|
||||||
|
|
||||||
// Called when the current block is no longer needed. Discards the block and makes the memory
|
// Called when the current block is no longer needed. Discards the block and makes the memory
|
||||||
// availible for new blocks.
|
// availible for new blocks.
|
||||||
|
|
|
@ -70,6 +70,13 @@ static volatile bool endstop_x_hit=false;
|
||||||
static volatile bool endstop_y_hit=false;
|
static volatile bool endstop_y_hit=false;
|
||||||
static volatile bool endstop_z_hit=false;
|
static volatile bool endstop_z_hit=false;
|
||||||
|
|
||||||
|
static bool old_x_min_endstop=false;
|
||||||
|
static bool old_x_max_endstop=false;
|
||||||
|
static bool old_y_min_endstop=false;
|
||||||
|
static bool old_y_max_endstop=false;
|
||||||
|
static bool old_z_min_endstop=false;
|
||||||
|
static bool old_z_max_endstop=false;
|
||||||
|
|
||||||
volatile long count_position[NUM_AXIS] = { 0, 0, 0, 0};
|
volatile long count_position[NUM_AXIS] = { 0, 0, 0, 0};
|
||||||
volatile char count_direction[NUM_AXIS] = { 1, 1, 1, 1};
|
volatile char count_direction[NUM_AXIS] = { 1, 1, 1, 1};
|
||||||
|
|
||||||
|
@ -260,6 +267,7 @@ ISR(TIMER1_COMPA_vect)
|
||||||
SERIAL_ERROR_START
|
SERIAL_ERROR_START
|
||||||
SERIAL_ERROR(*(unsigned short *)OCR1A);
|
SERIAL_ERROR(*(unsigned short *)OCR1A);
|
||||||
SERIAL_ERRORLNPGM(" ISR overtaking itself.");
|
SERIAL_ERRORLNPGM(" ISR overtaking itself.");
|
||||||
|
OCR1A = 0x30000;
|
||||||
return;
|
return;
|
||||||
} // The busy-flag is used to avoid reentering this interrupt
|
} // The busy-flag is used to avoid reentering this interrupt
|
||||||
|
|
||||||
|
@ -295,22 +303,26 @@ ISR(TIMER1_COMPA_vect)
|
||||||
WRITE(X_DIR_PIN, INVERT_X_DIR);
|
WRITE(X_DIR_PIN, INVERT_X_DIR);
|
||||||
count_direction[X_AXIS]=-1;
|
count_direction[X_AXIS]=-1;
|
||||||
#if X_MIN_PIN > -1
|
#if X_MIN_PIN > -1
|
||||||
if((READ(X_MIN_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_x > 0)) {
|
bool x_min_endstop=(READ(X_MIN_PIN) != X_ENDSTOPS_INVERTING);
|
||||||
|
if(x_min_endstop && old_x_min_endstop && (current_block->steps_x > 0)) {
|
||||||
endstops_trigsteps[X_AXIS] = count_position[X_AXIS];
|
endstops_trigsteps[X_AXIS] = count_position[X_AXIS];
|
||||||
endstop_x_hit=true;
|
endstop_x_hit=true;
|
||||||
step_events_completed = current_block->step_event_count;
|
step_events_completed = current_block->step_event_count;
|
||||||
}
|
}
|
||||||
|
old_x_min_endstop = x_min_endstop;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else { // +direction
|
else { // +direction
|
||||||
WRITE(X_DIR_PIN,!INVERT_X_DIR);
|
WRITE(X_DIR_PIN,!INVERT_X_DIR);
|
||||||
count_direction[X_AXIS]=1;
|
count_direction[X_AXIS]=1;
|
||||||
#if X_MAX_PIN > -1
|
#if X_MAX_PIN > -1
|
||||||
if((READ(X_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_x > 0)){
|
bool x_max_endstop=(READ(X_MAX_PIN) != X_ENDSTOPS_INVERTING);
|
||||||
|
if(x_max_endstop && old_x_max_endstop && (current_block->steps_x > 0)){
|
||||||
endstops_trigsteps[X_AXIS] = count_position[X_AXIS];
|
endstops_trigsteps[X_AXIS] = count_position[X_AXIS];
|
||||||
endstop_x_hit=true;
|
endstop_x_hit=true;
|
||||||
step_events_completed = current_block->step_event_count;
|
step_events_completed = current_block->step_event_count;
|
||||||
}
|
}
|
||||||
|
old_x_max_endstop = x_max_endstop;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,22 +330,26 @@ ISR(TIMER1_COMPA_vect)
|
||||||
WRITE(Y_DIR_PIN,INVERT_Y_DIR);
|
WRITE(Y_DIR_PIN,INVERT_Y_DIR);
|
||||||
count_direction[Y_AXIS]=-1;
|
count_direction[Y_AXIS]=-1;
|
||||||
#if Y_MIN_PIN > -1
|
#if Y_MIN_PIN > -1
|
||||||
if((READ(Y_MIN_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_y > 0)) {
|
bool y_min_endstop=(READ(Y_MIN_PIN) != Y_ENDSTOPS_INVERTING);
|
||||||
|
if(y_min_endstop && old_y_min_endstop && (current_block->steps_y > 0)) {
|
||||||
endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS];
|
endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS];
|
||||||
endstop_y_hit=true;
|
endstop_y_hit=true;
|
||||||
step_events_completed = current_block->step_event_count;
|
step_events_completed = current_block->step_event_count;
|
||||||
}
|
}
|
||||||
|
old_y_min_endstop = y_min_endstop;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else { // +direction
|
else { // +direction
|
||||||
WRITE(Y_DIR_PIN,!INVERT_Y_DIR);
|
WRITE(Y_DIR_PIN,!INVERT_Y_DIR);
|
||||||
count_direction[Y_AXIS]=1;
|
count_direction[Y_AXIS]=1;
|
||||||
#if Y_MAX_PIN > -1
|
#if Y_MAX_PIN > -1
|
||||||
if((READ(Y_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_y > 0)){
|
bool y_max_endstop=(READ(Y_MAX_PIN) != Y_ENDSTOPS_INVERTING);
|
||||||
|
if(y_max_endstop && old_y_max_endstop && (current_block->steps_y > 0)){
|
||||||
endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS];
|
endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS];
|
||||||
endstop_y_hit=true;
|
endstop_y_hit=true;
|
||||||
step_events_completed = current_block->step_event_count;
|
step_events_completed = current_block->step_event_count;
|
||||||
}
|
}
|
||||||
|
old_y_max_endstop = y_max_endstop;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,22 +357,26 @@ ISR(TIMER1_COMPA_vect)
|
||||||
WRITE(Z_DIR_PIN,INVERT_Z_DIR);
|
WRITE(Z_DIR_PIN,INVERT_Z_DIR);
|
||||||
count_direction[Z_AXIS]=-1;
|
count_direction[Z_AXIS]=-1;
|
||||||
#if Z_MIN_PIN > -1
|
#if Z_MIN_PIN > -1
|
||||||
if((READ(Z_MIN_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_z > 0)) {
|
bool z_min_endstop=(READ(Z_MIN_PIN) != Z_ENDSTOPS_INVERTING);
|
||||||
|
if(z_min_endstop && old_z_min_endstop && (current_block->steps_z > 0)) {
|
||||||
endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
|
endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
|
||||||
endstop_z_hit=true;
|
endstop_z_hit=true;
|
||||||
step_events_completed = current_block->step_event_count;
|
step_events_completed = current_block->step_event_count;
|
||||||
}
|
}
|
||||||
|
old_z_min_endstop = z_min_endstop;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else { // +direction
|
else { // +direction
|
||||||
WRITE(Z_DIR_PIN,!INVERT_Z_DIR);
|
WRITE(Z_DIR_PIN,!INVERT_Z_DIR);
|
||||||
count_direction[Z_AXIS]=1;
|
count_direction[Z_AXIS]=1;
|
||||||
#if Z_MAX_PIN > -1
|
#if Z_MAX_PIN > -1
|
||||||
if((READ(Z_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_z > 0)){
|
bool z_max_endstop=(READ(Z_MAX_PIN) != Z_ENDSTOPS_INVERTING);
|
||||||
|
if(z_max_endstop && old_z_max_endstop && (current_block->steps_z > 0)) {
|
||||||
endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
|
endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
|
||||||
endstop_z_hit=true;
|
endstop_z_hit=true;
|
||||||
step_events_completed = current_block->step_event_count;
|
step_events_completed = current_block->step_event_count;
|
||||||
}
|
}
|
||||||
|
old_z_max_endstop = z_max_endstop;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -654,6 +674,13 @@ void st_set_position(const long &x, const long &y, const long &z, const long &e)
|
||||||
CRITICAL_SECTION_END;
|
CRITICAL_SECTION_END;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void st_set_e_position(const long &e)
|
||||||
|
{
|
||||||
|
CRITICAL_SECTION_START;
|
||||||
|
count_position[E_AXIS] = e;
|
||||||
|
CRITICAL_SECTION_END;
|
||||||
|
}
|
||||||
|
|
||||||
long st_get_position(char axis)
|
long st_get_position(char axis)
|
||||||
{
|
{
|
||||||
long count_pos;
|
long count_pos;
|
||||||
|
|
|
@ -31,6 +31,7 @@ void st_synchronize();
|
||||||
|
|
||||||
// Set current position in steps
|
// Set current position in steps
|
||||||
void st_set_position(const long &x, const long &y, const long &z, const long &e);
|
void st_set_position(const long &x, const long &y, const long &z, const long &e);
|
||||||
|
void st_set_e_position(const long &e);
|
||||||
|
|
||||||
// Get current position in steps
|
// Get current position in steps
|
||||||
long st_get_position(char axis);
|
long st_get_position(char axis);
|
||||||
|
|
Reference in a new issue