Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u -r1943944469d5a9f841f366ef9d8969c3072bd7ab -r4a20fdc5e32937930ea3793b831b8d4852e453d1 --- firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 1943944469d5a9f841f366ef9d8969c3072bd7ab) +++ firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 4a20fdc5e32937930ea3793b831b8d4852e453d1) @@ -130,9 +130,7 @@ 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 roPumpFlowRateRunningSum = 0; ///< RO pump flow rate running sum static F32 roPumpPressureRunningSum = 0; ///< RO pump pressure running sum @@ -190,7 +188,20 @@ 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; + // Initialize the variables + rampUp2FlowTimeoutCounter = 0; + roControlTimerCounter = 0; + roPumpOpenLoopTargetDutyCycle = 0; + roPumpFlowRateRunningSum = 0; + roPumpPressureRunningSum = 0; + measuredFlowReadingsSum = 0; + flowFilterCounter = 0; + rampUp2FlowTimeoutCounter = 0; + flowVerificationCounter = 0; + roPumpDataPublicationTimerCounter = 0; + roPumpState = RO_PUMP_OFF_STATE; + roPumpControlMode = NUM_OF_PUMP_CONTROL_MODES; + roPumpControlModeSet = roPumpControlMode; } /*********************************************************************//** @@ -260,7 +271,7 @@ // 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_PRESSURE_SELECTED, roFlowRate ) + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_RO_PUMP_INVALID_PRESSURE_SELECTED, roFlowRate ) } return result; @@ -289,6 +300,7 @@ flowVerificationCounter = 0; isROPumpOn = FALSE; rampUp2FlowTimeoutCounter = 0; + targetROPumpPressure = 0; resetPIController( PI_CONTROLLER_ID_RO_PUMP, MIN_RO_PUMP_DUTY_CYCLE ); } @@ -342,18 +354,22 @@ { F32 currentFlow = getMeasuredROFlowRate(); F32 targetFlow = getTargetROPumpFlowRate(); - F32 error = 1.0 - ( currentFlow / targetFlow ); + F32 error = fabs( 1.0 - ( currentFlow / targetFlow ) ); BOOL isFlowOutOfRange = error > MAX_ALLOWED_FLOW_DEVIATION; // Figure out whether flow is out of range from which side if ( isFlowOutOfRange ) { - 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 ); + //BOOL isFlowOutOfUpperRange = currentFlow > targetFlow; + //BOOL isFlowOutOfLowerRange = currentFlow < targetFlow; + if ( currentFlow > targetFlow ) + { + checkPersistentAlarm( PERSISTENT_ALARM_RO_FLOW_RATE_OUT_OF_UPPER_RANGE, TRUE, currentFlow ); + } + else + { + checkPersistentAlarm( PERSISTENT_ALARM_RO_FLOW_RATE_OUT_OF_LOWER_RANGE, TRUE, currentFlow ); + } } } @@ -805,8 +821,8 @@ if ( TRUE == isTestingActivated() ) { U32 intvl = value / TASK_PRIORITY_INTERVAL; - roPumpDataPublishInterval.ovData = intvl; - roPumpDataPublishInterval.override = OVERRIDE_KEY; + roPumpDataPublishInterval.ovData = intvl; + roPumpDataPublishInterval.override = OVERRIDE_KEY; result = TRUE; }