Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u -r036a11ec6f48682b47e67ddcc7a7772d81647f4b -r531b1d4319ac57897a745edef872c0258728fe56 --- firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 036a11ec6f48682b47e67ddcc7a7772d81647f4b) +++ firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 531b1d4319ac57897a745edef872c0258728fe56) @@ -53,8 +53,8 @@ #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.22F ///< P term for RO pump ramp up to flow control. -#define ROP_FLOW_CONTROL_P_COEFFICIENT 0.4F ///< P term for RO pump flow control. -#define ROP_FLOW_CONTROL_I_COEFFICIENT 0.3F ///< I term for RO pump 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. @@ -70,7 +70,7 @@ // 110000 pulses/liter // For 2 LPM => 2LPM x 110000 pulses/liter * 1 edges/pulse * 1 min/60 seconds = 3666.66 counts/sec => 272.72 microseconds => for 1 LPM = 136.36 counts #define RO_FLOW_ADC_TO_LPM_FACTOR 272.72F ///< 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.1F ///< Slope of flow to PWM line equation. +#define ROP_FLOW_TO_PWM_SLOPE 0.5F ///< Slope of flow to PWM line equation. #define ROP_FLOW_TO_PWM_INTERCEPT 0.0F ///< Intercept of flow to PWM line equation. /// Initial conversion factor from target flow rate to PWM duty cycle estimate. @@ -240,9 +240,8 @@ targetROPumpMaxPressure = maxPressure; targetROPumpFlowRateLPM = 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 = roPumpFlowToPWM( currentROPumpProfile, targetROPumpFlowRateLPM ); roControlTimerCounter = 0; isROPumpOn = TRUE; result = TRUE; @@ -432,7 +431,6 @@ pendingROPumpCmdMaxPressure = 0.0F; pendingROPumpCmdTargetFlow = 0.0F; roPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; - roPumpState = RO_PUMP_RAMP_UP_TO_TARGET_FLOW_STATE; // Get the initial guess of the duty cycle roPumpPWMDutyCyclePct = roPumpFlowToPWM( currentROPumpProfile, targetROPumpFlowRateLPM ); roControlTimerCounter = 0; @@ -578,17 +576,17 @@ 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 ( getTargetROPumpFlowRateLPM() > 0.0F && roPumpControlMode == PUMP_CONTROL_MODE_CLOSED_LOOP ) + if ( ( getTargetROPumpFlowRateLPM() > 0.0F ) && ( PUMP_CONTROL_MODE_CLOSED_LOOP == roPumpControlMode ) ) { // Set pump to on isROPumpOn = TRUE; roPumpDutyCyclePctSet = roPumpFlowToPWM( currentROPumpProfile, getTargetROPumpFlowRateLPM() ); setROPumpControlSignalDutyCycle( roPumpDutyCyclePctSet ); - state = RO_PUMP_RAMP_UP_TO_TARGET_FLOW_STATE; + state = RO_PUMP_CONTROL_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.0F && roPumpControlMode == PUMP_CONTROL_MODE_OPEN_LOOP ) + if ( ( roPumpOpenLoopTargetDutyCycle > 0.0F ) && ( PUMP_CONTROL_MODE_OPEN_LOOP == roPumpControlMode ) ) { setROPumpControlSignalDutyCycle( roPumpOpenLoopTargetDutyCycle ); isROPumpOn = TRUE; @@ -602,55 +600,16 @@ * @brief * 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 + * @details Inputs: none + * @details Outputs: none * @return next state of the controller state machine *************************************************************************/ static RO_PUMP_STATE_T handleROPumpRampUpToTargetFlowState( void ) { - RO_PUMP_STATE_T state = RO_PUMP_RAMP_UP_TO_TARGET_FLOW_STATE; + RO_PUMP_STATE_T state = RO_PUMP_CONTROL_TO_TARGET_FLOW_STATE; - // Get the current pressure from the sensor - F32 actualPressure = getMeasuredDGPressure( PRESSURE_SENSOR_RO_PUMP_OUTLET ); - F32 targetFlowRate = getTargetROPumpFlowRateLPM(); - F32 actualFlowRate = getMeasuredFlowRateLPM( RO_FLOW_SENSOR ); - F32 flowRateDeviation = fabs( targetFlowRate - actualFlowRate ) / targetFlowRate; - BOOL isFlowOutOfRange = flowRateDeviation > ROP_FLOW_TARGET_TOLERANCE; - F32 targetPressure = getTargetROPumpPressurePSI(); + // TODO - remove function and state - obsolete - if ( ++roControlTimerCounter >= ROP_RAMP_UP_CONTROL_INTERVAL ) - { - // If the actual pressure is greater than the target pressure or it is within the tolerance of the maximum pressure, move to set - // to target pressure straight. At the beginning the maximum pressure is set in the targetROPumpPressure override variable. - // If the flow rate was reached without reaching to maximum pressure, the pressure that was set to targetROPumpPressure override will - // 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_MAX_PRES, roPumpDutyCyclePctSet ); - state = RO_PUMP_CONTROL_TO_MAX_PRESSURE_STATE; - } - // If the actual flow is still far from target flow, update the duty cycle using the I controller and stay in this state - else if ( TRUE == isFlowOutOfRange ) - { - 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_FLOW, roPumpDutyCyclePctSet ); - state = RO_PUMP_CONTROL_TO_TARGET_FLOW_STATE; - } - - roControlTimerCounter = 0; - } - return state; }