From 25d08d6b8ed8d496c1e2eaaed4189c4c67f5b6d7 Mon Sep 17 00:00:00 2001 From: Clough42 Date: Wed, 24 Feb 2021 21:04:40 -0800 Subject: [PATCH 1/3] Panic stop with error message if stepper output backlog exceeds a configured value. --- els-f280049c/Configuration.h | 13 +++++ els-f280049c/StepperDrive.cpp | 3 +- els-f280049c/StepperDrive.h | 96 +++++++++++++++++++++------------- els-f280049c/UserInterface.cpp | 29 ++++++++++ els-f280049c/UserInterface.h | 3 ++ els-f280049c/main.cpp | 5 ++ 6 files changed, 112 insertions(+), 37 deletions(-) diff --git a/els-f280049c/Configuration.h b/els-f280049c/Configuration.h index ab279f2..96c48d7 100644 --- a/els-f280049c/Configuration.h +++ b/els-f280049c/Configuration.h @@ -146,6 +146,19 @@ +//================================================================================ +// VALIDATION/TRIP +// +// Validation thresholds and automatic trip behavior. +//================================================================================ + +// Maximum number of buffered steps +// The ELS can only output steps at approximately 100KHz. If you ask the ELS to +// output steps faster than this, it will get behind and will stop automatically +// when the buffered step count exceeds this value. +#define MAX_BUFFERED_STEPS 100 + + //================================================================================ // CPU / TIMING // diff --git a/els-f280049c/StepperDrive.cpp b/els-f280049c/StepperDrive.cpp index 324d026..35cf385 100644 --- a/els-f280049c/StepperDrive.cpp +++ b/els-f280049c/StepperDrive.cpp @@ -63,8 +63,9 @@ void StepperDrive :: initHardware(void) GPIO_CLEAR_STEP; GPIO_CLEAR_DIRECTION; - GPIO_SET_ENABLE; EDIS; + + setEnabled(true); } diff --git a/els-f280049c/StepperDrive.h b/els-f280049c/StepperDrive.h index d155155..63f0a8c 100644 --- a/els-f280049c/StepperDrive.h +++ b/els-f280049c/StepperDrive.h @@ -91,6 +91,11 @@ class StepperDrive // Uint16 state; + // + // Is the drive enabled? + // + bool enabled; + public: StepperDrive(); void initHardware(void); @@ -99,6 +104,8 @@ class StepperDrive void incrementCurrentPosition(int32 increment); void setCurrentPosition(int32 position); + bool checkStepBacklog(); + void setEnabled(bool); bool isAlarm(); @@ -121,9 +128,19 @@ inline void StepperDrive :: setCurrentPosition(int32 position) this->currentPosition = position; } +inline bool StepperDrive :: checkStepBacklog() +{ + if( abs(this->desiredPosition - this->currentPosition) > MAX_BUFFERED_STEPS ) { + setEnabled(false); + return true; + } + return false; +} + inline void StepperDrive :: setEnabled(bool enabled) { - if( enabled ) { + this->enabled = enabled; + if( this->enabled ) { GPIO_SET_ENABLE; } else @@ -144,45 +161,52 @@ inline bool StepperDrive :: isAlarm() inline void StepperDrive :: ISR(void) { - switch( this->state ) { + if(enabled) { + + switch( this->state ) { + + case 0: + // Step = 0; Dir = 0 + if( this->desiredPosition < this->currentPosition ) { + GPIO_SET_STEP; + this->state = 2; + } + else if( this->desiredPosition > this->currentPosition ) { + GPIO_SET_DIRECTION; + this->state = 1; + } + break; + + case 1: + // Step = 0; Dir = 1 + if( this->desiredPosition > this->currentPosition ) { + GPIO_SET_STEP; + this->state = 3; + } + else if( this->desiredPosition < this->currentPosition ) { + GPIO_CLEAR_DIRECTION; + this->state = 0; + } + break; + + case 2: + // Step = 1; Dir = 0 + GPIO_CLEAR_STEP; + this->currentPosition--; + this->state = 0; + break; - case 0: - // Step = 0; Dir = 0 - if( this->desiredPosition < this->currentPosition ) { - GPIO_SET_STEP; - this->state = 2; - } - else if( this->desiredPosition > this->currentPosition ) { - GPIO_SET_DIRECTION; + case 3: + // Step = 1; Dir = 1 + GPIO_CLEAR_STEP; + this->currentPosition++; this->state = 1; + break; } - break; - case 1: - // Step = 0; Dir = 1 - if( this->desiredPosition > this->currentPosition ) { - GPIO_SET_STEP; - this->state = 3; - } - else if( this->desiredPosition < this->currentPosition ) { - GPIO_CLEAR_DIRECTION; - this->state = 0; - } - break; - - case 2: - // Step = 1; Dir = 0 - GPIO_CLEAR_STEP; - this->currentPosition--; - this->state = 0; - break; - - case 3: - // Step = 1; Dir = 1 - GPIO_CLEAR_STEP; - this->currentPosition++; - this->state = 1; - break; + } else { + // not enabled; just keep current position in sync + this->currentPosition = this->desiredPosition; } } diff --git a/els-f280049c/UserInterface.cpp b/els-f280049c/UserInterface.cpp index 0bf1200..7ced22b 100644 --- a/els-f280049c/UserInterface.cpp +++ b/els-f280049c/UserInterface.cpp @@ -52,6 +52,22 @@ const MESSAGE SETTINGS_MESSAGE_1 = .next = &SETTINGS_MESSAGE_2 }; +extern const MESSAGE BACKLOG_PANIC_MESSAGE_2; +const MESSAGE BACKLOG_PANIC_MESSAGE_1 = +{ + .message = { LETTER_T, LETTER_O, LETTER_O, BLANK, LETTER_F, LETTER_A, LETTER_S, LETTER_T }, + .displayTime = UI_REFRESH_RATE_HZ * .5, + .next = &BACKLOG_PANIC_MESSAGE_2 +}; +const MESSAGE BACKLOG_PANIC_MESSAGE_2 = +{ + .message = { BLANK, LETTER_R, LETTER_E, LETTER_S, LETTER_E, LETTER_T, BLANK, BLANK }, + .displayTime = UI_REFRESH_RATE_HZ * .5, + .next = &BACKLOG_PANIC_MESSAGE_1 +}; + + + const Uint16 VALUE_BLANK[4] = { BLANK, BLANK, BLANK, BLANK }; UserInterface :: UserInterface(ControlPanel *controlPanel, Core *core, FeedTableFactory *feedTableFactory) @@ -126,6 +142,18 @@ void UserInterface :: overrideMessage( void ) } } +void UserInterface :: clearMessage( void ) +{ + this->message = NULL; + this->messageTime = 0; + controlPanel->setMessage(NULL); +} + +void UserInterface :: panicStepBacklog( void ) +{ + setMessage(&BACKLOG_PANIC_MESSAGE_1); +} + void UserInterface :: loop( void ) { // read the RPM up front so we can use it to make decisions @@ -143,6 +171,7 @@ void UserInterface :: loop( void ) // these keys should only be sensitive when the machine is stopped if( keys.bit.POWER ) { this->core->setPowerOn(!this->core->isPowerOn()); + clearMessage(); } // these should only work when the power is on diff --git a/els-f280049c/UserInterface.h b/els-f280049c/UserInterface.h index d193914..59c4eb0 100644 --- a/els-f280049c/UserInterface.h +++ b/els-f280049c/UserInterface.h @@ -60,11 +60,14 @@ class UserInterface LED_REG calculateLEDs(); void setMessage(const MESSAGE *message); void overrideMessage( void ); + void clearMessage( void ); public: UserInterface(ControlPanel *controlPanel, Core *core, FeedTableFactory *feedTableFactory); void loop( void ); + + void panicStepBacklog( void ); }; #endif // __USERINTERFACE_H diff --git a/els-f280049c/main.cpp b/els-f280049c/main.cpp index 24c4872..15ef30e 100644 --- a/els-f280049c/main.cpp +++ b/els-f280049c/main.cpp @@ -139,6 +139,11 @@ void main(void) // mark beginning of loop for debugging debug.begin2(); + // check for step backlog and panic the system if it occurs + if( stepperDrive.checkStepBacklog() ) { + userInterface.panicStepBacklog(); + } + // service the user interface userInterface.loop(); From eef24189c326d04442b7f246463498c55cbda4d1 Mon Sep 17 00:00:00 2001 From: Clough42 Date: Wed, 24 Feb 2021 21:12:44 -0800 Subject: [PATCH 2/3] Allow econst to span ram banks in debug mode. --- els-f280049c/28004x_generic_ram_lnk.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/els-f280049c/28004x_generic_ram_lnk.cmd b/els-f280049c/28004x_generic_ram_lnk.cmd index 5fd166d..4c608dd 100644 --- a/els-f280049c/28004x_generic_ram_lnk.cmd +++ b/els-f280049c/28004x_generic_ram_lnk.cmd @@ -105,7 +105,7 @@ SECTIONS .stack : > RAMM1, PAGE = 1 .ebss : > RAMLS5|RAMLS6, PAGE = 1 - .econst : > RAMLS5|RAMLS6, PAGE = 1 + .econst : >> RAMLS5|RAMLS6, PAGE = 1 .esysmem : > RAMLS5|RAMLS6, PAGE = 1 ramgs0 : > RAMGS0, PAGE = 1 From 84ab988fcbedb336d29baa8ee3ea47fd3f5ef05d Mon Sep 17 00:00:00 2001 From: Clough42 Date: Wed, 24 Feb 2021 21:16:37 -0800 Subject: [PATCH 3/3] Roll version number to 1.4.00 --- els-f280049c/UserInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/els-f280049c/UserInterface.cpp b/els-f280049c/UserInterface.cpp index 7ced22b..cc29952 100644 --- a/els-f280049c/UserInterface.cpp +++ b/els-f280049c/UserInterface.cpp @@ -28,7 +28,7 @@ const MESSAGE STARTUP_MESSAGE_2 = { - .message = { LETTER_E, LETTER_L, LETTER_S, DASH, ONE | POINT, THREE | POINT, ZERO, ONE }, + .message = { LETTER_E, LETTER_L, LETTER_S, DASH, ONE | POINT, FOUR | POINT, ZERO, ZERO }, .displayTime = UI_REFRESH_RATE_HZ * 1.5 };