Index: firmware/App/Controllers/ConcentratePumps.c =================================================================== diff -u -ra683ad9f7451beffab6c2b6b8c1049c4c167a6dc -ra580886223882d877287b27c65214067a2e01fd9 --- firmware/App/Controllers/ConcentratePumps.c (.../ConcentratePumps.c) (revision a683ad9f7451beffab6c2b6b8c1049c4c167a6dc) +++ firmware/App/Controllers/ConcentratePumps.c (.../ConcentratePumps.c) (revision a580886223882d877287b27c65214067a2e01fd9) @@ -141,7 +141,7 @@ static CONCENTRATE_PUMP_STATE_T handleConcentratePumpRampToTargetSpeedState( CONCENTRATE_PUMPS_T pumpId ); static CONCENTRATE_PUMP_STATE_T handleConcentratePumpControlTargetSpeedState( CONCENTRATE_PUMPS_T pumpId ); static BOOL stepConcentratePumpToTargetSpeed( CONCENTRATE_PUMPS_T pumpId ); -static void calcMeasuredPumpsSpeed( CONCENTRATE_PUMPS_T pumpId, U16 pulseWidthCount ); +static void calcMeasuredPumpsSpeed( void ); static void monitorPumpSpeed( CONCENTRATE_PUMPS_T pumpId, ALARM_ID_T alarm ); /*********************************************************************//** @@ -204,8 +204,8 @@ NUMBER_OF_ACID_AND_BICARB_NV_DATA_TO_CHECK, ALARM_ID_DG_BICARB_CONCENTRATE_INVALID_CAL_RECORD ); } - calcMeasuredPumpsSpeed( CONCENTRATEPUMPS_CP1_ACID, getFPGACP1HallSensePulseWidth() ); - calcMeasuredPumpsSpeed( CONCENTRATEPUMPS_CP2_BICARB, getFPGACP2HallSensePulseWidth() ); + // Calculate pump speed for each defined pump + calcMeasuredPumpsSpeed(); concentratePumps[ CONCENTRATEPUMPS_CP1_ACID ].parked.data = (U32)getFPGAAcidPumpIsParked(); concentratePumps[ CONCENTRATEPUMPS_CP2_BICARB ].parked.data = (U32)getFPGABicarbPumpIsParked(); @@ -825,32 +825,68 @@ /*********************************************************************//** * @brief - * The calcMeasuredPumpsSpeed function calculates the concentrate pump flow - * rate using the hall sense pulse width count. + * The calcMeasuredPumpsSpeed function iterates through the concentrate + * pumps and calculates the concentrate pump flow. It also checks that + * the hall sensor pulse width count for the concentrate pump is valid. * @details Inputs: none * @details Outputs: measuredPumpSpeed - * @param pumpId concentrate pump id to increase current step speed - * @param pulseWidthCount hall sense pulse width count reading from FPGA * @return none *************************************************************************/ -static void calcMeasuredPumpsSpeed( CONCENTRATE_PUMPS_T pumpId, U16 pulseWidthCount ) +static void calcMeasuredPumpsSpeed( void ) { - F32 pulseWidthInMicroSeconds = (F32)pulseWidthCount * CONCENTRATE_PUMP_HALL_SENSE_PERIOD_RESOLUTION; - BOOL isPulseWidthOut = ( pulseWidthInMicroSeconds <= (F32)CONCENTRATE_PUMP_MIN_ALLOWED_HALL_SENSOR_COUNT ? TRUE : FALSE ); + U16 pulseWidthCount = 0; + F32 pulseWidthInMicroSeconds = 0.0F; + BOOL isPulseWidthOut = FALSE; + CONCENTRATE_PUMPS_T pumpId; + CONCENTRATE_PUMPS_T pumpInAlarm = CONCENTRATEPUMPS_FIRST; + F32 pumpInAlarmPulseWidthInMicroSeconds = 0.0F; - concentratePumps[ pumpId ].pulseWidthUS = pulseWidthInMicroSeconds; + for ( pumpId = CONCENTRATEPUMPS_FIRST; pumpId < NUM_OF_CONCENTRATE_PUMPS; pumpId++ ) + { + switch (pumpId) + { + case CONCENTRATEPUMPS_CP1_ACID: + { + pulseWidthCount = getFPGACP1HallSensePulseWidth(); + break; + } + case CONCENTRATEPUMPS_CP2_BICARB: + { + pulseWidthCount = getFPGACP2HallSensePulseWidth(); + break; + } + default: + { + break; + } + } - checkPersistentAlarm( ALARM_ID_DG_CONC_PUMP_HALL_SENSOR_OUT_OF_RANGE, isPulseWidthOut, pulseWidthInMicroSeconds, - CONCENTRATE_PUMP_MIN_ALLOWED_HALL_SENSOR_COUNT ); + pulseWidthInMicroSeconds = pulseWidthCount * CONCENTRATE_PUMP_HALL_SENSE_PERIOD_RESOLUTION; + concentratePumps[ pumpId ].pulseWidthUS = pulseWidthInMicroSeconds; + BOOL isPumpPulseWidthOut = ( pulseWidthInMicroSeconds <= (F32)CONCENTRATE_PUMP_MIN_ALLOWED_HALL_SENSOR_COUNT ? TRUE : FALSE ); - if ( CONCENTRATE_PUMP_ZERO_FLOW_RATE == pulseWidthCount ) - { - concentratePumps[ pumpId ].measuredPumpSpeed.data = 0.0F; + // Determine measured speed for the pump + if ( CONCENTRATE_PUMP_ZERO_FLOW_RATE == pulseWidthCount ) + { + concentratePumps[ pumpId ].measuredPumpSpeed.data = 0.0F; + } + else if ( FALSE == isPumpPulseWidthOut ) + { + concentratePumps[ pumpId ].measuredPumpSpeed.data = ( US_PER_SECOND / pulseWidthInMicroSeconds ) * CONCENTRATE_PUMP_VOLUME_PER_PULSE * SEC_PER_MIN; + } + + // If pulse width is out of range capture pump out of range, pumpId and pulse width + if ( TRUE == isPumpPulseWidthOut) + { + // Pulse width for this concentrate pump is out of range + isPulseWidthOut = TRUE; + pumpInAlarm = pumpId; + pumpInAlarmPulseWidthInMicroSeconds = pulseWidthInMicroSeconds; + } } - else if ( FALSE == isPulseWidthOut ) - { - concentratePumps[ pumpId ].measuredPumpSpeed.data = ( US_PER_SECOND / pulseWidthInMicroSeconds ) * CONCENTRATE_PUMP_VOLUME_PER_PULSE * SEC_PER_MIN; - } + + checkPersistentAlarm( ALARM_ID_DG_CONC_PUMP_HALL_SENSOR_OUT_OF_RANGE, isPulseWidthOut, pumpInAlarm, pumpInAlarmPulseWidthInMicroSeconds ); + } /*********************************************************************//**