Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u -rc31c6e4340c28577df4d146165ccbfc8f0a47134 -r3d8b84b8ce7ee9526fbabccb9e51d691a3df6305 --- firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision c31c6e4340c28577df4d146165ccbfc8f0a47134) +++ firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 3d8b84b8ce7ee9526fbabccb9e51d691a3df6305) @@ -69,8 +69,6 @@ #define FLOW_SENSOR_ZERO_READING 0xFFFF ///< Flow sensor reading indicates zero flow (or flow lower than can be detected by sensor). -#define FLOW_SAMPLES_TO_AVERAGE ( 250 / TASK_PRIORITY_INTERVAL ) ///< Averaging flow data over 250 ms intervals. -#define FLOW_AVERAGE_MULTIPLIER ( 1.0 / (F32)FLOW_SAMPLES_TO_AVERAGE ) ///< Optimization - multiplying is faster than dividing. #define MAX_ALLOWED_FLOW_DEVIATION 0.1 ///< Max allowed deviation from target flow. #define FLOW_OUT_OF_RANGE_PERSISTENT_INTERVAL 5 * MS_PER_SECOND ///< Flow out of range time out in counts. #define MAX_PRESSURE_TARGET_TOLERANCE 5 ///< Pressure tolerance from maximum set pressure by user in psi. @@ -127,7 +125,7 @@ static F32 roPumpFlowRateRunningSum = 0; ///< RO pump flow rate running sum static F32 roPumpPressureRunningSum = 0; ///< RO pump pressure running sum -/* These variables are used for POST. POST has not been implemented yet +/* TODO These variables are used for POST. POST has not been implemented yet static RO_PUMP_SELF_TEST_STATE_T roPumpSelfTestState = RO_PUMP_SELF_TEST_STATE_START; ///< Current ro pump self test state static U32 roPumpSelfTestTimerCount = 0; ///< Timer counter for ro pump self test */ @@ -170,10 +168,10 @@ MIN_RO_PUMP_DUTY_CYCLE, MAX_RO_PUMP_DUTY_CYCLE ); // Initialize the persistent alarm for flow out of upper and lower range - initPersistentAlarm( PERSISTENT_ALARM_RO_FLOW_RATE_OUT_OF_UPPER_RANGE, ALARM_ID_FLOW_RATE_OUT_OF_RANGE, TRUE, + initPersistentAlarm( PERSISTENT_ALARM_RO_FLOW_RATE_OUT_OF_UPPER_RANGE, ALARM_ID_FLOW_RATE_OUT_OF_UPPER_RANGE, TRUE, FLOW_OUT_OF_RANGE_PERSISTENT_INTERVAL, FLOW_OUT_OF_RANGE_PERSISTENT_INTERVAL ); - initPersistentAlarm( PERSISTENT_ALARM_RO_FLOW_RATE_OUT_OF_LOWER_RANGE, ALARM_ID_FLOW_RATE_OUT_OF_RANGE, TRUE, + initPersistentAlarm( PERSISTENT_ALARM_RO_FLOW_RATE_OUT_OF_LOWER_RANGE, ALARM_ID_FLOW_RATE_OUT_OF_LOWER_RANGE, TRUE, FLOW_OUT_OF_RANGE_PERSISTENT_INTERVAL, FLOW_OUT_OF_RANGE_PERSISTENT_INTERVAL ); // Initialize the persistent alarm for max allowed pressure out of range @@ -198,25 +196,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; -} - -/*********************************************************************//** - * @brief * The setROPumpTargetFlowRate function sets a new target flow rate for the * RO pump. * @details Inputs: targetROPumpPressure, targetROPumpFlowRate, @@ -233,7 +212,7 @@ 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 <= MAX_ALLOWED_PRESSURE_PSI ) ) @@ -303,15 +282,15 @@ void execROPumpMonitor( void ) { U16 roFlowReading = getFPGAROPumpFlowRate(); - S32 roFlow = (S32)roFlowReading; + // Update sum for flow average calculation - measuredFlowReadingsSum += roFlow; + measuredFlowReadingsSum += (S32)roFlowReading; // Read the pressure at the sensor. The pump cannot be more that the maximum allowed pressure // 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; - checkPersistentAlarm( PERSISTENT_ALARM_RO_PUMP_PRESSURE_OUT_OF_RANGE, isPressureMax, actualPressure ); + checkPersistentAlarm( PERSISTENT_ALARM_RO_PUMP_PRESSURE_OUT_OF_RANGE, isPressureMax, actualPressure, MAX_ALLOWED_MEASURED_PRESSURE_PSI ); // Read flow at the control set if ( ++flowFilterCounter >= FLOW_SAMPLES_TO_AVERAGE ) @@ -340,21 +319,14 @@ F32 currentFlow = getMeasuredROFlowRate(); F32 targetFlow = getTargetROPumpFlowRate(); 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 ) + if ( error > MAX_ALLOWED_FLOW_DEVIATION ) { - //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 ); - } + BOOL isFlowOutOfUpperRange = currentFlow > targetFlow; + BOOL isFlowOutOfLowerRange = currentFlow < targetFlow; + checkPersistentAlarm( PERSISTENT_ALARM_RO_FLOW_RATE_OUT_OF_UPPER_RANGE, isFlowOutOfUpperRange, currentFlow, targetFlow ); + checkPersistentAlarm( PERSISTENT_ALARM_RO_FLOW_RATE_OUT_OF_LOWER_RANGE, isFlowOutOfLowerRange, currentFlow, targetFlow ); } } @@ -630,6 +602,25 @@ /*********************************************************************//** * @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; +} + +/*********************************************************************//** + * @brief * The setROPumpControlSignalDutyCycle function sets the duty cycle for the * RO pump to a given duty cycle. * @details Inputs: none @@ -811,7 +802,7 @@ if ( TRUE == isTestingActivated() ) { // The flow rate and pressure must be in range - if ( flow < MAX_RO_FLOWRATE_LPM && flow >= MIN_RO_FLOWRATE_LPM ) + if ( flow <= MAX_RO_FLOWRATE_LPM && flow >= MIN_RO_FLOWRATE_LPM ) { result = setROPumpTargetFlowRate( flow, MAX_ALLOWED_PRESSURE_PSI ); }