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; }