Commit 3444e44d authored by MagoKimbra's avatar MagoKimbra

Same fix

parent 77059690
This diff is collapsed.
/* /**
stepper.c - stepper motor driver: executes motion plans using stepper motors * stepper.cpp - stepper motor driver: executes motion plans using stepper motors
Part of Grbl * Marlin Firmware
*
Copyright (c) 2009-2011 Simen Svale Skogsrud * Derived from Grbl
* Copyright (c) 2009-2011 Simen Svale Skogsrud
Grbl is free software: you can redistribute it and/or modify *
it under the terms of the GNU General Public License as published by * Grbl is free software: you can redistribute it and/or modify
the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
(at your option) any later version. * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
Grbl is distributed in the hope that it will be useful, *
but WITHOUT ANY WARRANTY; without even the implied warranty of * Grbl is distributed in the hope that it will be useful,
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
You should have received a copy of the GNU General Public License *
along with Grbl. If not, see <http://www.gnu.org/licenses/>. * You should have received a copy of the GNU General Public License
*/ * along with Grbl. If not, see <http://www.gnu.org/licenses/>.
*/
/* The timer calculations of this module informed by the 'RepRap cartesian firmware' by Zack Smith /* The timer calculations of this module informed by the 'RepRap cartesian firmware' by Zack Smith
and Philipp Tiefenbacher. */ and Philipp Tiefenbacher. */
...@@ -45,7 +46,7 @@ block_t *current_block; // A pointer to the block currently being traced ...@@ -45,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
...@@ -66,7 +67,7 @@ volatile static unsigned long step_events_completed; // The number of step event ...@@ -66,7 +67,7 @@ volatile static unsigned long step_events_completed; // The number of step event
static long acceleration_time, deceleration_time; static long acceleration_time, deceleration_time;
//static unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate; //static unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
static unsigned short acc_step_rate; // needed for deccelaration start point static unsigned short acc_step_rate; // needed for deceleration start point
static char step_loops; static char step_loops;
static unsigned short OCR1A_nominal; static unsigned short OCR1A_nominal;
static unsigned short step_loops_nominal; static unsigned short step_loops_nominal;
...@@ -75,10 +76,6 @@ volatile long endstops_trigsteps[3] = { 0 }; ...@@ -75,10 +76,6 @@ volatile long endstops_trigsteps[3] = { 0 };
volatile long endstops_stepsTotal, endstops_stepsDone; volatile long endstops_stepsTotal, endstops_stepsDone;
static volatile char endstop_hit_bits = 0; // use X_MIN, Y_MIN, Z_MIN and Z_PROBE as BIT value static volatile char endstop_hit_bits = 0; // use X_MIN, Y_MIN, Z_MIN and Z_PROBE as BIT value
#ifdef NPR2
static bool old_e_min_endstop = false;
#endif
#ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED
bool abort_on_endstop_hit = false; bool abort_on_endstop_hit = false;
#endif #endif
...@@ -112,6 +109,10 @@ static bool old_z_max_endstop = false; ...@@ -112,6 +109,10 @@ static bool old_z_max_endstop = false;
static bool old_z_probe_endstop = false; static bool old_z_probe_endstop = false;
#endif #endif
#ifdef NPR2
static bool old_e_min_endstop = false;
#endif
static bool check_endstops = true; static bool check_endstops = true;
volatile long count_position[NUM_AXIS] = { 0 }; volatile long count_position[NUM_AXIS] = { 0 };
...@@ -412,17 +413,18 @@ void set_stepper_direction() { ...@@ -412,17 +413,18 @@ void set_stepper_direction() {
NORM_E_DIR(); NORM_E_DIR();
count_direction[E_AXIS] = 1; count_direction[E_AXIS] = 1;
} }
#endif #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() {
// Set directions TO DO This should be done once during init of trapezoid. Endstops -> interrupt if (current_block->direction_bits != out_bits) {
out_bits = current_block->direction_bits; out_bits = current_block->direction_bits;
set_stepper_direction(); 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;
...@@ -557,8 +559,7 @@ ISR(TIMER1_COMPA_vect) { ...@@ -557,8 +559,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
#if HAS_Z_MIN #if HAS_Z_MIN
#ifdef Z_DUAL_ENDSTOPS #ifdef Z_DUAL_ENDSTOPS
...@@ -601,8 +602,7 @@ ISR(TIMER1_COMPA_vect) { ...@@ -601,8 +602,7 @@ ISR(TIMER1_COMPA_vect) {
old_z_probe_endstop = z_probe_endstop; old_z_probe_endstop = z_probe_endstop;
#endif #endif
} }
else { // +direction else { // z +direction
#if HAS_Z_MAX #if HAS_Z_MAX
#ifdef Z_DUAL_ENDSTOPS #ifdef Z_DUAL_ENDSTOPS
...@@ -992,12 +992,12 @@ void st_init() { ...@@ -992,12 +992,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)
...@@ -1076,6 +1076,8 @@ void st_init() { ...@@ -1076,6 +1076,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
} }
...@@ -1111,10 +1113,13 @@ long st_get_position(uint8_t axis) { ...@@ -1111,10 +1113,13 @@ long st_get_position(uint8_t axis) {
return count_pos; return count_pos;
} }
float st_get_position_mm(uint8_t axis) { #ifdef ENABLE_AUTO_BED_LEVELING
float steper_position_in_steps = st_get_position(axis);
return steper_position_in_steps / axis_steps_per_unit[axis]; float st_get_position_mm(AxisEnum axis) {
} return st_get_position(axis) / axis_steps_per_unit[axis];
}
#endif // ENABLE_AUTO_BED_LEVELING
void finishAndDisableSteppers() { void finishAndDisableSteppers() {
st_synchronize(); st_synchronize();
......
...@@ -70,8 +70,10 @@ void st_set_e_position(const long &e); ...@@ -70,8 +70,10 @@ void st_set_e_position(const long &e);
// Get current position in steps // Get current position in steps
long st_get_position(uint8_t axis); long st_get_position(uint8_t axis);
// Get current position in mm #ifdef ENABLE_AUTO_BED_LEVELING
float st_get_position_mm(uint8_t axis); // Get current position in mm
float st_get_position_mm(AxisEnum axis);
#endif
// The stepper subsystem goes to sleep when it runs out of things to execute. Call this // The stepper subsystem goes to sleep when it runs out of things to execute. Call this
// to notify the subsystem that it is time to go to work. // to notify the subsystem that it is time to go to work.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment