Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u -r4b25bf00656b9067a13541014fa1333386a7ed95 -r2c08db070a6e09306caf461e7aceeb53097fd995 --- firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 4b25bf00656b9067a13541014fa1333386a7ed95) +++ firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 2c08db070a6e09306caf461e7aceeb53097fd995) @@ -1,14 +1,14 @@ /************************************************************************** * -* Copyright (c) 2020-2022 Diality Inc. - All Rights Reserved. +* Copyright (c) 2020-2023 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * @file ROPump.c * -* @author (last) Michael Garthwaite -* @date (last) 21-Nov-2022 +* @author (last) Dara Navaei +* @date (last) 21-Dec-2022 * * @author (original) Sean * @date (original) 04-Apr-2020 @@ -52,9 +52,10 @@ #define MIN_RO_PUMP_DUTY_CYCLE 0.0F ///< Min duty cycle. #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.15F ///< P term for RO pump flow control. -#define ROP_FLOW_CONTROL_I_COEFFICIENT 0.65F ///< I term for RO pump flow control. - +#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.22F ///< P term for RO pump ramp up to flow control. +#define ROP_FLOW_CONTROL_P_COEFFICIENT 0.15F ///< P term for RO pump flow control. +#define ROP_FLOW_CONTROL_I_COEFFICIENT 0.65F ///< I term for RO pump flow control. #define ROP_MAX_PRESSURE_P_COEFFICIENT 0.01F ///< P term for RO pump max pressure control. #define ROP_MAX_PRESSURE_I_COEFFICIENT 0.01F ///< I term for RO pump max pressure control. #define ROP_PWM_STEP_LIMIT 0.50F ///< Current maximum PWM step limit used in RO Profiles. @@ -154,7 +155,6 @@ static RO_PUMP_STATE_T handleROPumpOpenLoopState( void ); static F32 roPumpFlowToPWM( RO_PI_FLOW_PROFILES_T profileID, F32 targetFlow ); -static void setROPumpTargetDutyCycle( F32 duty ); static void setROPumpControlSignalDutyCycle( F32 dutyCycle ); static void stopROPump( void ); static void publishROPumpData( void ); @@ -308,6 +308,40 @@ /*********************************************************************//** * @brief + * The setROPumpTargetDutyCycle function sets the duty cycle that the + * pump should run. + * @details Inputs: roPumpOpenLoopTargetDutyCycle, roPumpPWMDutyCyclePct, + * roPumpPWMDutyCyclePctSet, roPumpControlMode + * @details Outputs: roPumpOpenLoopTargetDutyCycle, roPumpPWMDutyCyclePct, + * roPumpPWMDutyCyclePctSet, roPumpControlMode + * @param: duty which is the duty cycle + * @return none + *************************************************************************/ +BOOL setROPumpTargetDutyCycle( F32 duty ) +{ + BOOL status = FALSE; + + if ( ( duty >= MIN_RO_PUMP_DUTY_CYCLE ) && ( duty <= MAX_RO_PUMP_DUTY_CYCLE ) ) + { + roPumpOpenLoopTargetDutyCycle = duty; + roPumpPWMDutyCyclePct = roPumpOpenLoopTargetDutyCycle; + roPumpDutyCyclePctSet = roPumpPWMDutyCyclePct; + roPumpControlMode = PUMP_CONTROL_MODE_OPEN_LOOP; + status = TRUE; + + // Set the new duty cycle of the pump + setROPumpControlSignalDutyCycle( roPumpOpenLoopTargetDutyCycle ); + } + else + { + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_DG_INVALID_RO_PUMP_DUTY_CYCLE_SELECTED, duty ) + } + + return status; +} + +/*********************************************************************//** + * @brief * The signalROPumpHardStop function stops the RO pump immediately and * resets all the variables associated with the RO pump run. * @details Inputs: targetROPumpFlowRate, roPumpState, roPumpPWMDutyCyclePct, @@ -326,7 +360,7 @@ roPumpPWMDutyCyclePct = 0.0F; roPumpOpenLoopTargetDutyCycle = 0.0F; roControlTimerCounter = 0; - isROPumpOn = FALSE; + //isROPumpOn = FALSE; // TODo remove targetROPumpMaxPressure = 0; pendingROPumpCmdMaxPressure = 0.0F; pendingROPumpCmdTargetFlow = 0.0F; @@ -576,6 +610,7 @@ static RO_PUMP_STATE_T handleROPumpOffState( void ) { RO_PUMP_STATE_T state = RO_PUMP_OFF_STATE; + isROPumpOn = FALSE; // If there is a flow, transition to the PI controller to get the corresponding pressure of that flow if ( ( getTargetROPumpFlowRateLPM() > 0.0F ) && ( PUMP_CONTROL_MODE_CLOSED_LOOP == roPumpControlMode ) ) @@ -712,28 +747,6 @@ /*********************************************************************//** * @brief - * The setROPumpTargetDutyCycle function sets the duty cycle that the - * pump should run. - * @details Inputs: roPumpOpenLoopTargetDutyCycle, roPumpPWMDutyCyclePct, - * roPumpPWMDutyCyclePctSet, roPumpControlMode - * @details Outputs: roPumpOpenLoopTargetDutyCycle, roPumpPWMDutyCyclePct, - * roPumpPWMDutyCyclePctSet, roPumpControlMode - * @param: duty which is the duty cycle - * @return none - *************************************************************************/ -static void setROPumpTargetDutyCycle( F32 duty ) -{ - roPumpOpenLoopTargetDutyCycle = duty; - roPumpPWMDutyCyclePct = roPumpOpenLoopTargetDutyCycle; - roPumpDutyCyclePctSet = roPumpPWMDutyCyclePct; - roPumpControlMode = PUMP_CONTROL_MODE_OPEN_LOOP; - - // Set the new duty cycle of the pump - setROPumpControlSignalDutyCycle( roPumpOpenLoopTargetDutyCycle ); -} - -/*********************************************************************//** - * @brief * The setROPumpControlSignalDutyCycle function sets the duty cycle for the * RO pump to a given duty cycle. * @details Inputs: none @@ -987,7 +1000,7 @@ if ( TRUE == isTestingActivated() ) { // Check if duty cycle is within range - if ( value >= MIN_RO_PUMP_DUTY_CYCLE && value <= MAX_RO_PUMP_DUTY_CYCLE ) + if ( ( value >= MIN_RO_PUMP_DUTY_CYCLE ) && ( value <= MAX_RO_PUMP_DUTY_CYCLE ) ) { setROPumpTargetDutyCycle( value ); result = TRUE;