From 7711032223063c629a51f9628c0516f47538cf01 Mon Sep 17 00:00:00 2001 From: Clough42 Date: Sat, 10 Oct 2020 15:40:49 -0700 Subject: [PATCH 1/6] Make power button disable stepper drive and turn off control panel. --- els-f280049c/Core.cpp | 7 +++ els-f280049c/Core.h | 10 +++ els-f280049c/StepperDrive.h | 13 ++++ els-f280049c/UserInterface.cpp | 112 ++++++++++++++++++--------------- els-f280049c/UserInterface.h | 2 +- 5 files changed, 91 insertions(+), 53 deletions(-) diff --git a/els-f280049c/Core.cpp b/els-f280049c/Core.cpp index 266ee46..e0fc0c4 100644 --- a/els-f280049c/Core.cpp +++ b/els-f280049c/Core.cpp @@ -40,6 +40,8 @@ Core :: Core( Encoder *encoder, StepperDrive *stepperDrive ) this->previousSpindlePosition = 0; this->previousFeedDirection = 0; this->previousFeed = NULL; + + this->powerOn = true; // default to power on } void Core :: setReverse(bool reverse) @@ -54,6 +56,11 @@ void Core :: setReverse(bool reverse) } } +void Core :: setPowerOn(bool powerOn) +{ + this->powerOn = powerOn; + this->stepperDrive->setEnabled(powerOn); +} diff --git a/els-f280049c/Core.h b/els-f280049c/Core.h index b843601..af21e7e 100644 --- a/els-f280049c/Core.h +++ b/els-f280049c/Core.h @@ -54,6 +54,8 @@ class Core int32 feedRatio(Uint32 count); + bool powerOn; + public: Core( Encoder *encoder, StepperDrive *stepperDrive ); @@ -62,6 +64,9 @@ class Core Uint16 getRPM(void); bool isAlarm(); + bool isPowerOn(); + void setPowerOn(bool); + void ISR( void ); }; @@ -84,6 +89,11 @@ inline bool Core :: isAlarm() return this->stepperDrive->isAlarm(); } +inline bool Core :: isPowerOn() +{ + return this->powerOn; +} + inline int32 Core :: feedRatio(Uint32 count) { #ifdef USE_FLOATING_POINT diff --git a/els-f280049c/StepperDrive.h b/els-f280049c/StepperDrive.h index cd2bc99..d155155 100644 --- a/els-f280049c/StepperDrive.h +++ b/els-f280049c/StepperDrive.h @@ -99,6 +99,8 @@ class StepperDrive void incrementCurrentPosition(int32 increment); void setCurrentPosition(int32 position); + void setEnabled(bool); + bool isAlarm(); void ISR(void); @@ -119,6 +121,17 @@ inline void StepperDrive :: setCurrentPosition(int32 position) this->currentPosition = position; } +inline void StepperDrive :: setEnabled(bool enabled) +{ + if( enabled ) { + GPIO_SET_ENABLE; + } + else + { + GPIO_CLEAR_ENABLE; + } +} + inline bool StepperDrive :: isAlarm() { #ifdef USE_ALARM_PIN diff --git a/els-f280049c/UserInterface.cpp b/els-f280049c/UserInterface.cpp index 4bca9a1..2e0c5cd 100644 --- a/els-f280049c/UserInterface.cpp +++ b/els-f280049c/UserInterface.cpp @@ -52,6 +52,8 @@ const MESSAGE SETTINGS_MESSAGE_1 = .next = &SETTINGS_MESSAGE_2 }; +const Uint16 VALUE_BLANK[4] = { BLANK, BLANK, BLANK, BLANK }; + UserInterface :: UserInterface(ControlPanel *controlPanel, Core *core, FeedTableFactory *feedTableFactory) { this->controlPanel = controlPanel; @@ -66,6 +68,8 @@ UserInterface :: UserInterface(ControlPanel *controlPanel, Core *core, FeedTable this->keys.all = 0xff; + loadFeedTable(); + setMessage(&STARTUP_MESSAGE_1); } @@ -75,15 +79,23 @@ const FEED_THREAD *UserInterface::loadFeedTable() return this->feedTable->current(); } -LED_REG UserInterface::calculateLEDs(const FEED_THREAD *selectedFeed) +LED_REG UserInterface::calculateLEDs() { // get the LEDs for this feed - LED_REG leds = selectedFeed->leds; + LED_REG leds = feedTable->current()->leds; - // and add a few of our own - leds.bit.POWER = 1; - leds.bit.REVERSE = this->reverse; - leds.bit.FORWARD = ! this->reverse; + if( this->core->isPowerOn() ) + { + // and add a few of our own + leds.bit.POWER = 1; + leds.bit.REVERSE = this->reverse; + leds.bit.FORWARD = ! this->reverse; + } + else + { + // power is off + leds.all = 0; + } return leds; } @@ -114,19 +126,12 @@ void UserInterface :: overrideMessage( void ) void UserInterface :: loop( void ) { - const FEED_THREAD *newFeed = NULL; - // read the RPM up front so we can use it to make decisions Uint16 currentRpm = core->getRPM(); // display an override message, if there is one overrideMessage(); - // just in case, initialize the first time through - if( feedTable == NULL ) { - newFeed = loadFeedTable(); - } - // read keypresses from the control panel keys = controlPanel->getKeys(); @@ -134,25 +139,31 @@ void UserInterface :: loop( void ) if( currentRpm == 0 ) { // these keys should only be sensitive when the machine is stopped - if( keys.bit.IN_MM ) - { - this->metric = ! this->metric; - newFeed = loadFeedTable(); - } - if( keys.bit.FEED_THREAD ) - { - this->thread = ! this->thread; - newFeed = loadFeedTable(); + if( keys.bit.POWER ) { + this->core->setPowerOn(!this->core->isPowerOn()); } - if( keys.bit.FWD_REV ) - { - this->reverse = ! this->reverse; - // feed table hasn't changed, but we need to trigger an update - newFeed = loadFeedTable(); - } - if( keys.bit.SET ) - { - setMessage(&SETTINGS_MESSAGE_1); + + // these should only work when the power is on + if( this->core->isPowerOn() ) { + if( keys.bit.IN_MM ) + { + this->metric = ! this->metric; + core->setFeed(loadFeedTable()); + } + if( keys.bit.FEED_THREAD ) + { + this->thread = ! this->thread; + core->setFeed(loadFeedTable()); + } + if( keys.bit.FWD_REV ) + { + this->reverse = ! this->reverse; + core->setReverse(this->reverse); + } + if( keys.bit.SET ) + { + setMessage(&SETTINGS_MESSAGE_1); + } } } @@ -161,35 +172,32 @@ void UserInterface :: loop( void ) { #endif // IGNORE_ALL_KEYS_WHEN_RUNNING - // these keys can be operated when the machine is running - if( keys.bit.UP ) - { - newFeed = feedTable->next(); - } - if( keys.bit.DOWN ) - { - newFeed = feedTable->previous(); + // these should only work when the power is on + if( this->core->isPowerOn() ) { + // these keys can be operated when the machine is running + if( keys.bit.UP ) + { + core->setFeed(feedTable->next()); + } + if( keys.bit.DOWN ) + { + core->setFeed(feedTable->previous()); + } } #ifdef IGNORE_ALL_KEYS_WHEN_RUNNING } #endif // IGNORE_ALL_KEYS_WHEN_RUNNING - // if we have changed the feed - if( newFeed != NULL ) { - // update the display - LED_REG leds = this->calculateLEDs(newFeed); - controlPanel->setLEDs(leds); - controlPanel->setValue(newFeed->display); + // update the control panel + controlPanel->setLEDs(calculateLEDs()); + controlPanel->setValue(feedTable->current()->display); + controlPanel->setRPM(currentRpm); - // update the core - core->setFeed(newFeed); - core->setReverse(this->reverse); + if( ! core->isPowerOn() ) + { + controlPanel->setValue(VALUE_BLANK); } - // update the RPM display - controlPanel->setRPM(currentRpm); - - // write data out to the display controlPanel->refresh(); } diff --git a/els-f280049c/UserInterface.h b/els-f280049c/UserInterface.h index 2be3ce4..d193914 100644 --- a/els-f280049c/UserInterface.h +++ b/els-f280049c/UserInterface.h @@ -57,7 +57,7 @@ class UserInterface Uint16 messageTime; const FEED_THREAD *loadFeedTable(); - LED_REG calculateLEDs(const FEED_THREAD *selectedFeed); + LED_REG calculateLEDs(); void setMessage(const MESSAGE *message); void overrideMessage( void ); From 72c75c6a07b6898df2259e9cadc1bbbffe5be8fe Mon Sep 17 00:00:00 2001 From: Clough42 Date: Sat, 10 Oct 2020 15:57:30 -0700 Subject: [PATCH 2/6] Roll version to 1.3.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 2e0c5cd..1be8d76 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, TWO | POINT, ZERO, ZERO }, + .message = { LETTER_E, LETTER_L, LETTER_S, DASH, ONE | POINT, THREE | POINT, ZERO, ZERO }, .displayTime = UI_REFRESH_RATE_HZ * 1.5 }; From a4cfe972e68b7cd5610806b2cc375064a12a5807 Mon Sep 17 00:00:00 2001 From: clough42 Date: Sat, 10 Oct 2020 17:18:28 -0600 Subject: [PATCH 3/6] Manual merge of travistabbal's different stepper rates for feed and threading. (#95) --- els-f280049c/Configuration.h | 5 ++++ els-f280049c/Tables.cpp | 56 +++++++++++++++++++++--------------- 2 files changed, 38 insertions(+), 23 deletions(-) diff --git a/els-f280049c/Configuration.h b/els-f280049c/Configuration.h index 3216572..8581663 100644 --- a/els-f280049c/Configuration.h +++ b/els-f280049c/Configuration.h @@ -67,6 +67,11 @@ #define STEPPER_MICROSTEPS 8 #define STEPPER_RESOLUTION 200 +// Separate step and microstep settings for feed rates. Redefine these if your +// lathe has a separate feed drive train with a different ratio. +#define STEPPER_MICROSTEPS_FEED STEPPER_MICROSTEPS +#define STEPPER_RESOLUTION_FEED STEPPER_RESOLUTION + // Step, direction and enable pins are normally active-high // #define INVERT_STEP_PIN true // #define INVERT_DIRECTION_PIN true diff --git a/els-f280049c/Tables.cpp b/els-f280049c/Tables.cpp index 4465926..fea7ab2 100644 --- a/els-f280049c/Tables.cpp +++ b/els-f280049c/Tables.cpp @@ -82,11 +82,11 @@ const FEED_THREAD inch_thread_table[] = // #if defined(LEADSCREW_TPI) -#define THOU_IN_NUMERATOR(thou) ((Uint64)thou*LEADSCREW_TPI*STEPPER_RESOLUTION*STEPPER_MICROSTEPS) +#define THOU_IN_NUMERATOR(thou) ((Uint64)thou*LEADSCREW_TPI*STEPPER_RESOLUTION_FEED*STEPPER_MICROSTEPS_FEED) #define THOU_IN_DENOMINATOR(thou) ((Uint64)ENCODER_RESOLUTION*1000) #endif #if defined(LEADSCREW_HMM) -#define THOU_IN_NUMERATOR(thou) ((Uint64)thou*254*STEPPER_RESOLUTION*STEPPER_MICROSTEPS) +#define THOU_IN_NUMERATOR(thou) ((Uint64)thou*254*STEPPER_RESOLUTION_FEED*STEPPER_MICROSTEPS_FEED) #define THOU_IN_DENOMINATOR(thou) ((Uint64)ENCODER_RESOLUTION*100*LEADSCREW_HMM) #endif #define THOU_IN_FRACTION(thou) .numerator = THOU_IN_NUMERATOR(thou), .denominator = THOU_IN_DENOMINATOR(thou) @@ -171,29 +171,39 @@ const FEED_THREAD metric_thread_table[] = // Each row in the table defines a standard metric feed, with the display data, // LED indicator states and gear ratio fraction to use. // +#if defined(LEADSCREW_TPI) +#define HMM_NUMERATOR_FEED(hmm) ((Uint64)hmm*10*LEADSCREW_TPI*STEPPER_RESOLUTION_FEED*STEPPER_MICROSTEPS_FEED) +#define HMM_DENOMINATOR_FEED(hmm) ((Uint64)ENCODER_RESOLUTION*254*100) +#endif +#if defined(LEADSCREW_HMM) +#define HMM_NUMERATOR_FEED(hmm) ((Uint64)hmm*STEPPER_RESOLUTION_FEED*STEPPER_MICROSTEPS_FEED) +#define HMM_DENOMINATOR_FEED(hmm) ((Uint64)ENCODER_RESOLUTION*LEADSCREW_HMM) +#endif +#define HMM_FRACTION_FEED(hmm) .numerator = HMM_NUMERATOR_FEED(hmm), .denominator = HMM_DENOMINATOR_FEED(hmm) + const FEED_THREAD metric_feed_table[] = { - { .display = {BLANK, POINT, ZERO, TWO}, .leds = LED_FEED | LED_MM, HMM_FRACTION(2) }, - { .display = {BLANK, POINT, ZERO, FIVE}, .leds = LED_FEED | LED_MM, HMM_FRACTION(5) }, - { .display = {BLANK, POINT, ZERO, SEVEN}, .leds = LED_FEED | LED_MM, HMM_FRACTION(7) }, - { .display = {BLANK, POINT, ONE, ZERO}, .leds = LED_FEED | LED_MM, HMM_FRACTION(10) }, - { .display = {BLANK, POINT, ONE, TWO}, .leds = LED_FEED | LED_MM, HMM_FRACTION(12) }, - { .display = {BLANK, POINT, ONE, FIVE}, .leds = LED_FEED | LED_MM, HMM_FRACTION(15) }, - { .display = {BLANK, POINT, ONE, SEVEN}, .leds = LED_FEED | LED_MM, HMM_FRACTION(17) }, - { .display = {BLANK, POINT, TWO, ZERO}, .leds = LED_FEED | LED_MM, HMM_FRACTION(20) }, - { .display = {BLANK, POINT, TWO, TWO}, .leds = LED_FEED | LED_MM, HMM_FRACTION(22) }, - { .display = {BLANK, POINT, TWO, FIVE}, .leds = LED_FEED | LED_MM, HMM_FRACTION(25) }, - { .display = {BLANK, POINT, TWO, SEVEN}, .leds = LED_FEED | LED_MM, HMM_FRACTION(27) }, - { .display = {BLANK, POINT, THREE, ZERO}, .leds = LED_FEED | LED_MM, HMM_FRACTION(30) }, - { .display = {BLANK, POINT, THREE, FIVE}, .leds = LED_FEED | LED_MM, HMM_FRACTION(35) }, - { .display = {BLANK, POINT, FOUR, ZERO}, .leds = LED_FEED | LED_MM, HMM_FRACTION(40) }, - { .display = {BLANK, POINT, FOUR, FIVE}, .leds = LED_FEED | LED_MM, HMM_FRACTION(45) }, - { .display = {BLANK, POINT, FIVE, ZERO}, .leds = LED_FEED | LED_MM, HMM_FRACTION(50) }, - { .display = {BLANK, POINT, FIVE, FIVE}, .leds = LED_FEED | LED_MM, HMM_FRACTION(55) }, - { .display = {BLANK, POINT, SIX, ZERO}, .leds = LED_FEED | LED_MM, HMM_FRACTION(60) }, - { .display = {BLANK, POINT, SEVEN, ZERO}, .leds = LED_FEED | LED_MM, HMM_FRACTION(70) }, - { .display = {BLANK, POINT, EIGHT, FIVE}, .leds = LED_FEED | LED_MM, HMM_FRACTION(85) }, - { .display = {BLANK, ONE | POINT, ZERO, ZERO}, .leds = LED_FEED | LED_MM, HMM_FRACTION(100) }, + { .display = {BLANK, POINT, ZERO, TWO}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(2) }, + { .display = {BLANK, POINT, ZERO, FIVE}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(5) }, + { .display = {BLANK, POINT, ZERO, SEVEN}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(7) }, + { .display = {BLANK, POINT, ONE, ZERO}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(10) }, + { .display = {BLANK, POINT, ONE, TWO}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(12) }, + { .display = {BLANK, POINT, ONE, FIVE}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(15) }, + { .display = {BLANK, POINT, ONE, SEVEN}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(17) }, + { .display = {BLANK, POINT, TWO, ZERO}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(20) }, + { .display = {BLANK, POINT, TWO, TWO}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(22) }, + { .display = {BLANK, POINT, TWO, FIVE}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(25) }, + { .display = {BLANK, POINT, TWO, SEVEN}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(27) }, + { .display = {BLANK, POINT, THREE, ZERO}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(30) }, + { .display = {BLANK, POINT, THREE, FIVE}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(35) }, + { .display = {BLANK, POINT, FOUR, ZERO}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(40) }, + { .display = {BLANK, POINT, FOUR, FIVE}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(45) }, + { .display = {BLANK, POINT, FIVE, ZERO}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(50) }, + { .display = {BLANK, POINT, FIVE, FIVE}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(55) }, + { .display = {BLANK, POINT, SIX, ZERO}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(60) }, + { .display = {BLANK, POINT, SEVEN, ZERO}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(70) }, + { .display = {BLANK, POINT, EIGHT, FIVE}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(85) }, + { .display = {BLANK, ONE | POINT, ZERO, ZERO}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(100) }, }; From 050860df6e432c556d39bcf2588dd52b9f60aa6d Mon Sep 17 00:00:00 2001 From: Clough42 Date: Sat, 10 Oct 2020 16:43:22 -0700 Subject: [PATCH 4/6] Fix startup initialization so the stepper/servo will actually run. --- els-f280049c/UserInterface.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/els-f280049c/UserInterface.cpp b/els-f280049c/UserInterface.cpp index 1be8d76..95ac690 100644 --- a/els-f280049c/UserInterface.cpp +++ b/els-f280049c/UserInterface.cpp @@ -68,7 +68,9 @@ UserInterface :: UserInterface(ControlPanel *controlPanel, Core *core, FeedTable this->keys.all = 0xff; - loadFeedTable(); + // initialize the core so we start up correctly + core->setReverse(this->reverse); + core->setFeed(loadFeedTable()); setMessage(&STARTUP_MESSAGE_1); } From 1dc851024c2f1eafd65e7a81a678dd022a334c49 Mon Sep 17 00:00:00 2001 From: Clough42 Date: Sat, 10 Oct 2020 17:12:32 -0700 Subject: [PATCH 5/6] Update version to 1.3.01. --- 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 95ac690..0bf1200 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, ZERO }, + .message = { LETTER_E, LETTER_L, LETTER_S, DASH, ONE | POINT, THREE | POINT, ZERO, ONE }, .displayTime = UI_REFRESH_RATE_HZ * 1.5 }; From 0a10330e4fde4d026795569741c1c521e5fd69eb Mon Sep 17 00:00:00 2001 From: clough42 Date: Sat, 10 Oct 2020 18:12:45 -0600 Subject: [PATCH 6/6] Change tachometer update to twice per second to reduce jitter. (#96) --- els-f280049c/Configuration.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/els-f280049c/Configuration.h b/els-f280049c/Configuration.h index 8581663..ab279f2 100644 --- a/els-f280049c/Configuration.h +++ b/els-f280049c/Configuration.h @@ -161,7 +161,7 @@ #define UI_REFRESH_RATE_HZ 100 // RPM recalculation rate, in Hz -#define RPM_CALC_RATE_HZ 10 +#define RPM_CALC_RATE_HZ 2 // Microprocessor system clock #define CPU_CLOCK_MHZ 100