Index: firmware/App/Controllers/DialysateFlow.c =================================================================== diff -u -ra4669c80291e85fa5ce17d77ebcfd0c882831202 -r4468dcb6d88bb364c60412ac368d1420adb66b27 --- firmware/App/Controllers/DialysateFlow.c (.../DialysateFlow.c) (revision a4669c80291e85fa5ce17d77ebcfd0c882831202) +++ firmware/App/Controllers/DialysateFlow.c (.../DialysateFlow.c) (revision 4468dcb6d88bb364c60412ac368d1420adb66b27) @@ -121,7 +121,7 @@ if ( TRUE == isNewCalibrationRecordAvailable() ) { getNVRecord2Driver( GET_CAL_FLOW_SENSORS, (U08*)&flowSensorsCalRecord, sizeof( DG_FLOW_SENSORS_CAL_RECORD_T ), - NUM_OF_CAL_DATA_FLOW_SENSORS, ALARM_ID_DG_DIALYSATE_FLOW_SENSOR_INVALID_CAL_RECORD ); + NUM_OF_CAL_DATA_FLOW_SENSORS, ALARM_ID_DG_RO_FLOW_SENSOR_INVALID_CAL_RECORD ); } // Read flow at the control set Index: firmware/App/Controllers/Heaters.c =================================================================== diff -u -r87ebf31788a90216c65e0264e2b8cb21d25e5b9b -r4468dcb6d88bb364c60412ac368d1420adb66b27 --- firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision 87ebf31788a90216c65e0264e2b8cb21d25e5b9b) +++ firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision 4468dcb6d88bb364c60412ac368d1420adb66b27) @@ -22,8 +22,8 @@ #include "AlarmMgmt.h" #include "DGDefs.h" +#include "FlowSensors.h" #include "Heaters.h" -#include "InternalADC.h" #include "MessageSupport.h" #include "ModeFill.h" #include "NVDataMgmt.h" @@ -37,6 +37,7 @@ #include "TaskPriority.h" #include "TemperatureSensors.h" #include "Timers.h" +#include "Voltages.h" /** * @addtogroup Heaters @@ -48,26 +49,30 @@ #define HEATERS_MAX_DUTY_CYCLE 1.00F ///< Heaters max duty cycle (100%). #define HEATERS_MIN_DUTY_CYCLE 0.00F ///< Heaters minimum duty cycle (0.00%). #define HEATERS_MIN_HEAT_DISINFECT_DUTY_CYCLE 0.6F ///< Heaters minimum duty cycle during heat disinfect. +#define HEATERS_MIN_EST_GAIN 0.2F ///< Heaters minimum estimation gain. +#define HEATERS_MAX_EST_GAIN 5.0F ///< Heaters maximum estimation gain. +#define HEATERS_NEUTRAL_EST_GAIN 1.0F ///< Heaters neutral estimation gain. #define HEATERS_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Heaters data publish interval. #define MINIMUM_TARGET_TEMPERATURE 10.0F ///< Minimum allowed target temperature for the heaters. #define MAXIMUM_TARGET_TEMPERATURE 90.0F ///< Maximum allowed target temperature for the heaters. -#define HEATERS_ON_NO_FLOW_TIMEOUT_MS ( 1 * MS_PER_SECOND ) ///< Heaters on with no flow time out in milliseconds. +#define HEATERS_ON_NO_FLOW_TIMEOUT_MS ( 10 * MS_PER_SECOND ) ///< Heaters on with no flow time out in milliseconds. #define HEATERS_MAX_OPERATING_VOLTAGE_V 24.0F ///< Heaters max operating voltage in volts. #define HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Heaters voltage out of range time out in milliseconds. #define HEATERS_MAX_VOLTAGE_OUT_OF_RANGE_TOL 0.2F ///< Heaters max voltage out of range tolerance. #define TRIMMER_HEATER_MAX_POWER_W 66.5F ///< Trimmer heater maximum power in Watts. #define TRIMMER_HEATER_CONTROL_CHECK_INTERVAL_COUNT ( ( 30 * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ) ///< Trimmer heater control interval count. #define DELTA_TEMPERATURE_TIME_COSNTANT_C 8.6F ///< Delta temperature calculated from time constant. -#define PRIMARY_HEATER_DUTY_CYCLE_PER_TEMPERATURE_C 0.03F ///< Primary heaters duty cycle per temperature in C. +#define PRIMARY_HEATER_DUTY_CYCLE_PER_TEMPERATURE_C 0.015F ///< Primary heaters duty cycle per temperature in C. #define DATA_PUBLISH_COUNTER_START_COUNT 70 ///< Data publish counter start count. #define MIN_RO_HEATER_FLOWRATE_LPM 0.2F ///< Minimum target RO heater flow rate in L/min. static const F32 WATER_SPECIFIC_HEAT_DIVIDED_BY_MINUTES = 4184 / SEC_PER_MIN; ///< Water specific heat in J/KgC / 60. static const F32 PRIMARY_HEATERS_MAXIMUM_POWER_WATTS = 475 + 237.5F; ///< Primary heaters maximum power (main primary = 475W and small primary = 237.5W). +static const F32 HEATERS_VOLTAGE_TOLERANCE_V = HEATERS_MAX_OPERATING_VOLTAGE_V * HEATERS_MAX_VOLTAGE_OUT_OF_RANGE_TOL; ///< Heaters voltage tolerance in volts. /// Heaters exec states typedef enum Heaters_Exec_States @@ -91,7 +96,7 @@ F32 dutycycle; ///< Heater duty cycle. F32 targetFlow; ///< Heater target flow. BOOL hasTargetTempChanged; ///< Heater target temperature change flag indicator. - F32 heaterEfficiency; ///< Heater efficiency during the run. + F32 heaterEstGain; ///< Heater estimation gain during the run. BOOL hasTargetBeenReached; ///< Heater flag to indicate whether the target temperature has been reached. F32 calculatedTemperature; ///< Heater calculated temperature. DG_RESERVOIR_ID_T inactiveRsrvr; ///< Heater inactive reservoir. @@ -146,7 +151,7 @@ heatersStatus[ heater ].dutycycle = 0.0; heatersStatus[ heater ].targetFlow = 0.0; heatersStatus[ heater ].hasTargetTempChanged = FALSE; - heatersStatus[ heater ].heaterEfficiency = 1.0; // Assuming 100% efficiency during initialization until it is updated + heatersStatus[ heater ].heaterEstGain = HEATERS_NEUTRAL_EST_GAIN; heatersStatus[ heater ].hasTargetBeenReached = FALSE; } @@ -160,7 +165,8 @@ initPersistentAlarm( ALARM_ID_DG_TRIMMER_HEATER_VOLTAGE_OUT_OF_RANGE, HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS, HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS ); - initPersistentAlarm( ALARM_ID_DG_FLOW_TOO_LOW_WHILE_HEATER_ON, HEATERS_ON_NO_FLOW_TIMEOUT_MS, HEATERS_ON_NO_FLOW_TIMEOUT_MS ); + initPersistentAlarm( ALARM_ID_RO_FLOW_TOO_LOW_WHILE_PRIMARY_HEATER_IS_ON, HEATERS_ON_NO_FLOW_TIMEOUT_MS, HEATERS_ON_NO_FLOW_TIMEOUT_MS ); + initPersistentAlarm( ALARM_ID_DIALYSATE_FLOW_TOO_LOW_WHILE_TRIMMER_HEATER_IS_ON, HEATERS_ON_NO_FLOW_TIMEOUT_MS, HEATERS_ON_NO_FLOW_TIMEOUT_MS ); } /*********************************************************************//** @@ -179,6 +185,7 @@ if( heater < NUM_OF_DG_HEATERS ) { +#ifndef DISABLE_HEATERS_AND_TEMPS // Assume the target temperature has not changed heatersStatus[ heater ].hasTargetTempChanged = FALSE; @@ -189,6 +196,7 @@ heatersStatus[ heater ].hasTargetTempChanged = TRUE; result = TRUE; } +#endif } else { @@ -222,9 +230,10 @@ { BOOL status = FALSE; + if( heater < NUM_OF_DG_HEATERS ) { - if ( TRUE == heatersStatus[ heater ].hasTargetTempChanged ) + if ( HEATER_EXEC_STATE_OFF == heatersStatus[ heater ].state ) { status = TRUE; heatersStatus[ heater ].startHeaterSignal = TRUE; @@ -329,17 +338,32 @@ // Check if the heater is on and if it is, check the flow sensor's status if ( TRUE == heatersStatus[ heater ].isHeaterOn ) { - // TODO add the function that gets the flow of the new flow sensor for DG. For now it is assumed that trimmer heater flow sensor - // is not 0 so the heater can run if needed - F32 measFlow = ( DG_PRIMARY_HEATER == heater ? getMeasuredROFlowRateLPM() : 50.0 ); - F32 minFlow = ( DG_PRIMARY_HEATER == heater ? MIN_RO_HEATER_FLOWRATE_LPM : MIN_RO_HEATER_FLOWRATE_LPM ); - BOOL isFlowLow = ( measFlow < minFlow ? TRUE : FALSE ); + ALARM_ID_T alarm; + F32 measFlow; + F32 minFlow; + BOOL isFlowLow; - checkPersistentAlarm( ALARM_ID_DG_FLOW_TOO_LOW_WHILE_HEATER_ON, isFlowLow, measFlow, minFlow ); + if ( DG_PRIMARY_HEATER == heater ) + { + alarm = ALARM_ID_RO_FLOW_TOO_LOW_WHILE_PRIMARY_HEATER_IS_ON; + measFlow = getMeasuredFlowRateLPM( RO_FLOW_SENSOR ); + minFlow = MIN_RO_FLOWRATE_LPM; + } + else + { + alarm = ALARM_ID_DIALYSATE_FLOW_TOO_LOW_WHILE_TRIMMER_HEATER_IS_ON; + measFlow = getMeasuredFlowRateLPM( DIALYSATE_FLOW_SENSOR ); + minFlow = MIN_DIALYSATE_FLOWRATE_LPM; + } + + isFlowLow = ( measFlow < minFlow ? TRUE : FALSE ); + + checkPersistentAlarm( alarm, isFlowLow, measFlow, minFlow ); } else { - checkPersistentAlarm( ALARM_ID_DG_FLOW_TOO_LOW_WHILE_HEATER_ON, FALSE, 0.0, 0.0 ); + checkPersistentAlarm( ALARM_ID_RO_FLOW_TOO_LOW_WHILE_PRIMARY_HEATER_IS_ON, FALSE, 0.0, 0.0 ); + checkPersistentAlarm( ALARM_ID_DIALYSATE_FLOW_TOO_LOW_WHILE_TRIMMER_HEATER_IS_ON, FALSE, 0.0, 0.0 ); } } @@ -356,20 +380,61 @@ /*********************************************************************//** * @brief - * The resetHeatersEfficiency function resets the heaters efficiency upon + * The resetHeatersEstimationGain function resets the heaters estimation gain upon * the start of a treatment. * @details Inputs: none * @details Outputs: heaterStatus * @return none *************************************************************************/ -void resetHeatersEfficiency( void ) +void resetHeatersEstimationGain( void ) { - heatersStatus[ DG_PRIMARY_HEATER ].heaterEfficiency = 1.0; - heatersStatus[ DG_TRIMMER_HEATER ].heaterEfficiency = 1.0; + heatersStatus[ DG_PRIMARY_HEATER ].heaterEstGain = HEATERS_NEUTRAL_EST_GAIN; + heatersStatus[ DG_TRIMMER_HEATER ].heaterEstGain = HEATERS_NEUTRAL_EST_GAIN; } /*********************************************************************//** * @brief + * The calculateHeaterEstimationGain function calculates the heater estimation + * gain. + * @details Inputs: none + * @details Outputs: heatersStatus + * @return none + *************************************************************************/ +void calculateHeaterEstimationGain( DG_HEATERS_T heater ) +{ +#ifndef _RELEASE_ + if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_HEATERS_EFFICIENCY ) != SW_CONFIG_ENABLE_VALUE ) +#endif + { + F32 heaterEstGain = heatersStatus[ heater ].heaterEstGain; + F32 heaterDutyCycle = heatersStatus[ heater ].dutycycle; + F32 lastFillTemperature = getAvgFillTemperature(); + F32 primaryTargetTemperature = heatersStatus[ heater ].targetTemp; + BOOL isTempUnderTarget = ( lastFillTemperature < primaryTargetTemperature ? TRUE : FALSE ); + + if ( TRUE == isTempUnderTarget ) + { + if ( heaterDutyCycle < HEATERS_MAX_DUTY_CYCLE ) + { + heaterEstGain += ( primaryTargetTemperature - lastFillTemperature ) * PRIMARY_HEATER_DUTY_CYCLE_PER_TEMPERATURE_C; + } + } + else + { + if ( heaterDutyCycle > HEATERS_MIN_DUTY_CYCLE ) + { + heaterEstGain -= ( lastFillTemperature - primaryTargetTemperature ) * PRIMARY_HEATER_DUTY_CYCLE_PER_TEMPERATURE_C; + } + } + + heaterEstGain = MAX( heaterEstGain, HEATERS_MIN_EST_GAIN ); + heaterEstGain = MIN( heaterEstGain, HEATERS_MAX_EST_GAIN ); + heatersStatus[ heater ].heaterEstGain = heaterEstGain; + } +} + +/*********************************************************************//** + * @brief * The handleHeaterStateOff function handles the heater not running state. * @details Inputs: heaterStatus * @details Outputs: heaterStatus @@ -420,10 +485,9 @@ else if ( ( DG_MODE_GENE == opMode ) || ( DG_MODE_DRAI == opMode ) ) { targetTemperature += DELTA_TEMPERATURE_TIME_COSNTANT_C; - // Use target flow rate during Idle and drain - targetFlow = getTargetROPumpFlowRateLPM(); - dutyCycle = calculatePrimaryHeaterDutyCycle( targetTemperature, inletTemperature, targetFlow, FALSE ); - state = HEATER_EXEC_STATE_PRIMARY_CONTROL_TO_TARGET; + targetFlow = getTargetROPumpFlowRateLPM(); + dutyCycle = calculatePrimaryHeaterDutyCycle( targetTemperature, inletTemperature, targetFlow, FALSE ); + state = HEATER_EXEC_STATE_PRIMARY_CONTROL_TO_TARGET; } else if ( ( DG_MODE_HEAT == opMode ) || ( DG_MODE_CHEM == opMode ) ) { @@ -433,6 +497,11 @@ dutyCycle = calculatePrimaryHeaterDutyCycle( targetTemperature, inletTemperature, targetFlow, FALSE ); state = HEATER_EXEC_STATE_CONTROL_TO_DISINFECT_TARGET; } + else + { + // No other modes are using the heaters + // TODO software fault + } // Update the calculated target temperature heatersStatus[ DG_PRIMARY_HEATER ].calculatedTemperature = targetTemperature; @@ -525,7 +594,7 @@ if ( ( DG_MODE_FILL == opMode ) || ( DG_MODE_GENE == opMode ) || ( DG_MODE_DRAI == opMode ) ) { - currentTemperature = getTrimmerHeaterTargetTemperature(); + currentTemperature = getReservoirCurrentTemperature(); dutyCycle = calculateTrimmerHeaterDutyCycle( targetTemperature, currentTemperature, targetFlowLPM, TRUE ); state = HEATER_EXEC_STATE_TRIMMER_CONTROL_TO_TARGET; } @@ -572,14 +641,13 @@ { // When the trimmer heater is on, its duty cycle is adjusted at the control interval. For this control check, // dialysate inlet temperature sensor is used rather than the theoretical calculations. - F32 outletRedundantTemperature = getTemperatureValue( TEMPSENSORS_INLET_DIALYSATE ); // TODO Change to TRo in DVT + F32 outletRedundantTemperature = getTemperatureValue( TEMPSENSORS_OUTLET_REDUNDANT ); F32 targetTemperature = heatersStatus[ DG_TRIMMER_HEATER ].targetTemp; F32 targetFlowLPM = heatersStatus[ DG_TRIMMER_HEATER ].targetFlow; F32 dutyCycle = calculateTrimmerHeaterDutyCycle( targetTemperature, outletRedundantTemperature, targetFlowLPM, TRUE ); trimmerHeaterControlCounter = 0; - - setHeaterDutyCycle( DG_TRIMMER_HEATER, dutyCycle ); + setHeaterDutyCycle( DG_TRIMMER_HEATER, ( heatersStatus[ DG_TRIMMER_HEATER ].dutycycle + dutyCycle ) ); } return state; @@ -629,48 +697,13 @@ *************************************************************************/ static F32 calculatePrimaryHeaterDutyCycle( F32 targetTemperature, F32 currentTemperature, F32 flow, BOOL checkEfficiency ) { - // Get the primary heater's efficiency and the last fill temperature from the ModeFill - F32 heaterEfficiency = heatersStatus[ DG_PRIMARY_HEATER ].heaterEfficiency; - -#ifndef _RELEASE_ - if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_HEATERS_EFFICIENCY ) != SW_CONFIG_ENABLE_VALUE ) -#endif - { - if ( TRUE == checkEfficiency ) - { - F32 lastFillTemperature = getLastFillTemperature(); - F32 primaryTargetTemperature = heatersStatus[ DG_PRIMARY_HEATER ].targetTemp; - - // If the last fill temperature > target temperature, it means the primary heater overshot the duty cycle - // so with its efficiency is toned down for the next fill cycle - // If the heater under-shoots the duty cycle, the efficiency increases the duty cycle for the next fill cycle - if ( lastFillTemperature - primaryTargetTemperature < 0.0F ) - { - heaterEfficiency -= ( lastFillTemperature - primaryTargetTemperature ) * PRIMARY_HEATER_DUTY_CYCLE_PER_TEMPERATURE_C; - } - else - { - heaterEfficiency += ( primaryTargetTemperature - lastFillTemperature ) * PRIMARY_HEATER_DUTY_CYCLE_PER_TEMPERATURE_C; - } - - // If the efficiency is less than 0, set it to 0 but if the efficiency is greater than 100, it is not enforced - // to be 100 since the duty cycle range check will cap the duty cycle to 100 anyways. - heaterEfficiency = MAX( heaterEfficiency, 0.0 ); - - // Update the heaters efficiency - heatersStatus[ DG_PRIMARY_HEATER ].heaterEfficiency = heaterEfficiency; - } - } - // Duty cycle = ( 69.73 * flow rate * deltaT / primary heater maximum power ) ^ 1/2 // Multiply the duty cycle to the heater efficiency - F32 dutyCycle = sqrt( ( WATER_SPECIFIC_HEAT_DIVIDED_BY_MINUTES * - fabs( targetTemperature - currentTemperature ) * flow ) / PRIMARY_HEATERS_MAXIMUM_POWER_WATTS ) * heaterEfficiency; + F32 dutyCycle = sqrt( ( WATER_SPECIFIC_HEAT_DIVIDED_BY_MINUTES * fabs( targetTemperature - currentTemperature ) * flow ) / PRIMARY_HEATERS_MAXIMUM_POWER_WATTS ); + dutyCycle *= heatersStatus[ DG_PRIMARY_HEATER ].heaterEstGain; + dutyCycle = MIN( dutyCycle, HEATERS_MAX_DUTY_CYCLE ); + dutyCycle = MAX( dutyCycle, HEATERS_MIN_DUTY_CYCLE ); - // Check the boundaries of the calculated duty cycle - dutyCycle = MIN( dutyCycle, HEATERS_MAX_DUTY_CYCLE ); - dutyCycle = MAX( dutyCycle, HEATERS_MIN_DUTY_CYCLE ); - return dutyCycle; } @@ -690,8 +723,8 @@ static F32 calculateTrimmerHeaterDutyCycle( F32 targetTemperature, F32 currentTemperature, F32 flow, BOOL checkEfficiency ) { // Get the primary heater's efficiency and the last fill temperature from the ModeFill - F32 heaterEfficiency = heatersStatus[ DG_TRIMMER_HEATER ].heaterEfficiency; - F32 dutyCycle = 0.0; + F32 heaterEstGain = heatersStatus[ DG_TRIMMER_HEATER ].heaterEstGain; + F32 dutyCycle = 0.0; #ifndef _RELEASE_ if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_HEATERS_EFFICIENCY ) != SW_CONFIG_ENABLE_VALUE ) @@ -705,7 +738,7 @@ // Duty cycle = ( 69.73 * flow rate * deltaT / primary heater maximum power ) and multiply the duty cycle to the heater efficiency dutyCycle = ( ( flow * WATER_SPECIFIC_HEAT_DIVIDED_BY_MINUTES * - ( targetTemperature - currentTemperature ) * heaterEfficiency ) / TRIMMER_HEATER_MAX_POWER_W ) * heaterEfficiency; + ( targetTemperature - currentTemperature ) ) / TRIMMER_HEATER_MAX_POWER_W ) * heaterEstGain; // Check the boundaries of the calculated duty cycle dutyCycle = MIN( dutyCycle, HEATERS_MAX_DUTY_CYCLE ); @@ -803,13 +836,12 @@ data.trimmerTargetTemp = heatersStatus[ DG_TRIMMER_HEATER ].targetTemp; data.primaryHeaterState = heatersStatus[ DG_PRIMARY_HEATER ].state; data.trimmerHeaterState = heatersStatus[ DG_TRIMMER_HEATER ].state; - data.primaryEfficiency = heatersStatus[ DG_PRIMARY_HEATER ].heaterEfficiency * 100; + data.primaryEfficiency = heatersStatus[ DG_PRIMARY_HEATER ].heaterEstGain * 100; data.primaryCalcTargetTemp = heatersStatus[ DG_PRIMARY_HEATER ].calculatedTemperature; data.trimmerCalcCurrentTemp = heatersStatus[ DG_TRIMMER_HEATER ].calculatedTemperature; + dataPublicationTimerCounter = 0; broadcastData( MSG_ID_DG_HEATERS_DATA, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&data, sizeof( HEATERS_DATA_T ) ); - - dataPublicationTimerCounter = 0; } } @@ -822,29 +854,34 @@ *************************************************************************/ static void monitorHeatersVoltage( void ) { - F32 mainPriVoltage = getIntADCVoltageConverted( INT_ADC_PRIMARY_HEATER_24_VOLTS ); - // TODO it is assumed that the main and small primary heaters have equal voltage since the PWMs are divided into 2 - // before applying the PWMs to the heaters. Right now, there is no ADC channel available for the small primary - // heater so the main primary heater's ADC channel is used for the small primary heater as well. - F32 smallPriVoltage = getIntADCVoltageConverted( INT_ADC_PRIMARY_HEATER_24_VOLTS ); - F32 trimmerVoltage = getIntADCVoltageConverted( INT_ADC_TRIMMER_HEATER_24_VOLTS ); + // NOTE: Default to using Primary heater voltage from FPGA + F32 mainPriVoltage = getMonitoredLineLevel( MONITORED_LINE_24V_PRIM_HTR_V );; +#ifndef _RELEASE_ + if ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_ENABLE_V3_SYSTEM ) ) + { + // V3 use CPU based value for Primary, same as Secondary + mainPriVoltage = getMonitoredLineLevel( MONITORED_LINE_24V_SEC_HTR_V ); + } +#endif + F32 smallPriVoltage = getMonitoredLineLevel( MONITORED_LINE_24V_SEC_HTR_V ); + F32 trimmerVoltage = getMonitoredLineLevel( MONITORED_LINE_24V_TRIM_HTR_V ); // Voltage to PWM is reverse. If PWM = 0 -> V = 24V - F32 mainPri = heatersStatus[ DG_PRIMARY_HEATER ].dutycycle > NEARLY_ZERO ? heatersStatus[ DG_PRIMARY_HEATER ].dutycycle : 1.0; - F32 smallPri = heatersStatus[ DG_PRIMARY_HEATER ].dutycycle > NEARLY_ZERO ? heatersStatus[ DG_PRIMARY_HEATER ].dutycycle : 1.0; - F32 trimmer = heatersStatus[ DG_TRIMMER_HEATER ].dutycycle > NEARLY_ZERO ? heatersStatus[ DG_TRIMMER_HEATER ].dutycycle : 1.0; + F32 mainPriDC = heatersStatus[ DG_PRIMARY_HEATER ].dutycycle; + F32 smallPriDC = heatersStatus[ DG_PRIMARY_HEATER ].dutycycle; + F32 trimmerDC = heatersStatus[ DG_TRIMMER_HEATER ].dutycycle; - F32 mainPriVoltageTol = HEATERS_MAX_VOLTAGE_OUT_OF_RANGE_TOL * mainPriVoltage; - F32 smallPriVoltageTol = HEATERS_MAX_VOLTAGE_OUT_OF_RANGE_TOL * smallPriVoltage; - F32 trimmerVoltageTol = HEATERS_MAX_VOLTAGE_OUT_OF_RANGE_TOL * trimmerVoltage; + F32 mainPriExpectedVoltage = HEATERS_MAX_OPERATING_VOLTAGE_V * ( 1.0 - mainPriDC ); + F32 smallPriExpectedVoltage = HEATERS_MAX_OPERATING_VOLTAGE_V * ( 1.0 - smallPriDC ); + F32 trimmerExpectedVoltage = HEATERS_MAX_OPERATING_VOLTAGE_V * ( 1.0 - trimmerDC ); - BOOL isMainPriOut = ( fabs( ( HEATERS_MAX_OPERATING_VOLTAGE_V * mainPri ) - mainPriVoltage ) > mainPriVoltageTol ? TRUE : FALSE ); - BOOL isSmallPriOut = ( fabs( ( HEATERS_MAX_OPERATING_VOLTAGE_V * smallPri ) - smallPriVoltage ) > smallPriVoltageTol ? TRUE : FALSE ); - BOOL isTrimmerOut = ( fabs( ( HEATERS_MAX_OPERATING_VOLTAGE_V * trimmer ) - trimmerVoltage ) > trimmerVoltageTol ? TRUE : FALSE ); + BOOL isMainPriOut = ( fabs( mainPriExpectedVoltage - mainPriVoltage ) > HEATERS_VOLTAGE_TOLERANCE_V ? TRUE : FALSE ); + BOOL isSmallPriOut = ( fabs( smallPriExpectedVoltage - smallPriVoltage ) > HEATERS_VOLTAGE_TOLERANCE_V ? TRUE : FALSE ); + BOOL isTrimmerOut = ( fabs( trimmerExpectedVoltage - trimmerVoltage ) > HEATERS_VOLTAGE_TOLERANCE_V ? TRUE : FALSE ); - //checkPersistentAlarm( ALARM_ID_DG_MAIN_PRIMARY_HEATER_VOLTAGE_OUT_OF_RANGE, isMainPriOut, mainPri, mainPriVoltageTol ); - //checkPersistentAlarm( ALARM_ID_DG_SMALL_PRIMARY_HEATER_VOLTAGE_OUT_OF_RANGE, isSmallPriOut, smallPri, smallPriVoltageTol ); - //checkPersistentAlarm( ALARM_ID_DG_TRIMMER_HEATER_VOLTAGE_OUT_OF_RANGE, isTrimmerOut, trimmer, trimmerVoltageTol ); + //checkPersistentAlarm( ALARM_ID_DG_MAIN_PRIMARY_HEATER_VOLTAGE_OUT_OF_RANGE, isMainPriOut, mainPriDC, HEATERS_VOLTAGE_TOLERANCE_V ); + //checkPersistentAlarm( ALARM_ID_DG_SMALL_PRIMARY_HEATER_VOLTAGE_OUT_OF_RANGE, isSmallPriOut, smallPriDC, HEATERS_VOLTAGE_TOLERANCE_V ); + //checkPersistentAlarm( ALARM_ID_DG_TRIMMER_HEATER_VOLTAGE_OUT_OF_RANGE, isTrimmerOut, trimmerDC, HEATERS_VOLTAGE_TOLERANCE_V ); } Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u -r87ebf31788a90216c65e0264e2b8cb21d25e5b9b -r4468dcb6d88bb364c60412ac368d1420adb66b27 --- firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 87ebf31788a90216c65e0264e2b8cb21d25e5b9b) +++ firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 4468dcb6d88bb364c60412ac368d1420adb66b27) @@ -21,6 +21,7 @@ #include "mibspi.h" #include "ConcentratePumps.h" +#include "FlowSensors.h" #include "FPGA.h" #include "InternalADC.h" #include "NVDataMgmt.h" @@ -56,7 +57,7 @@ #define ROP_RAMP_UP_CONTROL_INTERVAL ( 500 / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the RO pump is controlled. #define ROP_RAMP_UP_P_COEFFICIENT 0.22F ///< P term for RO pump ramp up to flow control. #define ROP_FLOW_CONTROL_P_COEFFICIENT 0.4F ///< P term for RO pump flow control. -#define ROP_FLOW_CONTROL_I_COEFFICIENT 0.05F ///< I term for RO pump flow control. +#define ROP_FLOW_CONTROL_I_COEFFICIENT 0.3F ///< I term for RO pump flow control. #define ROP_MAX_PRESSURE_P_COEFFICIENT 0.01F ///< P term for RO pump max pressure control. #define ROP_MAX_PRESSURE_I_COEFFICIENT 0.01F ///< I term for RO pump max pressure control. @@ -233,7 +234,7 @@ // For now maximum allowed pressure is inserted into the target pressure override // if the target flow rate exceeded the max pressure, it will set the maximum pressure targetROPumpMaxPressure = maxPressure; - targetROPumpFlowRateLPM = roFlowRate; + targetROPumpFlowRateLPM = roFlowRate; roPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; roPumpState = RO_PUMP_RAMP_UP_TO_TARGET_FLOW_STATE; // Get the initial guess of the duty cycle @@ -375,12 +376,11 @@ measuredROFlowRateLPM.data = flow - ( getMeasuredPumpSpeed( CONCENTRATEPUMPS_CP1_ACID ) / ML_PER_LITER ) - ( getMeasuredPumpSpeed( CONCENTRATEPUMPS_CP2_BICARB ) / ML_PER_LITER ); - // If the flow is less than a certain value, FPGA will return 0xFFFF meaning that - // the flow is 0. - if ( FLOW_SENSOR_ZERO_READING == roFlowReading ) - { - measuredROFlowRateLPM.data = 0.0; - } + // If the flow is less than a certain value, FPGA will return 0xFFFF meaning that the flow is 0. + if ( FLOW_SENSOR_ZERO_READING == roFlowReading ) + { + measuredROFlowRateLPM.data = 0.0; + } measuredFlowReadingsSum = 0; flowFilterCounter = 0; @@ -600,6 +600,18 @@ /*********************************************************************//** * @brief + * The resetROGenerateVolumeL function resets the RO generated volume in liters. + * @details Inputs: none + * @details Outputs: roVolumeL + * @return none + *************************************************************************/ +void resetROGenerateVolumeL( void ) +{ + roVolumeL = 0.0; +} + +/*********************************************************************//** + * @brief * The handleROPumpOffState function handles the RO pump off state of the * controller state machine. * @details Inputs: roPumpControlMode, roPumpPWMDutyCyclePctSet, @@ -649,7 +661,7 @@ // Get the current pressure from the sensor F32 actualPressure = getMeasuredDGPressure( PRESSURE_SENSOR_RO_PUMP_OUTLET ); F32 targetFlowRate = getTargetROPumpFlowRateLPM(); - F32 actualFlowRate = (F32)getMeasuredROFlowRateLPM(); + F32 actualFlowRate = getMeasuredFlowRateLPM( RO_FLOW_SENSOR ); //(F32)getMeasuredROFlowRateLPM(); F32 flowRateDeviation = fabs( targetFlowRate - actualFlowRate ) / targetFlowRate; BOOL isFlowOutOfRange = flowRateDeviation > ROP_FLOW_TARGET_TOLERANCE; F32 targetPressure = getTargetROPumpPressure(); @@ -713,7 +725,7 @@ } else { - roPumpDutyCyclePctSet = runPIController( PI_CONTROLLER_ID_RO_PUMP_FLOW, getTargetROPumpFlowRateLPM(), getMeasuredROFlowRateLPM() ); + roPumpDutyCyclePctSet = runPIController( PI_CONTROLLER_ID_RO_PUMP_FLOW, getTargetROPumpFlowRateLPM(), getMeasuredFlowRateLPM( RO_FLOW_SENSOR ) /*getMeasuredROFlowRateLPM()*/ ); } setROPumpControlSignalDutyCycle( roPumpDutyCyclePctSet ); @@ -749,7 +761,7 @@ } else { - roPumpDutyCyclePctSet = runPIController( PI_CONTROLLER_ID_RO_PUMP_MAX_PRES, getTargetROPumpFlowRateLPM(), getMeasuredROFlowRateLPM() ); + roPumpDutyCyclePctSet = runPIController( PI_CONTROLLER_ID_RO_PUMP_MAX_PRES, getTargetROPumpFlowRateLPM(), getMeasuredFlowRateLPM( RO_FLOW_SENSOR ) /*getMeasuredROFlowRateLPM()*/ ); } setROPumpControlSignalDutyCycle( roPumpDutyCyclePctSet ); @@ -846,10 +858,9 @@ if ( ++roPumpDataPublicationTimerCounter >= getU32OverrideValue( &roPumpDataPublishInterval ) ) { RO_PUMP_DATA_T pumpData; - pumpData.roPumpTgtFlowRateLM = getTargetROPumpFlowRateLPM(); pumpData.roPumpTgtPressure = getTargetROPumpPressure(); - pumpData.measROFlowRate = getMeasuredROFlowRateLPM(); + pumpData.measROFlowRate = getMeasuredFlowRateLPM( RO_FLOW_SENSOR ); //getMeasuredROFlowRateLPM(); pumpData.roPumpDutyCycle = roPumpDutyCyclePctSet * FRACTION_TO_PERCENT_FACTOR; pumpData.roPumpState = (U32)roPumpState; pumpData.roPumpFBDutyCycle = roPumpFeedbackDutyCyclePct * FRACTION_TO_PERCENT_FACTOR; @@ -931,6 +942,14 @@ { result = setROPumpTargetFlowRateLPM( flow, MAX_ALLOWED_PRESSURE_PSI ); } + + // If the flow is less than a very small number, it means 0 LPM flow rate has been requested + // and this is coming from Dialin so the user requested the pump to stop + if ( fabs( flow ) < NEARLY_ZERO ) + { + signalROPumpHardStop(); + result = TRUE; + } } return result; Index: firmware/App/Controllers/ROPump.h =================================================================== diff -u -r599bf09c73fca5e18a55e750133ac2eb93dd2c51 -r4468dcb6d88bb364c60412ac368d1420adb66b27 --- firmware/App/Controllers/ROPump.h (.../ROPump.h) (revision 599bf09c73fca5e18a55e750133ac2eb93dd2c51) +++ firmware/App/Controllers/ROPump.h (.../ROPump.h) (revision 4468dcb6d88bb364c60412ac368d1420adb66b27) @@ -22,7 +22,7 @@ /** * @defgroup ROPump ROPump - * @brief RO Pump monitor and controller module. Controls and monitors the RO pump. + * @brief RO Pump monitor and controller module. Controls and monitors the RO pump and the flow meter. * The flow meter is manufactured by SwissFlow, PN: 82015311. * The diaphragm (RO) pump is manufactured by Aquatec, PN: 5889-2MM1-V724DY. * @@ -32,7 +32,7 @@ // ********** public definitions ********** #define MAX_RO_FLOWRATE_LPM 1.8F ///< Maximum target RO flow rate in L/min. -#define MIN_RO_FLOWRATE_LPM 0.2F ///< Minimum target RO flow rate in L/min. +#define MIN_RO_FLOWRATE_LPM 0.0F ///< Minimum target RO flow rate in L/min. /// RO pump data struct. typedef struct Index: firmware/App/Modes/ModeChemicalDisinfect.c =================================================================== diff -u -r87ebf31788a90216c65e0264e2b8cb21d25e5b9b -r4468dcb6d88bb364c60412ac368d1420adb66b27 --- firmware/App/Modes/ModeChemicalDisinfect.c (.../ModeChemicalDisinfect.c) (revision 87ebf31788a90216c65e0264e2b8cb21d25e5b9b) +++ firmware/App/Modes/ModeChemicalDisinfect.c (.../ModeChemicalDisinfect.c) (revision 4468dcb6d88bb364c60412ac368d1420adb66b27) @@ -36,6 +36,7 @@ #include "Timers.h" #include "UVReactors.h" #include "Valves.h" +#include "CPLD.h" /** * @addtogroup DGChemicalDisinfectMode @@ -236,6 +237,8 @@ initChemicalDisinfectMode(); + setCPLDCleanLEDColor( CPLD_CLEAN_LED_YELLOW ); + return chemDisinfectState; } @@ -1299,7 +1302,7 @@ // Set the disinfect flags setDisinfectStatus( TRUE ); - setLastDisinfectDate( getRTCTimestamp() ); + setLastDisinfectDate( USAGE_INFO_CHEMICAL_DISINFECT, getRTCTimestamp() ); break; } Index: firmware/App/Modes/ModeFlush.c =================================================================== diff -u -r87ebf31788a90216c65e0264e2b8cb21d25e5b9b -r4468dcb6d88bb364c60412ac368d1420adb66b27 --- firmware/App/Modes/ModeFlush.c (.../ModeFlush.c) (revision 87ebf31788a90216c65e0264e2b8cb21d25e5b9b) +++ firmware/App/Modes/ModeFlush.c (.../ModeFlush.c) (revision 4468dcb6d88bb364c60412ac368d1420adb66b27) @@ -31,6 +31,7 @@ #include "Timers.h" #include "UVReactors.h" #include "Valves.h" +#include "CPLD.h" /** * @addtogroup DGFlushMode @@ -163,6 +164,8 @@ initFlushMode(); + setCPLDCleanLEDColor( CPLD_CLEAN_LED_BLUE ); + return flushState; } Index: firmware/App/Modes/ModeHeatDisinfect.c =================================================================== diff -u -r87ebf31788a90216c65e0264e2b8cb21d25e5b9b -r4468dcb6d88bb364c60412ac368d1420adb66b27 --- firmware/App/Modes/ModeHeatDisinfect.c (.../ModeHeatDisinfect.c) (revision 87ebf31788a90216c65e0264e2b8cb21d25e5b9b) +++ firmware/App/Modes/ModeHeatDisinfect.c (.../ModeHeatDisinfect.c) (revision 4468dcb6d88bb364c60412ac368d1420adb66b27) @@ -38,6 +38,7 @@ #include "Timers.h" #include "UVReactors.h" #include "Valves.h" +#include "CPLD.h" /** * @addtogroup DGHeatDisinfectMode @@ -261,6 +262,8 @@ initHeatDisinfectMode(); + setCPLDCleanLEDColor( CPLD_CLEAN_LED_ORANGE ); + return heatDisinfectState; } @@ -1228,7 +1231,7 @@ // Set the disinfect flags setDisinfectStatus( TRUE ); - setLastDisinfectDate( getRTCTimestamp() ); + setLastDisinfectDate( USAGE_INFO_HEAT_DISINFECT, getRTCTimestamp() ); break; case HEAT_DISINFECT_HEAT_UP_IN_PROGRESS: