Fix Baby Stepping on 32-Bit platforms (#8001)

Also, Max7219 debug code was used for this effort.   It has been
improved and hardened.
This commit is contained in:
Roxy-3D 2017-10-16 16:29:37 -05:00 committed by GitHub
parent 3b7b0492f8
commit 6cb26c98c8
6 changed files with 196 additions and 61 deletions

View file

@ -125,7 +125,7 @@
// Optional custom name for your RepStrap or other custom machine
// Displayed in the LCD "Ready" message
#define CUSTOM_MACHINE_NAME "FT-2020 v2"
#define CUSTOM_MACHINE_NAME "FT-2020 v3"
// Define this to set a unique identifier for this printer, (Used by some programs to differentiate between machines)
// You can use an online service to generate a random UUID. (eg http://www.uuidgenerator.net/version4)
@ -691,6 +691,7 @@
// X and Y axis travel speed (mm/m) between probes
#define XY_PROBE_SPEED 7500
// Speed for the first approach when double-probing (with PROBE_DOUBLE_TOUCH)
#define Z_PROBE_SPEED_FAST HOMING_FEEDRATE_Z
@ -750,6 +751,7 @@
#define INVERT_X_DIR false
#define INVERT_Y_DIR true
#define INVERT_Z_DIR true
// Enable this option for Toshiba stepper drivers
//#define CONFIG_STEPPERS_TOSHIBA
@ -789,16 +791,7 @@
#define Y_MAX_POS 182
#define Z_MAX_POS 175
/**
* Software Endstops
*
* - Prevent moves outside the set machine bounds.
* - Individual axes can be disabled, if desired.
* - X and Y only apply to Cartesian robots.
* - Use 'M211' to set software endstops on/off or report current state
*/
// Min software endstops curtail movement below minimum coordinate bounds
// If enabled, axes won't move below MIN_POS in response to movement commands.
//#define MIN_SOFTWARE_ENDSTOPS
#if ENABLED(MIN_SOFTWARE_ENDSTOPS)
#define MIN_SOFTWARE_ENDSTOP_X
@ -806,7 +799,7 @@
#define MIN_SOFTWARE_ENDSTOP_Z
#endif
// Max software endstops curtail movement above maximum coordinate bounds
// If enabled, axes won't move above MAX_POS in response to movement commands.
#define MAX_SOFTWARE_ENDSTOPS
#if ENABLED(MAX_SOFTWARE_ENDSTOPS)
#define MAX_SOFTWARE_ENDSTOP_X
@ -939,8 +932,6 @@
#define ABL_PROBE_PT_3_X 170
#define ABL_PROBE_PT_3_Y 10
#elif ENABLED(AUTO_BED_LEVELING_UBL)
//===========================================================================
@ -1681,12 +1672,12 @@
// leaving it undefined or defining as 0 will disable the servo subsystem
// If unsure, leave commented / disabled
//
#define NUM_SERVOS 2 // Servo index starts with 0 for M280 command
#define NUM_SERVOS 1 // Servo index starts with 0 for M280 command
// Delay (in milliseconds) before the next move will start, to give the servo time to reach its target angle.
// 300ms is a good value but you can try less delay.
// If the servo can't reach the requested position, increase it.
#define SERVO_DELAY { 500, 500 }
#define SERVO_DELAY { 500 }
// Servo deactivation
//

View file

@ -534,7 +534,7 @@
#endif
// Show a progress bar on HD44780 LCDs for SD printing
#define LCD_PROGRESS_BAR
//#define LCD_PROGRESS_BAR
#if ENABLED(LCD_PROGRESS_BAR)
// Amount of time (ms) to show the bar
@ -592,6 +592,7 @@
// Enable this option and reduce the value to optimize screen updates.
// The normal delay is 10µs. Use the lowest value that still gives a reliable display.
//#define DOGM_SPI_DELAY_US 5
#endif // DOGLCD
// @section safety
@ -620,7 +621,7 @@
#if ENABLED(BABYSTEPPING)
//#define BABYSTEP_XY // Also enable X/Y Babystepping. Not supported on DELTA!
#define BABYSTEP_INVERT_Z false // Change if Z babysteps should go the other way
#define BABYSTEP_MULTIPLICATOR 100 // Babysteps are very small. Increase for faster motion.
#define BABYSTEP_MULTIPLICATOR 16 // Babysteps are very small. Increase for faster motion.
//#define BABYSTEP_ZPROBE_OFFSET // Enable to combine M851 and Babystepping
#define DOUBLECLICK_FOR_Z_BABYSTEPPING // Double-click on the Status Screen for Z Babystepping.
#define DOUBLECLICK_MAX_INTERVAL 1250 // Maximum interval between clicks, in milliseconds.
@ -1313,8 +1314,8 @@
#define USER_DESC_4 "Heat Bed/Home/Level"
#define USER_GCODE_4 "M140 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\nG28\nG29"
//#define USER_DESC_5 "Home & Info"
//#define USER_GCODE_5 "G28\nM503"
#define USER_DESC_5 "Home & Info"
#define USER_GCODE_5 "G28\nM503"
#endif
/**
@ -1423,15 +1424,20 @@
//#define MAX7219_DIN_PIN 57 // on RAMPS
//#define MAX7219_LOAD_PIN 44 // on RAMPS
#define MAX7219_CLK_PIN 77 // on Re-ARM // Configuration of the 3 pins to control the display
#define MAX7219_DIN_PIN 78 // on Re-ARM
#define MAX7219_LOAD_PIN 79 // on Re-ARM
//#define MAX7219_CLK_PIN 77 // on Re-ARM // Configuration of the 3 pins to control the display
//#define MAX7219_DIN_PIN 78 // on Re-ARM
//#define MAX7219_LOAD_PIN 79 // on Re-ARM
#define MAX7219_CLK_PIN 30 // for RAMPS E1 // Configuration of the 3 pins to control the display
#define MAX7219_DIN_PIN 34 // for RAMPS E1
#define MAX7219_LOAD_PIN 36 // for RAMPS E1
/**
* Sample debug features
* If you add more debug displays, be careful to avoid conflicts!
*/
#define MAX7219_DEBUG_PRINTER_ALIVE // Blink corner LED of 8x8 matrix to show that the firmware is functioning
#define MAX7219_DEBUG_STEPPER_HEAD 3 // Show the stepper queue head position on this and the next LED matrix row
#define MAX7219_DEBUG_STEPPER_TAIL 5 // Show the stepper queue tail position on this and the next LED matrix row

View file

@ -39,12 +39,14 @@
* void Max7219_init();
* void Max7219_PutByte(uint8_t data);
* void Max7219(uint8_t reg, uint8_t data);
* void Max7219_LED_On(uint8_t row, uint8_t col);
* void Max7219_LED_Off(uint8_t row, uint8_t col);
* void Max7219_LED_Toggle(uint8_t row, uint8_t col);
* void Max7219_LED_On(uint8_t col, uint8_t row);
* void Max7219_LED_Off(uint8_t col, uint8_t row);
* void Max7219_LED_Toggle(uint8_t col, uint8_t row);
* void Max7219_Clear_Row(uint8_t row);
* void Max7219_Clear_Column(uint8_t col);
* void Max7219_Set_Row(uint8_t row, uint8_t val);
* void Max7219_Set_2_Rows(uint8_t row, uint16_t val);
* void Max7219_Set_4_Rows(uint8_t row, uint32_t val);
* void Max7219_Set_Column(uint8_t col, uint8_t val);
* void Max7219_idle_tasks();
*/
@ -62,9 +64,10 @@
static uint8_t LEDs[8] = { 0 };
void Max7219_PutByte(uint8_t data) {
CRITICAL_SECTION_START
for (uint8_t i = 8; i--;) {
#ifdef CPU_32_BIT // The 32-bit processors are so fast, a small delay in the code is needed
// to let the signal wires stabilize.
delayMicroseconds(5); // to let the signal wires stabilize.
WRITE(MAX7219_CLK_PIN, LOW); // tick
delayMicroseconds(5);
WRITE(MAX7219_DIN_PIN, (data & 0x80) ? HIGH : LOW); // send 1 or 0 based on data bit
@ -79,14 +82,22 @@ void Max7219_PutByte(uint8_t data) {
data <<= 1;
}
CRITICAL_SECTION_END
}
void Max7219(const uint8_t reg, const uint8_t data) {
#ifdef CPU_32_BIT
delayMicroseconds(5);
#endif
CRITICAL_SECTION_START
WRITE(MAX7219_LOAD_PIN, LOW); // begin
#ifdef CPU_32_BIT // The 32-bit processors are so fast, a small delay in the code is needed
delayMicroseconds(5); // to let the signal wires stabilize.
#endif
Max7219_PutByte(reg); // specify register
#ifdef CPU_32_BIT
delayMicroseconds(5);
#endif
Max7219_PutByte(data); // put data
#ifdef CPU_32_BIT
delayMicroseconds(5);
@ -96,45 +107,103 @@ void Max7219(const uint8_t reg, const uint8_t data) {
delayMicroseconds(5);
#endif
WRITE(MAX7219_LOAD_PIN, HIGH);
CRITICAL_SECTION_END
#ifdef CPU_32_BIT
delayMicroseconds(5);
#endif
}
void Max7219_LED_Set(const uint8_t row, const uint8_t col, const bool on) {
if (row > 7 || col > 7) return;
if (row > 7 || col > 7) {
int r,c;
r = row;
c = col;
SERIAL_ECHOPAIR("??? Max7219_LED_Set(",r);
SERIAL_ECHOPAIR(",",c);
SERIAL_ECHO(")\n");
return;
}
if (TEST(LEDs[row], col) == on) return; // if LED is already on/off, leave alone
if (on) SBI(LEDs[row], col); else CBI(LEDs[row], col);
Max7219(8 - row, LEDs[row]);
}
void Max7219_LED_On(const uint8_t row, const uint8_t col) {
Max7219_LED_Set(row, col, true);
void Max7219_LED_On(const uint8_t col, const uint8_t row) {
if (row > 7 || col > 7) {
int r,c;
r = row;
c = col;
SERIAL_ECHOPAIR("??? Max7219_LED_On(",c);
SERIAL_ECHOPAIR(",",r);
SERIAL_ECHO(")\n");
return;
}
Max7219_LED_Set(col, row, true);
}
void Max7219_LED_Off(const uint8_t row, const uint8_t col) {
Max7219_LED_Set(row, col, false);
void Max7219_LED_Off(const uint8_t col, const uint8_t row) {
if (row > 7 || col > 7) {
int r,c;
r = row;
c = col;
SERIAL_ECHOPAIR("??? Max7219_LED_Off(",r);
SERIAL_ECHOPAIR(",",c);
SERIAL_ECHO(")\n");
return;
}
Max7219_LED_Set(col, row, false);
}
void Max7219_LED_Toggle(const uint8_t row, const uint8_t col) {
if (row > 7 || col > 7) return;
void Max7219_LED_Toggle(const uint8_t col, const uint8_t row) {
if (row > 7 || col > 7) {
int r,c;
r = row;
c = col;
SERIAL_ECHOPAIR("??? Max7219_LED_Toggle(",r);
SERIAL_ECHOPAIR(",",c);
SERIAL_ECHO(")\n");
return;
}
if (TEST(LEDs[row], col))
Max7219_LED_Off(row, col);
Max7219_LED_Off(col, row);
else
Max7219_LED_On(row, col);
Max7219_LED_On(col, row);
}
void Max7219_Clear_Column(const uint8_t col) {
if (col > 7) return;
if (col > 7) {
int c;
c = col;
SERIAL_ECHOPAIR("??? Max7219_Clear_Column(",c);
SERIAL_ECHO(")\n");
return;
}
LEDs[col] = 0;
Max7219(8 - col, LEDs[col]);
}
void Max7219_Clear_Row(const uint8_t row) {
if (row > 7) return;
if (row > 7) {
int r;
r = row;
SERIAL_ECHOPAIR("??? Max7219_Clear_Row(",r);
SERIAL_ECHO(")\n");
return;
}
for (uint8_t c = 0; c <= 7; c++)
Max7219_LED_Off(c, row);
}
void Max7219_Set_Row(const uint8_t row, const uint8_t val) {
if (row > 7) return;
if (row > 7 || val>255) {
int r, v;
r = row;
v = val;
SERIAL_ECHOPAIR("??? Max7219_Set_Row(",r);
SERIAL_ECHOPAIR(",",v);
SERIAL_ECHO(")\n");
return;
}
for (uint8_t b = 0; b <= 7; b++)
if (TEST(val, b))
Max7219_LED_On(7 - b, row);
@ -142,8 +211,47 @@ void Max7219_Set_Row(const uint8_t row, const uint8_t val) {
Max7219_LED_Off(7 - b, row);
}
void Max7219_Set_2_Rows(const uint8_t row, const uint16_t val) {
if (row > 6 || val>65535) {
int r, v;
r = row;
v = val;
SERIAL_ECHOPAIR("??? Max7219_Set_2_Rows(",r);
SERIAL_ECHOPAIR(",",v);
SERIAL_ECHO(")\n");
return;
}
Max7219_Set_Row(row+1, (val & 0xff00) >> 8 );
Max7219_Set_Row(row+0, (val & 0xff));
}
void Max7219_Set_4_Rows(const uint8_t row, const uint32_t val) {
if (row > 4 ) {
int r;
long v;
r = row;
v = val;
SERIAL_ECHOPAIR("??? Max7219_Set_4_Rows(",r);
SERIAL_ECHOPAIR(",",v);
SERIAL_ECHO(")\n");
return;
}
Max7219_Set_Row(row+3, (val & 0xff000000) >> 24);
Max7219_Set_Row(row+2, (val & 0xff0000) >> 16);
Max7219_Set_Row(row+1, (val & 0xff00) >> 8);
Max7219_Set_Row(row+0, (val & 0xff));
}
void Max7219_Set_Column(const uint8_t col, const uint8_t val) {
if (col > 7) return;
if (val > 255 || col > 7) {
int v,c;
v = val;
c = col;
SERIAL_ECHOPAIR("??? Max7219_Column(",c);
SERIAL_ECHOPAIR(",",v);
SERIAL_ECHO(")\n");
return;
}
LEDs[col] = val;
Max7219(8 - col, LEDs[col]);
}
@ -206,10 +314,23 @@ void Max7219_init() {
* or clear a row is not very significant.
*/
void Max7219_idle_tasks() {
#if MAX7219_DEBUG_STEPPER_HEAD || MAX7219_DEBUG_STEPPER_TAIL || MAX7219_DEBUG_STEPPER_QUEUE
CRITICAL_SECTION_START
#if MAX7219_DEBUG_STEPPER_HEAD || MAX7219_DEBUG_STEPPER_QUEUE
uint8_t head;
head = planner.block_buffer_head;
#endif
#if MAX7219_DEBUG_STEPPER_TAIL || MAX7219_DEBUG_STEPPER_QUEUE
uint8_t tail;
tail = planner.block_buffer_tail;
#endif
CRITICAL_SECTION_END
#endif
#if ENABLED(MAX7219_DEBUG_PRINTER_ALIVE)
static int debug_cnt = 0;
#ifdef CPU_32_BIT
if (debug_cnt++ > 400) {
if (debug_cnt++ > 1000) {
#else
if (debug_cnt++ > 100) {
#endif
@ -219,26 +340,40 @@ void Max7219_idle_tasks() {
#endif
#ifdef MAX7219_DEBUG_STEPPER_HEAD
Max7219_Clear_Row(MAX7219_DEBUG_STEPPER_HEAD);
Max7219_Clear_Row(MAX7219_DEBUG_STEPPER_HEAD + 1);
if ( planner.block_buffer_head < 8)
Max7219_LED_On( planner.block_buffer_head, MAX7219_DEBUG_STEPPER_HEAD);
else
Max7219_LED_On( planner.block_buffer_head-8, MAX7219_DEBUG_STEPPER_HEAD+1);
static int16_t last_head_cnt=0;
if (last_head_cnt != head) {
if ( last_head_cnt < 8)
Max7219_LED_Off( last_head_cnt, MAX7219_DEBUG_STEPPER_HEAD);
else
Max7219_LED_Off( last_head_cnt-8, MAX7219_DEBUG_STEPPER_HEAD+1);
last_head_cnt = head;
if ( head < 8)
Max7219_LED_On(head, MAX7219_DEBUG_STEPPER_HEAD);
else
Max7219_LED_On(head-8, MAX7219_DEBUG_STEPPER_HEAD+1);
}
#endif
#ifdef MAX7219_DEBUG_STEPPER_TAIL
Max7219_Clear_Row(MAX7219_DEBUG_STEPPER_TAIL);
Max7219_Clear_Row(MAX7219_DEBUG_STEPPER_TAIL + 1);
if ( planner.block_buffer_tail < 8)
Max7219_LED_On( planner.block_buffer_tail, MAX7219_DEBUG_STEPPER_TAIL );
else
Max7219_LED_On( planner.block_buffer_tail-8, MAX7219_DEBUG_STEPPER_TAIL+1 );
static int16_t last_tail_cnt=0;
if (last_tail_cnt != tail) {
if ( last_tail_cnt < 8)
Max7219_LED_Off( last_tail_cnt, MAX7219_DEBUG_STEPPER_TAIL);
else
Max7219_LED_Off( last_tail_cnt-8, MAX7219_DEBUG_STEPPER_TAIL+1);
last_tail_cnt = tail;
if ( tail < 8)
Max7219_LED_On(tail, MAX7219_DEBUG_STEPPER_TAIL);
else
Max7219_LED_On(tail-8, MAX7219_DEBUG_STEPPER_TAIL+1);
}
#endif
#ifdef MAX7219_DEBUG_STEPPER_QUEUE
static int16_t last_depth = 0;
int16_t current_depth = planner.block_buffer_head - planner.block_buffer_tail;
int16_t current_depth = head - tail;
if (current_depth != last_depth) { // usually, no update will be needed.
if (current_depth < 0) current_depth += BLOCK_BUFFER_SIZE;
NOMORE(current_depth, BLOCK_BUFFER_SIZE);
@ -249,10 +384,10 @@ void Max7219_idle_tasks() {
en = max(current_depth, last_depth);
if (current_depth < last_depth)
for (uint8_t i = st; i <= en; i++) // clear the highest order LEDs
Max7219_LED_Off(i >> 1, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1));
Max7219_LED_Off(i/2, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1));
else
for (uint8_t i = st; i <= en; i++) // set the highest order LEDs
Max7219_LED_On(i >> 1, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1));
for (uint8_t i = st; i <= en; i++) // set the LEDs to current depth
Max7219_LED_On(i/2, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1));
last_depth = current_depth;
}

View file

@ -40,12 +40,14 @@
* void Max7219_PutByte(uint8_t data);
* void Max7219(uint8_t reg, uint8_t data);
* void Max7219_LED_Set(uint8_t row, uint8_t col, bool on);
* void Max7219_LED_On(uint8_t row, uint8_t col);
* void Max7219_LED_Off(uint8_t row, uint8_t col);
* void Max7219_LED_On(uint8_t col, uint8_t row);
* void Max7219_LED_Off(uint8_t col, uint8_t row);
* void Max7219_LED_Toggle(uint8_t row, uint8_t col);
* void Max7219_Clear_Row(uint8_t row);
* void Max7219_Clear_Column(uint8_t col);
* void Max7219_Set_Row(uint8_t row, uint8_t val);
* void Max7219_Set_2_Rows(uint8_t row, uint16_t val);
* void Max7219_Set_4_Rows(uint8_t row, uint32_t val);
* void Max7219_Set_Column(uint8_t col, uint8_t val);
* void Max7219_idle_tasks();
*/

View file

@ -1294,6 +1294,7 @@ void Stepper::report_positions() {
_ENABLE(AXIS); \
_SAVE_START; \
_APPLY_DIR(AXIS, _INVERT_DIR(AXIS)^direction^INVERT); \
_PULSE_WAIT; \
_APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS), true); \
_PULSE_WAIT; \
_APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS), true); \

View file

@ -441,7 +441,7 @@ class Temperature {
#if ENABLED(BABYSTEPPING)
static void babystep_axis(const AxisEnum axis, const int distance) {
static void babystep_axis(const AxisEnum axis, const int16_t distance) {
if (axis_known_position[axis]) {
#if IS_CORE
#if ENABLED(BABYSTEP_XY)