Index: firmware/App/Controllers/ConcentratePumps.c =================================================================== diff -u -r80028d3b1eef322950c1a5b74c282df2ba989ff5 -r3f22d883958a14b6193d6cd59c9acdbbd359b69e --- firmware/App/Controllers/ConcentratePumps.c (.../ConcentratePumps.c) (revision 80028d3b1eef322950c1a5b74c282df2ba989ff5) +++ firmware/App/Controllers/ConcentratePumps.c (.../ConcentratePumps.c) (revision 3f22d883958a14b6193d6cd59c9acdbbd359b69e) @@ -36,6 +36,7 @@ #define CONCENTRATE_PUMP_MIN_SPEED 3.0 ///< Minimum speed for concentrate pump in mL per min. #define CONCENTRATE_PUMP_MAX_SPEED 49.0 ///< Maximum speed for concentrate pump in mL per min. #define CONCENTRATE_PUMP_ERROR_TOLERANCE 0.02 ///< Measured speed needs to be within 2% of commanded speed. +#define CONCENTRATE_PUMP_ZERO_FLOW_RATE_PULSE_WIDTH 0xFFFF ///< Pulse width value when zero flow rate or pump is off. #define CONCENTRATE_PUMP_VOLUME_PER_REV 0.15 ///< Volume output every revolution (mL). #define CONCENTRATE_PUMP_PULSE_PER_REV 4.0 ///< Number of pulses generate for every revolution. @@ -83,7 +84,9 @@ static void stepConcentratePumpToTargetSpeed( CONCENTRATE_PUMPS_T pumpId ); static CONCENTRATE_PUMP_STATE_T handleConcentratePumpOnState( void ); + static U32 getPublishConcentratePumpDataInterval( void ); +static void calcMeasuredPumpsSpeed( CONCENTRATE_PUMPS_T pumpId, U16 pulseWidthCount ); static F32 getMeasuredPumpSpeed( CONCENTRATE_PUMPS_T pumpId ); /*********************************************************************//** @@ -122,20 +125,17 @@ { CONCENTRATE_PUMP_DATA_T data; - F32 const cp1PulseWidthInSecond = (F32)( getFPGACP1HallSensePulseWidth() * CONCENTRATE_PUMP_HALL_SENSE_PERIOD_RESOLUTION ) / US_PER_SECOND; - F32 const cp2PulseWidthInSecond = (F32)( getFPGACP2HallSensePulseWidth() * CONCENTRATE_PUMP_HALL_SENSE_PERIOD_RESOLUTION ) / US_PER_SECOND; + calcMeasuredPumpsSpeed( CONCENTRATEPUMPS_CP1, getFPGACP1HallSensePulseWidth() ); + calcMeasuredPumpsSpeed( CONCENTRATEPUMPS_CP2, getFPGACP2HallSensePulseWidth() ); - measuredPumpSpeed[ CONCENTRATEPUMPS_CP1 ].data = ( 1 / cp1PulseWidthInSecond ) * CONCENTRATE_PUMP_VOLUME_PER_PULSE * SEC_PER_MIN; - measuredPumpSpeed[ CONCENTRATEPUMPS_CP2 ].data = ( 1 / cp2PulseWidthInSecond ) * CONCENTRATE_PUMP_VOLUME_PER_PULSE * SEC_PER_MIN; - - F32 const cp1Error = fabs( getMeasuredPumpSpeed( CONCENTRATEPUMPS_CP1 ) - pumpTargetSpeed[ CONCENTRATEPUMPS_CP1 ] ) / pumpTargetSpeed[ CONCENTRATEPUMPS_CP1 ]; - F32 const cp2Error = fabs( getMeasuredPumpSpeed( CONCENTRATEPUMPS_CP2 ) - pumpTargetSpeed[ CONCENTRATEPUMPS_CP2 ] ) / pumpTargetSpeed[ CONCENTRATEPUMPS_CP2 ]; - data.cp1TargetSpeed = pumpTargetSpeed[ CONCENTRATEPUMPS_CP1 ]; data.cp1MeasuredSpeed = getMeasuredPumpSpeed( CONCENTRATEPUMPS_CP1 ); data.cp2TargetSpeed = pumpTargetSpeed[ CONCENTRATEPUMPS_CP2 ]; data.cp2MeasuredSpeed = getMeasuredPumpSpeed( CONCENTRATEPUMPS_CP2 ); + F32 const cp1Error = fabs( getMeasuredPumpSpeed( CONCENTRATEPUMPS_CP1 ) - currentPumpSpeed[ CONCENTRATEPUMPS_CP1 ] ) / currentPumpSpeed[ CONCENTRATEPUMPS_CP1 ]; + F32 const cp2Error = fabs( getMeasuredPumpSpeed( CONCENTRATEPUMPS_CP2 ) - currentPumpSpeed[ CONCENTRATEPUMPS_CP2 ] ) / currentPumpSpeed[ CONCENTRATEPUMPS_CP2 ]; + checkPersistentAlarm( PERSISTENT_ALARM_CP1_SPEED_CONTROL_ERROR, cp1Error > CONCENTRATE_PUMP_ERROR_TOLERANCE, cp1Error ); checkPersistentAlarm( PERSISTENT_ALARM_CP2_SPEED_CONTROL_ERROR, cp2Error > CONCENTRATE_PUMP_ERROR_TOLERANCE, cp2Error ); @@ -372,6 +372,27 @@ /*********************************************************************//** * @brief + * The calcMeasuredPumpsSpeed function calculates the concentrate pump flow + * rate using the hall sense pulse width count. + * @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 ) +{ + F32 const pulseWidthInSecond = (F32)( pulseWidthCount * CONCENTRATE_PUMP_HALL_SENSE_PERIOD_RESOLUTION ) / US_PER_SECOND; + measuredPumpSpeed[ pumpId ].data = ( 1 / pulseWidthInSecond ) * CONCENTRATE_PUMP_VOLUME_PER_PULSE * SEC_PER_MIN; + + if ( CONCENTRATE_PUMP_ZERO_FLOW_RATE_PULSE_WIDTH == pulseWidthCount ) + { + measuredPumpSpeed[ pumpId ].data = 0.0; + } +} + +/*********************************************************************//** + * @brief * The getMeasuredPumpSpeed function gets the measured concentrate pump flow rate. * @details Inputs: measuredPumpSpeed * @details Outputs: none Index: firmware/App/Modes/ModeFill.c =================================================================== diff -u -r80028d3b1eef322950c1a5b74c282df2ba989ff5 -r3f22d883958a14b6193d6cd59c9acdbbd359b69e --- firmware/App/Modes/ModeFill.c (.../ModeFill.c) (revision 80028d3b1eef322950c1a5b74c282df2ba989ff5) +++ firmware/App/Modes/ModeFill.c (.../ModeFill.c) (revision 3f22d883958a14b6193d6cd59c9acdbbd359b69e) @@ -94,19 +94,6 @@ /*********************************************************************//** * @brief - * The exitFillMode function prepares to exit fill mode. - * @details Inputs: none - * @details Outputs: requests concentrate pumps off, set valve to no fill - * @return none - *************************************************************************/ -void exitFillMode( void ) -{ - setValveState( VPO, VALVE_STATE_NOFILL_C_TO_NO ); - requestConcentratePumpsOff(); -} - -/*********************************************************************//** - * @brief * The execFillMode function executes the fill mode state machine. * @details Inputs: fillState * @details Outputs: Check water quality, fill mode state machine executed Index: firmware/App/Modes/OperationModes.c =================================================================== diff -u -r80028d3b1eef322950c1a5b74c282df2ba989ff5 -r3f22d883958a14b6193d6cd59c9acdbbd359b69e --- firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision 80028d3b1eef322950c1a5b74c282df2ba989ff5) +++ firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision 3f22d883958a14b6193d6cd59c9acdbbd359b69e) @@ -69,7 +69,6 @@ // ********** private function prototypes ********** static DG_OP_MODE_T arbitrateModeRequest( void ); -static void exitCurrentOperationMode( DG_OP_MODE_T oldMode ); static void transitionToNewOperationMode( DG_OP_MODE_T newMode ); static void broadcastOperationMode( void ); @@ -135,7 +134,6 @@ if ( currentMode != newMode ) { // handle transition to new mode - exitCurrentOperationMode( currentMode ); transitionToNewOperationMode( newMode ); currentMode = newMode; } @@ -272,28 +270,6 @@ /*********************************************************************//** * @brief - * The exitCurrentOperationMode function undergo the process of exit the - * current operation mode. - * @details Inputs: none - * @details Outputs: clean up when exit current mode - * @param oldMode old op mode to clean up - * @return none - *************************************************************************/ -static void exitCurrentOperationMode( DG_OP_MODE_T oldMode ) -{ - switch ( oldMode ) - { - case DG_MODE_FILL: - exitFillMode(); - break; - default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, 0, (U32)oldMode ) // TODO - add s/w fault enum to 1st data param - break; - } -} - -/*********************************************************************//** - * @brief * The transitionToNewOperationMode function undergo the process of transition * to new operation mode. * @details Inputs: none Index: firmware/App/Services/Reservoirs.c =================================================================== diff -u -r62ee40b55ed96eb0de1c0f05455eb986f76c1842 -r3f22d883958a14b6193d6cd59c9acdbbd359b69e --- firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 62ee40b55ed96eb0de1c0f05455eb986f76c1842) +++ firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 3f22d883958a14b6193d6cd59c9acdbbd359b69e) @@ -17,6 +17,7 @@ #include // for memcpy() +#include "ConcentratePumps.h" #include "Heaters.h" #include "LoadCell.h" #include "ModeRecirculate.h" @@ -196,7 +197,8 @@ // stop fill command only valid in fill mode if ( DG_MODE_FILL == getCurrentOperationMode() ) { - fillVolumeTargetMl.data = 0; + fillVolumeTargetMl.data = 0; + requestConcentratePumpsOff(); requestNewOperationMode( DG_MODE_CIRC ); result = TRUE; } Index: firmware/App/Tasks/TaskGeneral.c =================================================================== diff -u -ra726311564521affd46cbbaf129bdffb22e1d58f -r3f22d883958a14b6193d6cd59c9acdbbd359b69e --- firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision a726311564521affd46cbbaf129bdffb22e1d58f) +++ firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision 3f22d883958a14b6193d6cd59c9acdbbd359b69e) @@ -61,15 +61,17 @@ // manage data received from other sub-systems execSystemCommRx(); + + // monitor concentrate pumps + execConcentratePumpMonitor(); // manage RO pump execROPumpController(); // manage drain pump - execDrainPumpController(); + execDrainPumpController(); - // manage concentrate pump - execConcentratePumpMonitor(); + // manage concentrate pumps execConcentratePumpController(); // manage time-based reservoir tasks