Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u -r376dfac415321b3d85405e5ef16c48f2118f0f20 -rb576eac158a7bcffd16012dcd5d737e7df4f61d9 --- firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 376dfac415321b3d85405e5ef16c48f2118f0f20) +++ firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision b576eac158a7bcffd16012dcd5d737e7df4f61d9) @@ -59,15 +59,14 @@ #define ROP_FLOW_TO_PWM(flow) ( ROP_FLOW_TO_PWM_SLOPE * log(flow) + ROP_FLOW_TO_PWM_INTERCEPT ) ///< PWM line equation for flow converted to percentage. #define FP_FLOW_RATE_BELOW_TARGET_TIMEOUT_MS ( 10 * MS_PER_SECOND ) ///< Timeout for flow rate below 75% of target flow rate -#define FP_FLOW_RATE_BELOW_TARGET_CLEAR_MS ( 10 * MS_PER_SECOND ) ///< Clear timeout for flow rate below target flow rate +#define FP_FLOW_RATE_BELOW_TARGET_CLEAR_MS ( 10 * MS_PER_SECOND ) ///< Clear timeout for flow rate below target flow rate +#define PERMEATE_FLOW_LOW_OUT_OF_RANGE_EXEMPT_MS ( 10 * MS_PER_SECOND ) ///< Permeate flow low alarm exempt for 10 seconds after starting from Off // ********** private data ********** static RO_PUMP_STATE_T roPumpState; ///< Current state of pump controller state machine. -static RO_PUMP_STATE_T prevROPumpState; ///< Previous state of RO pump controller state machine. static BOOL isROPumpOn; ///< Flag indicating whether pump is currently running. static BOOL stopPumpRequest; ///< Flag indicating pump stop is requested. -static BOOL exemptLowFlowAlarm; ///< Flag indicating whether to exempt low permeate flow alarm. static U32 roPumpDataPublicationTimerCounter; ///< Used to schedule RO pump data publication to CAN bus. static OVERRIDE_U32_T roPumpDataPublishInterval; ///< Interval (in ms) at which to publish boost pump data to CAN bus. static U32 roControlTimerCounter; ///< Determines when to perform control on RO pump. @@ -76,7 +75,7 @@ static F32 roPumpDutyCyclePctSet; ///< Currently set RO pump PWM duty cycle. static OVERRIDE_F32_T roPumpOpenLoopTargetDutyCycle; ///< Target RO pump open loop PWM. static BOOL roPumpStartControl; ///< boolean to determine when closed loop flow control starts -static U32 lowFlowExemptTimer; ///< Timer to exempt low flow rate alarm +static U32 timeSinceStart; ///< Time when RO pump is started from off state. // ********** private function prototypes ********** @@ -85,6 +84,7 @@ static RO_PUMP_STATE_T handleROPumpControlToTargetPressureState( void ); static RO_PUMP_STATE_T handleROPumpOpenLoopState( void ); +static U32 getROPumpLowFlowExemptTimer( void ); static F32 roPumpPresToPWM( F32 targetPressure ); static F32 roPumpFlowToPWM( U32 targetFlow ); static void stopROPump( void ); @@ -93,10 +93,7 @@ /*********************************************************************//** * @brief * The initROPump function initializes the RO Pump module. - * @details \b Inputs: roPumpState, prevROPumpState, roPumpControlMode, isROPumpOn, - * stopPumpRequest, roControlTimerCounter, roPumpDutyCyclePctSet, - * roPumpOpenLoopTargetDutyCycle, roPumpDataPublicationTimerCounter, roPumpDataPublishInterval, - * targetROPumpFlowRate, targetROPumpPressure, exemptLowFlowAlarm, lowFlowExemptTimer + * @details \b Inputs: none * @details \b Outputs: RO Pump controller unit initialized * @return none *************************************************************************/ @@ -113,10 +110,8 @@ MIN_FLUID_PUMP_DUTY_CYCLE_PCT, MAX_FLUID_PUMP_DUTY_CYCLE_PCT, FALSE, 0 ); roPumpState = RO_PUMP_OFF_STATE; - prevROPumpState = RO_PUMP_OFF_STATE; isROPumpOn = FALSE; stopPumpRequest = FALSE; - exemptLowFlowAlarm = TRUE; roControlTimerCounter = 0; roPumpDutyCyclePctSet = 0.0F; roPumpStartControl = FALSE; @@ -137,7 +132,7 @@ roPumpOpenLoopTargetDutyCycle.ovData = 0.0; roPumpOpenLoopTargetDutyCycle.ovInitData = 0.0; roPumpOpenLoopTargetDutyCycle.override = OVERRIDE_RESET; - lowFlowExemptTimer = 0; + timeSinceStart = 0; stopROPump(); } @@ -179,15 +174,6 @@ break; } - if ( prevROPumpState == RO_PUMP_OFF_STATE ) - { - exemptLowFlowAlarm = TRUE; - } - else - { - exemptLowFlowAlarm = FALSE; - } - prevROPumpState = roPumpState; // Publish RO pump data on interval publishROPumpData(); } @@ -204,7 +190,7 @@ { RO_PUMP_STATE_T state = RO_PUMP_OFF_STATE; isROPumpOn = FALSE; - lowFlowExemptTimer = 0; + timeSinceStart = 0; // If there is a target flow set, transition to the PI controller and control to flow if ( getTargetROPumpFlowRateMLPM() > 0 ) @@ -215,7 +201,6 @@ resetPIController( PI_CONTROLLER_ID_RO_PUMP_FLOW, roPumpDutyCyclePctSet, 0.0F ); setFluidPumpPctToPWMDutyCycle( P12_PUMP, roPumpDutyCyclePctSet ); roPumpStartControl = FALSE; - lowFlowExemptTimer = getMSTimerCount(); state = RO_PUMP_CONTROL_TO_TARGET_FLOW_STATE; } // If there is a target pressure set, transition to the PI controller and control to pressure. @@ -226,7 +211,6 @@ roPumpDutyCyclePctSet = roPumpPresToPWM( getTargetROPumpPressure() ); resetPIController( PI_CONTROLLER_ID_RO_PUMP_PRES, roPumpDutyCyclePctSet, 0.0F ); setFluidPumpPctToPWMDutyCycle( P12_PUMP, roPumpDutyCyclePctSet ); - lowFlowExemptTimer = getMSTimerCount(); state = RO_PUMP_CONTROL_TO_TARGET_PRESSURE_STATE; } // If the target duty cycle is greater than zero (minimum is 10%) and the mode has been set to open @@ -236,10 +220,14 @@ roPumpDutyCyclePctSet = getTargetROPumpDutyCyclePCT(); setFluidPumpPctToPWMDutyCycle( P12_PUMP, roPumpDutyCyclePctSet ); isROPumpOn = TRUE; - lowFlowExemptTimer = getMSTimerCount(); state = RO_PUMP_OPEN_LOOP_STATE; } + if ( state != RO_PUMP_OFF_STATE ) + { + timeSinceStart = getMSTimerCount(); + } + return state; } @@ -618,28 +606,35 @@ /*********************************************************************//** * @brief - * The getROPumpLowFlowExemptTimer function gets the timer when RO pump - * starts from Off state. + * The exemptROPumpLowFlowAlarm function gets the flag whether or not + * to exempt the low flow alarm. * @details \b Inputs: none * @details \b Outputs: none - * @return the timer when RO pump started from Off state (in ms). + * @return the flag whether or not to exempt low flow alarm. *************************************************************************/ -U32 getROPumpLowFlowExemptTimer( void ) +BOOL exemptROPumpLowFlowAlarm( void ) { - return lowFlowExemptTimer; + BOOL result = FALSE; + + if ( ( roPumpState == RO_PUMP_CONTROL_TO_TARGET_FLOW_STATE ) && ( FALSE == didTimeout( getROPumpLowFlowExemptTimer(), PERMEATE_FLOW_LOW_OUT_OF_RANGE_EXEMPT_MS ) ) ) + { + result = TRUE; + } + + return result; } /*********************************************************************//** * @brief - * The getROPumpLowFlowExemptFlag function gets the flag whether or not - * to exempt the low flow alarm. + * The getROPumpLowFlowExemptTimer function gets the timer when RO pump + * starts from Off state. * @details \b Inputs: none * @details \b Outputs: none - * @return the flag whether or not to exempt low flow alarm (in mL/min). + * @return the timer when RO pump started from Off state (in ms). *************************************************************************/ -BOOL getROPumpLowFlowExemptFlag( void ) +static U32 getROPumpLowFlowExemptTimer( void ) { - return exemptLowFlowAlarm; + return timeSinceStart; } /*********************************************************************//**