Index: firmware/App/Controllers/Heaters.c =================================================================== diff -u -r8a553b10a224c745cb4bd6d963c867391905ba8c -re59287e5915e01c44af22fc54eafc29cb0f6c2c0 --- firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision 8a553b10a224c745cb4bd6d963c867391905ba8c) +++ firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision e59287e5915e01c44af22fc54eafc29cb0f6c2c0) @@ -324,12 +324,13 @@ if ( TRUE == heaterCmdPtr->startHeater ) { - if ( ( MINIMUM_TARGET_TEMPERATURE <= heaterCmdPtr->targetTemp ) && ( heaterCmdPtr->targetTemp <= MAXIMUM_TARGET_TEMPERATURE ) ) + if ( ( heaterCmdPtr->targetTemp >= MINIMUM_TARGET_TEMPERATURE ) && ( heaterCmdPtr->targetTemp <= MAXIMUM_TARGET_TEMPERATURE ) ) { cmdResponse.rejected = FALSE; + + heatersStatus[ DG_TRIMMER_HEATER ].targetTemp = heaterCmdPtr->targetTemp; // TODo do we need to remove this since the trimmer heater is set in the reservoirs #ifndef DISABLE_HEATERS_AND_TEMPS - //heatersStatus[ DG_TRIMMER_HEATER ].targetTemp = heaterCmdPtr->targetTemp; DEBUG_DENALI - //heatersStatus[ DG_TRIMMER_HEATER ].startHeaterSignal = TRUE; + //heatersStatus[ DG_TRIMMER_HEATER ].startHeaterSignal = TRUE; // DEBUG_DENALI #endif } else @@ -617,12 +618,11 @@ HEATERS_STATE_T state = HEATER_EXEC_STATE_TRIMMER_CONTROL_TO_TARGET; DG_HEATERS_T heater = DG_TRIMMER_HEATER; - //if ( TRUE == haveHeaterControlConditionsChanged( heater ) ) // TODO do we need this kind of check from trimmer?? + if ( TRUE == haveHeaterControlConditionsChanged( heater ) ) // TODO do we need this kind of check from trimmer?? { - //state = HEATER_EXEC_STATE_TRIMMER_RAMP_TO_TARGET; + state = HEATER_EXEC_STATE_TRIMMER_RAMP_TO_TARGET; } - return state; } @@ -668,23 +668,24 @@ /*if ( TRUE == checkEfficiency ) { - F32 lastFillTemperature = getLastFillTemperature(); + F32 lastFillTemperature = getLastFillTemperature(); + F32 trimmerTargetTemperature = heatersStatus[ DG_TRIMMER_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 undershoots the duty cycle, the efficiency increases the duty cycle for the next fill cycle - if ( lastFillTemperature - targetTemperature > MAXIMUM_ALLOWED_TARGET_TEMPERATURE_DEVIATION_C ) + // If the heater under-shoots the duty cycle, the efficiency increases the duty cycle for the next fill cycle + if ( lastFillTemperature - trimmerTargetTemperature > MAXIMUM_ALLOWED_TARGET_TEMPERATURE_DEVIATION_C ) { - heaterEfficiency -= ( lastFillTemperature - targetTemperature ) * PRIMARY_HEATER_DUTY_CYCLE_PER_TEMPERATURE_C; + heaterEfficiency -= ( lastFillTemperature - trimmerTargetTemperature ) * PRIMARY_HEATER_DUTY_CYCLE_PER_TEMPERATURE_C; } - else if ( lastFillTemperature - targetTemperature <= MAXIMUM_ALLOWED_TARGET_TEMPERATURE_DEVIATION_C ) + else if ( lastFillTemperature - trimmerTargetTemperature <= MAXIMUM_ALLOWED_TARGET_TEMPERATURE_DEVIATION_C ) { - heaterEfficiency += ( lastFillTemperature - targetTemperature ) * PRIMARY_HEATER_DUTY_CYCLE_PER_TEMPERATURE_C; + heaterEfficiency += ( lastFillTemperature - trimmerTargetTemperature ) * PRIMARY_HEATER_DUTY_CYCLE_PER_TEMPERATURE_C; } // Update the heaters efficiency heatersStatus[ DG_PRIMARY_HEATER ].heaterEfficiency = heaterEfficiency; - }*/ // TODO bring this part back + }*/ // Duty cycle = ( 69.73 * flow rate * deltaT / primary heater maximum power ) ^ 1/2 // Multiply the duty cycle to the heater efficiency @@ -711,7 +712,7 @@ * efficiency * @return calculated duty cycle *************************************************************************/ -static F32 calculateTrimmerHeaterDutyCycle( F32 targetTemperature, F32 currentTemperature, F32 flow, BOOL checkEfficiency ) +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; @@ -720,7 +721,7 @@ if ( TRUE == checkEfficiency ) { - // TODO add the trimmer efficiency + // TODO Do we need to recalculate the efficiency? } dutyCycle = flow * WATER_SPECIFIC_HEAT_DIVIDED_BY_MINUTES * ( targetTemperature - currentTemperature ) * heaterEfficiency; @@ -745,7 +746,7 @@ static BOOL haveHeaterControlConditionsChanged( DG_HEATERS_T heater ) { BOOL status = FALSE; - F32 targetFlow = getTargetROPumpFlowRate(); + F32 targetFlow = ( DG_PRIMARY_HEATER == heater ? getTargetROPumpFlowRate() : getTargetDialysateFlowLPM() ); BOOL hasFlowChanged = ( fabs( targetFlow - heatersStatus[ heater ].targetROFlow ) > NEARLY_ZERO ? TRUE : FALSE ); // Check if the target flow has changed or the target temperature has changed. Index: firmware/App/Controllers/Heaters.h =================================================================== diff -u -r8a553b10a224c745cb4bd6d963c867391905ba8c -re59287e5915e01c44af22fc54eafc29cb0f6c2c0 --- firmware/App/Controllers/Heaters.h (.../Heaters.h) (revision 8a553b10a224c745cb4bd6d963c867391905ba8c) +++ firmware/App/Controllers/Heaters.h (.../Heaters.h) (revision e59287e5915e01c44af22fc54eafc29cb0f6c2c0) @@ -62,7 +62,7 @@ F32 primaryEfficiency; ///< Primary heater efficiency F32 dialysateTargetLPM; ///< TODO remove this variable later F32 interimTargetTemp; ///< TODO remove this variable later - F32 targetHeaterFlowLPM ///< TODO remove this variable later + F32 targetHeaterFlowLPM; ///< TODO remove this variable later } HEATERS_DATA_T; // ********** Public function prototypes ********** Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u -r353d01d31bc69d4d1901ff09097ee610bb1c9dbc -re59287e5915e01c44af22fc54eafc29cb0f6c2c0 --- firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 353d01d31bc69d4d1901ff09097ee610bb1c9dbc) +++ firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision e59287e5915e01c44af22fc54eafc29cb0f6c2c0) @@ -383,7 +383,7 @@ // but the pump is not able to achieve the flow. if ( ( PUMP_CONTROL_MODE_CLOSED_LOOP == roPumpControlMode ) && ( RO_PUMP_CONTROL_TO_TARGET_FLOW_STATE == roPumpState ) ) { - F32 currentFlow = getMeasuredROFlowRate(); + F32 currentFlow = getMeasuredROFlowRateLPM(); F32 targetFlow = getTargetROPumpFlowRate(); // The flow cannot be out of range for than 10% of the target flow BOOL isFlowOutOfRange = ( fabs( 1.0 - ( currentFlow / targetFlow ) ) > MAX_ALLOWED_FLOW_DEVIATION ? TRUE : FALSE ); @@ -534,12 +534,12 @@ /*********************************************************************//** * @brief - * The getMeasuredROFlowRate function gets the measured RO pump flow rate. + * The getMeasuredROFlowRateLPM function gets the measured RO pump flow rate. * @details Inputs: measuredROFlowRateLPM * @details Outputs: measuredROFlowRateLPM * @return the current RO pump flow rate (in L/min). *************************************************************************/ -F32 getMeasuredROFlowRate( void ) +F32 getMeasuredROFlowRateLPM( void ) { return getF32OverrideValue( &measuredROFlowRateLPM ); } @@ -608,7 +608,7 @@ // Get the current pressure from the sensor F32 actualPressure = getMeasuredDGPressure( PRESSURE_SENSOR_RO_PUMP_OUTLET ); F32 targetFlowRate = getTargetROPumpFlowRate(); - F32 actualFlowRate = (F32)getMeasuredROFlowRate(); + F32 actualFlowRate = (F32)getMeasuredROFlowRateLPM(); F32 flowRateDeviation = fabs( targetFlowRate - actualFlowRate ) / targetFlowRate; BOOL isFlowOutOfRange = flowRateDeviation > ROP_FLOW_TARGET_TOLERANCE; @@ -674,7 +674,7 @@ } else { - roPumpDutyCyclePctSet = runPIController( PI_CONTROLLER_ID_RO_PUMP_FLOW, getTargetROPumpFlowRate(), getMeasuredROFlowRate() ); + roPumpDutyCyclePctSet = runPIController( PI_CONTROLLER_ID_RO_PUMP_FLOW, getTargetROPumpFlowRate(), getMeasuredROFlowRateLPM() ); } setROPumpControlSignalDutyCycle( roPumpDutyCyclePctSet ); @@ -710,7 +710,7 @@ } else { - roPumpDutyCyclePctSet = runPIController( PI_CONTROLLER_ID_RO_PUMP_MAX_PRES, getTargetROPumpFlowRate(), getMeasuredROFlowRate() ); + roPumpDutyCyclePctSet = runPIController( PI_CONTROLLER_ID_RO_PUMP_MAX_PRES, getTargetROPumpFlowRate(), getMeasuredROFlowRateLPM() ); } setROPumpControlSignalDutyCycle( roPumpDutyCyclePctSet ); @@ -852,7 +852,7 @@ pumpData.roPumpTgtFlowRate = getTargetROPumpFlowRate(); pumpData.roPumpTgtPressure = getTargetROPumpPressure(); - pumpData.measROFlowRate = getMeasuredROFlowRate(); + pumpData.measROFlowRate = getMeasuredROFlowRateLPM(); pumpData.roPumpDutyCycle = roPumpDutyCyclePctSet * FRACTION_TO_PERCENT_FACTOR; pumpData.roPumpState = (U32)roPumpState; pumpData.roPumpFBDutyCycle = roPumpFeedbackDutyCyclePct * FRACTION_TO_PERCENT_FACTOR; Index: firmware/App/Controllers/ROPump.h =================================================================== diff -u -r353d01d31bc69d4d1901ff09097ee610bb1c9dbc -re59287e5915e01c44af22fc54eafc29cb0f6c2c0 --- firmware/App/Controllers/ROPump.h (.../ROPump.h) (revision 353d01d31bc69d4d1901ff09097ee610bb1c9dbc) +++ firmware/App/Controllers/ROPump.h (.../ROPump.h) (revision e59287e5915e01c44af22fc54eafc29cb0f6c2c0) @@ -61,7 +61,7 @@ BOOL isROPumpRunning( void ); F32 getTargetROPumpFlowRate( void ); -F32 getMeasuredROFlowRate( void ); +F32 getMeasuredROFlowRateLPM( void ); F32 getTargetROPumpPressure( void ); Index: firmware/App/Controllers/TemperatureSensors.c =================================================================== diff -u -r103d68b3ba3059d3988923fb1fb8ead0eccfd526 -re59287e5915e01c44af22fc54eafc29cb0f6c2c0 --- firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 103d68b3ba3059d3988923fb1fb8ead0eccfd526) +++ firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision e59287e5915e01c44af22fc54eafc29cb0f6c2c0) @@ -841,6 +841,7 @@ TEMPERATURE_SENSORS_DATA_T data; data.inletPrimaryHeater = getTemperatureValue( TEMPSENSORS_INLET_PRIMARY_HEATER ); + data.heatDisinfect = getTemperatureValue( TEMPSENSORS_HEAT_DISINFECT ); data.outletPrimaryHeater = getTemperatureValue( TEMPSENSORS_OUTLET_PRIMARY_HEATER ); data.conductivitySensor1 = getTemperatureValue( TEMPSENSORS_CONDUCTIVITY_SENSOR_1 ); data.conductivitySensor2 = getTemperatureValue( TEMPSENSORS_CONDUCTIVITY_SENSOR_2 ); Index: firmware/App/Controllers/TemperatureSensors.h =================================================================== diff -u -r94a190522ce398399c7b93c59f788d7666ec0060 -re59287e5915e01c44af22fc54eafc29cb0f6c2c0 --- firmware/App/Controllers/TemperatureSensors.h (.../TemperatureSensors.h) (revision 94a190522ce398399c7b93c59f788d7666ec0060) +++ firmware/App/Controllers/TemperatureSensors.h (.../TemperatureSensors.h) (revision e59287e5915e01c44af22fc54eafc29cb0f6c2c0) @@ -60,6 +60,7 @@ typedef struct { F32 inletPrimaryHeater; ///< Inlet primary heater temperature sensor + F32 heatDisinfect; ///< Heat Disinfect temperature sensor F32 outletPrimaryHeater; ///< Outlet primary heater temperature sensor F32 conductivitySensor1; ///< Conductivity sensor 1 temperature sensor F32 conductivitySensor2; ///< Conductivity sensor 2 temperature sensor @@ -77,12 +78,12 @@ F32 internalTHDORTD; ///< THDo RTD channel temperature sensor F32 internalTDIRTD; ///< TDI RTD channel temperature sensor F32 internalCondSnsrTemp; ///< Conductivity Sensor internal temperature sensor - U32 primaryThermoCoupleRaw; ///< Primary heaters thermocouple raw ADC value - U32 primaryColdjuncRaw; ///< Primary heaters cold junction raw ADC value - U32 trimmerThermoCoupleRaw; ///< Trimmer heater thermocouple raw ADC value - U32 trimmerColdjuncRaw; ///< Trimmer heater cold junction raw ADC value - S32 cond1Raw; ///< Conductivity sensor 1 raw temperature ADC value - S32 cond2Raw; ///< Conductivity sensor 2 raw temperature ADC value + U32 primaryThermoCoupleRaw; ///< Primary heaters thermocouple raw ADC value // TODO remove later? + U32 primaryColdjuncRaw; ///< Primary heaters cold junction raw ADC value // TODO remove later? + U32 trimmerThermoCoupleRaw; ///< Trimmer heater thermocouple raw ADC value // TODO remove later? + U32 trimmerColdjuncRaw; ///< Trimmer heater cold junction raw ADC value // TODO remove later? + S32 cond1Raw; ///< Conductivity sensor 1 raw temperature ADC value // TODO remove later? + S32 cond2Raw; ///< Conductivity sensor 2 raw temperature ADC value // TODO remove later? } TEMPERATURE_SENSORS_DATA_T; // ********** public function prototypes ********** Index: firmware/App/DGCommon.h =================================================================== diff -u -r6bb7cd715299d16c131ab074fac0e62d8022f235 -re59287e5915e01c44af22fc54eafc29cb0f6c2c0 --- firmware/App/DGCommon.h (.../DGCommon.h) (revision 6bb7cd715299d16c131ab074fac0e62d8022f235) +++ firmware/App/DGCommon.h (.../DGCommon.h) (revision e59287e5915e01c44af22fc54eafc29cb0f6c2c0) @@ -57,7 +57,7 @@ // Turn these flags on to disable dialysate mixing #define DISABLE_DIALYSATE_CHECK 1 // Disabled for Tom - #define DISABLE_MIXING 1 +// #define DISABLE_MIXING 1 //#define DISABLE_FLOW_CONTROL_TREATMENT 1 #define DISABLE_ACK_ALARM 1 Index: firmware/App/Modes/ModeChemicalDisinfect.c =================================================================== diff -u -r353d01d31bc69d4d1901ff09097ee610bb1c9dbc -re59287e5915e01c44af22fc54eafc29cb0f6c2c0 --- firmware/App/Modes/ModeChemicalDisinfect.c (.../ModeChemicalDisinfect.c) (revision 353d01d31bc69d4d1901ff09097ee610bb1c9dbc) +++ firmware/App/Modes/ModeChemicalDisinfect.c (.../ModeChemicalDisinfect.c) (revision e59287e5915e01c44af22fc54eafc29cb0f6c2c0) @@ -1045,7 +1045,7 @@ DG_CHEM_DISINFECT_STATE_T state = DG_CHEM_DISINFECT_STATE_FILL_WITH_WATER_AND_DISINFECTANT; // Get the flow rate that is used for mixing - F32 measuredROFlowRate = getMeasuredROFlowRate(); + F32 measuredROFlowRate = getMeasuredROFlowRateLPM(); // If the flow is less than the minimum, request the concentrate pump to be on but do // control it. Index: firmware/App/Modes/ModeFill.c =================================================================== diff -u -r8a553b10a224c745cb4bd6d963c867391905ba8c -re59287e5915e01c44af22fc54eafc29cb0f6c2c0 --- firmware/App/Modes/ModeFill.c (.../ModeFill.c) (revision 8a553b10a224c745cb4bd6d963c867391905ba8c) +++ firmware/App/Modes/ModeFill.c (.../ModeFill.c) (revision e59287e5915e01c44af22fc54eafc29cb0f6c2c0) @@ -88,13 +88,13 @@ static U32 concentrateTestStartTime; ///< Starting time for concentrate test. static U32 concentratePumpPrimeCount; ///< Interval count for concentrate pump prime. -static F32 totalROFlowRate_mL_min; ///< Total RO flow rate over period of time. +static F32 totalROFlowRateMLPM; ///< Total RO flow rate over period of time. static F32 acidConductivityTotal; ///< Total of acid conductivity during fill. static F32 dialysateConductivityTotal; ///< Total of dialysate conductivity during fill. static U32 conductivitySampleCount; ///< Sample count of conductivity during fill. -static OVERRIDE_F32_T usedAcidVolume_mL = { 0.0, 0.0, 0.0, 0.0 }; ///< The integrated acid concentration volume has been used in ml. -static OVERRIDE_F32_T usedBicarbVolume_mL = { 0.0, 0.0, 0.0, 0.0 }; ///< The integrated bicarb concentration volume has been used in ml. +static OVERRIDE_F32_T usedAcidVolumeML = { 0.0, 0.0, 0.0, 0.0 }; ///< The integrated acid concentration volume has been used in ml. +static OVERRIDE_F32_T usedBicarbVolumeML = { 0.0, 0.0, 0.0, 0.0 }; ///< The integrated bicarb concentration volume has been used in ml. // ********** private function prototypes ********** @@ -122,23 +122,13 @@ fillState = DG_FILL_MODE_STATE_START; dialysateFillStartTime = 0; reservoirBaseWeight = 0.0; - totalROFlowRate_mL_min = 0.0; + totalROFlowRateMLPM = 0.0; concentrateTestStartTime = 0; acidConductivityTotal = 0.0; dialysateConductivityTotal = 0.0; conductivitySampleCount = 0; concentratePumpPrimeCount = 0; - // Get the heaters info form the NV data management - /*DG_HEATERS_RECORD_T heaterInfo = getHeatersInfoReocrd(); - // If the data in the NV data management was not initialized properly, set it to 0 otherwise, set the average flow rate - fillStatus.fillFlowRateAverage = ( heaterInfo.averageFillFlow < NEARLY_ZERO ? 0.0 : heaterInfo.averageFillFlow ); - fillStatus.fillFlowRateRunningSum = 0.0; - fillStatus.fillSampleCounter = 0; - fillStatus.fillTemperatureRunningSum = 0.0; - fillStatus.fillTemperatureAverage = 0.0; - fillStatus.fillLastTemperature = 0.0;*/ // TODO take this out of here. This only should be initialized once at the beginning of the treatment - initPersistentAlarm( ALARM_ID_ACID_CONDUCTIVITY_OUT_OF_RANGE, 0, EMPTY_BOTTLE_DETECT_PERSISTENT_PERIOD_MS ); initPersistentAlarm( ALARM_ID_BICARB_CONDUCTIVITY_OUT_OF_RANGE, 0, EMPTY_BOTTLE_DETECT_PERSISTENT_PERIOD_MS ); } @@ -282,6 +272,28 @@ /*********************************************************************//** * @brief + * The resetFillStatusParameters function resets the fill status parameters. + * @details Inputs: none + * @details Outputs: fillStatus + * @return none + *************************************************************************/ +void resetFillStatusParameters( void ) +{ + // Get the heaters info form the NV data management + DG_HEATERS_RECORD_T heaterInfo = getHeatersInfoReocrd(); + // If the data in the NV data management was not initialized properly, set it to 0 otherwise, set the average flow rate + fillStatus.fillFlowRateAverage = ( heaterInfo.averageFillFlow < NEARLY_ZERO ? 0.0 : heaterInfo.averageFillFlow ); + fillStatus.fillFlowRateRunningSum = 0.0; + fillStatus.fillSampleCounter = 0; + fillStatus.fillTemperatureRunningSum = 0.0; + // At the beginning the last and average temperatures are considered as the trimmer heater target temperature which + // is the dialysate temperature + fillStatus.fillTemperatureAverage = getHeaterTargetTemperature( DG_TRIMMER_HEATER ); + fillStatus.fillLastTemperature = getHeaterTargetTemperature( DG_TRIMMER_HEATER ); +} + +/*********************************************************************//** + * @brief * The handleCheckInletWaterState function checks for inlet water quality * before jumping to dialysate production state. * @details Inputs: Temperature and conductivity alarms @@ -327,8 +339,8 @@ DG_FILL_MODE_STATE_T result = DG_FILL_MODE_STATE_BICARB_PUMP_CHECK; DG_BICARB_CONCENTRATES_RECORD_T bicarb = getBicarbConcentrateCalRecord(); - F32 measuredROFlowRate_mL_min = getMeasuredROFlowRate() * ML_PER_LITER; - F32 bicarbPumpFlowRate_mL_min = measuredROFlowRate_mL_min * bicarb.bicarbConcentrate[ CAL_DATA_BICARB_CONCENTRATE_1 ].bicarbConcMixRatio + F32 measuredROFlowRateMLPM = getMeasuredROFlowRateLPM() * ML_PER_LITER; + F32 bicarbPumpFlowRateMLPM = measuredROFlowRateMLPM * bicarb.bicarbConcentrate[ CAL_DATA_BICARB_CONCENTRATE_1 ].bicarbConcMixRatio + CONCENTRATE_PUMP_PRIME_EXTRA_SPEED_ML_MIN; #ifndef DISABLE_DIALYSATE_CHECK @@ -337,13 +349,13 @@ F32 bicarbConductivity = MAX_BICARB_CONCENTRATE_CONDUCTIVITY; #endif - bicarbPumpFlowRate_mL_min = MIN( bicarbPumpFlowRate_mL_min, CONCENTRATE_PUMP_MAX_SPEED ); + bicarbPumpFlowRateMLPM = MIN( bicarbPumpFlowRateMLPM, CONCENTRATE_PUMP_MAX_SPEED ); - if ( MIN_BICARB_CONCENTRATE_CONDUCTIVITY <= bicarbConductivity ) + if ( bicarbConductivity >= MIN_BICARB_CONCENTRATE_CONDUCTIVITY ) { // Reduce acid pump speed after reaching minimum conductivity // This prevents conductivity value to go out of sensor's range - setConcentratePumpTargetSpeed( CONCENTRATEPUMPS_CP2_BICARB, bicarbPumpFlowRate_mL_min ); + setConcentratePumpTargetSpeed( CONCENTRATEPUMPS_CP2_BICARB, bicarbPumpFlowRateMLPM ); if ( concentratePumpPrimeCount++ > CONCENTRATE_PUMP_PRIME_INTERVAL ) { @@ -385,8 +397,8 @@ DG_FILL_MODE_STATE_T result = DG_FILL_MODE_STATE_ACID_PUMP_CHECK; DG_ACID_CONCENTRATES_RECORD_T acid = getAcidConcentrateCalRecord(); - F32 measuredROFlowRate_mL_min = getMeasuredROFlowRate() * ML_PER_LITER; - F32 acidPumpFlowRate_mL_min = measuredROFlowRate_mL_min * acid.acidConcentrate[ CAL_DATA_ACID_CONCENTRATE_1 ].acidConcMixRatio + + F32 measuredROFlowRateMLPM = getMeasuredROFlowRateLPM() * ML_PER_LITER; + F32 acidPumpFlowRateMLPM = measuredROFlowRateMLPM * acid.acidConcentrate[ CAL_DATA_ACID_CONCENTRATE_1 ].acidConcMixRatio + CONCENTRATE_PUMP_PRIME_EXTRA_SPEED_ML_MIN; #ifndef DISABLE_DIALYSATE_CHECK @@ -395,13 +407,13 @@ F32 acidConductivity = MAX_ACID_CONCENTRATE_CONDUCTIVITY; #endif - acidPumpFlowRate_mL_min = MIN( acidPumpFlowRate_mL_min, CONCENTRATE_PUMP_MAX_SPEED ); + acidPumpFlowRateMLPM = MIN( acidPumpFlowRateMLPM, CONCENTRATE_PUMP_MAX_SPEED ); - if ( MIN_ACID_CONCENTRATE_CONDUCTIVITY <= acidConductivity ) + if ( acidConductivity >= MIN_ACID_CONCENTRATE_CONDUCTIVITY ) { // Reduce acid pump speed after reaching minimum conductivity // This prevents conductivity value to go out of sensor's range - setConcentratePumpTargetSpeed( CONCENTRATEPUMPS_CP1_ACID, acidPumpFlowRate_mL_min ); + setConcentratePumpTargetSpeed( CONCENTRATEPUMPS_CP1_ACID, acidPumpFlowRateMLPM ); if ( concentratePumpPrimeCount++ > CONCENTRATE_PUMP_PRIME_INTERVAL ) { @@ -435,8 +447,8 @@ *************************************************************************/ static DG_FILL_MODE_STATE_T handleDialysateProductionState( void ) { - DG_FILL_MODE_STATE_T result = DG_FILL_MODE_STATE_DIALYSATE_PRODUCTION; - F32 measuredROFlowRate_mL_min = getMeasuredROFlowRate() * ML_PER_LITER; + DG_FILL_MODE_STATE_T result = DG_FILL_MODE_STATE_DIALYSATE_PRODUCTION; + F32 measuredROFlowRateMLPM = getMeasuredROFlowRateLPM() * ML_PER_LITER; #ifndef DISABLE_DIALYSATE_CHECK if ( ( TRUE == isWaterQualityGood() ) && ( TRUE == checkDialysateTemperature() ) ) @@ -445,7 +457,7 @@ #endif { // Prime mixing before deliver result to reservoir - handleDialysateMixing( measuredROFlowRate_mL_min ); + handleDialysateMixing( measuredROFlowRateMLPM ); #ifndef DISABLE_MIXING requestConcentratePumpOn( CONCENTRATEPUMPS_CP1_ACID ); requestConcentratePumpOn( CONCENTRATEPUMPS_CP2_BICARB ); @@ -477,9 +489,9 @@ *************************************************************************/ static DG_FILL_MODE_STATE_T handleDeliverDialysateState( void ) { - F32 integratedVolume_mL; + F32 integratedVolumeML; - F32 measuredROFlowRate_mL_min = getMeasuredROFlowRate() * ML_PER_LITER; + F32 measuredROFlowRateMLPM = getMeasuredROFlowRateLPM() * ML_PER_LITER; F32 acidConductivity = getConductivityValue( CONDUCTIVITYSENSORS_CD1_SENSOR ); F32 dialysateConductivity = getConductivityValue( CONDUCTIVITYSENSORS_CD2_SENSOR ); BOOL isAcidConductivityOutOfRange = ( acidConductivity <= MIN_ACID_CONCENTRATE_CONDUCTIVITY ) || @@ -491,20 +503,20 @@ DG_RESERVOIR_ID_T inactiveReservoir = getInactiveReservoir(); // Set concentrate pumps speed based off RO pump flow rate - handleDialysateMixing( measuredROFlowRate_mL_min ); + handleDialysateMixing( measuredROFlowRateMLPM ); - totalROFlowRate_mL_min += measuredROFlowRate_mL_min; - integratedVolume_mL = totalROFlowRate_mL_min * FLOW_INTEGRATOR * ACID_BICARB_CONCENTRATE_ADDITION_MULTIPLER; - usedAcidVolume_mL.data += getMeasuredPumpSpeed( CONCENTRATEPUMPS_CP1_ACID ) * FLOW_INTEGRATOR; - usedBicarbVolume_mL.data += getMeasuredPumpSpeed( CONCENTRATEPUMPS_CP2_BICARB ) * FLOW_INTEGRATOR; + totalROFlowRateMLPM += measuredROFlowRateMLPM; + integratedVolumeML = totalROFlowRateMLPM * FLOW_INTEGRATOR * ACID_BICARB_CONCENTRATE_ADDITION_MULTIPLER; + usedAcidVolumeML.data += getMeasuredPumpSpeed( CONCENTRATEPUMPS_CP1_ACID ) * FLOW_INTEGRATOR; + usedBicarbVolumeML.data += getMeasuredPumpSpeed( CONCENTRATEPUMPS_CP2_BICARB ) * FLOW_INTEGRATOR; acidConductivityTotal += acidConductivity; dialysateConductivityTotal += dialysateConductivity; conductivitySampleCount++; // DG is delivering dialysate keep collecting the sample counter and the measured flow fillStatus.fillSampleCounter += 1; - fillStatus.fillFlowRateRunningSum += getMeasuredROFlowRate(); + fillStatus.fillFlowRateRunningSum += getMeasuredROFlowRateLPM(); fillStatus.fillTemperatureRunningSum += getTemperatureValue( (U32)TEMPSENSORS_OUTLET_PRIMARY_HEATER ); #ifndef DISABLE_DIALYSATE_CHECK @@ -518,7 +530,7 @@ if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_ACID_CONDUCTIVITY_OUT_OF_RANGE, isAcidConductivityOutOfRange ) ) { - usedAcidVolume_mL.data = 0.0; + usedAcidVolumeML.data = 0.0; requestConcentratePumpOff( CONCENTRATEPUMPS_CP1_ACID ); requestConcentratePumpOff( CONCENTRATEPUMPS_CP2_BICARB ); setValveState( VPO, VALVE_STATE_NOFILL_C_TO_NO ); @@ -527,36 +539,36 @@ if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_BICARB_CONDUCTIVITY_OUT_OF_RANGE, isDialysateConductivityOutOfRange ) ) { - usedBicarbVolume_mL.data = 0.0; + usedBicarbVolumeML.data = 0.0; requestConcentratePumpOff( CONCENTRATEPUMPS_CP1_ACID ); requestConcentratePumpOff( CONCENTRATEPUMPS_CP2_BICARB ); setValveState( VPO, VALVE_STATE_NOFILL_C_TO_NO ); result = DG_FILL_MODE_STATE_PAUSED; } #endif #ifndef DISABLE_MIXING - if ( ( ACID_CONCENTRATION_BOTTLE_VOLUME_ML - getF32OverrideValue( &usedAcidVolume_mL ) ) <= CONCENTRATION_BOTTLE_LOW_VOLUME_ML ) + if ( ( ACID_CONCENTRATION_BOTTLE_VOLUME_ML - getF32OverrideValue( &usedAcidVolumeML ) ) <= CONCENTRATION_BOTTLE_LOW_VOLUME_ML ) { activateAlarmNoData( ALARM_ID_DG_ACID_BOTTLE_LOW_VOLUME ); } - if ( ( BICARB_CONCENTRATION_BOTTLE_VOLUME_ML - getF32OverrideValue( &usedBicarbVolume_mL ) ) <= CONCENTRATION_BOTTLE_LOW_VOLUME_ML ) + if ( ( BICARB_CONCENTRATION_BOTTLE_VOLUME_ML - getF32OverrideValue( &usedBicarbVolumeML ) ) <= CONCENTRATION_BOTTLE_LOW_VOLUME_ML ) { activateAlarmNoData( ALARM_ID_DG_BICARB_BOTTLE_LOW_VOLUME ); } #endif // If we've reached our target fill to volume (by weight), we're done filling - go back to generation idle mode if ( TRUE == hasTargetFillVolumeBeenReached( inactiveReservoir ) ) { - F32 filledVolume_mL = getReservoirWeight( inactiveReservoir ) - reservoirBaseWeight; - F32 integratedVolumeToLoadCellReadingPercent = fabs( 1 - ( filledVolume_mL / integratedVolume_mL ) ); - F32 avgAcidConductivity = acidConductivityTotal / conductivitySampleCount; // TODO - should we be checking this below? - F32 avgDialysateConductivity = dialysateConductivityTotal / conductivitySampleCount; + F32 filledVolumeML = getReservoirWeight( inactiveReservoir ) - reservoirBaseWeight; + F32 integratedVolumeToLoadCellReadingPercent = fabs( 1 - ( filledVolumeML / integratedVolumeML ) ); + F32 avgAcidConductivity = acidConductivityTotal / conductivitySampleCount; // TODO - should we be checking this below? + F32 avgDialysateConductivity = dialysateConductivityTotal / conductivitySampleCount; if ( integratedVolumeToLoadCellReadingPercent > FLOW_INTEGRATED_VOLUME_CHECK_TOLERANCE ) { #ifndef DISABLE_FLOW_CHECK_IN_FILL - SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DG_FLOW_METER_CHECK_FAILURE, filledVolume_mL, integratedVolume_mL ); + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DG_FLOW_METER_CHECK_FAILURE, filledVolumeML, integratedVolumeML ); #endif } Index: firmware/App/Modes/ModeFill.h =================================================================== diff -u -ra3960210792d0811093a6913e505d43eda1918ea -re59287e5915e01c44af22fc54eafc29cb0f6c2c0 --- firmware/App/Modes/ModeFill.h (.../ModeFill.h) (revision a3960210792d0811093a6913e505d43eda1918ea) +++ firmware/App/Modes/ModeFill.h (.../ModeFill.h) (revision e59287e5915e01c44af22fc54eafc29cb0f6c2c0) @@ -39,12 +39,14 @@ U32 execFillMode( void ); // execute the fill mode state machine (call from OperationModes) -F32 getAvgFillFlowRate( void ); // TODO do we need this? +F32 getAvgFillFlowRate( void ); F32 getAvgFillTemperature( void ); F32 getLastFillTemperature( void ); +void resetFillStatusParameters( void ); + /**@}*/ #endif Index: firmware/App/Modes/ModeFlush.c =================================================================== diff -u -r353d01d31bc69d4d1901ff09097ee610bb1c9dbc -re59287e5915e01c44af22fc54eafc29cb0f6c2c0 --- firmware/App/Modes/ModeFlush.c (.../ModeFlush.c) (revision 353d01d31bc69d4d1901ff09097ee610bb1c9dbc) +++ firmware/App/Modes/ModeFlush.c (.../ModeFlush.c) (revision e59287e5915e01c44af22fc54eafc29cb0f6c2c0) @@ -694,7 +694,7 @@ { DG_FLUSH_STATE_T state = DG_FLUSH_STATE_FLUSH_CIRCULATION_DRAIN_LINE; - F32 waterFlowRate = getMeasuredROFlowRate(); + F32 waterFlowRate = getMeasuredROFlowRateLPM(); F32 waterVolume = ( ( waterFlowRate / SEC_PER_MIN ) / ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ); // Integrate volume of water moved through line Index: firmware/App/Modes/ModeGenIdle.c =================================================================== diff -u -r8a553b10a224c745cb4bd6d963c867391905ba8c -re59287e5915e01c44af22fc54eafc29cb0f6c2c0 --- firmware/App/Modes/ModeGenIdle.c (.../ModeGenIdle.c) (revision 8a553b10a224c745cb4bd6d963c867391905ba8c) +++ firmware/App/Modes/ModeGenIdle.c (.../ModeGenIdle.c) (revision e59287e5915e01c44af22fc54eafc29cb0f6c2c0) @@ -208,7 +208,7 @@ static DG_GEN_IDLE_MODE_STATE_T handleFlushLinesState( void ) { DG_GEN_IDLE_MODE_STATE_T result = DG_GEN_IDLE_MODE_STATE_FLUSH_LINES; - F32 waterFlowRate = getMeasuredROFlowRate(); + F32 waterFlowRate = getMeasuredROFlowRateLPM(); F32 waterVolume = ( ( waterFlowRate / SEC_PER_MIN ) / ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ); // Integrate volume of water moved through line Index: firmware/App/Modes/ModeStandby.c =================================================================== diff -u -r94a190522ce398399c7b93c59f788d7666ec0060 -re59287e5915e01c44af22fc54eafc29cb0f6c2c0 --- firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision 94a190522ce398399c7b93c59f788d7666ec0060) +++ firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision e59287e5915e01c44af22fc54eafc29cb0f6c2c0) @@ -46,19 +46,20 @@ // ********** private data ********** -static DG_STANDBY_MODE_STATE_T standbyState = DG_STANDBY_MODE_STATE_START; ///< Currently active standby state. -static BOOL stopSampleWaterRequest = FALSE; ///< Flag indicating HD has requested to stop sample water -static BOOL startSampleWaterRequest = FALSE; ///< Flag indicating HD has requested to start sample water -static BOOL flushFilterRequest = FALSE; ///< Flag indicating HD has requested to flush filters -static BOOL endSampleWaterRequest = FALSE; ///< Flag indicating HD has requested to end sample water +static DG_STANDBY_MODE_STATE_T standbyState = DG_STANDBY_MODE_STATE_START; ///< Currently active standby state. +static BOOL stopSampleWaterRequest = FALSE; ///< Flag indicating HD has requested to stop sample water +static BOOL startSampleWaterRequest = FALSE; ///< Flag indicating HD has requested to start sample water +static BOOL flushFilterRequest = FALSE; ///< Flag indicating HD has requested to flush filters +static BOOL endSampleWaterRequest = FALSE; ///< Flag indicating HD has requested to end sample water -static BOOL pendingStartDGRequest = FALSE; ///< Flag indicating HD has requested DG start (go to generation idle mode). -static U32 waterSampleStartTime = 0; ///< Time stamp for start of water sample state. -static U32 filterFlushStartTime = 0; ///< Time stamp for start of filter flush state. -static U32 filterFlushPublishTimerCounter = 0; ///< Filter flush data publish timer counter. -/// Filter flush time period in ms. -static OVERRIDE_U32_T filterFlushTimePeriod = { FILTER_FLUSH_TIME_MS, FILTER_FLUSH_TIME_MS, 0, 0 }; +static BOOL pendingStartDGRequest = FALSE; ///< Flag indicating HD has requested DG start (go to generation idle mode). +static U32 waterSampleStartTime = 0; ///< Time stamp for start of water sample state. +static U32 filterFlushStartTime = 0; ///< Time stamp for start of filter flush state. +static U32 filterFlushPublishTimerCounter = 0; ///< Filter flush data publish timer counter. +static OVERRIDE_U32_T filterFlushTimePeriod = { FILTER_FLUSH_TIME_MS, + FILTER_FLUSH_TIME_MS, 0, 0 }; ///< Filter flush time period in ms. + // ********** private function prototypes ********** static DG_STANDBY_MODE_STATE_T handleStandbyIdleState( void ); Index: firmware/App/Services/Reservoirs.c =================================================================== diff -u -r8a553b10a224c745cb4bd6d963c867391905ba8c -re59287e5915e01c44af22fc54eafc29cb0f6c2c0 --- firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 8a553b10a224c745cb4bd6d963c867391905ba8c) +++ firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision e59287e5915e01c44af22fc54eafc29cb0f6c2c0) @@ -55,8 +55,8 @@ // TODO add doxygen comments yes for all of the new variables and align them #define RESERVOIR_TEMPERATURE_TAU_C_PER_MIN -0.512 ///< Reservoir temperature time constant C/min. #define ULTRAFILTER_TEMPERATURE_TAU_C_PER_MIN -0.512 ///< Ultrafilter temperature time constant C/min. -#define ULTRAFILTER_VOLUME_ML 700 -#define RESERVOIR_EXTRA_TEMPERATURE 1.0 +#define ULTRAFILTER_VOLUME_ML 700 +#define RESERVOIR_EXTRA_TEMPERATURE 1.0 // ********** private data ********** @@ -95,6 +95,7 @@ static BOOL tareLoadCellRequest; ///< Flag indicates if load cell tare has been requested by HD. static DG_RESERVOIR_VOLUME_RECORD_T reservoirsCalRecord; ///< DG reservoirs non-volatile record. static F32 targetFillFlowRateLPM; ///< Target fill flow rate in L/min. +static BOOL isThisTheFirstCycle = TRUE; // TODO add doxygen comments static const F32 ULTRAFILTER_TAU_C_PER_MS = ULTRAFILTER_TEMPERATURE_TAU_C_PER_MIN / ( SEC_PER_MIN * MS_PER_SECOND ); @@ -109,7 +110,7 @@ * The initReservoirs function initializes the Reservoirs module. * @details Inputs: none * @details Outputs: activeReservoir.data, fillVolumeTargetMl.data, - * drainVolumeTargetMl.data, targetFillFlowRateLPM + * drainVolumeTargetMl.data, targetFillFlowRateLPM, isThisTheFirstCycle * @return none *************************************************************************/ void initReservoirs( void ) @@ -118,6 +119,7 @@ fillVolumeTargetMl.data = DEFAULT_FILL_VOLUME_ML; drainVolumeTargetMl.data = DEFAULT_DRAIN_VOLUME_ML; targetFillFlowRateLPM = 0.0; + isThisTheFirstCycle = TRUE; } /*********************************************************************//** @@ -548,6 +550,16 @@ heatersTempCalc.timeReservoirFillMS = params.timeReservoirFillMS; heatersTempCalc.tempTargetTrimmer = params.trimmerTargetTemperature; heatersTempCalc.flowTargetDialysateLPM = params.dialysateFlowLPM; + + // Set the trimmer heater target temperature since this value is needed for calculations + setHeaterTargetTemperature( DG_TRIMMER_HEATER, heatersTempCalc.tempTargetTrimmer ); + + // Check if this is the first time that the dialysate heating parameters are set in DG + if ( TRUE == isThisTheFirstCycle ) + { + resetFillStatusParameters(); + isThisTheFirstCycle = FALSE; + } } /*********************************************************************//** @@ -562,12 +574,12 @@ { F32 UFTimeConstant = 0.0; F32 targetFillVolML = getTargetFillVolumeML(); - F32 tempLastFill = getLastFillTemperature() < NEARLY_ZERO ? heatersTempCalc.tempTargetTrimmer : getLastFillTemperature(); // TODO move to reset fill items function - F32 tempAvgFill = getAvgFillTemperature() < NEARLY_ZERO ? heatersTempCalc.tempTargetTrimmer : getAvgFillTemperature(); // TODO move this to the reset function + F32 tempLastFill = getLastFillTemperature(); + F32 tempAvgFill = getAvgFillTemperature(); - heatersTempCalc.timeUFDecayMS = (F32)heatersTempCalc.timeReservoirCycleMS - heatersTempCalc.timeReservoirFillMS; - UFTimeConstant = heatersTempCalc.timeUFDecayMS * ULTRAFILTER_TAU_C_PER_MS; - heatersTempCalc.tempUFFill = tempLastFill + UFTimeConstant; + heatersTempCalc.timeUFDecayMS = (F32)heatersTempCalc.timeReservoirCycleMS - heatersTempCalc.timeReservoirFillMS; + UFTimeConstant = heatersTempCalc.timeUFDecayMS * ULTRAFILTER_TAU_C_PER_MS; + heatersTempCalc.tempUFFill = tempLastFill + UFTimeConstant; F32 ultrafilterPart = ( ULTRAFILTER_VOLUME_ML / targetFillVolML ) * heatersTempCalc.tempUFFill; F32 fillPart = ( ( targetFillVolML - ULTRAFILTER_VOLUME_ML ) / targetFillVolML ) * tempAvgFill; @@ -593,7 +605,7 @@ F32 tempTarget = 0.0; F32 targetFillVolML = getTargetFillVolumeML(); F32 UFTimeConstant = 0.0; - F32 tempLastFill = getLastFillTemperature() < NEARLY_ZERO ? heatersTempCalc.tempTargetTrimmer : getLastFillTemperature(); // TODO move this to the reset function + F32 tempLastFill = getLastFillTemperature(); F32 tempReservoirUse = heatersTempCalc.tempTargetTrimmer + RESERVOIR_EXTRA_TEMPERATURE; heatersTempCalc.tempReservoirEndFill = tempReservoirUse - ( heatersTempCalc.timeReservoirFill2SwitchMS * RESERVOIR_TAU_C_PER_MS );