Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u -r9ce06772b2f651c57144327e6cbf886e2bc22dee -r9047c6e1db73ac20849a63b8cbec33041c28b0d5 --- firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 9ce06772b2f651c57144327e6cbf886e2bc22dee) +++ firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 9047c6e1db73ac20849a63b8cbec33041c28b0d5) @@ -53,20 +53,20 @@ #define ROP_CONTROL_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the RO pump is controlled. #define ROP_RAMP_UP_CONTROL_INTERVAL ( 500 / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the RO pump is controlled. -#define ROP_P_COEFFICIENT 0.25 ///< P term for RO pump pressure control. -#define ROP_I_COEFFICIENT 0.25 ///< I term for RO pump pressure control. +#define ROP_RAMP_UP_P_COEFFICIENT 0.22 ///< P term for RO pump ramp up to flow control. +#define ROP_FLOW_CONTROL_P_COEFFICIENT 0.25 ///< P term for RO pump flow control. +#define ROP_FLOW_CONTROL_I_COEFFICIENT 0.25 ///< I term for RO pump flow control. +#define ROP_MAX_PRESSURE_P_COEFFICIENT 0.01 ///< P term for RO pump max pressure control. +#define ROP_MAX_PRESSURE_I_COEFFICIENT 0.01 ///< I term for RO pump max pressure control. #define ROP_FLOW_TARGET_TOLERANCE 0.03 ///< Tolerance in between the target flow rate and the actual flow rate in percentage. -#define ROP_RAMP_DOWN_DUTY_CYCLE_RATIO 0.01 ///< Pump ramp down duty cycle ratio when the pressure higher than max defined. +#define ROP_RAMP_DOWN_DUTY_CYCLE_RATIO 0.03 ///< Pump ramp down duty cycle ratio when the pressure higher than max defined. #define FLOW_SENSOR_ZERO_READING 0xFFFF ///< Flow sensor reading indicates zero flow (or flow lower than can be detected by sensor). #define FLOW_SAMPLES_TO_AVERAGE ( 250 / TASK_PRIORITY_INTERVAL ) ///< Averaging flow data over 250 ms intervals. #define FLOW_AVERAGE_MULTIPLIER ( 1.0 / (F32)FLOW_SAMPLES_TO_AVERAGE ) ///< Optimization - multiplying is faster than dividing. -/// The time in counts to check the flow and make sure it is in range. -#define FLOW_VERIFICATION_COUNTER_TARGET ( 2 * MS_PER_SECOND / TASK_GENERAL_INTERVAL ) //TODO remove - #define RO_FLOW_ADC_TO_LPM_FACTOR 5555 ///< Conversion factor from ADC counts to LPM (liters/min) for RO flow rate (multiply this by inverse of FPGA reading). #define ROP_FLOW_TO_PWM_SLOPE 0.1 ///< Slope of flow to PWM line equation. @@ -87,66 +87,62 @@ #define MAX_ALLOWED_RAMP_UP_TIME ( 10 * MS_PER_SECOND ) ///< Maximum allowed ramp up time to a flow rate in ms. #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 SAFETY_SHUTDOWN_TIMEOUT ( 3 * MS_PER_SECOND ) ///< RO pump safety shutdown activation timeout in ms. -#define ROP_FLOW_STABILIZE_TIME ( 3 * MS_PER_SECOND ) ///< Time required for RO flow to stabilize. TODO remove -#define ROP_MAX_RAMP_UP_RETRY 5 ///< Maximum ramp up retires before alarm. -// ************ New defines for pump control ****************// - - /// Enumeration of RO pump states. typedef enum ROPump_States { - RO_PUMP_OFF_STATE = 0, ///< RO pump off state - RO_PUMP_RAMP_UP_STATE, ///< RO pump ramp up to target flow rate state - RO_PUMP_CONTROL_TO_TARGET_STATE, ///< RO pump control to target pressure state - RO_PUMP_OPEN_LOOP_STATE, ///< RO pump open loop state - NUM_OF_RO_PUMP_STATES ///< Number of RO pump states + RO_PUMP_OFF_STATE = 0, ///< RO pump off state. + RO_PUMP_RAMP_UP_TO_TARGET_FLOW_STATE, ///< RO pump ramp up to target flow rate state. + RO_PUMP_CONTROL_TO_TARGET_FLOW_STATE, ///< RO pump control to target flow state. + RO_PUMP_CONTROL_TO_MAX_PRESSURE_STATE, ///< RO pump control to max pressure state. + RO_PUMP_OPEN_LOOP_STATE, ///< RO pump open loop state. + NUM_OF_RO_PUMP_STATES ///< Number of RO pump states. } RO_PUMP_STATE_T; /// Enumeration of RO pump self-test states. typedef enum ROPump_Self_Test_States { - RO_PUMP_SELF_TEST_STATE_START = 0, ///< RO pump self-test start state - RO_PUMP_TEST_STATE_IN_PROGRESS, ///< RO pump self-tests in progress state - RO_PUMP_TEST_STATE_COMPLETE, ///< RO pump self-tests completed state - NUM_OF_RO_PUMP_SELF_TEST_STATES ///< Number of RO pump self-test states + RO_PUMP_SELF_TEST_STATE_START = 0, ///< RO pump self-test start state. + RO_PUMP_TEST_STATE_IN_PROGRESS, ///< RO pump self-tests in progress state. + RO_PUMP_TEST_STATE_COMPLETE, ///< RO pump self-tests completed state. + NUM_OF_RO_PUMP_SELF_TEST_STATES ///< Number of RO pump self-test states. } RO_PUMP_SELF_TEST_STATE_T; // ********** private data ********** -static RO_PUMP_STATE_T roPumpState = RO_PUMP_OFF_STATE; ///< current state of RO pump controller state machine. -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 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 RO_PUMP_STATE_T roPumpState = RO_PUMP_OFF_STATE; ///< current state of RO pump controller state machine. +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 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 F32 targetROPumpFlowRate = 0.0; ///< Target RO flow rate (in L/min). -static F32 targetROPumpPressure = 0; ///< Target RO pressure (in PSI). +static F32 targetROPumpFlowRate = 0.0; ///< Target RO flow rate (in L/min). +static F32 targetROPumpMaxPressure = 0.0; ///< Target RO max allowed pressure (in PSI). 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 L/min). + 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 L/min). -static U32 roControlTimerCounter = 0; ///< determines when to perform control on RO pump. -static F32 roPumpOpenLoopTargetDutyCycle = 0; ///< Target RO pump open loop PWM. +static U32 roControlTimerCounter = 0; ///< determines when to perform control on RO pump. +static F32 roPumpOpenLoopTargetDutyCycle = 0; ///< Target RO pump open loop PWM. /* TODO 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 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 S32 measuredFlowReadingsSum = 0; ///< Raw flow reading sums for averaging. -static U32 flowFilterCounter = 0; ///< Flow filtering counter. -static U32 rampUpRetryCount = 0; ///< Number of ramp up retries. +static S32 measuredFlowReadingsSum = 0; ///< Raw flow reading sums for averaging. +static U32 flowFilterCounter = 0; ///< Flow filtering counter. // ********** private function prototypes ********** static RO_PUMP_STATE_T handleROPumpOffState( void ); -static RO_PUMP_STATE_T handleROPumpRampUpState( void ); -static RO_PUMP_STATE_T handleROPumpControlToTargetState( void ); +static RO_PUMP_STATE_T handleROPumpRampUpToTargetFlowState( void ); +static RO_PUMP_STATE_T handleROPumpControlToTargetFlowState( void ); +static RO_PUMP_STATE_T handleROPumpControlToMaxPressureState( void ); static RO_PUMP_STATE_T handleROPumpOpenLoopState( void ); static void setROPumpTargetDutyCycle( F32 duty ); @@ -169,10 +165,14 @@ { stopROPump(); - // Initialize RO pump PI controller - initializePIController( PI_CONTROLLER_ID_RO_PUMP, MIN_RO_PUMP_DUTY_CYCLE, ROP_P_COEFFICIENT, ROP_I_COEFFICIENT, + // Initialize RO pump PI controller to flow + initializePIController( PI_CONTROLLER_ID_RO_PUMP_FLOW, MIN_RO_PUMP_DUTY_CYCLE, ROP_FLOW_CONTROL_P_COEFFICIENT, ROP_FLOW_CONTROL_I_COEFFICIENT, MIN_RO_PUMP_DUTY_CYCLE, MAX_RO_PUMP_DUTY_CYCLE ); + // Initialize RO pump PI controller t maximum pressure + initializePIController( PI_CONTROLLER_ID_RO_PUMP_MAX_PRES, MIN_RO_PUMP_DUTY_CYCLE, ROP_MAX_PRESSURE_P_COEFFICIENT, ROP_MAX_PRESSURE_I_COEFFICIENT, + MIN_RO_PUMP_DUTY_CYCLE, MAX_RO_PUMP_DUTY_CYCLE ); + // 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_UPPER_RANGE, TRUE, FLOW_OUT_OF_RANGE_PERSISTENT_INTERVAL, FLOW_OUT_OF_RANGE_PERSISTENT_INTERVAL ); @@ -197,7 +197,6 @@ measuredFlowReadingsSum = 0; flowFilterCounter = 0; roPumpDataPublicationTimerCounter = 0; - rampUpRetryCount = 0; roPumpState = RO_PUMP_OFF_STATE; roPumpControlMode = NUM_OF_PUMP_CONTROL_MODES; roPumpControlModeSet = roPumpControlMode; @@ -228,11 +227,13 @@ { // 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 = maxPressure; - targetROPumpFlowRate = roFlowRate; - roPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; + targetROPumpMaxPressure = maxPressure; + targetROPumpFlowRate = roFlowRate; + roPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; + roPumpState = RO_PUMP_RAMP_UP_TO_TARGET_FLOW_STATE; // Get the initial guess of the duty cycle - roPumpPWMDutyCyclePct = ROP_FLOW_TO_PWM_DC( roFlowRate ); + roPumpPWMDutyCyclePct = ROP_FLOW_TO_PWM_DC( roFlowRate ); + roControlTimerCounter = 0; result = TRUE; } // Requested max pressure is out of range @@ -271,8 +272,8 @@ roPumpOpenLoopTargetDutyCycle = 0.0; roControlTimerCounter = 0; isROPumpOn = FALSE; - targetROPumpPressure = 0; - resetPIController( PI_CONTROLLER_ID_RO_PUMP, MIN_RO_PUMP_DUTY_CYCLE ); + targetROPumpMaxPressure = 0; + resetPIController( PI_CONTROLLER_ID_RO_PUMP_FLOW, MIN_RO_PUMP_DUTY_CYCLE ); } /*********************************************************************//** @@ -320,7 +321,7 @@ // 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 ) + /*if ( roPumpControlMode == PUMP_CONTROL_MODE_CLOSED_LOOP && roPumpState == RO_PUMP_CONTROL_TO_TARGET_FLOW_STATE ) { F32 const currentFlow = getMeasuredROFlowRate(); F32 const targetFlow = getTargetROPumpFlowRate(); @@ -346,7 +347,7 @@ { activateSafetyShutdown(); } - } + }*/ // Publish RO pump data on interval publishROPumpData(); @@ -367,14 +368,18 @@ roPumpState = handleROPumpOffState(); break; - case RO_PUMP_RAMP_UP_STATE: - roPumpState = handleROPumpRampUpState(); + case RO_PUMP_RAMP_UP_TO_TARGET_FLOW_STATE: + roPumpState = handleROPumpRampUpToTargetFlowState(); break; - case RO_PUMP_CONTROL_TO_TARGET_STATE: - roPumpState = handleROPumpControlToTargetState(); + case RO_PUMP_CONTROL_TO_TARGET_FLOW_STATE: + roPumpState = handleROPumpControlToTargetFlowState(); break; + case RO_PUMP_CONTROL_TO_MAX_PRESSURE_STATE: + roPumpState = handleROPumpControlToMaxPressureState(); + break; + case RO_PUMP_OPEN_LOOP_STATE: roPumpState = handleROPumpOpenLoopState(); break; @@ -427,7 +432,7 @@ *************************************************************************/ static RO_PUMP_STATE_T handleROPumpOffState( void ) { - RO_PUMP_STATE_T result = RO_PUMP_OFF_STATE; + RO_PUMP_STATE_T state = RO_PUMP_OFF_STATE; // If there is a flow, transition to the PI controller to get the corresponding pressure of that flow if ( getTargetROPumpFlowRate() > 0 && roPumpControlMode == PUMP_CONTROL_MODE_CLOSED_LOOP ) @@ -437,33 +442,33 @@ isROPumpOn = TRUE; roPumpDutyCyclePctSet = ROP_FLOW_TO_PWM_DC( getTargetROPumpFlowRate() ); setROPumpControlSignalDutyCycle( roPumpDutyCyclePctSet ); - result = RO_PUMP_RAMP_UP_STATE; + state = RO_PUMP_RAMP_UP_TO_TARGET_FLOW_STATE; } // If the target duty cycle is greater than zero (minimum is 10%) and the mode has been set to open // loop, set the duty cycle if ( roPumpOpenLoopTargetDutyCycle > 0 && roPumpControlMode == PUMP_CONTROL_MODE_OPEN_LOOP ) { setROPumpControlSignalDutyCycle( roPumpOpenLoopTargetDutyCycle ); isROPumpOn = TRUE; - result = RO_PUMP_OPEN_LOOP_STATE; + state = RO_PUMP_OPEN_LOOP_STATE; } - return result; + return state; } /*********************************************************************//** * @brief - * The handleROPumpRampUpState function handles the RO pump ramp up state - * of the controller state machine. + * The handleROPumpRampUpToTargetFlowState function handles the RO pump + * ramp up to flow 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 ) +static RO_PUMP_STATE_T handleROPumpRampUpToTargetFlowState( void ) { - RO_PUMP_STATE_T result = RO_PUMP_RAMP_UP_STATE; + RO_PUMP_STATE_T state = RO_PUMP_RAMP_UP_TO_TARGET_FLOW_STATE; // Get the current pressure from the sensor F32 actualPressure = getMeasuredDGPressure( PRESSURE_SENSOR_RO_PUMP_OUTLET ); @@ -492,76 +497,117 @@ // be reset to the corresponding pressure of the target flow rate. if ( ( actualPressure > targetPressure ) || ( ( targetPressure - actualPressure ) < MAX_PRESSURE_TARGET_TOLERANCE ) ) { - resetPIController( PI_CONTROLLER_ID_RO_PUMP, roPumpDutyCyclePctSet ); - result = RO_PUMP_CONTROL_TO_TARGET_STATE; + resetPIController( PI_CONTROLLER_ID_RO_PUMP_MAX_PRES, roPumpDutyCyclePctSet ); + state = RO_PUMP_CONTROL_TO_MAX_PRESSURE_STATE; } // else if ( TRUE == isFlowOutOfRange ) { - roPumpDutyCyclePctSet += ( targetFlowRate - actualFlowRate ) * 0.5; - //roPumpDutyCyclePctSet = ROP_FLOW_TO_PWM_DC( getTargetROPumpFlowRate() ); + roPumpDutyCyclePctSet += ( targetFlowRate - actualFlowRate ) * ROP_RAMP_UP_P_COEFFICIENT; + // If the duty cycle is out of the define range for the RO pump, set the boundaries + roPumpDutyCyclePctSet = roPumpDutyCyclePctSet < MIN_RO_PUMP_DUTY_CYCLE ? MIN_RO_PUMP_DUTY_CYCLE : roPumpDutyCyclePctSet; + roPumpDutyCyclePctSet = roPumpDutyCyclePctSet > MAX_RO_PUMP_DUTY_CYCLE ? MAX_RO_PUMP_DUTY_CYCLE : roPumpDutyCyclePctSet; + setROPumpControlSignalDutyCycle( roPumpDutyCyclePctSet ); } // Reached to the target flow go to the next state else { - resetPIController( PI_CONTROLLER_ID_RO_PUMP, roPumpDutyCyclePctSet ); - result = RO_PUMP_CONTROL_TO_TARGET_STATE; + resetPIController( PI_CONTROLLER_ID_RO_PUMP_FLOW, roPumpDutyCyclePctSet ); + state = RO_PUMP_CONTROL_TO_TARGET_FLOW_STATE; } roControlTimerCounter = 0; } - /*if ( TRUE == setupROPumpControl ) - { - //resetPersistentAlarmTimer( ALARM_ID_RO_PUMP_RAMP_UP_TO_FLOW_TIMEOUT ); - result = RO_PUMP_CONTROL_SETUP_STATE; - }*/ - - return result; + return state; } /*********************************************************************//** * @brief - * The handleROPumpControlToTargetState function handles the control to - * target state of the RO pump controller state machine. + * The handleROPumpControlToTargetFlowState function handles the control to + * target flow state of the RO pump controller state machine. * @details Inputs: roPumpPWMDutyCyclePctSet, roControlTimerCounter, * roPumpControlModeSet * @details Outputs: roPumpPWMDutyCyclePctSet, roControlTimerCounter * @return next state of the controller state machine *************************************************************************/ -static RO_PUMP_STATE_T handleROPumpControlToTargetState( void ) +static RO_PUMP_STATE_T handleROPumpControlToTargetFlowState( void ) { - RO_PUMP_STATE_T result = RO_PUMP_CONTROL_TO_TARGET_STATE; + RO_PUMP_STATE_T state = RO_PUMP_CONTROL_TO_TARGET_FLOW_STATE; // Control at set interval - if ( ++roControlTimerCounter >= ROP_CONTROL_INTERVAL && roPumpControlModeSet == PUMP_CONTROL_MODE_CLOSED_LOOP ) + if ( ++roControlTimerCounter >= ROP_CONTROL_INTERVAL && roPumpControlMode == PUMP_CONTROL_MODE_CLOSED_LOOP ) { // Get the pressure to use it for setting the control F32 actualPressure = getMeasuredDGPressure( PRESSURE_SENSOR_RO_PUMP_OUTLET ); - if ( actualPressure >= targetROPumpPressure ) + + + if ( actualPressure >= targetROPumpMaxPressure ) { + resetPIController( PI_CONTROLLER_ID_RO_PUMP_MAX_PRES, roPumpDutyCyclePctSet ); + state = RO_PUMP_CONTROL_TO_MAX_PRESSURE_STATE; + } + else + { + roPumpDutyCyclePctSet = runPIController( PI_CONTROLLER_ID_RO_PUMP_FLOW, getTargetROPumpFlowRate(), getMeasuredROFlowRate() ); + } + + setROPumpControlSignalDutyCycle( roPumpDutyCyclePctSet ); + + roControlTimerCounter = 0; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleROPumpControlToMaxPressureState function handles the control + * to max pressure state of the RO pump controller state machine. + * @details Inputs: roPumpPWMDutyCyclePctSet, roControlTimerCounter, + * roPumpControlModeSet + * @details Outputs: roPumpPWMDutyCyclePctSet, roControlTimerCounter + * @return next state of the controller state machine + *************************************************************************/ +static RO_PUMP_STATE_T handleROPumpControlToMaxPressureState( void ) +{ + RO_PUMP_STATE_T state = RO_PUMP_CONTROL_TO_MAX_PRESSURE_STATE; + + // Get the pressure to use it for setting the control + F32 actualPressure = getMeasuredDGPressure( PRESSURE_SENSOR_RO_PUMP_OUTLET ); + + // Control at set interval + if ( ++roControlTimerCounter >= ROP_CONTROL_INTERVAL && roPumpControlMode == PUMP_CONTROL_MODE_CLOSED_LOOP ) + { + if ( actualPressure > targetROPumpMaxPressure ) + { roPumpDutyCyclePctSet -= ROP_RAMP_DOWN_DUTY_CYCLE_RATIO; - resetPIController( PI_CONTROLLER_ID_RO_PUMP, roPumpDutyCyclePctSet ); + resetPIController( PI_CONTROLLER_ID_RO_PUMP_MAX_PRES, roPumpDutyCyclePctSet ); } else { - roPumpDutyCyclePctSet = runPIController( PI_CONTROLLER_ID_RO_PUMP, getTargetROPumpFlowRate(), getMeasuredROFlowRate() ); + roPumpDutyCyclePctSet = runPIController( PI_CONTROLLER_ID_RO_PUMP_MAX_PRES, getTargetROPumpFlowRate(), getMeasuredROFlowRate() ); } setROPumpControlSignalDutyCycle( roPumpDutyCyclePctSet ); roControlTimerCounter = 0; } - /*if ( TRUE == setupROPumpControl ) + // Check if the actual pressure is out of tolerance from max pressure. + // If it is out, go back to ramp up state and to try to reach to target flow again + if ( ( targetROPumpMaxPressure - actualPressure ) > MAX_PRESSURE_TARGET_TOLERANCE ) { - result = RO_PUMP_CONTROL_SETUP_STATE; - }*/ + state = RO_PUMP_CONTROL_TO_TARGET_FLOW_STATE; - return result; + roControlTimerCounter = 0; + } + + return state; } + /*********************************************************************//** * @brief * The handleROPumpOpenLoopState function handles the open loop state of @@ -684,7 +730,7 @@ *************************************************************************/ F32 getTargetROPumpPressure( void ) { - return targetROPumpPressure; + return targetROPumpMaxPressure; } /*********************************************************************//** @@ -805,7 +851,7 @@ // Make sure the requested pressure is in range if ( value >= MIN_ALLOWED_PRESSURE_PSI && value <= MAX_ALLOWED_PRESSURE_PSI ) { - targetROPumpPressure = value; + targetROPumpMaxPressure = value; result = TRUE; } }