Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u -rc7ea3969643ead419cbfcd34c3cb203c45bcad71 -rfab0257d4913c021698418277e742c2a61e0368e --- firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision c7ea3969643ead419cbfcd34c3cb203c45bcad71) +++ firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision fab0257d4913c021698418277e742c2a61e0368e) @@ -8,7 +8,7 @@ * @file ROPump.c * * @author (last) Dara Navaei -* @date (last) 26-Apr-2023 +* @date (last) 31-May-2023 * * @author (original) Sean * @date (original) 04-Apr-2020 @@ -387,8 +387,13 @@ // to make sure the hardware (especially the ROF) is not damaged. If it is the case, we need to stop immediately F32 actualPressure = getMeasuredDGPressure( PRESSURE_SENSOR_RO_PUMP_OUTLET ); BOOL isPressureMax = ( actualPressure >= MAX_ALLOWED_MEASURED_PRESSURE_PSI ? TRUE : FALSE ); - BOOL isDutyCylceOutOfRange = FALSE; + BOOL isDutyCycleOutOfRange = FALSE; + // The feedback voltage is on the 0V line so when the duty cycle is 0, the feedback is 2.5V + // The duty cycle is calculated by getting the 1 - (ratio of feedback / to the voltage at 0 percent duty cycle). + roPumpFeedbackDutyCyclePct.data = 1.0F - ( roFeedbackVoltage / ROP_FEEDBACK_0_PCT_DUTY_CYCLE_VOLTAGE ); + isDutyCycleOutOfRange = ( fabs( getROFeedbackDutyCycle() - roPumpDutyCyclePctSet ) > ROP_DUTY_CYCLE_OUT_OF_RANGE_TOLERANCE ? TRUE : FALSE ); + checkPersistentAlarm( ALARM_ID_DG_RO_PUMP_PRESSURE_OUT_OF_RANGE, isPressureMax, actualPressure, MAX_ALLOWED_MEASURED_PRESSURE_PSI ); if ( ( getMeasuredFlowRateLPM( RO_FLOW_SENSOR ) > NEARLY_ZERO ) && ( VALVE_STATE_CLOSED == getValveStateName( VBF ) ) ) @@ -416,6 +421,7 @@ switch ( getCurrentOperationMode() ) { case DG_MODE_GENE: + case DG_MODE_CHFL: // The flow cannot be out of target by more than +/- 100 mL/min isFlowOutOfRange = ( ( fabs( currentFlowLPM - targetFlowLPM ) * ML_PER_LITER ) > MAX_ALLOWED_FLOW_DEVIATION_MLPM ); isFlowOutOfUpperRange = ( isFlowOutOfRange && ( currentFlowLPM > targetFlowLPM ) ? TRUE : FALSE ); @@ -433,7 +439,6 @@ case DG_MODE_FLUS: case DG_MODE_HEAT: case DG_MODE_CHEM: - case DG_MODE_CHFL: // The flow cannot be out of range for than 10% of the target flow isFlowOutOfRange = ( fabs( 1.0F - ( currentFlowLPM / targetFlowLPM ) ) > MAX_ALLOWED_FLOW_DEVIATION_PCT ? TRUE : FALSE ); isFlowOutOfUpperRange = ( isFlowOutOfRange && ( currentFlowLPM > targetFlowLPM ) ? TRUE : FALSE ); @@ -461,13 +466,8 @@ if ( getHardwareConfigStatus() != HW_CONFIG_BETA ) #endif { - // The feedback voltage is on the 0V line so when the duty cycle is 0, the feedback is 2.5V - // The duty cycle is calculated by getting the 1 - (ratio of feedback / to the voltage at 0 percent duty cycle). - roPumpFeedbackDutyCyclePct.data = 1.0F - ( roFeedbackVoltage / ROP_FEEDBACK_0_PCT_DUTY_CYCLE_VOLTAGE ); - isDutyCylceOutOfRange = ( fabs( getROFeedbackDutyCycle() - roPumpDutyCyclePctSet ) > ROP_DUTY_CYCLE_OUT_OF_RANGE_TOLERANCE ? TRUE : FALSE ); + checkPersistentAlarm( ALARM_ID_DG_RO_PUMP_DUTY_CYCLE_OUT_OF_RANGE, isDutyCycleOutOfRange, getROFeedbackDutyCycle(), roPumpDutyCyclePctSet ); - checkPersistentAlarm( ALARM_ID_DG_RO_PUMP_DUTY_CYCLE_OUT_OF_RANGE, isDutyCylceOutOfRange, getROFeedbackDutyCycle(), roPumpDutyCyclePctSet ); - // Check if it the alarm has timed out and if the pump is supposed to be off but it is still on, activate the safety shutdown if ( ( TRUE == isAlarmActive( ALARM_ID_DG_RO_PUMP_DUTY_CYCLE_OUT_OF_RANGE ) ) && ( FALSE == isROPumpOn ) ) { @@ -735,11 +735,13 @@ F32 actualPressure = getMeasuredDGPressure( PRESSURE_SENSOR_RO_PUMP_OUTLET ); // Control at set interval - if ( ++roControlTimerCounter >= ROP_CONTROL_INTERVAL && roPumpControlMode == PUMP_CONTROL_MODE_CLOSED_LOOP ) + if ( ( ++roControlTimerCounter >= ROP_CONTROL_INTERVAL ) && ( roPumpControlMode == PUMP_CONTROL_MODE_CLOSED_LOOP ) ) { if ( actualPressure > targetROPumpMaxPressure ) { + // Reduce the duty cycle and make sure it does not go below 0% roPumpDutyCyclePctSet -= ROP_RAMP_DOWN_DUTY_CYCLE_RATIO; + roPumpDutyCyclePctSet = MAX( roPumpDutyCyclePctSet, MIN_RO_PUMP_DUTY_CYCLE ); resetPIController( PI_CONTROLLER_ID_RO_PUMP_MAX_PRES, roPumpDutyCyclePctSet ); } else