From 695bfa04bf51f337c06d171c6959d9a125dbe34b Mon Sep 17 00:00:00 2001 From: EmbeddedMan Date: Thu, 19 Nov 2020 20:38:29 -0600 Subject: [PATCH] Optimization (6) : Using a boolean flag to keep track of when moves are done (runs out of steps) rather than checking step counter multiple times. --- EBB_firmware/app.X/source/ebb.c | 43 +++++++++++++++++++++++++-------- EBB_firmware/app.X/source/ebb.h | 1 + 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/EBB_firmware/app.X/source/ebb.c b/EBB_firmware/app.X/source/ebb.c index 2c2f409..31e7fb6 100644 --- a/EBB_firmware/app.X/source/ebb.c +++ b/EBB_firmware/app.X/source/ebb.c @@ -404,18 +404,18 @@ LATDbits.LATD1 = 1; ) { // Only output DIR bits if we are actually doing something - if (CurrentCommand.Steps[0] || CurrentCommand.Steps[1]) + if (CurrentCommand.Active[0] || CurrentCommand.Active[1]) { if (CurrentCommand.Command == COMMAND_MOTOR_MOVE_TIMED) { // Has time run out for this command yet? - if (CurrentCommand.Steps[0]) + if (CurrentCommand.Active[0]) { // Nope. So count this ISR tick, and then see if we need to take a step CurrentCommand.Steps[0]--; - if (CurrentCommand.Steps[0] != 0) + if (CurrentCommand.Steps[0] == 0) { - AllDone = FALSE; + CurrentCommand.Active[0] = FALSE; } // Motor 1 @@ -456,7 +456,7 @@ LATDbits.LATD1 = 1; // This only fires if the Command is COMMAND_MOTOR_MOVE // Only do this if there are steps left to take - if (CurrentCommand.Steps[0]) + if (CurrentCommand.Active[0]) { // For acceleration, we now add a bit to StepAdd each time through as well CurrentCommand.Rate[0].value += CurrentCommand.Accel[0]; @@ -471,10 +471,13 @@ LATDbits.LATD1 = 1; OutByte = OutByte | STEP1_BIT; TookStep = TRUE; CurrentCommand.Steps[0]--; + if (CurrentCommand.Steps[0] == 0) + { + CurrentCommand.Active[0] = FALSE; + } } - AllDone = FALSE; } - if (CurrentCommand.Steps[1]) + if (CurrentCommand.Active[1]) { // For acceleration, we now add a bit to StepAdd each time through as well CurrentCommand.Rate[1].value += CurrentCommand.Accel[1]; @@ -489,16 +492,19 @@ LATDbits.LATD1 = 1; OutByte = OutByte | STEP2_BIT; TookStep = TRUE; CurrentCommand.Steps[1]--; + if (CurrentCommand.Steps[1] == 0) + { + CurrentCommand.Active[1] = FALSE; + } } - AllDone = FALSE; } // We want to allow for a one-ISR tick move, which requires us to check // to see if the move has been completed here (to load the next command // immediately rather than waiting for the next tick). This primarily gives // us simpler math when figuring out how long moves will take. - if (CurrentCommand.Steps[0] == 0 && CurrentCommand.Steps[1] == 0) + if (CurrentCommand.Active[0] || CurrentCommand.Active[1]) { - AllDone = TRUE; + AllDone = FALSE; } } if (TookStep) @@ -714,6 +720,23 @@ LATDbits.LATD1 = 1; { acc_union[1].value = 0; } + // Set the "Active" flags for this move based on steps for each axis + if (CurrentCommand.Steps[0]) + { + CurrentCommand.Active[0] = TRUE; + } + else + { + CurrentCommand.Active[0] = FALSE; + } + if (CurrentCommand.Steps[1]) + { + CurrentCommand.Active[1] = TRUE; + } + else + { + CurrentCommand.Active[1] = FALSE; + } } FIFOEmpty = TRUE; } diff --git a/EBB_firmware/app.X/source/ebb.h b/EBB_firmware/app.X/source/ebb.h index e35c3d9..47c5d39 100644 --- a/EBB_firmware/app.X/source/ebb.h +++ b/EBB_firmware/app.X/source/ebb.h @@ -113,6 +113,7 @@ typedef struct UINT16 ServoRate; UINT8 SEState; UINT16 SEPower; + UINT8 Active[NUMBER_OF_STEPPERS]; } MoveCommandType; // Define global things that depend on the board type