Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -r8da12f877491ce76e60645acfa738458f954293a -r75e1ae332d1446dddf9b8d4ce6e8317449c57d67 --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision 8da12f877491ce76e60645acfa738458f954293a) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision 75e1ae332d1446dddf9b8d4ce6e8317449c57d67) @@ -7,8 +7,8 @@ * * @file Valves.c * -* @author (last) Darren Cox -* @date (last) 12-Jan-2023 +* @author (last) Dara Navaei +* @date (last) 22-Jan-2023 * * @author (original) Dara Navaei * @date (original) 07-Aug-2020 @@ -252,6 +252,7 @@ static void publishValvesData( VALVE_T valve ); static void setValveNextStep( VALVE_T valve, U32 stepChange ); static S16 getValvePositionCounts( VALVE_T valve ); +static BOOL isValveCloseToCommandedPosition( VALVE_T valve, VALVE_POSITION_T positionToCheck ); // These functions will be used in debug only mode #ifdef DEBUG_ENABLED @@ -479,6 +480,19 @@ /*********************************************************************//** * @brief + * The resetValvesPOSTState function resets the valves POST state; + * @details Inputs: none + * @details Outputs: valveSelfTestState, valvesSelfTestResult + * @return none + *************************************************************************/ +void resetValvesPOSTState( void ) +{ + valveSelfTestState = VALVE_SELF_TEST_ENABLE_VALVES; + valvesSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; +} + +/*********************************************************************//** + * @brief * The execValves function executes the valves exec state machine. * @details Inputs: valvesStatus * @details Outputs: valvesStatus @@ -809,7 +823,8 @@ } else if ( ( TRUE == valvesStatus[ valve ].hasValveBeenHomed ) && ( TRUE == valvesStatus[ valve ].hasTransitionBeenRequested ) ) { - if ( valvesStatus[ valve ].currentPosition != valvesStatus[ valve ].pendingCommandedPosition ) + if ( ( valvesStatus[ valve ].currentPosition != valvesStatus[ valve ].pendingCommandedPosition ) || + ( FALSE == isValveCloseToCommandedPosition( valve, valvesStatus[ valve ].pendingCommandedPosition ) ) ) { // Just set the valves to transition so it will not be in a known position for a while valvesStatus[ valve ].commandedPosition = valvesStatus[ valve ].pendingCommandedPosition; @@ -945,7 +960,7 @@ { // Get the set and reset bits for the particular valve U16 control = VALVE_CONTROL_MODES_SET_BITS[ valve ][ mode ]; - U16 reset = VALVE_CONTROL_MODES_RESET_BITS[ valve ]; + U16 reset = VALVE_CONTROL_MODES_RESET_BITS[ valve ]; // Reset the control bits of the particular valve valvesControlSetBits &= reset; @@ -1158,9 +1173,9 @@ static void getAndMonitorValvesCurrentFPGAPosition( void ) { VALVE_T valve; - S16 currentPosition = 0; - S16 commandedPosition = 0; VALVE_POSITION_T commandedPositionEnum; + S16 currentPosition = 0; + S16 commandedPosition = 0; // Get the position of the valves and update the structure of each valve valvesStatus[ VDI ].currentPositionInCounts.data = (S32)getFPGAValveDialyzerInletPosition(); @@ -1196,10 +1211,13 @@ if ( valvesStatus[ valve ].positionOutOfRangeCounter > MAX_POS_DEVIATION_TIME_INTERVAL_COUNTER ) { + // If the valve's deviation from target was more than the counts for the define period of time trigger the alarm. + // Also, set the state to Idle so in the fault mode, the valve can transition to Pos C. The exec state is directly set here + // because this is a monitor function that is called in the controller function. + valvesStatus[ valve ].execState = VALVE_STATE_IDLE; SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_VALVE_POSITION_OUT_OF_RANGE, (U32)valve, currentPosition ); } - else if ( ( abs( currentPosition - commandedPosition ) < MAX_DEVIATION_FROM_TARGET_IN_COUNTS ) && - ( valvesStatus[ valve ].positionOutOfRangeCounter > 0 ) ) + else if ( ( TRUE == isValveCloseToCommandedPosition( valve, commandedPositionEnum ) ) && ( valvesStatus[ valve ].positionOutOfRangeCounter > 0 ) ) { valvesStatus[ valve ].positionOutOfRangeCounter = 0; } @@ -1256,11 +1274,11 @@ *************************************************************************/ static void setValveNextStep( VALVE_T valve, U32 stepChange ) { - S16 nextStep = 0; + S16 nextStep = 0; VALVE_POSITION_T currentPositionEnum = valvesStatus[ valve ].currentPosition; VALVE_POSITION_T commandedPositionEnum = valvesStatus[ valve ].commandedPosition; - S16 currentPosition = getValvePositionCounts( valve ); - S16 commandedPosition = valvesStatus[ valve ].positions[ commandedPositionEnum ]; + S16 currentPosition = getValvePositionCounts( valve ); + S16 commandedPosition = valvesStatus[ valve ].positions[ commandedPositionEnum ]; // If the next step is less than the specified step change, set that if ( abs( currentPosition - commandedPosition ) <= stepChange ) @@ -1334,6 +1352,27 @@ return position; } +/*********************************************************************//** + * @brief + * The isValveCloseToCommandedPosition function checks whether a valve is close + * to its commanded position or not + * @details Inputs: valvesStatus + * @details Outputs: none + * @param valve that its position in counts is requested + * @param positionToCheck the position enum (can be commanded to pending commanded enums + * to check) + * @return TRUE if the valve is within accepted deviation from commanded otherwise, + * FALSE + *************************************************************************/ +static BOOL isValveCloseToCommandedPosition( VALVE_T valve, VALVE_POSITION_T positionToCheck ) +{ + S16 currentPosition = getValvePositionCounts( valve ); + S16 commandedPosition = valvesStatus[ valve ].positions[ positionToCheck ]; + BOOL isInRange = ( abs( currentPosition - commandedPosition ) < MAX_DEVIATION_FROM_TARGET_IN_COUNTS ? TRUE : FALSE ); + + return isInRange; +} + #ifdef DEBUG_ENABLED /*********************************************************************//** * @brief