Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u -r3417933e6edf61a914c428e2fa944b3b349272a4 -r39405d73782b8b9cf1fc26238640e683efcebbb5 --- firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 3417933e6edf61a914c428e2fa944b3b349272a4) +++ firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 39405d73782b8b9cf1fc26238640e683efcebbb5) @@ -17,6 +17,7 @@ #include // for log() #include "Flow.h" +#include "FPOperationModes.h" //#include "NVDataMgmt.h" #include "Messaging.h" #include "MessageSupport.h" @@ -39,8 +40,8 @@ #define RO_PUMP_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the RO Pump data is published on the CAN bus. #define ROP_CONTROL_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the RO pump is controlled. -#define ROP_FLOW_CONTROL_P_COEFFICIENT 0.1F ///< P term for RO pump flow control. -#define ROP_FLOW_CONTROL_I_COEFFICIENT 0.8F ///< I term for RO pump flow control. +#define ROP_FLOW_CONTROL_P_COEFFICIENT 0.000065F ///< P term for RO pump flow control. +#define ROP_FLOW_CONTROL_I_COEFFICIENT 0.00022F ///< I term for RO pump flow control. #define ROP_MIN_FLOW_TO_CONTROL_PCT 0.75F #define ROP_PRESSURE_CONTROL_P_COEFFICIENT 0.15F ///< P term for RO pump pressure control. #define ROP_PRESSURE_CONTROL_I_COEFFICIENT 0.65F ///< I term for RO pump pressure control. @@ -57,6 +58,9 @@ #define ROP_FLOW_TO_PWM_PCT(flow) ( ( ROP_FLOW_TO_PWM_SLOPE * log(flow) + ROP_FLOW_TO_PWM_INTERCEPT ) / MAX_FLUID_PUMP_PWM_DUTY_CYCLE ) ///< PWM line equation for flow converted to percentage. #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 + // ********** private data ********** static RO_PUMP_STATE_T roPumpState; ///< Current state of pump controller state machine. @@ -104,6 +108,8 @@ initializePIController( PI_CONTROLLER_ID_RO_PUMP_PRES, MIN_FLUID_PUMP_DUTY_CYCLE_PCT, ROP_PRESSURE_CONTROL_P_COEFFICIENT, ROP_PRESSURE_CONTROL_I_COEFFICIENT, MIN_FLUID_PUMP_DUTY_CYCLE_PCT, MAX_FLUID_PUMP_DUTY_CYCLE_PCT, FALSE, 0 ); + initPersistentAlarm( ALARM_ID_FP_PERMEATE_FLOW_RATE_BELOW_TARGET, FP_FLOW_RATE_BELOW_TARGET_CLEAR_MS, FP_FLOW_RATE_BELOW_TARGET_TIMEOUT_MS ); + roPumpState = RO_PUMP_OFF_STATE; isROPumpOn = FALSE; stopPumpRequest = FALSE; @@ -123,9 +129,9 @@ targetROPumpPressure.ovData = 0.0F; targetROPumpPressure.ovInitData = 0.0F; targetROPumpPressure.override = OVERRIDE_RESET; - roPumpOpenLoopTargetDutyCycle.data = 0; - roPumpOpenLoopTargetDutyCycle.ovData = 0; - roPumpOpenLoopTargetDutyCycle.ovInitData = 0; + roPumpOpenLoopTargetDutyCycle.data = 0.0; + roPumpOpenLoopTargetDutyCycle.ovData = 0.0; + roPumpOpenLoopTargetDutyCycle.ovInitData = 0.0; roPumpOpenLoopTargetDutyCycle.override = OVERRIDE_RESET; stopROPump(); @@ -241,14 +247,22 @@ if ( getTargetROPumpFlowRateMLPM() > 0 ) { ///transition to closed loop - resetPIController( PI_CONTROLLER_ID_RO_PUMP_FLOW, getTargetROPumpDutyCyclePCT(), 0 ); + if ( getCurrentFPOperationMode() == FP_MODE_GENP ) + { + roPumpDutyCyclePctSet = getCurrentROPumpDutyCyclePCT(); + } + else + { + roPumpDutyCyclePctSet = roPumpFlowToPWM( getTargetROPumpFlowRateMLPM() ); + } + resetPIController( PI_CONTROLLER_ID_RO_PUMP_FLOW, roPumpDutyCyclePctSet, 0.0F ); state = RO_PUMP_CONTROL_TO_TARGET_FLOW_STATE; } // If there is a target pressure set, transition to the PI controller and control to pressure. else if ( getTargetROPumpPressure() > 0.0F ) { //transition to closed loop - resetPIController( PI_CONTROLLER_ID_RO_PUMP_PRES, getTargetROPumpPressure(), 0 ); + resetPIController( PI_CONTROLLER_ID_RO_PUMP_PRES, getTargetROPumpPressure(), 0.0F ); state = RO_PUMP_CONTROL_TO_TARGET_PRESSURE_STATE; } else if ( (F32)getTargetROPumpDutyCyclePCT() == 0.0F ) @@ -271,6 +285,9 @@ { RO_PUMP_STATE_T state = RO_PUMP_CONTROL_TO_TARGET_FLOW_STATE; F32 nexttgtflow = 0.0; + F32 currentFlowRate = 0.0; + F32 adjustedFlowRRate = 0.0; + BOOL isFlowRateLow = FALSE; // Check if need to switch control modes if ( getTargetROPumpPressure() > 0.0F ) @@ -293,20 +310,27 @@ } else if ( ++roControlTimerCounter >= ROP_CONTROL_INTERVAL ) { + currentFlowRate = getFilteredFlow( P16_FLOW ); + adjustedFlowRRate = (F32)getTargetROPumpFlowRateMLPM() * ROP_MIN_FLOW_TO_CONTROL_PCT; + // P16 flow seems to lag in current Leahi HW. We will wait till we hit a % of target flow before we start changing control. - if( ( TRUE == roPumpStartControl ) || ( getFilteredFlow( P16_FLOW ) >= ( (F32)getTargetROPumpFlowRateMLPM() * ROP_MIN_FLOW_TO_CONTROL_PCT ) ) ) + if( ( TRUE == roPumpStartControl ) || ( currentFlowRate >= ( adjustedFlowRRate ) ) ) { - //roPumpDutyCyclePctSet = runPIController( PI_CONTROLLER_ID_RO_PUMP_FLOW, (F32)getTargetROPumpFlowRateMLPM(), getFilteredFlow( P16_FLOW ) ); - //setFluidPumpPctToPWMDutyCycle( P12_PUMP, roPumpDutyCyclePctSet ); - nexttgtflow = runPIController( PI_CONTROLLER_ID_RO_PUMP_FLOW, (F32)getTargetROPumpFlowRateMLPM(), getFilteredFlow( P16_FLOW ) ); - nexttgtflow = (U16)MIN( ROP_FLOW_TO_PWM( nexttgtflow ), ( MAX_FLUID_PUMP_PWM_DUTY_CYCLE * MAX_FLUID_PUMP_DUTY_CYCLE_PCT ) ); - setFluidPumpPWMDutyCycle( P12_PUMP, nexttgtflow ); + roPumpDutyCyclePctSet = runPIController( PI_CONTROLLER_ID_RO_PUMP_FLOW, (F32)getTargetROPumpFlowRateMLPM(), currentFlowRate ); + roPumpDutyCyclePctSet = MIN( roPumpDutyCyclePctSet, ( MAX_FLUID_PUMP_PWM_DUTY_CYCLE * MAX_FLUID_PUMP_DUTY_CYCLE_PCT ) ); + setFluidPumpPctToPWMDutyCycle( P12_PUMP, roPumpDutyCyclePctSet ); + if ( FALSE == roPumpStartControl ) { roPumpStartControl = TRUE; } } roControlTimerCounter = 0; + + //is flow rate less than 75% of the target flow rate + // wait for 10 seconds for timeout + isFlowRateLow = ( ( currentFlowRate < ( adjustedFlowRRate ) ) ? TRUE : FALSE); + checkPersistentAlarm( ALARM_ID_FP_PERMEATE_FLOW_RATE_BELOW_TARGET, isFlowRateLow, currentFlowRate, adjustedFlowRRate); } return state; @@ -586,7 +610,7 @@ * The roPumpPresToPWM function calculates the duty cycle for the given target * pressure. * @details \b Inputs: none - * @details \b Outputs: dutyCyclePct + * @details \b Outputs: none * @param targetPressure target pressure value to control in PSI * @return the current target RO pump PWM in a percentage. *************************************************************************/ @@ -602,7 +626,7 @@ * The roPumpFlowToPWM function calculates the duty cycle for the given target * flow rate. * @details \b Inputs: none - * @details \b Outputs: dutyCyclePct + * @details \b Outputs: none * @param targetFlow target flow value to control in in mL/min * @return the current target RO pump PWM in a percentage. *************************************************************************/ @@ -615,10 +639,11 @@ /*********************************************************************//** * @brief - * The signalROPumpStop function stops the P12 pump immediately and + * The signalROPumpHardStop function stops the P12 pump immediately and * resets all the variables associated with the P12 pump run. - * @details \b Inputs: roPumpState[] - * @details \b Outputs: stopPumpRequest[] + * @details \b Inputs: targetROPumpFlowRate, targetROPumpPressure + * @details \b Outputs: roPumpState, roPumpDutyCyclePctSet, roControlTimerCounter, + * roPumpOpenLoopTargetDutyCycle, targetROPumpFlowRate, targetROPumpPressure * @return none *************************************************************************/ void signalROPumpHardStop( void ) @@ -727,8 +752,10 @@ * @brief * The testROPumpTargetPressureOverride function overrides the RO pump * data publish interval. - * @details \b Inputs: targetROPumpPressure - * @details \b Outputs: targetROPumpPressure + * @details \b Inputs: targetROPumpPressure, targetROPumpFlowRate, + * roPumpOpenLoopTargetDutyCycle + * @details \b Outputs: targetROPumpPressure, targetROPumpFlowRate, + * roPumpOpenLoopTargetDutyCycle * @param message Override message from Dialin which includes the value * of the target pressure * @return TRUE if override successful, FALSE if not @@ -776,8 +803,10 @@ * @brief * The testROPumpTargetFlowOverride function overrides the RO pump * data publish interval. - * @details \b Inputs: targetROPumpFlowRate - * @details \b Outputs: targetROPumpFlowRate + * @details \b Inputs: targetROPumpFlowRate, roPumpOpenLoopTargetDutyCycle, + * targetROPumpPressure + * @details \b Outputs: targetROPumpFlowRate, roPumpOpenLoopTargetDutyCycle, + * targetROPumpPressure * @param message Override message from Dialin which includes the value * of the target flow * @return TRUE if override successful, FALSE if not @@ -825,8 +854,10 @@ * @brief * The testROPumpTargetDutyCycleOverride function overrides the RO pump * duty cycle. - * @details \b Inputs: roPumpOpenLoopTargetDutyCycle - * @details \b Outputs: roPumpOpenLoopTargetDutyCycle + * @details \b Inputs: roPumpOpenLoopTargetDutyCycle, targetROPumpPressure, + * targetROPumpFlowRate + * @details \b Outputs: roPumpOpenLoopTargetDutyCycle, targetROPumpPressure, + * targetROPumpFlowRate * @param message Override message from Dialin which includes the value * of the target flow * @return TRUE if override successful, FALSE if not @@ -873,8 +904,8 @@ /*********************************************************************//** * @brief * The testBoostPumpHardStopOverride function stops the RO pump. - * @details \b Inputs: boostPumpOpenLoopTargetDutyCycle - * @details \b Outputs: boostPumpOpenLoopTargetDutyCycle + * @details \b Inputs: roPumpOpenLoopTargetDutyCycle + * @details \b Outputs: roPumpOpenLoopTargetDutyCycle * @param message Override message from Dialin which includes the value * of the target flow * @return TRUE if override successful, FALSE if not