Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u -r45f4646609e6dd39691102e109d0b5c14f97e054 -r3eb7c2e62c727be195cd937d49957db9d4ba83b4 --- firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 45f4646609e6dd39691102e109d0b5c14f97e054) +++ firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 3eb7c2e62c727be195cd937d49957db9d4ba83b4) @@ -20,7 +20,6 @@ #include "etpwm.h" #include "mibspi.h" -#include "AlarmDefs.h" #include "FPGA.h" #include "OperationModes.h" #include "PIControllers.h" @@ -35,9 +34,6 @@ #ifdef EMC_TEST_BUILD #include "Heaters.h" #endif -#ifdef ENABLE_DIP_SWITCHES -#include "Valves.h" -#endif /** * @addtogroup ROPump @@ -53,7 +49,7 @@ #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_RAMP_UP_P_COEFFICIENT 0.22 ///< P term for RO pump ramp up to flow 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. @@ -78,7 +74,7 @@ #define FLOW_SENSOR_ZERO_READING 0xFFFF ///< Flow sensor reading indicates zero flow (or flow lower than can be detected by sensor). #define MAX_ALLOWED_FLOW_DEVIATION 0.1 ///< Max allowed deviation from target flow. -#define FLOW_OUT_OF_RANGE_PERSISTENT_INTERVAL ( 10 * MS_PER_SECOND ) ///< Flow out of range time out in counts. +#define FLOW_OUT_OF_RANGE_PERSISTENT_INTERVAL ( 12 * MS_PER_SECOND ) ///< 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 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. @@ -110,23 +106,24 @@ // ********** 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 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 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. TODO do we need this? 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). +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 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 @@ -197,6 +194,7 @@ roPumpState = RO_PUMP_OFF_STATE; roPumpControlMode = NUM_OF_PUMP_CONTROL_MODES; roPumpControlModeSet = roPumpControlMode; + isROPumpOn = FALSE; } /*********************************************************************//** @@ -231,6 +229,7 @@ // Get the initial guess of the duty cycle roPumpPWMDutyCyclePct = ROP_FLOW_TO_PWM_DC( roFlowRate ); roControlTimerCounter = 0; + isROPumpOn = TRUE; result = TRUE; } // Requested max pressure is out of range @@ -316,12 +315,15 @@ flowFilterCounter = 0; } - // 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_FLOW_STATE ) +#ifndef IGNORE_RO_PUMP_MONITOR + // To monitor the flow, the control mode must be in closed loop mode and the pump should be control to flow state + // If the pump is controlled to the maximum pressure, the flow might be different from the target flow for more than 10% + // but the pump is not able to achieve the flow. + if ( ( PUMP_CONTROL_MODE_CLOSED_LOOP == roPumpControlMode ) && ( RO_PUMP_CONTROL_TO_TARGET_FLOW_STATE == roPumpState ) ) { F32 const currentFlow = getMeasuredROFlowRate(); F32 const targetFlow = getTargetROPumpFlowRate(); + // The flow cannot be out of range for than 10% of the target flow BOOL const isFlowOutOfRange = fabs( 1.0 - ( currentFlow / targetFlow ) ) > MAX_ALLOWED_FLOW_DEVIATION; // Figure out whether flow is out of range from which side BOOL const isFlowOutOfUpperRange = isFlowOutOfRange && ( currentFlow > targetFlow ); @@ -344,7 +346,8 @@ { activateSafetyShutdown(); } - }*/ + } +#endif // Publish RO pump data on interval publishROPumpData(); @@ -475,15 +478,6 @@ F32 flowRateDeviation = fabs( targetFlowRate - actualFlowRate ) / targetFlowRate; BOOL isFlowOutOfRange = flowRateDeviation > ROP_FLOW_TARGET_TOLERANCE; - // If the ramp up persistent alarm is active, turn off the pump and go to off state - /*if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_RO_PUMP_RAMP_UP_TO_FLOW_TIMEOUT, isFlowOutOfRange ) ) - { - stopROPump(); - result = RO_PUMP_OFF_STATE; - SET_ALARM_WITH_2_F32_DATA( ALARM_ID_RO_PUMP_RAMP_UP_TO_FLOW_TIMEOUT, actualFlowRate, MAX_ALLOWED_RAMP_UP_TIME ); - }*/ - // Control at set interval - //else if ( ++roControlTimerCounter >= ROP_RAMP_UP_CONTROL_INTERVAL ) if ( ++roControlTimerCounter >= ROP_RAMP_UP_CONTROL_INTERVAL ) { F32 targetPressure = getTargetROPumpPressure();