Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -r0f9838d6b8606a6a9853ccb6157e4c25d70ddd02 -r0e6c78b7815234ff1ef1fa8f9d083376aa634583 --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision 0f9838d6b8606a6a9853ccb6157e4c25d70ddd02) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision 0e6c78b7815234ff1ef1fa8f9d083376aa634583) @@ -251,6 +251,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 @@ -821,7 +822,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; @@ -957,7 +959,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; @@ -1170,9 +1172,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(); @@ -1208,10 +1210,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; } @@ -1268,11 +1273,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 ) @@ -1346,6 +1351,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