Browse Source

Debugging of the stepper timer routine. When enabled through
DEBUG_STEPPER_TIMER_MISSED, the printer is halted on stepper timer overflow
and an error message is displayed.

bubnikv 7 years ago
parent
commit
3e6d853364

+ 1 - 0
Firmware/Configuration_prusa.h

@@ -127,6 +127,7 @@ const bool Z_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic o
 //#define DEBUG_DISABLE_FANCHECK     //disable fan check (no ISR INT7, check disabled)
 //#define DEBUG_DISABLE_FSENSORCHECK //disable fsensor check (no ISR INT7, check disabled)
 #define DEBUG_DUMP_TO_2ND_SERIAL   //dump received characters to 2nd serial line
+//#define DEBUG_STEPPER_TIMER_MISSED // Stop on stepper timer overflow, beep and display a message.
 #endif
 
 

+ 5 - 0
Firmware/language_all.cpp

@@ -2039,6 +2039,11 @@ const char * const MSG_STEEL_SHEET_CHECK_LANG_TABLE[LANG_NUM] PROGMEM = {
 	MSG_STEEL_SHEET_CHECK_CZ
 };
 
+const char MSG_STEPPER_TIMER_OVERFLOW_ERROR_EN[] PROGMEM = "Error - stepper timer overflow";
+const char * const MSG_STEPPER_TIMER_OVERFLOW_ERROR_LANG_TABLE[1] PROGMEM = {
+	MSG_STEPPER_TIMER_OVERFLOW_ERROR_EN
+};
+
 const char MSG_STEPPER_TOO_HIGH_EN[] PROGMEM = "Steprate too high: ";
 const char * const MSG_STEPPER_TOO_HIGH_LANG_TABLE[1] PROGMEM = {
 	MSG_STEPPER_TOO_HIGH_EN

+ 2 - 0
Firmware/language_all.h

@@ -672,6 +672,8 @@ extern const char* const MSG_STATS_TOTALPRINTTIME_LANG_TABLE[LANG_NUM];
 #define MSG_STATS_TOTALPRINTTIME LANG_TABLE_SELECT(MSG_STATS_TOTALPRINTTIME_LANG_TABLE)
 extern const char* const MSG_STEEL_SHEET_CHECK_LANG_TABLE[LANG_NUM];
 #define MSG_STEEL_SHEET_CHECK LANG_TABLE_SELECT(MSG_STEEL_SHEET_CHECK_LANG_TABLE)
+extern const char* const MSG_STEPPER_TIMER_OVERFLOW_ERROR_LANG_TABLE[1];
+#define MSG_STEPPER_TIMER_OVERFLOW_ERROR LANG_TABLE_SELECT_EXPLICIT(MSG_STEPPER_TIMER_OVERFLOW_ERROR_LANG_TABLE, 0)
 extern const char* const MSG_STEPPER_TOO_HIGH_LANG_TABLE[1];
 #define MSG_STEPPER_TOO_HIGH LANG_TABLE_SELECT_EXPLICIT(MSG_STEPPER_TOO_HIGH_LANG_TABLE, 0)
 extern const char* const MSG_STOPPED_LANG_TABLE[1];

+ 1 - 0
Firmware/language_en.h

@@ -261,6 +261,7 @@
 #define(length=20, lines=4) MSG_FIL_ADJUSTING								"Adjusting filaments. Please wait."
 #define(length=20,lines=8) MSG_CONFIRM_NOZZLE_CLEAN_FIL_ADJ			"Filaments are now adjusted. Please clean the nozzle for calibration. Click when done."
 #define(length=20, lines=4) MSG_STACK_ERROR						"Error - static memory has been overwritten"
+#define(length=20, lines=4) MSG_STEPPER_TIMER_OVERFLOW_ERROR	"Error - stepper timer overflow"
 #define(length=20, lines=1) MSG_CALIBRATE_E						"Calibrate E"
 //#define(length=20, lines=1) MSG_RESET_CALIBRATE_E				"Reset E Cal."
 #define(length=20, lines=8) MSG_E_CAL_KNOB						"Rotate knob until mark reaches extruder body. Click when done."

+ 14 - 0
Firmware/stepper.cpp

@@ -126,6 +126,10 @@ uint8_t LastStepMask = 0;
   #define _NEXT_ISR(T) OCR1A = T
 #endif
 
+#ifdef DEBUG_STEPPER_TIMER_MISSED
+extern bool stepper_timer_overflow_state;
+#endif /* DEBUG_STEPPER_TIMER_MISSED */
+
 //===========================================================================
 //=============================functions         ============================
 //===========================================================================
@@ -842,6 +846,16 @@ void isr() {
 #ifdef TMC2130
 	tmc2130_st_isr(LastStepMask);
 #endif //TMC2130
+#ifdef DEBUG_STEPPER_TIMER_MISSED
+  // Verify whether the next planned timer interrupt has not been missed already.  
+  // This debugging test takes < 1.125us
+  // This skews the profiling slightly as the fastest stepper timer
+  // interrupt repeats at a 100us rate (10kHz).
+  if (OCR1A < TCNT1) {
+    stepper_timer_overflow_state = true;
+    WRITE(BEEPER, HIGH);
+  }
+#endif
 }
 
 #ifdef LIN_ADVANCE

+ 16 - 0
Firmware/ultralcd.cpp

@@ -5109,6 +5109,19 @@ void stack_error() {
 	 while (1) delay_keep_alive(1000);
 }
 
+#ifdef DEBUG_STEPPER_TIMER_MISSED
+bool stepper_timer_overflow_state = false;
+void stepper_timer_overflow() {
+  SET_OUTPUT(BEEPER);
+  WRITE(BEEPER, HIGH);
+  delay(1000);
+  WRITE(BEEPER, LOW);
+  lcd_display_message_fullscreen_P(MSG_STEPPER_TIMER_OVERFLOW_ERROR);
+  //err_triggered = 1;
+   while (1) delay_keep_alive(1000);
+}
+#endif /* DEBUG_STEPPER_TIMER_MISSED */
+
 #ifdef SDSUPPORT
 static void lcd_autostart_sd()
 {
@@ -6779,6 +6792,9 @@ void lcd_update(uint8_t lcdDrawUpdateOverride)
 	  lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
 	  }
 	if (!SdFatUtil::test_stack_integrity()) stack_error();
+#ifdef DEBUG_STEPPER_TIMER_MISSED
+  if (stepper_timer_overflow_state) stepper_timer_overflow();
+#endif /* DEBUG_STEPPER_TIMER_MISSED */
 	lcd_ping(); //check that we have received ping command if we are in farm mode
 	if (lcd_commands_type == LCD_COMMAND_V2_CAL) lcd_commands();
 }