Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
clough42 committed Feb 26, 2021
2 parents 7a5f6fb + 84ab988 commit adbd47f
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 39 deletions.
2 changes: 1 addition & 1 deletion els-f280049c/28004x_generic_ram_lnk.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions els-f280049c/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
3 changes: 2 additions & 1 deletion els-f280049c/StepperDrive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ void StepperDrive :: initHardware(void)

GPIO_CLEAR_STEP;
GPIO_CLEAR_DIRECTION;
GPIO_SET_ENABLE;
EDIS;

setEnabled(true);
}


Expand Down
96 changes: 60 additions & 36 deletions els-f280049c/StepperDrive.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ class StepperDrive
//
Uint16 state;

//
// Is the drive enabled?
//
bool enabled;

public:
StepperDrive();
void initHardware(void);
Expand All @@ -99,6 +104,8 @@ class StepperDrive
void incrementCurrentPosition(int32 increment);
void setCurrentPosition(int32 position);

bool checkStepBacklog();

void setEnabled(bool);

bool isAlarm();
Expand All @@ -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
Expand All @@ -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;
}
}

Expand Down
31 changes: 30 additions & 1 deletion els-f280049c/UserInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions els-f280049c/UserInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions els-f280049c/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit adbd47f

Please sign in to comment.