Index: firmware/App/Controllers/DrainPump.c =================================================================== diff -u -r1f500f8e6159a3fbab85ea68389e918a6df66400 -r58129c9bb3053c39efa07f60e975f17e2a04755a --- firmware/App/Controllers/DrainPump.c (.../DrainPump.c) (revision 1f500f8e6159a3fbab85ea68389e918a6df66400) +++ firmware/App/Controllers/DrainPump.c (.../DrainPump.c) (revision 58129c9bb3053c39efa07f60e975f17e2a04755a) @@ -22,7 +22,8 @@ #include "DrainPump.h" #include "FPGA.h" -#include "OperationModes.h" +#include "OperationModes.h" +#include "PersistentAlarm.h" #include "PIControllers.h" #include "Pressures.h" #include "SystemCommMessages.h" @@ -42,19 +43,25 @@ // ********** private definitions ********** #define DRAIN_PUMP_MIN_DAC ( ( (F32)MIN_DRAIN_PUMP_RPM * \ - DRP_SPEED_RPM_TO_ADC_FACTOR ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ///<, Drain pump minimum RPM to DAC conversion + DRP_SPEED_RPM_TO_ADC_FACTOR ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ///< Drain pump minimum RPM to DAC conversion. #define DRAIN_PUMP_MAX_DAC ( ( (F32)MAX_DRAIN_PUMP_RPM * \ - DRP_SPEED_RPM_TO_ADC_FACTOR ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ///< Drain pump maximum RPM to DAC conversion -#define DRAIN_PUMP_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< interval (ms/task time) at which the Drain Pump data is published on the CAN bus + DRP_SPEED_RPM_TO_ADC_FACTOR ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ///< Drain pump maximum RPM to DAC conversion. +#define DRAIN_PUMP_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< interval (ms/task time) at which the Drain Pump data is published on the CAN bus. -#define DRP_CONTROL_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< interval (ms/task time) at which the Drain pump is controlled +#define DRP_CONTROL_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< interval (ms/task time) at which the Drain pump is controlled. -#define DRP_SPEED_ADC_TO_RPM_FACTOR 12.94 ///< conversion factor from ADC counts to RPM for Drain pump -#define DRP_SPEED_RPM_TO_ADC_FACTOR ( 1.0 / DRP_SPEED_ADC_TO_RPM_FACTOR ) ///< conversion factor from RPM to ADC counts for Drain pump +#define DRP_SPEED_ADC_TO_RPM_CONVERSION 12.94 ///< conversion factor from ADC counts to RPM for Drain pump. +#define DRP_SPEED_RPM_TO_ADC_FACTOR ( 1.0 / DRP_SPEED_ADC_TO_RPM_CONVERSION ) ///< conversion factor from RPM to ADC counts for Drain pump. -#define DRAIN_PUMP_P_COEFFICIENT 0.5 ///< P term for drain pump delta pressure control -#define DRAIN_PUMP_I_COEFFICIENT 1.0 ///< I term for drain pump delta pressure control +#define DRAIN_PUMP_P_COEFFICIENT 0.5 ///< P term for drain pump delta pressure control. +#define DRAIN_PUMP_I_COEFFICIENT 1.0 ///< I term for drain pump delta pressure control. +#define MIN_ALLOWED_TARGET_DELTA_PRESSURE -10.0 ///< Minimum allowed delta pressure for closed loop control. +#define MAX_ALLOWED_TARGET_DELTA_PRESSURE 10.0 ///< Maximum allowed delta pressure for closed loop control. + +#define MAX_ALLOWED_OPEN_LOOP_RPM_OUT_OF_RANGE 20 ///< Maximum allowed RPM out of range from target RPM in open loop. +#define OPEN_LOOP_RPM_OUT_OF_RANGE_TIME_OUT ( 5000 / TASK_PRIORITY_INTERVAL ) ///< Open loop RPM out of range time out in counts. + /// Enumeration of drain pump states. typedef enum DrainPump_States { @@ -93,11 +100,12 @@ static OVERRIDE_U32_T drainPumpDataPublishInterval = { DRAIN_PUMP_DATA_PUB_INTERVAL, DRAIN_PUMP_DATA_PUB_INTERVAL, 0, 0 }; ///< interval (in ms) at which to publish RO flow data to CAN bus -static OVERRIDE_U32_T targetDrainPumpSpeed = { 0, 0, 0, 0 }; ///< Target RO pressure (in PSI) +static OVERRIDE_U32_T targetDrainPumpRPM = { 0, 0, 0, 0 }; ///< Target drain pump RPM static OVERRIDE_F32_T targetDrainPumpDeltaPressure = { 0.0, 0.0, 0.0, 0.0 }; ///< Target delta pressure for the drain pump -static U32 drainControlTimerCounter = 0; ///< determines when to perform control on drain pump -static BOOL hasClosedLoopBeenRequested = FALSE; ///< Close loop pump control flag +static U32 drainControlTimerCounter = 0; ///< Determines when to perform control on drain pump +static BOOL hasClosedLoopBeenRequested = FALSE; ///< Closed loop pump control flag +static U32 currentDrainPumpRPM = 0; ///< Current drain pump RPM from feedback /* These variables are used for POST. POST will be implemented later static DRAIN_PUMP_SELF_TEST_STATE_T drainPumpSelfTestState = DRAIN_PUMP_SELF_TEST_STATE_START; ///< current drain pump self test state @@ -116,9 +124,8 @@ /*********************************************************************//** * @brief * The initDrainPump function initializes the DrainPump module. - * @details - * Inputs : none - * Outputs : DrainPump module initialized. + * @details Inputs: hasClosedLoopBeenRequested + * @details Outputs: hasClosedLoopBeenRequested * @return none *************************************************************************/ void initDrainPump( void ) @@ -130,32 +137,38 @@ // Initialize the drain pump PI controller initializePIController( PI_CONTROLLER_ID_DRAIN_PUMP, DRAIN_PUMP_MIN_DAC, DRAIN_PUMP_P_COEFFICIENT, DRAIN_PUMP_I_COEFFICIENT, - DRAIN_PUMP_MIN_DAC, DRAIN_PUMP_MAX_DAC ); + DRAIN_PUMP_MIN_DAC, DRAIN_PUMP_MAX_DAC ); + + // Initialize the persistent alarm for open loop RPM out of range + initPersistentAlarm( PERSISTENT_ALARM_DRAIN_PUMP_RPM_OUT_OF_RANGE, ALARM_ID_DRAIN_PUMP_RPM_OUT_OF_RANGE, TRUE, + OPEN_LOOP_RPM_OUT_OF_RANGE_TIME_OUT, OPEN_LOOP_RPM_OUT_OF_RANGE_TIME_OUT ); } /*********************************************************************//** * @brief - * The setDrainPumpTargetSpeed function sets a new target speed for the drain pump. - * @details - * Inputs: none - * Outputs: targetDrainPumpPressure - * @param rpm new target drain pump speed (in RPM). - * @return: TRUE if new target speed is set, FALSE if not + * The setDrainPumpTargetSpeed function sets a new target RPM for the + * drain pump. + * @details Inputs: drainPumpDAC, targetDrainPumpSpeed, drainPumpControlMode, + * drainPumpControlModeSet + * @details Outputs: drainPumpDAC, targetDrainPumpSpeed, drainPumpControlMode, + * drainPumpControlModeSet + * @param rpm new drain pump target RPM + * @return: TRUE if new target RPM is set, FALSE if not *************************************************************************/ -BOOL setDrainPumpTargetSpeed( U32 rpm ) +BOOL setDrainPumpTargetRPM( U32 rpm ) { BOOL result = FALSE; - if ( ( 0 == rpm ) || - ( ( rpm >= MIN_DRAIN_PUMP_RPM ) && ( rpm <= MAX_DRAIN_PUMP_RPM ) ) ) + if ( ( 0 == rpm ) || ( ( rpm >= MIN_DRAIN_PUMP_RPM ) && ( rpm <= MAX_DRAIN_PUMP_RPM ) ) ) { #ifdef EMC_TEST_BUILD drainPumpDAC = (U32)((F32)2500 * DRP_SPEED_RPM_TO_ADC_FACTOR + FLOAT_TO_INT_ROUNDUP_OFFSET); #else drainPumpDAC = (U32)((F32)rpm * DRP_SPEED_RPM_TO_ADC_FACTOR + FLOAT_TO_INT_ROUNDUP_OFFSET); #endif - targetDrainPumpSpeed.data = rpm; - drainPumpControlMode = PUMP_CONTROL_MODE_OPEN_LOOP; + targetDrainPumpRPM.data = rpm; + drainPumpControlMode = PUMP_CONTROL_MODE_OPEN_LOOP; + drainPumpControlModeSet = drainPumpControlMode; result = TRUE; } @@ -164,71 +177,91 @@ /*********************************************************************//** * @brief - * The setDrainPumpTargetDeltaPressure function sets the target delta\n - * pressure in between the PRd and PDr sensors - * @details - * Inputs: targetDrainPumpDeltaP - * Outputs: targetDrainPumpDeltaP - * @param: deltaP : new target drain pump delta pressure + * The setDrainPumpTargetDeltaPressure function sets the target delta + * pressure in between the PRd and PDr sensors. + * @details Inputs: targetDrainPumpDeltaPressure, hasClosedLoopBeenRequested, + * drainPumpDAC, drainPumpControlMode, drainPumpControlModeSet + * @details Outputs: targetDrainPumpDeltaPressure, hasClosedLoopBeenRequested, + * drainPumpDAC, drainPumpControlMode, drainPumpControlModeSet + * @param deltaP new target drain pump delta pressure * @return: TRUE if new target speed is set, FALSE if not *************************************************************************/ BOOL setDrainPumpTargetDeltaPressure( F32 deltaP ) { BOOL result = FALSE; - targetDrainPumpDeltaPressure.data = deltaP; - hasClosedLoopBeenRequested = TRUE; - drainPumpDAC = DRAIN_PUMP_MIN_DAC; - drainPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; - result = TRUE; + // Check the delta pressure is in range + if ( deltaP >= MIN_ALLOWED_TARGET_DELTA_PRESSURE && deltaP <= MIN_ALLOWED_TARGET_DELTA_PRESSURE ) + { + // Set all the variables for closed loop mode + targetDrainPumpDeltaPressure.data = deltaP; + hasClosedLoopBeenRequested = TRUE; + drainPumpDAC = DRAIN_PUMP_MIN_DAC; + drainPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; + drainPumpControlModeSet = drainPumpControlMode; + result = TRUE; + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_DRAIN_PUMP_INVALID_DELTA_PRESSURE_SELECTED, deltaP ) + } + return result; } /*********************************************************************//** * @brief * The signalDrainPumpHardStop function stops the Drain pump immediately. - * @details - * Inputs: none - * Outputs: Drain pump stopped, set point reset, state changed to off - * @return: none + * @details Inputs: targetDrainPumpSpeed, drainPumpState, drainPumpControlMode, + * hasClosedLoopBeenRequested, drainControlTimerCounter + * @details Outputs: targetDrainPumpSpeed, drainPumpState, drainPumpControlMode, + * hasClosedLoopBeenRequested, drainControlTimerCounter + * @return none *************************************************************************/ void signalDrainPumpHardStop( void ) -{ - targetDrainPumpSpeed.data = 0; - stopDrainPump(); - drainPumpState = DRAIN_PUMP_OFF_STATE; +{ + stopDrainPump(); + + // Reset all the variables to stop mode + targetDrainPumpRPM.data = 0; + drainPumpState = DRAIN_PUMP_OFF_STATE; hasClosedLoopBeenRequested = FALSE; - drainPumpControlMode = NUM_OF_PUMP_CONTROL_MODES; // Set the control mode to none - drainControlTimerCounter = 0; + drainPumpControlMode = NUM_OF_PUMP_CONTROL_MODES; // Set the control mode to none + drainControlTimerCounter = 0; } /*********************************************************************//** * @brief * The execDrainPumpMonitor function executes the drain pump monitor. - * @details - * Inputs: none - * Outputs: none - * @return: none + * @details Inputs: currentDrainPumpRPM + * @details Outputs: currentDrainPumpRPM + * @return none *************************************************************************/ void execDrainPumpMonitor( void ) -{ - U16 drnPumpSpd = getFPGADrainPumpSpeed(); +{ + // Convert speed ADC to RPM + currentDrainPumpRPM = getFPGADrainPumpSpeed() * DRP_SPEED_ADC_TO_RPM_CONVERSION; + + // The RPM is only checked in open loop state that the pump is run at a fixed RPM. + // The persistent alarm waits for a couple of seconds before raising an alarm, this is supposed to cover + // when the pump is turned on and it takes a while to ramp up to target RPM. + if( drainPumpControlModeSet == PUMP_CONTROL_MODE_OPEN_LOOP ) + { + // Check if RPM out of range. Using fabs since the read RPM can be above or below the target. + BOOL isRPMOutOfRange = fabs( currentDrainPumpRPM - getTargetDrainPumpRPM() ) > MAX_ALLOWED_OPEN_LOOP_RPM_OUT_OF_RANGE; + checkPersistentAlarm( PERSISTENT_ALARM_DRAIN_PUMP_RPM_OUT_OF_RANGE, isRPMOutOfRange, currentDrainPumpRPM ); + } - // TODO - convert drain pump speed to RPM - - // TODO - check(s) ??? - - // publish drain pump data on interval + // Publish drain pump data on interval publishDrainPumpData(); } /*********************************************************************//** * @brief * The execDrainPumpController function executes the drain pump controller. - * @details - * Inputs: drainPumpState - * Outputs: drainPumpState + * @details Inputs: drainPumpState + * @details Outputs: drainPumpState * @return: none *************************************************************************/ void execDrainPumpController( void ) @@ -259,9 +292,8 @@ * @brief * The execDrainPumpTest function executes the state machine for the drain * pump self-test. - * @details - * Inputs: none - * Outputs: none + * @detailsInputs: TODO FILL UP + * @details Outputs: TODO FILL UP * @return: the current state of the Drain Pump self test. *************************************************************************/ SELF_TEST_STATUS_T execDrainPumpTest( void ) @@ -275,20 +307,19 @@ /*********************************************************************//** * @brief - * The getTargetDrainPumpSpeed function gets the current target drain pump - * speed. - * @details - * Inputs: targetDrainPumpSpeed - * Outputs : none - * @return: the current target drain pump speed. + * The getTargetDrainPumpRPM function gets the current target drain pump + * RPM. + * @details Inputs: targetDrainPumpRPM + * @details Outputs: targetDrainPumpRPM + * @return: the current target drain pump RPM. *************************************************************************/ -U32 getTargetDrainPumpSpeed( void ) +U32 getTargetDrainPumpRPM( void ) { - U32 result = targetDrainPumpSpeed.data; + U32 result = targetDrainPumpRPM.data; - if ( OVERRIDE_KEY == targetDrainPumpSpeed.override ) + if ( OVERRIDE_KEY == targetDrainPumpRPM.override ) { - result = targetDrainPumpSpeed.ovData; + result = targetDrainPumpRPM.ovData; } return result; @@ -318,10 +349,10 @@ * @brief * The handleDrainPumpOffState function handles the drain pump off state of * the drain pump controller state machine. - * @details - * Inputs: targetDrainPumpSpeed - * Outputs: drainPumpPWMDutyCyclePctSet - * @return: next state + * @details Inputs: drainPumpControlModeSet, drainPumpDACSet, drainPumpDAC + * hasClosedLoopBeenRequested + * @details Outputs: drainPumpDACSet + * @return: next state for the controller state machine *************************************************************************/ static DRAIN_PUMP_STATE_T handleDrainPumpOffState( void ) { @@ -335,7 +366,7 @@ setValveState( VPI, VALVE_STATE_OPEN ); setValveState( VRC, VALVE_STATE_DRAIN_C_TO_NO ); setValveState( VPO, VALVE_STATE_NOFILL_C_TO_NO ); - setDrainPumpTargetSpeed( 1000 ); + setDrainPumpTargetRPM( 1000 ); #ifdef EMC_TEST_BUILD setTrimmerHeaterTargetTemperature( 50.0 ); startTrimmerHeater(); @@ -346,7 +377,7 @@ // If the target drain pump speed was not 0 and the control mode // is open loop, set the drain pump to open loop - if ( getTargetDrainPumpSpeed() > 0 && drainPumpControlMode == PUMP_CONTROL_MODE_OPEN_LOOP ) + if ( getTargetDrainPumpRPM() > 0 && drainPumpControlModeSet == PUMP_CONTROL_MODE_OPEN_LOOP ) { // Set drain pump enable pin SET_DRAIN_PUMP_ENABLE(); @@ -359,7 +390,7 @@ } // If the drain pump is set to closed loop, call the proper state // It is checked for the value of delta pressure because it can be anything including 0 - else if ( drainPumpControlMode == PUMP_CONTROL_MODE_CLOSED_LOOP && hasClosedLoopBeenRequested ) + else if ( drainPumpControlModeSet == PUMP_CONTROL_MODE_CLOSED_LOOP && hasClosedLoopBeenRequested ) { // set drain pump enable pin SET_DRAIN_PUMP_ENABLE(); @@ -378,12 +409,11 @@ /*********************************************************************//** * @brief - * The handleDrainPumpControlToTargetState function handles the "control to - * target" state of the drain pump controller state machine. - * @details - * Inputs: none - * Outputs: drainPumpState - * @return: next state + * The handleDrainPumpControlToTargetState function handles the control to + * target state of the drain pump controller state machine. + * @details Inputs: drainControlTimerCounter, drainPumpDACSet + * @details Outputs: drainControlTimerCounter, drainPumpDACSet + * @return: next state of the controller state machine *************************************************************************/ static DRAIN_PUMP_STATE_T handleDrainPumpControlToTargetState( void ) { @@ -392,24 +422,16 @@ // control at set interval if ( ++drainControlTimerCounter >= DRP_CONTROL_INTERVAL ) { - F32 inletDrainPressure = getMeasuredDGPressure ( PRESSURE_SENSOR_DRAIN_PUMP_INLET ); + F32 inletDrainPressure = getMeasuredDGPressure ( PRESSURE_SENSOR_DRAIN_PUMP_INLET ); F32 outletDrainPressure = getMeasuredDGPressure ( PRESSURE_SENSOR_DRAIN_PUMP_OUTLET ); - F32 pressureDiff = outletDrainPressure - inletDrainPressure; - F32 dac = runPIController( PI_CONTROLLER_ID_DRAIN_PUMP, getTargetDrainPumpDeltaP(), pressureDiff ); - drainPumpDACSet = (U32)( dac + FLOAT_TO_INT_ROUNDUP_OFFSET ); + F32 pressureDiff = outletDrainPressure - inletDrainPressure; + F32 dac = runPIController( PI_CONTROLLER_ID_DRAIN_PUMP, getTargetDrainPumpDeltaP(), pressureDiff ); + // The PI controller sends the DAC out and it is rounded to the nearest offset and is fed to the FPGA + drainPumpDACSet = (U32)( dac + FLOAT_TO_INT_ROUNDUP_OFFSET ); setFPGADrainPumpSpeed( drainPumpDACSet ); - // From a merge from master - if ( drainPumpControlModeSet == PUMP_CONTROL_MODE_CLOSED_LOOP ) - { -#ifndef EMC_TEST_BUILD - // TODO - will drain pump have a closed loop? -#endif - } - drainControlTimerCounter = 0; } - // From a merge from master #ifdef DEBUG_ENABLED #ifdef ENABLE_DIP_SWITCHES @@ -433,35 +455,27 @@ /*********************************************************************//** * @brief - * The handleDrainPumpOpenLoopState function handles the open loop \n - * state - * @details - * Inputs: none - * Outputs: none - * @return: next state + * The handleDrainPumpOpenLoopState function handles the open loop state. + * @details Inputs: none + * @details Outputs: none + * @return next state of the controller state machine *************************************************************************/ static DRAIN_PUMP_STATE_T handleDrainPumpOpenLoopState( void ) { - /*if ( 0 == getTargetDrainPumpSpeed() ) - { - signalDrainPumpHardStop(); - - result = DRAIN_PUMP_OFF_STATE; - }*/ //TODO clean up return DRAIN_PUMP_OPEN_LOOP_STATE; } /*********************************************************************//** * @brief - * The stopDrainPump function sets the drain pump DAC to zero. - * @details - * Inputs: none - * Outputs: DAC zeroed - * @return: none + * The stopDrainPump function sets the drain pump DAC to zero and stops + * the pump. + * @details Inputs: drainPumpDAC, drainPumpDACSet + * @details Outputs: drainPumpDAC, drainPumpDACSet + * @return none *************************************************************************/ static void stopDrainPump( void ) { - drainPumpDAC = 0; + drainPumpDAC = 0; drainPumpDACSet = 0; setFPGADrainPumpSpeed( drainPumpDACSet ); CLR_DRAIN_PUMP_ENABLE(); @@ -471,9 +485,8 @@ * @brief * The getPublishDrainPumpDataInterval function gets the drain pump data * publication interval. - * @details - * Inputs: drainPumpDataPublishInterval - * Outputs: none + * @details Inputs: drainPumpDataPublishInterval + * @details Outputs: drainPumpDataPublishInterval * @return: the current Drain pump data publication interval (in ms). *************************************************************************/ static U32 getPublishDrainPumpDataInterval( void ) @@ -490,10 +503,10 @@ /*********************************************************************//** * @brief - * The publishDrainPumpData function publishes drain pump data at the set interval. - * @details + * The publishDrainPumpData function publishes drain pump data at the set + * interval. * @details Inputs: drainPumpDataPublicationTimerCounter - * @details Outputs: drainPumpDataPublicationTimerCounterus. + * @details Outputs: drainPumpDataPublicationTimerCounter * @return: none *************************************************************************/ static void publishDrainPumpData( void ) @@ -504,17 +517,16 @@ DRAIN_PUMP_DATA_T drainPumpData; // Populate the data structure for publication - drainPumpData.speedSetPoint = getTargetDrainPumpSpeed(); + drainPumpData.rpmSetPoint = getTargetDrainPumpRPM(); drainPumpData.pumpDACSet = drainPumpDACSet; - drainPumpData.drainPumpState = (U32)drainPumpState; + drainPumpData.drainPumpState = (U32)drainPumpState; + drainPumpData.drainPumpRPM = currentDrainPumpRPM; broadcastDrainPumpData( &drainPumpData ); drainPumpDataPublicationTimerCounter = 0; } } - -/**@}*/ /************************************************************************* * TEST SUPPORT FUNCTIONS @@ -525,10 +537,9 @@ * @brief * The testSetDrainPumpDataPublishIntervalOverride function overrides the * drain pump data publish interval. - * @details - * Inputs: none - * Outputs: drainPumpDataPublishInterval - * @param: value : override RO pump data publish interval with (in ms) + * @details Inputs: drainPumpDataPublishInterval + * @details Outputs: drainPumpDataPublishInterval + * @param value override drain pump data publish interval with (in ms) * @return: TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetDrainPumpDataPublishIntervalOverride( U32 value ) @@ -539,9 +550,9 @@ { U32 intvl = value / TASK_PRIORITY_INTERVAL; + drainPumpDataPublishInterval.ovData = intvl; + drainPumpDataPublishInterval.override = OVERRIDE_KEY; result = TRUE; - drainPumpDataPublishInterval.ovData = intvl; - drainPumpDataPublishInterval.override = OVERRIDE_KEY; } return result; @@ -551,107 +562,102 @@ * @brief * The testResetDrainPumpDataPublishIntervalOverride function resets the * override of the drain pump data publish interval. - * @details - * Inputs: none - * Outputs: drainPumpDataPublishInterval - * @return: TRUE if override reset successful, FALSE if not + * @details Inputs: drainPumpDataPublishInterval + * @details Outputs: drainPumpDataPublishInterval + * @return TRUE if override reset successful, FALSE if not *************************************************************************/ BOOL testResetDrainPumpDataPublishIntervalOverride( void ) { BOOL result = FALSE; if ( TRUE == isTestingActivated() ) { - result = TRUE; drainPumpDataPublishInterval.override = OVERRIDE_RESET; - drainPumpDataPublishInterval.ovData = drainPumpDataPublishInterval.ovInitData; + drainPumpDataPublishInterval.ovData = drainPumpDataPublishInterval.ovInitData; + result = TRUE; } return result; } /*********************************************************************//** * @brief - * The testSetTargetDrainPumpSpeedOverride function overrides the target - * drain pump speed (in RPM). - * @details - * Inputs: none - * Outputs: targetDrainPumpSpeed - * @param: value : override target drain pump speed (in RPM) + * The testSetTargetDrainPumpRPMOverride function overrides the target + * drain pump RPM. + * @details Inputs: targetDrainPumpRPM + * @details Outputs: targetDrainPumpRPM + * @param value override target drain pump RPM * @return: TRUE if override successful, FALSE if not *************************************************************************/ -BOOL testSetTargetDrainPumpSpeedOverride( U32 value ) +BOOL testSetTargetDrainPumpRPMOverride( U32 value ) { BOOL result = FALSE; if ( TRUE == isTestingActivated() ) { - targetDrainPumpSpeed.ovInitData = targetDrainPumpSpeed.data; // backup current target pressure - targetDrainPumpSpeed.ovData = value; - targetDrainPumpSpeed.override = OVERRIDE_KEY; - result = setDrainPumpTargetSpeed( value ); + targetDrainPumpRPM.ovInitData = targetDrainPumpRPM.data; // Backup current target RPM + targetDrainPumpRPM.ovData = value; + targetDrainPumpRPM.override = OVERRIDE_KEY; + result = setDrainPumpTargetRPM( value ); } return result; } /*********************************************************************//** * @brief - * The testResetTargetDrainPumpSpeedOverride function resets the override of the - * target drain pump speed (in RPM). - * @details - * Inputs: none - * Outputs: targetDrainPumpSpeed + * The testResetTargetDrainPumpRPMOverride function resets the override + * of the target drain pump RPM. + * @details Inputs: targetDrainPumpRPM + * @details Outputs: targetDrainPumpRPM * @return: TRUE if override reset successful, FALSE if not *************************************************************************/ -BOOL testResetTargetDrainPumpSpeedOverride( void ) +BOOL testResetTargetDrainPumpRPMOverride( void ) { BOOL result = FALSE; if ( TRUE == isTestingActivated() ) { - targetDrainPumpSpeed.data = targetDrainPumpSpeed.ovInitData; // restore pre-override target speed - targetDrainPumpSpeed.override = OVERRIDE_RESET; - targetDrainPumpSpeed.ovInitData = 0; - targetDrainPumpSpeed.ovData = 0; - result = setDrainPumpTargetSpeed( targetDrainPumpSpeed.data ); + targetDrainPumpRPM.data = targetDrainPumpRPM.ovInitData; // Restore pre-override target RPM + targetDrainPumpRPM.override = OVERRIDE_RESET; + targetDrainPumpRPM.ovInitData = 0; + targetDrainPumpRPM.ovData = 0; + result = setDrainPumpTargetRPM( targetDrainPumpRPM.data ); } return result; } /*********************************************************************//** * @brief - * The testSetTargetDrainPumpDeltaPressureOverride function overrides \n - * the target drain pump delta pressure - * @details - * Inputs: none - * Outputs: targetDrainPumpDeltaPressure - * @param: value : override target drain pump delta pressure - * @return: TRUE if override successful, FALSE if not + * The testSetTargetDrainPumpDeltaPressureOverride function overrides + * the target drain pump delta pressure. + * @details Inputs: targetDrainPumpDeltaPressure + * @details Outputs: targetDrainPumpDeltaPressure + * @param value override target drain pump delta pressure + * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetTargetDrainPumpDeltaPressureOverride( F32 value ) { BOOL result = FALSE; if ( TRUE == isTestingActivated() ) { - targetDrainPumpDeltaPressure.ovInitData = targetDrainPumpDeltaPressure.data; // backup current target delta pressure - targetDrainPumpDeltaPressure.ovData = value; - targetDrainPumpDeltaPressure.override = OVERRIDE_KEY; - result = setDrainPumpTargetDeltaPressure( value ); + targetDrainPumpDeltaPressure.ovInitData = targetDrainPumpDeltaPressure.data; // Backup current target delta pressure + targetDrainPumpDeltaPressure.ovData = value; + targetDrainPumpDeltaPressure.override = OVERRIDE_KEY; + result = setDrainPumpTargetDeltaPressure( value ); //TODO remove } return result; } /*********************************************************************//** * @brief - * The testResetTargetDrainPumpDeltaPressureOverride function resets the \n - * override of the target drain pump delta pressure - * @details - * Inputs: none - * Outputs: targetDrainPumpDeltaPressure + * The testResetTargetDrainPumpDeltaPressureOverride function resets the + * override of the target drain pump delta pressure. + * @details Inputs: targetDrainPumpDeltaPressure + * @details Outputs: targetDrainPumpDeltaPressure * @return: TRUE if override reset successful, FALSE if not *************************************************************************/ BOOL testResetTargetDrainPumpDeltaPressureOverride( void ) @@ -660,10 +666,10 @@ if ( TRUE == isTestingActivated() ) { - targetDrainPumpDeltaPressure.data = targetDrainPumpDeltaPressure.ovInitData; // restore pre-override target delta pressure - targetDrainPumpDeltaPressure.override = OVERRIDE_RESET; + targetDrainPumpDeltaPressure.data = targetDrainPumpDeltaPressure.ovInitData; // Restore pre-override target delta pressure + targetDrainPumpDeltaPressure.override = OVERRIDE_RESET; targetDrainPumpDeltaPressure.ovInitData = 0; - targetDrainPumpDeltaPressure.ovData = 0; + targetDrainPumpDeltaPressure.ovData = 0; result = setDrainPumpTargetDeltaPressure( targetDrainPumpDeltaPressure.data ); } Index: firmware/App/Controllers/DrainPump.h =================================================================== diff -u -r1f500f8e6159a3fbab85ea68389e918a6df66400 -r58129c9bb3053c39efa07f60e975f17e2a04755a --- firmware/App/Controllers/DrainPump.h (.../DrainPump.h) (revision 1f500f8e6159a3fbab85ea68389e918a6df66400) +++ firmware/App/Controllers/DrainPump.h (.../DrainPump.h) (revision 58129c9bb3053c39efa07f60e975f17e2a04755a) @@ -36,9 +36,10 @@ /// Drain pump data publish typedef struct { - U32 speedSetPoint; ///< Drain pump speed set point (for open loop) + U32 rpmSetPoint; ///< Drain pump speed set point (for open loop) U32 pumpDACSet; ///< Drain pump DAC set value U32 drainPumpState; ///< Drain pump state machine state + U32 drainPumpRPM; ///< Drain pump current RPM } DRAIN_PUMP_DATA_T; // ********** public function prototypes ********** @@ -47,23 +48,23 @@ void execDrainPumpMonitor( void ); void execDrainPumpController( void ); -BOOL setDrainPumpTargetSpeed( U32 rpm ); +BOOL setDrainPumpTargetRPM( U32 rpm ); BOOL setDrainPumpTargetDeltaPressure( F32 deltaP ); void signalDrainPumpHardStop( void ); SELF_TEST_STATUS_T execDrainPumpTest( void ); -U32 getTargetDrainPumpSpeed( void ); +U32 getTargetDrainPumpRPM( void ); F32 getTargetDrainPumpDeltaP( void ); BOOL testSetDrainPumpDataPublishIntervalOverride( U32 value ); BOOL testResetDrainPumpDataPublishIntervalOverride( void ); -BOOL testSetTargetDrainPumpSpeedOverride( U32 value ); -BOOL testResetTargetDrainPumpSpeedOverride( void ); +BOOL testSetTargetDrainPumpRPMOverride( U32 value ); +BOOL testResetTargetDrainPumpRPMOverride( void ); BOOL testSetTargetDrainPumpDeltaPressureOverride( F32 value ); BOOL testResetTargetDrainPumpDeltaPressureOverride( void ); Index: firmware/App/Controllers/Fans.c =================================================================== diff -u -r62a4d7b976107f7ac4d5013ce06f38f4a0bf65bd -r58129c9bb3053c39efa07f60e975f17e2a04755a --- firmware/App/Controllers/Fans.c (.../Fans.c) (revision 62a4d7b976107f7ac4d5013ce06f38f4a0bf65bd) +++ firmware/App/Controllers/Fans.c (.../Fans.c) (revision 58129c9bb3053c39efa07f60e975f17e2a04755a) @@ -20,7 +20,7 @@ #define FANS_MAX_ALLOWED_RAMP_UP_DELTA_DUTY_CYCLE 0.3 ///< Fans max allowed ramp up PWM change. #define FANS_MAX_ALLOWED_RAMP_DOWN_DELTA_DUTY_CYCLE 0.005 ///< Fans min allowed ramp down PWM change. -#define ONE_MINUTE_TO_MICRO_SECONDS ( SEC_PER_MIN * US_PER_SECOND ) ///< One minute to micro seconds conversion. +#define ONE_MINUTE_TO_MICRO_SECONDS ( SEC_PER_MIN * US_PER_SECOND ) ///< One minute to micro seconds conversion. #define TOGGLE_PERIOD_RESOLUTION 2.5 ///< FPGA fans toggle period resolution in micro seconds. #define ROTATIONAL_TO_TOGGLE_PERIOD_CONVERSION_COEFF 4 ///< FPGA rotational to toggle period conversion coefficient. @@ -521,7 +521,7 @@ * publish interval. * @details Inputs: fansPublishInterval * @details Outputs: fansPublishInterval - * @param: value : override fans data publish interval with (in ms) + * @param value : override fans data publish interval with (in ms) * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetFanPublishIntervalOverride( U32 value ) Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u -r62a4d7b976107f7ac4d5013ce06f38f4a0bf65bd -r58129c9bb3053c39efa07f60e975f17e2a04755a --- firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 62a4d7b976107f7ac4d5013ce06f38f4a0bf65bd) +++ firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 58129c9bb3053c39efa07f60e975f17e2a04755a) @@ -22,7 +22,8 @@ #include "FPGA.h" #include "OperationModes.h" -#include "PIControllers.h" +#include "PIControllers.h" +#include "PersistentAlarm.h" #include "Pressures.h" #include "ROPump.h" #include "SystemCommMessages.h" @@ -73,12 +74,16 @@ #define MAX_ALLOWED_FLOW_DEVIATION 0.1 ///< Max allowed deviation from target flow. #define FLOW_OUT_OF_RANGE_TIME_OUT ( 5000 / TASK_PRIORITY_INTERVAL ) ///< Flow out of range time out in counts. #define MAX_PRESSURE_TARGET_TOLERANCE 5 ///< Pressure tolerance from maximum set pressure by user in psi. -#define MAX_ALLOWED_PRESSURE_PSI 140 ///< Maximum allowed pressure that the RO pump can go to. -#define MIN_ALLOWED_PRESSURE_PSI 10 ///< Minimum allowed pressure that the RO pump can go to. +#define MAX_ALLOWED_PRESSURE_PSI 130 ///< Maximum allowed pressure that the RO pump can go to. +#define MIN_ALLOWED_PRESSURE_PSI 10 ///< Minimum allowed pressure that the RO pump can go to. +#define MAX_ALLOWED_MEASURED_PRESSURE_PSI 135 ///< Maximum allowed pressure that the sensor measures. RO pump shut off pressure is 140psi. +#define MAX_PRESSURE_OUT_OF_RANGE_TIME_OUT ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Maximum allowed time that the pressure can be very high. +#define MAX_ALLOWED_RAMP_UP_TIME ( 30 * MS_PER_SECOND ) ///< Maximum allowed ramp up time to a flow rate in ms. +#define RAMP_UP_TIME_OUT_COUNT ( MAX_ALLOWED_RAMP_UP_TIME / \ + TASK_GENERAL_INTERVAL ) ///< Ramp up time out in counts. // TODO - this is a place holder for real conversion -#define ROP_PSI_TO_PWM_DC(p) ( 0.2 + ( (F32)((p) - 100) * 0.01 ) ) ///< conversion factor from target PSI to PWM duty cycle estimate. -#define RO_FLOW_ADC_TO_LPM_FACTOR 10909.0909 ///< conversion factor from ADC counts to LPM (liters/min) for RO flow rate (multiply this by inverse of FPGA reading). +#define ROP_PSI_TO_PWM_DC(p) ( 0.2 + ( (F32)((p) - 100) * 0.01 ) ) ///< conversion factor from target PSI to PWM duty cycle estimate. TODO remove? /// Enumeration of RO pump states. typedef enum ROPump_States @@ -112,33 +117,34 @@ static U32 roPumpDataPublicationTimerCounter = 0; ///< used to schedule RO pump data publication to CAN bus static BOOL isROPumpOn = FALSE; ///< RO pump is currently running static F32 roPumpPWMDutyCyclePct = 0.0; ///< initial RO pump PWM duty cycle -static F32 roPumpDutyCyclePctSet = 0.0; ///< currently set RO pump PWM duty cycle +static F32 roPumpDutyCyclePctSet = 0.0; ///< currently set RO pump PWM duty cycle static PUMP_CONTROL_MODE_T roPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< requested RO pump control mode static PUMP_CONTROL_MODE_T roPumpControlModeSet = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< currently set RO pump control mode -static OVERRIDE_F32_T targetROPumpFlowRate = { 0, 0, 0, 0 }; ///< Target RO flow rate (in LPM) +static OVERRIDE_F32_T targetROPumpFlowRate = { 0, 0, 0, 0 }; ///< Target RO flow rate (in L/min) static OVERRIDE_U32_T roPumpDataPublishInterval = { RO_PUMP_DATA_PUB_INTERVAL, RO_PUMP_DATA_PUB_INTERVAL, 0, 0 }; ///< Interval (in ms) at which to publish RO flow data to CAN bus -static OVERRIDE_F32_T measuredROFlowRateLPM = { 0.0, 0.0, 0.0, 0 }; ///< measured RO flow rate (in LPM) +static OVERRIDE_F32_T measuredROFlowRateLPM = { 0.0, 0.0, 0.0, 0 }; ///< measured RO flow rate (in L/min) static U32 flowVerificationCounter = 0; ///< Counter to verify the flow is in range static U32 roControlTimerCounter = 0; ///< determines when to perform control on RO pump -static F32 roPumpOpenLoopTargetDutyCycle = 0; ///< Target RO pump open loop PWM +static F32 roPumpOpenLoopTargetDutyCycle = 0; ///< Target RO pump open loop PWM static F32 roPumpFlowRateRunningSum = 0; ///< RO pump flow rate running sum static F32 roPumpPressureRunningSum = 0; ///< RO pump pressure running sum - -static RO_PUMP_SELF_TEST_STATE_T roPumpSelfTestState = RO_PUMP_SELF_TEST_STATE_START; ///< current ro pump self test state -static U32 roPumpSelfTestTimerCount = 0; ///< timer counter for ro pump self test +/* These variables are used for POST. POST has not been implemented yet +static RO_PUMP_SELF_TEST_STATE_T roPumpSelfTestState = RO_PUMP_SELF_TEST_STATE_START; ///< Current ro pump self test state +static U32 roPumpSelfTestTimerCount = 0; ///< Timer counter for ro pump self test +*/ + static OVERRIDE_U32_T targetROPumpPressure = { 0, 0, 0, 0 }; ///< Target RO pressure (in PSI) static S32 measuredFlowReadingsSum = 0; ///< Raw flow reading sums for averaging static U32 flowFilterCounter = 0; ///< Flow filtering counter -static BOOL hasTargetFlowBeenReached = FALSE; ///< Flow set flag -static U32 flowOutOfRangeCounter = 0; +static U32 rampUp2FlowTimeoutCounter = 0; ///< Counter for ramping up to flow time // ********** private function prototypes ********** @@ -148,37 +154,43 @@ static RO_PUMP_STATE_T handleROPumpControlToTargetState( void ); static RO_PUMP_STATE_T handleROPumpOpenLoopState( void ); -static BOOL setROPumpTargetPressure( U32 roPressure ); static void setROPumpTargetDutyCycle( F32 duty ); -static void setROPumpControlSignalDutyCycle( F32 newPWM ); +static void setROPumpControlSignalDutyCycle( F32 dutyCycle ); static void stopROPump( void ); static void publishROPumpData( void ); static U32 getPublishROPumpDataInterval( void ); /*********************************************************************//** * @brief * The initROPump function initializes the RO Pump module. - * @details Inputs: hasTargetFlowBeenReached, flowOutOfRangeCounter - * @details Outputs: hasTargetFlowBeenReached, flowOutOfRangeCounter + * @details Inputs: rampUp2FlowTimeoutCounter + * @details Outputs: rampUp2FlowTimeoutCounter * @return none *************************************************************************/ void initROPump( void ) { stopROPump(); // Initialize RO pump PI controller - initializePIController( PI_CONTROLLER_ID_RO_PUMP, MIN_RO_PUMP_DUTY_CYCLE, - ROP_P_COEFFICIENT, ROP_I_COEFFICIENT, + initializePIController( PI_CONTROLLER_ID_RO_PUMP, MIN_RO_PUMP_DUTY_CYCLE, ROP_P_COEFFICIENT, ROP_I_COEFFICIENT, MIN_RO_PUMP_DUTY_CYCLE, MAX_RO_PUMP_DUTY_CYCLE ); // Initialize the I controller during ramp up - initializePIController( I_CONTROLLER_ID_RO_PUMP_RAMP_UP, MIN_RO_PUMP_DUTY_CYCLE, - ROP_RAMP_UP_P_COEFFICIENT, ROP_RAMP_UP_I_COEFFICIENT, + initializePIController( I_CONTROLLER_ID_RO_PUMP_RAMP_UP, MIN_RO_PUMP_DUTY_CYCLE, ROP_RAMP_UP_P_COEFFICIENT, ROP_RAMP_UP_I_COEFFICIENT, MIN_RO_PUMP_DUTY_CYCLE, MAX_RO_PUMP_DUTY_CYCLE ); - // Make sure the flow set flag has been set to FALSE until it is set - hasTargetFlowBeenReached = FALSE; - flowOutOfRangeCounter = 0; + // Initialize the persistent alarm for flow out of upper and lower range + initPersistentAlarm( PERSISTENT_ALARM_RO_FLOW_RATE_OUT_OF_UPPER_RANGE, ALARM_ID_FLOW_RATE_OUT_OF_RANGE, TRUE, + FLOW_OUT_OF_RANGE_TIME_OUT, FLOW_OUT_OF_RANGE_TIME_OUT ); + + initPersistentAlarm( PERSISTENT_ALARM_RO_FLOW_RATE_OUT_OF_LOWER_RANGE, ALARM_ID_FLOW_RATE_OUT_OF_RANGE, TRUE, + FLOW_OUT_OF_RANGE_TIME_OUT, FLOW_OUT_OF_RANGE_TIME_OUT ); + + // Initialize the persistent alarm for max allowed pressure out of range + initPersistentAlarm( PERSISTENT_ALARM_RO_PUMP_PRESSURE_OUT_OF_RANGE, ALARM_ID_RO_PUMP_PRESSURE_OUT_OF_RANGE, TRUE, + MAX_PRESSURE_OUT_OF_RANGE_TIME_OUT, MAX_PRESSURE_OUT_OF_RANGE_TIME_OUT ); + + rampUp2FlowTimeoutCounter = 0; } /*********************************************************************//** @@ -205,9 +217,9 @@ * The setROPumpTargetFlowRate function sets a new target flow rate for the * RO pump. * @details Inputs: targetROPumpPressure, targetROPumpFlowRate, - * roPumpControlMode + * roPumpControlMode, rampUp2FlowTimeoutCounter * @details Outputs: targetROPumpPressure, targetROPumpFlowRate, - * roPumpControlMode + * roPumpControlMode, rampUp2FlowTimeoutCounter * @param roFlowRate which is target RO flow rate * @param maxPressure which is the maximum allowed pressure that the RO pump * can reach @@ -216,24 +228,39 @@ BOOL setROPumpTargetFlowRate( F32 roFlowRate, F32 maxPressure ) { BOOL result = FALSE; - + + // First of all, the flow rate must be in range if ( roFlowRate < MAX_RO_FLOWRATE_LPM && roFlowRate >= MIN_RO_FLOWRATE_LPM ) - { - // For now maximum allowed pressure is inserted into the target pressure override - // if the target flow rate exceeded the max pressure, it will set the maximum pressure - targetROPumpPressure.data = maxPressure; - targetROPumpFlowRate.data = roFlowRate; - roPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; - roPumpPWMDutyCyclePct = ROP_FLOW_TO_PWM_DC( roFlowRate ); + { + // Then the max pressure that we are allowed to reach must be in range + if ( maxPressure >= MIN_ALLOWED_PRESSURE_PSI && maxPressure <= MIN_ALLOWED_PRESSURE_PSI ) + { + // For now maximum allowed pressure is inserted into the target pressure override + // if the target flow rate exceeded the max pressure, it will set the maximum pressure + targetROPumpPressure.data = maxPressure; + targetROPumpFlowRate.data = roFlowRate; + roPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; + // Get the initial guess of the duty cycle + roPumpPWMDutyCyclePct = ROP_FLOW_TO_PWM_DC( roFlowRate ); + rampUp2FlowTimeoutCounter = 0; + result = TRUE; + } + // Requested max pressure is out of range + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_RO_PUMP_INVALID_FLOW_RATE_SET, maxPressure ) + } + /*#ifdef EMC_TEST_BUILD roPumpPWMDutyCyclePct = 1.0; #else roPumpPWMDutyCyclePct = ROP_FLOW_TO_PWM_DC( roFlowRate ); #endif*/ - } - else // requested pressure out of range + } + // Requested flow rate is out of range + else { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_RO_PUMP_INVALID_FLOW_RATE_SET, roFlowRate ) + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_RO_PUMP_INVAID_PRESSURE_SELECTED, roFlowRate ) } return result; @@ -245,12 +272,10 @@ * resets all the variables associated with the RO pump run. * @details Inputs: targetROPumpFlowRate, roPumpState, roPumpPWMDutyCyclePct, * roPumpOpenLoopTargetDutyCycle, roControlTimerCounter, flowVerificationCounter, - * flowVerificationCounter, isROPumpOn, hasTargetFlowBeenReached, - * flowOutOfRangeCounter + * flowVerificationCounter, isROPumpOn, rampUp2FlowTimeoutCounter * @details Outputs: targetROPumpFlowRate, roPumpState, roPumpPWMDutyCyclePct, - * roPumpOpenLoopTargetDutyCycle, roControlTimerCounter, flowVerificationCounter, - * flowVerificationCounter, isROPumpOn, hasTargetFlowBeenReached, - * flowOutOfRangeCounter + * roPumpOpenLoopTargetDutyCycle, roControlTimerCounter, + * flowVerificationCounter, isROPumpOn, rampUp2FlowTimeoutCounter * @return none *************************************************************************/ void signalROPumpHardStop( void ) @@ -263,29 +288,35 @@ roControlTimerCounter = 0; flowVerificationCounter = 0; isROPumpOn = FALSE; - hasTargetFlowBeenReached = FALSE; - flowOutOfRangeCounter = 0; + rampUp2FlowTimeoutCounter = 0; resetPIController( PI_CONTROLLER_ID_RO_PUMP, MIN_RO_PUMP_DUTY_CYCLE ); } /*********************************************************************//** * @brief * The execROPumpMonitor function executes the RO pump monitor. * @details Inputs: measuredFlowReadingsSum, flowFilterCounter, - * measuredROFlowRateLPM, measuredROFlowRateLPM, hasTargetFlowBeenReached, + * measuredROFlowRateLPM, measuredROFlowRateLPM, roPumpState, * flowOutOfRangeCounter, roPumpControlMode * @details Outputs: measuredFlowReadingsSum, flowFilterCounter, - * measuredROFlowRateLPM, measuredROFlowRateLPM, flowOutOfRangeCounter + * measuredROFlowRateLPM, measuredROFlowRateLPM * @return none *************************************************************************/ void execROPumpMonitor( void ) { U16 roFlowReading = getFPGAROPumpFlowRate(); S32 roFlow = (S32)roFlowReading; - // Update sum for flow average calculation - measuredFlowReadingsSum += roFlow; - // Filter every 250ms + measuredFlowReadingsSum += roFlow; + + // Read the pressure at the sensor. The pump cannot be more that the maximum allowed pressure + // to make sure the hardware (especially the ROF) is not damaged. If it is the case, we need to + // stop immediately + F32 actualPressure = getMeasuredDGPressure( PRESSURE_SENSOR_RO_PUMP_OUTLET ); + BOOL isPressureMax = actualPressure >= MAX_ALLOWED_MEASURED_PRESSURE_PSI; + checkPersistentAlarm( PERSISTENT_ALARM_RO_PUMP_PRESSURE_OUT_OF_RANGE, isPressureMax, actualPressure ); + + // Read flow at the control set if ( ++flowFilterCounter >= FLOW_SAMPLES_TO_AVERAGE ) { F32 avgROFlow = (F32)measuredFlowReadingsSum * FLOW_AVERAGE_MULTIPLIER; @@ -299,41 +330,32 @@ else { measuredROFlowRateLPM.data = RO_FLOW_ADC_TO_LPM_FACTOR / avgROFlow; - } + } + measuredFlowReadingsSum = 0; flowFilterCounter = 0; } - // In order to check the flow rate deviation, the control mode must in closed loop and - // the target flow must have been set. There might be a time that the pump cannot reach to target flow - // and also it does not reach to maximum pressure. But after a certain timeout the flow will be set and the - // read flow will be checked to be in range. - if ( roPumpControlMode == PUMP_CONTROL_MODE_CLOSED_LOOP && hasTargetFlowBeenReached ) + // To monitor the flow, the control mode must be in closed loop and the pump should be control to target state, + // meaning, it is controlling to a certain pressure + if ( roPumpControlMode == PUMP_CONTROL_MODE_CLOSED_LOOP && roPumpState == RO_PUMP_CONTROL_TO_TARGET_STATE ) { - F32 currentFlow = getMeasuredROFlowRate(); - F32 targetFlow = getTargetROPumpFlowRate(); - F32 deviation = currentFlow / targetFlow; + F32 currentFlow = getMeasuredROFlowRate(); + F32 targetFlow = getTargetROPumpFlowRate(); + F32 error = 1 - ( currentFlow / targetFlow ); + BOOL isFlowOutOfRange = error > MAX_ALLOWED_FLOW_DEVIATION; - // If the flow is out of range for a certain amount of time in a row - if ( ++flowOutOfRangeCounter > FLOW_OUT_OF_RANGE_TIME_OUT && deviation > MAX_ALLOWED_FLOW_DEVIATION ) + // Figure out whether flow is out of range from which side + if ( isFlowOutOfRange ) { - // There are alarms for flow out of range and above the target or below the target - if ( currentFlow > targetFlow ) - { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_FLOW_RATE_OUT_OF_UPPER_RANGE, currentFlow, targetFlow ) - } - else - { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_FLOW_RATE_OUT_OF_LOWER_RANGE, currentFlow, targetFlow ) - } + BOOL isFlowOutOfUpperRange = currentFlow > targetFlow; + BOOL isFlowOutOfLowerRange = currentFlow < targetFlow; + // Check for flow out of range + checkPersistentAlarm( PERSISTENT_ALARM_RO_FLOW_RATE_OUT_OF_UPPER_RANGE, isFlowOutOfUpperRange, currentFlow ); + checkPersistentAlarm( PERSISTENT_ALARM_RO_FLOW_RATE_OUT_OF_LOWER_RANGE, isFlowOutOfLowerRange, currentFlow ); } - // If the counter is > 0 but the deviation is in range again, reset the counter - else if ( flowOutOfRangeCounter > 0 && deviation < MAX_ALLOWED_FLOW_DEVIATION ) - { - flowOutOfRangeCounter = 0; - } - } + } // Publish RO pump data on interval publishROPumpData(); @@ -474,22 +496,34 @@ /*********************************************************************//** * @brief - * The handleROPumpRampUpState function handles the RO pump ramp up state of - * the controller state machine. - * @details Inputs: roControlTimerCounter, roPumpPWMDutyCyclePctSet - * @details Outputs: roControlTimerCounter, roPumpPWMDutyCyclePctSet + * The handleROPumpRampUpState function handles the RO pump ramp up state + * of the controller state machine. + * @details Inputs: roControlTimerCounter, roPumpPWMDutyCyclePctSet, + * rampUp2FlowTimeoutCounter + * @details Outputs: roControlTimerCounter, roPumpPWMDutyCyclePctSet, + * rampUp2FlowTimeoutCounter * @return next state of the controller state machine *************************************************************************/ static RO_PUMP_STATE_T handleROPumpRampUpState( void ) { - RO_PUMP_STATE_T result = RO_PUMP_RAMP_UP_STATE; - + RO_PUMP_STATE_T result = RO_PUMP_RAMP_UP_STATE; + + // Get the current pressure from the sensor + F32 actualPressure = getMeasuredDGPressure( PRESSURE_SENSOR_RO_PUMP_OUTLET ); + + // If we are still in the ramp up mode after the specified time, get the current pressure + // and control from this + if ( ++rampUp2FlowTimeoutCounter > RAMP_UP_TIME_OUT_COUNT ) + { + targetROPumpPressure.data = actualPressure; + rampUp2FlowTimeoutCounter = 0; + result = RO_PUMP_CONTROL_TO_TARGET_STATE; + } // Control at set interval - if ( ++roControlTimerCounter >= ROP_CONTROL_INTERVAL ) + else if ( ++roControlTimerCounter >= ROP_CONTROL_INTERVAL ) { - F32 targetFlowRate = getTargetROPumpFlowRate(); - F32 actualFlowRate = (F32)getMeasuredROFlowRate(); - F32 actualPressure = getMeasuredDGPressure( PRESSURE_SENSOR_RO_PUMP_OUTLET ); + F32 targetFlowRate = getTargetROPumpFlowRate(); + F32 actualFlowRate = (F32)getMeasuredROFlowRate(); // If the actual pressure is greater than the target pressure or it is within the tolerance of the maximum pressure, move to set // to target pressure straight. At the beginning the maximum pressure is set in the targetROPumpPressure override variable. @@ -502,9 +536,8 @@ // If the actual flow is still far from target flow, update the duty cycle using the I controller and stay in this state else if ( fabs( actualFlowRate - targetFlowRate ) > ROP_FLOW_TARGET_TOLERANCE ) { - F32 newPWM = runPIController( I_CONTROLLER_ID_RO_PUMP_RAMP_UP, targetFlowRate, actualFlowRate ); - roPumpDutyCyclePctSet = newPWM; - setROPumpControlSignalDutyCycle( newPWM ); + roPumpDutyCyclePctSet = runPIController( I_CONTROLLER_ID_RO_PUMP_RAMP_UP, targetFlowRate, actualFlowRate ); + setROPumpControlSignalDutyCycle( roPumpDutyCyclePctSet ); } // Reached to the target flow go to the next state else @@ -513,7 +546,7 @@ } roControlTimerCounter = 0; - } + } return result; } @@ -522,10 +555,10 @@ * @brief * The handleROPumpVerifyFlowState function handles the RO pump verify * flow state of the RO pump controller state machine. - * @details Inputs: flowVerificationCounter, hasTargetFlowBeenReached, - * targetROPumpPressure, roPumpFlowRateRunningSum, roPumpFlowRateRunningSum - * @details Outputs: flowVerificationCounter, hasTargetFlowBeenReached, - * targetROPumpPressure, roPumpFlowRateRunningSum, roPumpFlowRateRunningSum + * @details Inputs: flowVerificationCounter, targetROPumpPressure, + * roPumpFlowRateRunningSum, roPumpFlowRateRunningSum + * @details Outputs: flowVerificationCounter, targetROPumpPressure, + * roPumpFlowRateRunningSum, roPumpFlowRateRunningSum * @return next state of the controller state machine *************************************************************************/ static RO_PUMP_STATE_T handleROPumpVerifyFlowState( void ) @@ -551,9 +584,6 @@ F32 targetFlowRate = getTargetROPumpFlowRate(); - // Reached to target flow rate - hasTargetFlowBeenReached = TRUE; - // Calculate the flow rate deviation from the target flow rate F32 flowRateDeviation = ( targetFlowRate - avgFlowRate ) / targetFlowRate; // Use the flow rate deviation to adjust the average calculated pressure. This @@ -599,8 +629,7 @@ // Get the pressure to use it for setting the control F32 actualPressure = getMeasuredDGPressure( PRESSURE_SENSOR_RO_PUMP_OUTLET ); - F32 newPWM = runPIController( PI_CONTROLLER_ID_RO_PUMP, getTargetROPumpPressure(), actualPressure ); - roPumpDutyCyclePctSet = newPWM; + roPumpDutyCyclePctSet = runPIController( PI_CONTROLLER_ID_RO_PUMP, getTargetROPumpPressure(), actualPressure ); setROPumpControlSignalDutyCycle( roPumpDutyCyclePctSet ); roControlTimerCounter = 0; @@ -636,42 +665,6 @@ static RO_PUMP_STATE_T handleROPumpOpenLoopState( void ) { return RO_PUMP_OPEN_LOOP_STATE; -} - -/*********************************************************************//** - * @brief - * The setROPumpTargetPressure function sets a new target pressure for the RO pump. - * @details Inputs : none - * @details Outputs : targetROPumpPressure, roPumpPWMDutyCyclePct - * @param roPressure new target RO pressure - * @return TRUE if new target pressure is set, FALSE if not - *************************************************************************/ -static BOOL setROPumpTargetPressure( U32 roPressure ) -{ - BOOL result = FALSE; - - // Verify pressure is in the allowed range - if ( roPressure >= MIN_ALLOWED_PRESSURE_PSI && roPressure <= MAX_ALLOWED_PRESSURE_PSI ) - { - targetROPumpPressure.data = roPressure; - // Set the control mode to open loop - roPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; - // set PWM duty cycle target to an estimated initial target based on target pressure - then we'll control to pressure going forward -#ifdef EMC_TEST_BUILD - roPumpPWMDutyCyclePct = 1.0; -#else - roPumpPWMDutyCyclePct = ROP_PSI_TO_PWM_DC( targetROPumpPressure.data ); -#endif - - result = TRUE; - } - // Invalid pressure was selected - else - { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_RO_PUMP_INVAID_PRESSURE_SELECTED, roPressure ) - } - - return result; } /*********************************************************************//** @@ -828,7 +821,6 @@ U32 intvl = value / TASK_PRIORITY_INTERVAL; roPumpDataPublishInterval.ovData = intvl; roPumpDataPublishInterval.override = OVERRIDE_KEY; - result = TRUE; } @@ -851,7 +843,6 @@ { roPumpDataPublishInterval.override = OVERRIDE_RESET; roPumpDataPublishInterval.ovData = roPumpDataPublishInterval.ovInitData; - result = TRUE; } @@ -867,16 +858,30 @@ * @param: value which is override target RO flow rate (in L/min) * @return TRUE if override successful, FALSE if not *************************************************************************/ -BOOL testSetTargetROPumpFlowRateOverride( F32 value ) +BOOL testSetTargetROPumpFlowAndPressure( F32 flow, F32 pressure ) { BOOL result = FALSE; if ( TRUE == isTestingActivated() ) - { - targetROPumpFlowRate.ovInitData = targetROPumpFlowRate.data; - targetROPumpFlowRate.ovData = value; - targetROPumpFlowRate.override = OVERRIDE_KEY; - //result = setROPumpTargetFlowRate( value ); TODO what should be pressure here? + { + // The flow rate and pressure must be in range + if ( flow < MAX_RO_FLOWRATE_LPM && flow >= MIN_RO_FLOWRATE_LPM ) + { + if ( pressure >= MIN_ALLOWED_PRESSURE_PSI && pressure <= MIN_ALLOWED_PRESSURE_PSI ) + { + // Set the override initial data and the override key in here for both flow and pressure. + // Both are needed in order to change the flow rate. + targetROPumpFlowRate.ovInitData = targetROPumpFlowRate.data; + targetROPumpFlowRate.override = OVERRIDE_KEY; + + targetROPumpPressure.ovInitData = targetROPumpPressure.data; + targetROPumpPressure.override = OVERRIDE_KEY; + + result = setROPumpTargetFlowRate( flow, pressure ); + + // Reset is needed to turn off the override key + } + } } return result; @@ -923,10 +928,14 @@ if ( TRUE == isTestingActivated() ) { - targetROPumpPressure.ovInitData = targetROPumpPressure.data; - targetROPumpPressure.ovData = value; - targetROPumpPressure.override = OVERRIDE_KEY; - result = setROPumpTargetPressure( value ); + // Make sure the requested pressure is in range + if ( value >= MIN_ALLOWED_PRESSURE_PSI && value <= MAX_ALLOWED_PRESSURE_PSI ) + { + targetROPumpPressure.ovInitData = targetROPumpPressure.data; + targetROPumpPressure.ovData = value; + targetROPumpPressure.override = OVERRIDE_KEY; + result = TRUE; + } } return result; @@ -950,7 +959,7 @@ targetROPumpPressure.override = OVERRIDE_RESET; targetROPumpPressure.ovInitData = 0; targetROPumpPressure.ovData = 0; - result = setROPumpTargetPressure( targetROPumpPressure.data ); + result = TRUE; } return result; @@ -974,7 +983,6 @@ measuredROFlowRateLPM.ovInitData = measuredROFlowRateLPM.data; measuredROFlowRateLPM.ovData = value; measuredROFlowRateLPM.override = OVERRIDE_KEY; - result = TRUE; } @@ -999,7 +1007,6 @@ measuredROFlowRateLPM.override = OVERRIDE_RESET; measuredROFlowRateLPM.ovInitData = 0.0; measuredROFlowRateLPM.ovData = 0.0; - result = TRUE; } @@ -1021,7 +1028,7 @@ if ( TRUE == isTestingActivated() ) { - // Check if duty cycle is within ranges + // Check if duty cycle is within range if ( value >= MIN_RO_PUMP_DUTY_CYCLE && value <= MAX_RO_PUMP_DUTY_CYCLE ) { setROPumpTargetDutyCycle( value ); @@ -1049,7 +1056,6 @@ // Reset of the duty cycle override means stop the pump and // reset all its variables signalROPumpHardStop(); - result = TRUE; } Index: firmware/App/Controllers/ROPump.h =================================================================== diff -u -r62a4d7b976107f7ac4d5013ce06f38f4a0bf65bd -r58129c9bb3053c39efa07f60e975f17e2a04755a --- firmware/App/Controllers/ROPump.h (.../ROPump.h) (revision 62a4d7b976107f7ac4d5013ce06f38f4a0bf65bd) +++ firmware/App/Controllers/ROPump.h (.../ROPump.h) (revision 58129c9bb3053c39efa07f60e975f17e2a04755a) @@ -22,22 +22,24 @@ /** * @defgroup ROPump ROPump - * @brief RO Pump monitor and controller module. Controls and monitors the RO pump. + * @brief RO Pump monitor and controller module. Controls and monitors the RO pump and the flow meter. + * The flow meter is manufactured by SwissFlow, PN: 82015311. + * The diaphragm (RO) pump is manufactured by Aquatec, PN: 5889-2MM1-V724DY. * * @addtogroup ROPump * @{ */ // ********** public definitions ********** -#define MAX_RO_FLOWRATE_LPM 1.2 ///< Maximum target RO flow rate (in LPM) -#define MIN_RO_FLOWRATE_LPM 0.2 ///< Minimum target RO flow rate (in LPM) +#define MAX_RO_FLOWRATE_LPM 1.0 ///< Maximum target RO flow rate in L/min. +#define MIN_RO_FLOWRATE_LPM 0.2 ///< Minimum target RO flow rate in L/min. /// RO pump data struct. typedef struct { F32 roPumpTgtPressure; ///< RO pump target pressure F32 measROFlowRate; ///< RO flow rate measurement - F32 roPumpDutyCycle; ///< RO pump pwm + F32 roPumpDutyCycle; ///< RO pump duty cycle U32 roPumpState; ///< RO pump current state } RO_PUMP_DATA_T; @@ -61,14 +63,16 @@ F32 getTargetROPumpPressure( void ); BOOL testSetROPumpDataPublishIntervalOverride( U32 value ); -BOOL testResetROPumpDataPublishIntervalOverride( void ); - -BOOL testSetTargetROPumpFlowRateOverride( F32 value ); -BOOL testResetTargetROPumpFlowRateOverride( void ); +BOOL testResetROPumpDataPublishIntervalOverride( void ); BOOL testSetMeasuredROFlowRateOverride( F32 value ); BOOL testResetMeasuredROFlowRateOverride( void ); +// These are not sensors, but since the functions are private, +// they can only be set from Dialin +BOOL testSetTargetROPumpFlowAndPressure( F32 flow, F32 pressure ); +BOOL testResetTargetROPumpFlowRateOverride( void ); //TODO remove? + BOOL testSetTargetROPumpPressureOverride( U32 value ); BOOL testResetTargetROPumpPressureOverride( void ); Index: firmware/App/Modes/ModeDrain.c =================================================================== diff -u -r54f45c387430e440ab4607451fc84dea61f273f1 -r58129c9bb3053c39efa07f60e975f17e2a04755a --- firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision 54f45c387430e440ab4607451fc84dea61f273f1) +++ firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision 58129c9bb3053c39efa07f60e975f17e2a04755a) @@ -70,7 +70,7 @@ // set initial actuator states setValveState( VDR, VALVE_STATE_DRAIN_C_TO_NO ); - setDrainPumpTargetSpeed( TARGET_DRAIN_PUMP_RPM ); + setDrainPumpTargetRPM( TARGET_DRAIN_PUMP_RPM ); } /*********************************************************************//** @@ -131,7 +131,7 @@ // if we've reached our target drain to volume (by weight), we're done draining - go back to re-circ mode if ( getReservoirDrainVolumeTargetMl() >= getLoadCellFilteredWeight( drainWeightLoadCell ) ) { - setDrainPumpTargetSpeed( 0 ); + setDrainPumpTargetRPM( 0 ); requestNewOperationMode( DG_MODE_CIRC ); } Index: firmware/App/Modes/ModeHeatDisinfect.c =================================================================== diff -u -r62a4d7b976107f7ac4d5013ce06f38f4a0bf65bd -r58129c9bb3053c39efa07f60e975f17e2a04755a --- firmware/App/Modes/ModeHeatDisinfect.c (.../ModeHeatDisinfect.c) (revision 62a4d7b976107f7ac4d5013ce06f38f4a0bf65bd) +++ firmware/App/Modes/ModeHeatDisinfect.c (.../ModeHeatDisinfect.c) (revision 58129c9bb3053c39efa07f60e975f17e2a04755a) @@ -683,7 +683,7 @@ setValveState( VRD, VALVE_STATE_R1_C_TO_NC ); setValveState( VRI, VALVE_STATE_R1_C_TO_NO ); setValveState( VRF, VALVE_STATE_R2_C_TO_NO ); - setDrainPumpTargetSpeed( drainPumpTargetRPM ); + setDrainPumpTargetRPM( drainPumpTargetRPM ); state = INTERNAL_HEAT_DISINFECT_STATE_EVACUATE_R1; } @@ -766,7 +766,7 @@ setValveState( VRD, VALVE_STATE_R1_C_TO_NC ); setValveState( VRI, VALVE_STATE_R1_C_TO_NO ); setValveState( VRF, VALVE_STATE_R2_C_TO_NO ); - setDrainPumpTargetSpeed( drainPumpTargetRPM ); //TODO commented for testing + setDrainPumpTargetRPM( drainPumpTargetRPM ); //TODO commented for testing state = INTERNAL_HEAT_DISINFECT_STATE_EVACUATE_R1; } Index: firmware/App/Services/AlarmMgmt.h =================================================================== diff -u -r62a4d7b976107f7ac4d5013ce06f38f4a0bf65bd -r58129c9bb3053c39efa07f60e975f17e2a04755a --- firmware/App/Services/AlarmMgmt.h (.../AlarmMgmt.h) (revision 62a4d7b976107f7ac4d5013ce06f38f4a0bf65bd) +++ firmware/App/Services/AlarmMgmt.h (.../AlarmMgmt.h) (revision 58129c9bb3053c39efa07f60e975f17e2a04755a) @@ -157,6 +157,7 @@ SW_FAULT_ID_DRAIN_PUMP_INVALID_EXEC_STATE, // 65 SW_FAULT_ID_UV_REACTORS_INVALID_REACTOR_SELECTD, SW_FAULT_ID_RO_PUMP_INVAID_PRESSURE_SELECTED, + SW_FAULT_ID_DRAIN_PUMP_INVALID_DELTA_PRESSURE_SELECTED, NUM_OF_SW_FAULT_IDS } SW_FAULT_ID_T; Index: firmware/App/Services/SystemComm.c =================================================================== diff -u -r62a4d7b976107f7ac4d5013ce06f38f4a0bf65bd -r58129c9bb3053c39efa07f60e975f17e2a04755a --- firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision 62a4d7b976107f7ac4d5013ce06f38f4a0bf65bd) +++ firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision 58129c9bb3053c39efa07f60e975f17e2a04755a) @@ -1205,6 +1205,19 @@ handleROPumpDutyCycleOverride( message ); break; + case MSG_ID_DG_RO_FLOW_RATE_OVERRIDE: + handleROFlowRateOverride( message ); + break; + + case MSG_ID_DG_RO_PUMP_TARGET_FLOW_OVERRIDE: + handleROPumpTargetFlowOverride( message ); + break; + + case MSG_ID_DG_RO_PUMP_TARGET_PRESSURE_OVERRIDE: + break; + + + default: // TODO - unrecognized message ID received - ignore break; Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -r62a4d7b976107f7ac4d5013ce06f38f4a0bf65bd -r58129c9bb3053c39efa07f60e975f17e2a04755a --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 62a4d7b976107f7ac4d5013ce06f38f4a0bf65bd) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 58129c9bb3053c39efa07f60e975f17e2a04755a) @@ -1142,30 +1142,6 @@ return result; } -/************************************************************************* - * @brief - * The handleSetROPumpPWM function handles the start of the RO pump with a\n - * PWM. The run is open loop - * @details - * Inputs : none - * Outputs : message handled - * @param message : a pointer to the message to handle - * @return result - *************************************************************************/ -BOOL handleSetROPumpPWM( MESSAGE_T * message ) -{ - BOOL result = FALSE; - - if ( message->hdr.payloadLen == sizeof(U32) ) - { - U32 roPumpPWM; - memcpy( &roPumpPWM, message->payload, sizeof(U32) ); - //result = setROPumpTargetPWM( roPumpPWM ); - } - - return result; -} - /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ @@ -1621,10 +1597,9 @@ /*********************************************************************//** * @brief * The handleTestROMeasuredFlowOverrideRequest function handles a request to - * override the RO flow rate. - * @details - * Inputs : none - * Outputs : message handled + * override the RO measured flow rate. + * @details Inputs: none + * @details Outputs: message handled * @param message a pointer to the message to handle * @return none *************************************************************************/ @@ -1705,11 +1680,11 @@ memcpy( &payload, message->payload, sizeof(TEST_OVERRIDE_PAYLOAD_T) ); if ( FALSE == payload.reset ) { - result = testSetTargetDrainPumpSpeedOverride( payload.state.u32 ); + result = testSetTargetDrainPumpRPMOverride( payload.state.u32 ); } else { - result = testResetTargetDrainPumpSpeedOverride(); + result = testResetTargetDrainPumpRPMOverride(); } } @@ -2223,8 +2198,8 @@ /*********************************************************************//** * @brief -* The handleStartStopOutletUVReactor function handles a request to turn on/off -* the outlet UV reactor. +* The handleStartStopOutletUVReactor function handles a request to turn +* on/off the outlet UV reactor. * @details Inputs: none * @details Outputs: message handled * @param message a pointer to the message to handle @@ -2290,7 +2265,7 @@ /*********************************************************************//** * @brief * The handleThermistorsDataPublishIntervalOverride function handles a request -* to override the publish interval of the thermistors data +* to override the publish interval of the thermistors data. * @details Inputs: none * @details Outputs: message handled * @param message a pointer to the message to handle @@ -2322,7 +2297,7 @@ /*********************************************************************//** * @brief * The handleThermisotrsValueOverride function handles a request to override -* a thermistor's value +* a thermistor's value. * @details Inputs: none * @details Outputs: message handled * @param message a pointer to the message to handle @@ -2354,7 +2329,7 @@ /*********************************************************************//** * @brief * The handleROPumpDutyCycleOverride function handles a request to override -* the RO pumps duty cycle +* the RO pumps duty cycle. * @details Inputs: none * @details Outputs: message handled * @param message a pointer to the message to handle @@ -2383,4 +2358,94 @@ sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); } +/*********************************************************************//** +* @brief +* The handleROFlowRateOverride function handles a request to override +* the RO flow rate. +* @details Inputs: none +* @details Outputs: message handled +* @param message a pointer to the message to handle +* @return none +*******************************************************************/ +void handleROFlowRateOverride( MESSAGE_T *message ) +{ + TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; + BOOL result = FALSE; + + // verify payload length + if ( sizeof(TEST_OVERRIDE_ARRAY_PAYLOAD_T) == message->hdr.payloadLen ) + { + memcpy( &payload, message->payload, sizeof(TEST_OVERRIDE_ARRAY_PAYLOAD_T) ); + if ( FALSE == payload.reset ) + { + result = testSetMeasuredROFlowRateOverride( payload.state.f32 ); + } + else + { + result = testResetMeasuredROFlowRateOverride(); + } + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +/*********************************************************************//** +* @brief +* The handleROPumpTargetFlowOverride function handles a request to override +* the RO pump target flow rate. +* @details Inputs: none +* @details Outputs: message handled +* @param message a pointer to the message to handle +* @return none +*******************************************************************/ +void handleROPumpTargetFlowOverride( MESSAGE_T *message ) +{ + TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; + BOOL result = FALSE; + + // verify payload length + if ( sizeof(TEST_OVERRIDE_ARRAY_PAYLOAD_T) == message->hdr.payloadLen ) + { + memcpy( &payload, message->payload, sizeof(TEST_OVERRIDE_ARRAY_PAYLOAD_T) ); + + result = setROPumpTargetFlowRate( payload.state.f32, payload.state.f32 ); + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +/*********************************************************************//** +* @brief +* The handleROPumpTargetPressureOverride function handles a request to +* override the RO pump target pressure. +* @details Inputs: none +* @details Outputs: message handled +* @param message a pointer to the message to handle +* @return none +*******************************************************************/ +void handleROPumpTargetPressureOverride( MESSAGE_T *message ) +{ + TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; + BOOL result = FALSE; + + // verify payload length + if ( sizeof(TEST_OVERRIDE_ARRAY_PAYLOAD_T) == message->hdr.payloadLen ) + { + memcpy( &payload, message->payload, sizeof(TEST_OVERRIDE_ARRAY_PAYLOAD_T) ); + if ( FALSE == payload.reset ) + { + result = testSetTargetROPumpPressureOverride( payload.state.f32 ); + } + else + { + result = testResetTargetROPumpPressureOverride(); + } + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + /**@}*/ Index: firmware/App/Services/SystemCommMessages.h =================================================================== diff -u -r62a4d7b976107f7ac4d5013ce06f38f4a0bf65bd -r58129c9bb3053c39efa07f60e975f17e2a04755a --- firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 62a4d7b976107f7ac4d5013ce06f38f4a0bf65bd) +++ firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 58129c9bb3053c39efa07f60e975f17e2a04755a) @@ -206,9 +206,6 @@ // MSG_ID_START_STOP_DG_HEAT_DISINFECT BOOL handleStartStopDGHeatDisinfect( MESSAGE_T *message ); -// MSG_ID_SET_RO_PUMP_PWM -BOOL handleSetROPumpPWM( MESSAGE_T * message ); - // MSG_ID_DRAIN_PUMP_SET_DELTA_PRESSURE_OVERRIDE void handleSetDrainPumpDeltaPressureOverrideRequest( MESSAGE_T *message ); @@ -271,6 +268,15 @@ // MSG_ID_DG_RO_PUMP_DUTY_CYCLE_OVERRIDE void handleROPumpDutyCycleOverride( MESSAGE_T *message ); +// MSG_ID_DG_RO_FLOW_RATE_OVERRIDE +void handleROFlowRateOverride( MESSAGE_T *message ); + +// MSG_ID_DG_RO_PUMP_TARGET_FLOW_OVERRIDE +void handleROPumpTargetFlowOverride( MESSAGE_T *message ); + +// MSG_ID_DG_RO_PUMP_TARGET_PRESSURE_OVERRIDE +void handleROPumpTargetPressureOverride( MESSAGE_T *message ); + /**@}*/ #endif