Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u -r497e910ca4972a1a993cb0ae1edf30d225283b34 -r00b32a5dad2e136d31cfaf0de16f7767b9920fec --- firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 497e910ca4972a1a993cb0ae1edf30d225283b34) +++ firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 00b32a5dad2e136d31cfaf0de16f7767b9920fec) @@ -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 */ @@ -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,9 +282,9 @@ 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 @@ -340,10 +319,9 @@ 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; @@ -624,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 @@ -805,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 ); }