Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u -r58129c9bb3053c39efa07f60e975f17e2a04755a -rf9b3862d01ce6c64bd05b8649e69b44fa155b8e0 --- firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 58129c9bb3053c39efa07f60e975f17e2a04755a) +++ firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision f9b3862d01ce6c64bd05b8649e69b44fa155b8e0) @@ -47,7 +47,7 @@ #define RO_PUMP_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Interval (ms/task time) at which the RO Pump data is published on the CAN bus. #define MAX_RO_PUMP_DUTY_CYCLE 0.99 ///< max duty cycle. -#define MIN_RO_PUMP_DUTY_CYCLE 0.1 ///< min duty cycle. +#define MIN_RO_PUMP_DUTY_CYCLE 0.0 ///< 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_P_COEFFICIENT 0.0020 ///< P term for RO pump pressure control. @@ -121,7 +121,9 @@ 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 OVERRIDE_F32_T targetROPumpFlowRate = { 0, 0, 0, 0 }; ///< Target RO flow rate (in L/min) +static F32 targetROPumpFlowRate = 0.0; ///< Target RO flow rate (in L/min) +static U32 targetROPumpPressure = 0; ///< Target RO 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 @@ -140,8 +142,6 @@ static U32 roPumpSelfTestTimerCount = 0; ///< Timer counter for ro pump self test */ -static OVERRIDE_U32_T targetROPumpPressure = { 0, 0, 0, 0 }; ///< Target RO pressure (in PSI) - static S32 measuredFlowReadingsSum = 0; ///< Raw flow reading sums for averaging static U32 flowFilterCounter = 0; ///< Flow filtering counter static U32 rampUp2FlowTimeoutCounter = 0; ///< Counter for ramping up to flow time @@ -225,20 +225,20 @@ * can reach * @return TRUE if new target flow rate is set successfully, FALSE if not *************************************************************************/ -BOOL setROPumpTargetFlowRate( F32 roFlowRate, F32 maxPressure ) +BOOL setROPumpTargetFlowRate( F32 roFlowRate, U32 maxPressure ) { BOOL result = FALSE; // First of all, the flow rate must be in range - if ( roFlowRate < MAX_RO_FLOWRATE_LPM && roFlowRate >= MIN_RO_FLOWRATE_LPM ) + if ( ( roFlowRate < MAX_RO_FLOWRATE_LPM ) && ( roFlowRate >= MIN_RO_FLOWRATE_LPM ) ) { // Then the max pressure that we are allowed to reach must be in range - if ( maxPressure >= MIN_ALLOWED_PRESSURE_PSI && maxPressure <= MIN_ALLOWED_PRESSURE_PSI ) + if ( ( maxPressure >= MIN_ALLOWED_PRESSURE_PSI ) && ( maxPressure <= MAX_ALLOWED_PRESSURE_PSI ) ) { // For now maximum allowed pressure is inserted into the target pressure override // if the target flow rate exceeded the max pressure, it will set the maximum pressure - targetROPumpPressure.data = maxPressure; - targetROPumpFlowRate.data = roFlowRate; + targetROPumpPressure = maxPressure; + targetROPumpFlowRate = roFlowRate; roPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; // Get the initial guess of the duty cycle roPumpPWMDutyCyclePct = ROP_FLOW_TO_PWM_DC( roFlowRate ); @@ -260,7 +260,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_INVAID_PRESSURE_SELECTED, roFlowRate ) + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_RO_PUMP_INVALID_PRESSURE_SELECTED, roFlowRate ) } return result; @@ -281,7 +281,7 @@ void signalROPumpHardStop( void ) { stopROPump(); - targetROPumpFlowRate.data = 0; + targetROPumpFlowRate = 0; roPumpState = RO_PUMP_OFF_STATE; roPumpPWMDutyCyclePct = 0.0; roPumpOpenLoopTargetDutyCycle = 0.0; @@ -342,7 +342,7 @@ { F32 currentFlow = getMeasuredROFlowRate(); F32 targetFlow = getTargetROPumpFlowRate(); - F32 error = 1 - ( currentFlow / targetFlow ); + F32 error = 1.0 - ( currentFlow / targetFlow ); BOOL isFlowOutOfRange = error > MAX_ALLOWED_FLOW_DEVIATION; // Figure out whether flow is out of range from which side @@ -515,7 +515,7 @@ // and control from this if ( ++rampUp2FlowTimeoutCounter > RAMP_UP_TIME_OUT_COUNT ) { - targetROPumpPressure.data = actualPressure; + targetROPumpPressure = actualPressure; rampUp2FlowTimeoutCounter = 0; result = RO_PUMP_CONTROL_TO_TARGET_STATE; } @@ -590,7 +590,7 @@ // pressure is used as the target pressure avgPressure = avgPressure + ( avgPressure * flowRateDeviation ); // Save the target pressure - targetROPumpPressure.data = avgPressure; + targetROPumpPressure = avgPressure; } // Reset the I controller for the flow rate as it is no longer needed @@ -725,14 +725,7 @@ *************************************************************************/ F32 getTargetROPumpFlowRate( void ) { - F32 result = targetROPumpFlowRate.data; - - if ( OVERRIDE_KEY == targetROPumpFlowRate.override ) - { - result = targetROPumpFlowRate.ovData; - } - - return result; + return targetROPumpFlowRate; } /*********************************************************************//** @@ -764,14 +757,7 @@ *************************************************************************/ F32 getTargetROPumpPressure( void ) { - F32 result = targetROPumpPressure.data; - - if ( OVERRIDE_KEY == targetROPumpPressure.override ) - { - result = targetROPumpPressure.ovData; - } - - return result; + return targetROPumpPressure; } /*********************************************************************//** @@ -853,12 +839,12 @@ * @brief * The testSetTargetROPumpFlowRateOverride function overrides the target * flow rate. - * @details Inputs: targetROPumpFlowRate - * @details Outputs: targetROPumpFlowRate - * @param: value which is override target RO flow rate (in L/min) + * @details Inputs: none + * @details Outputs: none + * @param value which is override target RO flow rate (in L/min) * @return TRUE if override successful, FALSE if not *************************************************************************/ -BOOL testSetTargetROPumpFlowAndPressure( F32 flow, F32 pressure ) +BOOL testSetTargetROPumpFlowAndPressure( F32 flow, U32 pressure ) { BOOL result = FALSE; @@ -867,50 +853,14 @@ // The flow rate and pressure must be in range if ( flow < MAX_RO_FLOWRATE_LPM && flow >= MIN_RO_FLOWRATE_LPM ) { - if ( pressure >= MIN_ALLOWED_PRESSURE_PSI && pressure <= MIN_ALLOWED_PRESSURE_PSI ) + if ( pressure >= MIN_ALLOWED_PRESSURE_PSI && pressure <= MAX_ALLOWED_PRESSURE_PSI ) { - // Set the override initial data and the override key in here for both flow and pressure. - // Both are needed in order to change the flow rate. - targetROPumpFlowRate.ovInitData = targetROPumpFlowRate.data; - targetROPumpFlowRate.override = OVERRIDE_KEY; - - targetROPumpPressure.ovInitData = targetROPumpPressure.data; - targetROPumpPressure.override = OVERRIDE_KEY; - result = setROPumpTargetFlowRate( flow, pressure ); - - // Reset is needed to turn off the override key } } } return result; -} - -/*********************************************************************//** - * @brief - * The testResetTargetROPumpFlowRateOverride function resets the override - * of the target RO flow rate. - * @details Inputs: targetROPumpFlowRate - * @details Outputs: targetROPumpFlowRate - * @return TRUE if override reset successful, FALSE if not - *************************************************************************/ -BOOL testResetTargetROPumpFlowRateOverride( void ) -{ - BOOL result = FALSE; - - if ( TRUE == isTestingActivated() ) - { - // Reset the override - targetROPumpFlowRate.data = targetROPumpFlowRate.ovInitData; - targetROPumpFlowRate.override = OVERRIDE_RESET; - targetROPumpFlowRate.ovInitData = 0; - targetROPumpFlowRate.ovData = 0; - // Set the flow rate back to its original as well as the pressure - result = setROPumpTargetFlowRate( targetROPumpFlowRate.data, getTargetROPumpPressure() ); - } - - return result; } /*********************************************************************//** @@ -922,7 +872,7 @@ * @param value override target RO pressure (in psi) * @return TRUE if override successful, FALSE if not *************************************************************************/ -BOOL testSetTargetROPumpPressureOverride( U32 value ) +BOOL testSetTargetROPumpPressure( U32 value ) { BOOL result = FALSE; @@ -931,39 +881,13 @@ // Make sure the requested pressure is in range if ( value >= MIN_ALLOWED_PRESSURE_PSI && value <= MAX_ALLOWED_PRESSURE_PSI ) { - targetROPumpPressure.ovInitData = targetROPumpPressure.data; - targetROPumpPressure.ovData = value; - targetROPumpPressure.override = OVERRIDE_KEY; + targetROPumpPressure = value; result = TRUE; } } return result; } - -/*********************************************************************//** - * @brief - * The testResetTargetROPumpPressureOverride function resets the override - * of the target RO pressure. - * @details Inputs: targetROPumpPressure - * @details Outputs: targetROPumpPressure - * @return TRUE if override reset successful, FALSE if not - *************************************************************************/ -BOOL testResetTargetROPumpPressureOverride( void ) -{ - BOOL result = FALSE; - - if ( TRUE == isTestingActivated() ) - { - targetROPumpPressure.data = targetROPumpPressure.ovInitData; - targetROPumpPressure.override = OVERRIDE_RESET; - targetROPumpPressure.ovInitData = 0; - targetROPumpPressure.ovData = 0; - result = TRUE; - } - - return result; -} /*********************************************************************//** * @brief @@ -1022,7 +946,7 @@ * @param value which is the duty cycle to be set * @return TRUE if override successful, FALSE if not *************************************************************************/ -BOOL testSetTargetDutyCycleOverride( F32 value ) +BOOL testSetTargetDutyCycle( F32 value ) { BOOL result = FALSE; @@ -1039,27 +963,4 @@ return result; } -/*********************************************************************//** - * @brief - * The testResetTargetDutyCyceOverride function resets and turns off the - * RO pump that was running at a certain duty cycle. - * @details Inputs: none - * @details Outputs: none - * @return TRUE if override successful, FALSE if not - *************************************************************************/ -BOOL testResetTargetDutyCyceOverride( void ) -{ - BOOL result = FALSE; - - if ( TRUE == isTestingActivated() ) - { - // Reset of the duty cycle override means stop the pump and - // reset all its variables - signalROPumpHardStop(); - result = TRUE; - } - - return result; -} - /**@}*/