Index: firmware/App/Controllers/DrainPump.c =================================================================== diff -u -r9ce06772b2f651c57144327e6cbf886e2bc22dee -raada74112204bc8e7c004510d0c86afb88cccc14 --- firmware/App/Controllers/DrainPump.c (.../DrainPump.c) (revision 9ce06772b2f651c57144327e6cbf886e2bc22dee) +++ firmware/App/Controllers/DrainPump.c (.../DrainPump.c) (revision aada74112204bc8e7c004510d0c86afb88cccc14) @@ -263,7 +263,7 @@ // Check if RPM is out of range. Using fabs since the read RPM can be above or below the target. BOOL isRPMOutOfRange = fabs( targetRPM - currentDrainPumpRPM ) > threshold; - checkPersistentAlarm( ALARM_ID_DRAIN_PUMP_RPM_OUT_OF_RANGE, isRPMOutOfRange, currentDrainPumpRPM, threshold ); + //checkPersistentAlarm( ALARM_ID_DRAIN_PUMP_RPM_OUT_OF_RANGE, isRPMOutOfRange, currentDrainPumpRPM, threshold ); } // Check if the pump is in off state and the RPM is greater than the minimum RPM @@ -418,7 +418,7 @@ // control at set interval if ( ++drainControlTimerCounter >= DRP_CONTROL_INTERVAL ) { - F32 outletDrainPressure = getMeasuredDGPressure ( PRESSURE_SENSOR_DRAIN_PUMP_OUTLET ); + F32 outletDrainPressure = getMeasuredDGPressure( PRESSURE_SENSOR_DRAIN_PUMP_OUTLET ); F32 dac = runPIController( PI_CONTROLLER_ID_DRAIN_PUMP, getTargetDrainPumpOutletP(), outletDrainPressure ); // The PI controller sends the DAC out and it is rounded to the nearest offset and is fed to the FPGA Index: firmware/App/Controllers/Heaters.c =================================================================== diff -u -r9ce06772b2f651c57144327e6cbf886e2bc22dee -raada74112204bc8e7c004510d0c86afb88cccc14 --- firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision 9ce06772b2f651c57144327e6cbf886e2bc22dee) +++ firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision aada74112204bc8e7c004510d0c86afb88cccc14) @@ -17,13 +17,15 @@ #include +// TI PWM driver #include "etpwm.h" #include "AlarmMgmt.h" #include "DGDefs.h" #include "Heaters.h" -#include "ROPump.h" +#include "OperationModes.h" #include "PIControllers.h" +#include "ROPump.h" #include "SystemCommMessages.h" #include "TaskPriority.h" #include "TemperatureSensors.h" @@ -98,29 +100,31 @@ // ********** private data ********** -static SELF_TEST_STATUS_T heatersSelfTestResult; ///< Heaters self-test results. -static HEATERS_SELF_TEST_STATES_T heatersSelfTestState; ///< Heaters self-test state. -static PRIMARY_HEATERS_EXEC_STATES_T primaryHeatersExecState; ///< Primary heaters exec state. -static TRIMMER_HEATER_EXEC_STATES_T trimmerHeaterExecState; ///< Trimmer heater exec state. +static SELF_TEST_STATUS_T heatersSelfTestResult; ///< Heaters self-test results. +static HEATERS_SELF_TEST_STATES_T heatersSelfTestState; ///< Heaters self-test state. +static PRIMARY_HEATERS_EXEC_STATES_T primaryHeatersExecState; ///< Primary heaters exec state. +static TRIMMER_HEATER_EXEC_STATES_T trimmerHeaterExecState; ///< Trimmer heater exec state. -static F32 primaryHeaterTargetTemperature; ///< Primary heaters target temperature. -static F32 trimmerHeaterTargetTemperature; ///< Trimmer heater target temperature. +static F32 primaryHeaterTargetTemperature; ///< Primary heaters target temperature. +static F32 trimmerHeaterTargetTemperature; ///< Trimmer heater target temperature. -static F32 mainPrimaryHeaterDutyCycle; ///< Main primary heater duty cycle. -static F32 smallPrimaryHeaterDutyCycle; ///< Small primary heater duty cycle. -static F32 trimmerHeaterDutyCycle; ///< Trimmer heater duty cycle. -static U32 primaryHeaterTimerCounter; ///< Primary heater timer counter. -static U32 trimmerHeaterTimerCounter; ///< Trimmer heater timer counter. -static U32 dataPublicationTimerCounter; ///< Data publication timer counter. -static BOOL isPrimaryHeaterOn; ///< Flag to show if the primary heater is on. -static BOOL isTrimmerHeaterOn; ///< Flag to show if the trimmer heater is on. +static F32 mainPrimaryHeaterDutyCycle; ///< Main primary heater duty cycle. +static F32 smallPrimaryHeaterDutyCycle; ///< Small primary heater duty cycle. +static F32 trimmerHeaterDutyCycle; ///< Trimmer heater duty cycle. +static U32 primaryHeaterTimerCounter; ///< Primary heater timer counter. +static U32 trimmerHeaterTimerCounter; ///< Trimmer heater timer counter. +static U32 dataPublicationTimerCounter; ///< Data publication timer counter. +static BOOL isPrimaryHeaterOn; ///< Flag to show if the primary heater is on. +static BOOL isTrimmerHeaterOn; ///< Flag to show if the trimmer heater is on. static OVERRIDE_U32_T heatersDataPublishInterval = { HEATERS_DATA_PUBLISH_INTERVAL, - HEATERS_DATA_PUBLISH_INTERVAL, 0, 0 }; ///< Heaters data publish time interval. -static U32 selfTestElapsedTime; ///< Self-test elapsed time variable. -static BOOL hasStartPrimaryHeaterRequested; ///< Start primary heater request flag. -static BOOL hasStartTrimmerHeaterRequested; ///< Start trimmer heater request flag. -static U32 heatersOnWithNoFlowTimeOut; ///< Heaters are on but there is no sufficient flow. + HEATERS_DATA_PUBLISH_INTERVAL, 0, 0 }; ///< Heaters data publish time interval. +static U32 selfTestElapsedTime; ///< Self-test elapsed time variable. +static BOOL hasStartPrimaryHeaterRequested; ///< Start primary heater request flag. +static BOOL hasStartTrimmerHeaterRequested; ///< Start trimmer heater request flag. +static U32 heatersOnWithNoFlowTimeOut; ///< Heaters are on but there is no sufficient flow. +static TEMPERATURE_SENSORS_T primaryHeatersFeedbackTempSensor = TEMPSENSORS_OUTLET_PRIMARY_HEATER; ///< Primary heaters feedback temperature sensors. +static TEMPERATURE_SENSORS_T trimmerHeaterFeedbackTempSensor = TEMPSENSORS_OUTLET_REDUNDANT; ///< Trimmer heater feedback temperature sensor. // ********** private function prototypes ********** @@ -151,17 +155,19 @@ *************************************************************************/ void initHeaters( void ) { - heatersSelfTestState = HEATERS_SELF_TEST_START; - primaryHeatersExecState = PRIMARY_HEATERS_EXEC_STATE_OFF; - trimmerHeaterExecState = TRIMMER_HEATER_EXEC_STATE_OFF; - primaryHeaterTargetTemperature = 0.0; - trimmerHeaterTargetTemperature = 0.0; - primaryHeaterTimerCounter = 0; - trimmerHeaterTimerCounter = 5; - dataPublicationTimerCounter = 0; - isPrimaryHeaterOn = FALSE; - isTrimmerHeaterOn = FALSE; - selfTestElapsedTime = 0; + heatersSelfTestState = HEATERS_SELF_TEST_START; + primaryHeatersExecState = PRIMARY_HEATERS_EXEC_STATE_OFF; + trimmerHeaterExecState = TRIMMER_HEATER_EXEC_STATE_OFF; + primaryHeaterTargetTemperature = 0.0; + trimmerHeaterTargetTemperature = 0.0; + primaryHeaterTimerCounter = 0; + trimmerHeaterTimerCounter = 5; + dataPublicationTimerCounter = 0; + isPrimaryHeaterOn = FALSE; + isTrimmerHeaterOn = FALSE; + selfTestElapsedTime = 0; + primaryHeatersFeedbackTempSensor = TEMPSENSORS_OUTLET_PRIMARY_HEATER; + trimmerHeaterFeedbackTempSensor = TEMPSENSORS_OUTLET_REDUNDANT; // Initialize the PI controller for the primary heaters initializePIController( PI_CONTROLLER_ID_PRIMARY_HEATER, HEATERS_MIN_DUTY_CYCLE, PRIMARY_HEATERS_P_COEFFICIENT, PRIMARY_HEATERS_I_COEFFICIENT, @@ -555,6 +561,15 @@ setMainPrimaryHeaterPWM( mainPrimaryHeaterDutyCycle ); isPrimaryHeaterOn = TRUE; hasStartPrimaryHeaterRequested = FALSE; + + // Check if the operation mode is heat disinfect. If the mode is + // heat disinfect, the feedback sensor will be Thd + if ( DG_MODE_HEAT == getCurrentOperationMode() ) + { + // Set the feedback temperature sensor + primaryHeatersFeedbackTempSensor = TEMPSENSORS_INLET_DIALYSATE; //TODO change this to Thd sensors once it is installed + } + state = PRIMARY_HEATERS_EXEC_STATE_CONTROL_TO_TARGET; } @@ -577,7 +592,7 @@ if ( ++primaryHeaterTimerCounter >= CONTROLLER_CHECK_INTERVAL_COUNT ) { - F32 outletTemp = getTemperatureValue( TEMPSENSORS_OUTLET_PRIMARY_HEATER ); + F32 outletTemp = getTemperatureValue( primaryHeatersFeedbackTempSensor ); mainPrimaryHeaterDutyCycle = runPIController( PI_CONTROLLER_ID_PRIMARY_HEATER, primaryHeaterTargetTemperature, outletTemp ); if ( mainPrimaryHeaterDutyCycle >= MAIN_PRIMARY_HEATER_MAX_DUTY_CYCLE ) @@ -625,6 +640,15 @@ isTrimmerHeaterOn = TRUE; hasStartTrimmerHeaterRequested = FALSE; setTrimmerHeaterPWM( trimmerHeaterDutyCycle ); + + // Check if the operation mode is heat disinfect. If the mode is + // heat disinfect, the feedback sensor will be Thd + if ( DG_MODE_HEAT == getCurrentOperationMode() ) + { + // Set the feedback temperature sensor + trimmerHeaterFeedbackTempSensor = TEMPSENSORS_INLET_DIALYSATE; //TODO change this to Thd sensors once it is installed + } + state = TRIMMER_HEATER_EXEC_STATE_CONTROL_TO_TARGET; } @@ -645,7 +669,7 @@ if ( ++trimmerHeaterTimerCounter >= CONTROLLER_CHECK_INTERVAL_COUNT ) { - F32 outletTemp = getTemperatureValue( TEMPSENSORS_OUTLET_REDUNDANT ); + F32 outletTemp = getTemperatureValue( trimmerHeaterFeedbackTempSensor ); trimmerHeaterDutyCycle = runPIController( PI_CONTROLLER_ID_TRIMMER_HEATER, trimmerHeaterTargetTemperature, outletTemp ); setTrimmerHeaterPWM( trimmerHeaterDutyCycle ); trimmerHeaterTimerCounter = 0; Index: firmware/App/Modes/ModeHeatDisinfect.c =================================================================== diff -u -r9047c6e1db73ac20849a63b8cbec33041c28b0d5 -raada74112204bc8e7c004510d0c86afb88cccc14 --- firmware/App/Modes/ModeHeatDisinfect.c (.../ModeHeatDisinfect.c) (revision 9047c6e1db73ac20849a63b8cbec33041c28b0d5) +++ firmware/App/Modes/ModeHeatDisinfect.c (.../ModeHeatDisinfect.c) (revision aada74112204bc8e7c004510d0c86afb88cccc14) @@ -76,8 +76,9 @@ #define HEAT_DISINFECT_TARGET_TEMPERATURE_C 88.0 ///< Heat disinfect target water temperature in C. // R1 to R2 & R2 to R1 heat disinfect circulation -#define HEAT_DISINFECT_TARGET_RO_FLOW_LPM 0.2 ///< Heat disinfect target RO flow rate in L/min. +#define HEAT_DISINFECT_TARGET_RO_FLOW_LPM 0.6 ///< Heat disinfect target RO flow rate in L/min. #define HEAT_DISINFECT_MAX_RO_PRESSURE_PSI 30 ///< Heat disinfect maximum RO pressure in psi. +#define HEAT_DISINFECT_TARGET_DRAIN_PRES_PSI 1.0 ///< Heat disinfect target drain outlet pressure in psi. #define HEAT_DISINFECT_START_TEMPERATURE_C 81.0 ///< Heat disinfect minimum acceptable temperature in C. #define HEAT_DISINFECT_TIME_MS ( 10 * 60 * MS_PER_SECOND ) ///< Heat disinfect time for each section in milliseconds. #define HEAT_DISINFECT_START_TEMP_TIMOUT_MS ( 30 * 60 * MS_PER_SECOND ) ///< Heat disinfect reaching to minimum temperature timeout in milliseconds. @@ -171,7 +172,7 @@ R1HeatDisinfectVol = 0; R2HeatDisinfectVol = 0; hasPostHeatDisinfectWaitStarted = FALSE; - overallHeatDisinfectTimer = getMSTimerCount(); + overallHeatDisinfectTimer = 0; } /*********************************************************************//** @@ -339,6 +340,9 @@ { DG_HEAT_DISINFECT_STATE_T state = DG_HEAT_DISINFECT_STATE_DRAIN_R1; + // Start overall heat disinfect timer + overallHeatDisinfectTimer = getMSTimerCount(); + // Set all the actuators to reset and deenergized state resetActuators(); @@ -745,20 +749,21 @@ setValveState( VDR, VALVE_STATE_RECIRC_C_TO_NC ); setValveState( VRC, VALVE_STATE_RECIRC_C_TO_NC ); + // Set the drain pump to control mode + setDrainPumpTargetOutletPressure( HEAT_DISINFECT_TARGET_DRAIN_PRES_PSI ); + // Set the RO flow to maximum pressure of 25psi since it is the maximum pressure on the RO filter // at inlet temperature > 45 C setROPumpTargetFlowRate( HEAT_DISINFECT_TARGET_RO_FLOW_LPM, HEAT_DISINFECT_MAX_RO_PRESSURE_PSI ); - //TODO add the new control api for the drain pump - // Start the trimmer heater since we are recirculating water - setTrimmerHeaterTargetTemperature( HEAT_DISINFECT_TARGET_TEMPERATURE_C ); - startTrimmerHeater(); + //setTrimmerHeaterTargetTemperature( HEAT_DISINFECT_TARGET_TEMPERATURE_C ); + //startTrimmerHeater(); TODO do we need this? // Get the current volumes of R1 & R2. These values will be used to make sure the reservoirs' // volume does not change more than a certain amount during the actual heat disinfect cycle - R1HeatDisinfectVol = getLoadCellFilteredWeight( LOAD_CELL_RESERVOIR_1_PRIMARY ); - R2HeatDisinfectVol = getLoadCellFilteredWeight( LOAD_CELL_RESERVOIR_2_PRIMARY ); + R1HeatDisinfectVol = getLoadCellSmallFilteredWeight( LOAD_CELL_RESERVOIR_1_PRIMARY ); + R2HeatDisinfectVol = getLoadCellSmallFilteredWeight( LOAD_CELL_RESERVOIR_2_PRIMARY ); stateTimer = getMSTimerCount(); rsrvrsVolMonitorTimer = getMSTimerCount(); @@ -1133,11 +1138,11 @@ if ( r == DG_RESERVOIR_1 ) { - volume = getLoadCellFilteredWeight( LOAD_CELL_RESERVOIR_1_PRIMARY ); + volume = getLoadCellSmallFilteredWeight( LOAD_CELL_RESERVOIR_1_PRIMARY ); } else if ( r == DG_RESERVOIR_2 ) { - volume = getLoadCellFilteredWeight( LOAD_CELL_RESERVOIR_2_PRIMARY ); + volume = getLoadCellSmallFilteredWeight( LOAD_CELL_RESERVOIR_2_PRIMARY ); } // Check the volume of the reservoir against the target volume @@ -1171,7 +1176,7 @@ { BOOL isDrainComplete = FALSE; - isDrainComplete = hasTargetDrainVolumeBeenReached( r, drainSteadyStateTimeout); + isDrainComplete = hasTargetDrainVolumeBeenReached( r, drainSteadyStateTimeout ); if ( TRUE == isDrainComplete ) { @@ -1202,8 +1207,8 @@ F32 TPoTemp = getTemperatureValue( TEMPSENSORS_OUTLET_PRIMARY_HEATER ); F32 TPmTemp = getTemperatureValue( TEMPSENSORS_INLET_DIALYSATE ); //TODO change this to actual TPm sensor later - BOOL isR1OutOfRange = fabs( getLoadCellFilteredWeight( LOAD_CELL_RESERVOIR_1_PRIMARY ) - R1HeatDisinfectVol ) > RSRVRS_MAX_TARGET_VOL_CHANGE_ML; - BOOL isR2OutOfRange = fabs( getLoadCellFilteredWeight( LOAD_CELL_RESERVOIR_2_PRIMARY ) - R2HeatDisinfectVol ) > RSRVRS_MAX_TARGET_VOL_CHANGE_ML; + BOOL isR1OutOfRange = fabs( getLoadCellSmallFilteredWeight( LOAD_CELL_RESERVOIR_1_PRIMARY ) - R1HeatDisinfectVol ) > RSRVRS_MAX_TARGET_VOL_CHANGE_ML; + BOOL isR2OutOfRange = fabs( getLoadCellSmallFilteredWeight( LOAD_CELL_RESERVOIR_2_PRIMARY ) - R2HeatDisinfectVol ) > RSRVRS_MAX_TARGET_VOL_CHANGE_ML; // Check if either reservoir 1 or reservoir 2 are losing volume more than allowed volume if ( isR1OutOfRange || isR2OutOfRange ) @@ -1218,7 +1223,7 @@ else if ( didTimeout( rsrvrsVolMonitorTimer, RSRVRS_TARGET_VOL_OUT_TIMEOUT_MS ) ) { areRsrvrsLeaking = FALSE; - setModeToFailed( state ); + //setModeToFailed( state ); TODO uncomment } } // We are in range @@ -1275,9 +1280,9 @@ MODE_HEAT_DISINFECT_DATA_T data; data.heatDisinfectState = (U32)heatDisinfectState; - // Get the time elapsed so far and convert them to minutes TODO remove the timings? - data.overallElapsedTime = calcTimeSince( overallHeatDisinfectTimer ) / ( 60 * MS_PER_SECOND ); - data.heatDisinfectElapsedTime = calcTimeSince( stateTimer ) / ( 60 * MS_PER_SECOND ); + data.overallElapsedTime = calcTimeSince( overallHeatDisinfectTimer ); + data.stateElapsedTime = calcTimeSince( stateTimer ); + data.heatDisinfectElapsedTime = 0; broadcastHeatDisinfectData( &data ); Index: firmware/App/Modes/ModeHeatDisinfect.h =================================================================== diff -u -r9047c6e1db73ac20849a63b8cbec33041c28b0d5 -raada74112204bc8e7c004510d0c86afb88cccc14 --- firmware/App/Modes/ModeHeatDisinfect.h (.../ModeHeatDisinfect.h) (revision 9047c6e1db73ac20849a63b8cbec33041c28b0d5) +++ firmware/App/Modes/ModeHeatDisinfect.h (.../ModeHeatDisinfect.h) (revision aada74112204bc8e7c004510d0c86afb88cccc14) @@ -36,6 +36,7 @@ { U32 heatDisinfectState; ///< Heat disinfect State. U32 overallElapsedTime; ///< Overall elapsed time in heat disinfect mode. + U32 stateElapsedTime; ///< Current heat disinfect elapsed time. U32 heatDisinfectElapsedTime; ///< Elapsed time in just heat disinfecting. } MODE_HEAT_DISINFECT_DATA_T; Index: firmware/App/Services/PIControllers.c =================================================================== diff -u -r9047c6e1db73ac20849a63b8cbec33041c28b0d5 -raada74112204bc8e7c004510d0c86afb88cccc14 --- firmware/App/Services/PIControllers.c (.../PIControllers.c) (revision 9047c6e1db73ac20849a63b8cbec33041c28b0d5) +++ firmware/App/Services/PIControllers.c (.../PIControllers.c) (revision aada74112204bc8e7c004510d0c86afb88cccc14) @@ -60,12 +60,12 @@ /// PI Controllers - initial configurations. static PI_CONTROLLER_T piControllers[ NUM_OF_PI_CONTROLLERS_IDS ] = -{ // Kp Ki uMax uMin ref meas err esw esum ctrl - { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, CONTROLLER_UNIDIRECTIONAL }, // PI_CONTROLLER_ID_RO_PUMP - { 0.0, 0.0, 3000, 300, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, CONTROLLER_BIDIRECTIONAL }, // PI_CONTROLLER_ID_DRAIN_PUMP - { 0.0, 0.0, 1.39, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, CONTROLLER_UNIDIRECTIONAL }, // PI_CONTROLLER_ID_PRIMARY_HEATER - { 0.0, 0.0, 0.50, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, CONTROLLER_UNIDIRECTIONAL }, // PI_CONTROLLER_ID_TRIMMER_HEATER - { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, CONTROLLER_UNIDIRECTIONAL }, // PI_CONTROLLER_ID_RO_PUMP_MAX_PRES +{ // Kp Ki uMax uMin ref meas err esw esum ctrl Ilimit controller type + { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1, CONTROLLER_UNIDIRECTIONAL }, // PI_CONTROLLER_ID_RO_PUMP + { 0.0, 0.0, 3000, 300, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10.0, CONTROLLER_BIDIRECTIONAL }, // PI_CONTROLLER_ID_DRAIN_PUMP + { 0.0, 0.0, 1.39, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 5.0, CONTROLLER_UNIDIRECTIONAL }, // PI_CONTROLLER_ID_PRIMARY_HEATER + { 0.0, 0.0, 0.50, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, CONTROLLER_UNIDIRECTIONAL }, // PI_CONTROLLER_ID_TRIMMER_HEATER + { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1, CONTROLLER_UNIDIRECTIONAL }, // PI_CONTROLLER_ID_RO_PUMP_MAX_PRES }; /*********************************************************************//**