Index: firmware/App/Controllers/Heaters.c =================================================================== diff -u -rb6fb8796a82272af1b5791be8cd3fc3b445e0f1d -r788c0f92052a7d8f0d67dd4ab607b48520013589 --- firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision b6fb8796a82272af1b5791be8cd3fc3b445e0f1d) +++ firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision 788c0f92052a7d8f0d67dd4ab607b48520013589) @@ -92,7 +92,7 @@ HEATERS_STATE_T state; ///< Heater state. BOOL startHeaterSignal; ///< Heater start indication flag. BOOL isHeaterOn; ///< Heater on/off status flag. - F32 dutycycle; ///< Heater duty cycle. + F32 dutyCycle; ///< Heater duty cycle. F32 targetFlow; ///< Heater target flow. BOOL hasTargetTempChanged; ///< Heater target temperature change flag indicator. F32 heaterEstGain; ///< Heater estimation gain during the run. @@ -147,7 +147,7 @@ heatersStatus[ heater ].state = HEATER_EXEC_STATE_OFF; heatersStatus[ heater ].startHeaterSignal = FALSE; heatersStatus[ heater ].isHeaterOn = FALSE; - heatersStatus[ heater ].dutycycle = 0.0; + heatersStatus[ heater ].dutyCycle = 0.0; heatersStatus[ heater ].targetFlow = 0.0; heatersStatus[ heater ].hasTargetTempChanged = FALSE; heatersStatus[ heater ].heaterEstGain = HEATERS_NEUTRAL_EST_GAIN; @@ -403,7 +403,7 @@ #endif { F32 heaterEstGain = heatersStatus[ heater ].heaterEstGain; - F32 heaterDutyCycle = heatersStatus[ heater ].dutycycle; + F32 heaterDutyCycle = heatersStatus[ heater ].dutyCycle; F32 lastFillTemperature = getAvgFillTemperature(); F32 primaryTargetTemperature = heatersStatus[ heater ].targetTemp; BOOL isTempUnderTarget = ( lastFillTemperature < primaryTargetTemperature ? TRUE : FALSE ); @@ -549,7 +549,7 @@ state = HEATER_EXEC_STATE_PRIMARY_RAMP_TO_TARGET; } - // If the heat disifect sensor indicates that the temperature is below target temperature but the target temperature had been reached + // If the heat disinfect sensor indicates that the temperature is below target temperature but the target temperature had been reached // before turn on the heaters with 100% power if ( ( heatDisinfectSensorTemp <= heatersStatus[ heater ].targetTemp ) && ( TRUE == heatersStatus[ heater ].hasTargetBeenReached ) ) { @@ -606,10 +606,15 @@ } // Update the calculated target temperature + // Reset the duty cycle since the reservoir has been switched heatersStatus[ heater ].calculatedTemperature = currentTemperature; heatersStatus[ heater ].inactiveRsrvr = getInactiveReservoir(); heatersStatus[ heater ].targetFlow = targetFlowLPM; + heatersStatus[ heater ].dutyCycle = 0.0F; trimmerHeaterControlCounter = 0; + + // Cap the minimum duty cycle. So if it is calculated to negative, set it to 0 + dutyCycle = MAX( dutyCycle, HEATERS_MIN_DUTY_CYCLE ); setHeaterDutyCycle( heater, dutyCycle ); return state; @@ -643,7 +648,7 @@ F32 dutyCycle = calculateTrimmerHeaterDutyCycle( targetTemperature, outletRedundantTemperature, targetFlowLPM, TRUE ); trimmerHeaterControlCounter = 0; - setHeaterDutyCycle( DG_TRIMMER_HEATER, ( heatersStatus[ DG_TRIMMER_HEATER ].dutycycle + dutyCycle ) ); + setHeaterDutyCycle( DG_TRIMMER_HEATER, ( heatersStatus[ DG_TRIMMER_HEATER ].dutyCycle + dutyCycle ) ); } return state; @@ -663,7 +668,7 @@ // Check if the requested duty cycle is different from what the heater's duty cycle is. // If the same duty cycle is requested, then it is not needed to send it again. This is to make sure // the same duty cycle is not sent to the hardware all the time. - if ( fabs( heatersStatus[ heater ].dutycycle - pwm ) > NEARLY_ZERO ) + if ( fabs( heatersStatus[ heater ].dutyCycle - pwm ) > NEARLY_ZERO ) { if ( DG_PRIMARY_HEATER == heater ) { @@ -676,7 +681,7 @@ } // Updated the heater's information - heatersStatus[ heater ].dutycycle = pwm; + heatersStatus[ heater ].dutyCycle = pwm; } } @@ -733,12 +738,9 @@ } // 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 ) ) / TRIMMER_HEATER_MAX_POWER_W ) * heaterEstGain; - - // Check the boundaries of the calculated duty cycle + dutyCycle = ( ( flow * WATER_SPECIFIC_HEAT_DIVIDED_BY_MINUTES * ( targetTemperature - currentTemperature ) ) / TRIMMER_HEATER_MAX_POWER_W ) * heaterEstGain; dutyCycle = MIN( dutyCycle, HEATERS_MAX_DUTY_CYCLE ); - dutyCycle = MAX( dutyCycle, HEATERS_MIN_DUTY_CYCLE ); + dutyCycle = MAX( dutyCycle, ( HEATERS_MAX_DUTY_CYCLE * -1.0F ) ); return dutyCycle; } @@ -823,11 +825,11 @@ { HEATERS_DATA_T data; - data.mainPrimayHeaterDC = heatersStatus[ DG_PRIMARY_HEATER ].dutycycle * 100.0; + data.mainPrimayHeaterDC = heatersStatus[ DG_PRIMARY_HEATER ].dutyCycle * 100.0; // The duty cycle of the primary heater is divided into 2 parts and is applied to main // and small primary heaters. So they are always the same. - data.smallPrimaryHeaterDC = heatersStatus[ DG_PRIMARY_HEATER ].dutycycle * 100.0; - data.trimmerHeaterDC = heatersStatus[ DG_TRIMMER_HEATER ].dutycycle * 100.0; + data.smallPrimaryHeaterDC = heatersStatus[ DG_PRIMARY_HEATER ].dutyCycle * 100.0; + data.trimmerHeaterDC = heatersStatus[ DG_TRIMMER_HEATER ].dutyCycle * 100.0; data.primaryTargetTemp = heatersStatus[ DG_PRIMARY_HEATER ].targetTemp; data.trimmerTargetTemp = heatersStatus[ DG_TRIMMER_HEATER ].targetTemp; data.primaryHeaterState = heatersStatus[ DG_PRIMARY_HEATER ].state; @@ -863,9 +865,9 @@ F32 trimmerVoltage = getMonitoredLineLevel( MONITORED_LINE_24V_TRIM_HTR_V ); // Voltage to PWM is reverse. If PWM = 0 -> V = 24V - F32 mainPriDC = heatersStatus[ DG_PRIMARY_HEATER ].dutycycle; - F32 smallPriDC = heatersStatus[ DG_PRIMARY_HEATER ].dutycycle; - F32 trimmerDC = heatersStatus[ DG_TRIMMER_HEATER ].dutycycle; + F32 mainPriDC = heatersStatus[ DG_PRIMARY_HEATER ].dutyCycle; + F32 smallPriDC = heatersStatus[ DG_PRIMARY_HEATER ].dutyCycle; + F32 trimmerDC = heatersStatus[ DG_TRIMMER_HEATER ].dutyCycle; F32 mainPriExpectedVoltage = HEATERS_MAX_OPERATING_VOLTAGE_V * ( 1.0 - mainPriDC ); F32 smallPriExpectedVoltage = HEATERS_MAX_OPERATING_VOLTAGE_V * ( 1.0 - smallPriDC ); Index: firmware/App/Controllers/TemperatureSensors.c =================================================================== diff -u -rae2b7f296dcd0247814356a28380b3ac582a8551 -r788c0f92052a7d8f0d67dd4ab607b48520013589 --- firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision ae2b7f296dcd0247814356a28380b3ac582a8551) +++ firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 788c0f92052a7d8f0d67dd4ab607b48520013589) @@ -901,7 +901,8 @@ errorCount = (U32)getFPGARTDErrorCount(); readCount = (U32)getFPGARTDReadCount(); - //checkFPGAPersistentAlarms( TWO_WIRE_ADC_TEMP_SENSORS, errorCount, readCount, TEMPSENSORS_INLET_PRIMARY_HEATER ); + + //checkFPGAPersistentAlarms( TWO_WIRE_ADC_TEMP_SENSORS, errorCount, readCount ); processTempSnsrsADCRead( TEMPSENSORS_INLET_PRIMARY_HEATER, getFPGATPiTemp(), errorCount, readCount, TRUE ); processTempSnsrsADCRead( TEMPSENSORS_OUTLET_PRIMARY_HEATER, getFPGATPoTemp(), errorCount, readCount, FALSE ); processTempSnsrsADCRead( TEMPSENSORS_CONDUCTIVITY_SENSOR_1, getFPGACD1Temp(), errorCount, readCount, FALSE ); @@ -913,6 +914,8 @@ { errorCount = (U32)getFPGATHdErrorCount(); readCount = (U32)getFPGATHdReadCount(); + + //checkFPGAPersistentAlarms( THD_ADC_TEMP_SENSORS, errorCount, readCount ); processTempSnsrsADCRead( TEMPSENSORS_HEAT_DISINFECT, getFPGATHdTemp(), errorCount, readCount, TRUE ); processTempSnsrsADCRead( TEMPSENSORS_INTERNAL_THD_RTD, getFPGATHdInternalTemp(), errorCount, readCount, FALSE ); @@ -922,15 +925,21 @@ baroConvConsts.temperatureCoeff = getFPGABaroTempCoeffOfTemperature(); errorCount = getFPGABaroErrorCount(); readCount = getFPGABaroReadCount(); + + //checkFPGAPersistentAlarms( BARO_SENSORS, errorCount, readCount ); processTempSnsrsADCRead( TEMPSENSORS_BAROMETRIC_TEMP_SENSOR, getFPGABaroTemperature(), errorCount, readCount, TRUE ); } errorCount = (U32)getFPGATRoErrorCount(); readCount = (U32)getFPGATRoReadCount(); + + checkFPGAPersistentAlarms( TRO_ADC_TEMP_SENSORS, errorCount, readCount ); processTempSnsrsADCRead( TEMPSENSORS_OUTLET_REDUNDANT, getFPGATRoTemp(), errorCount, readCount, TRUE ); - errorCount = (U32)getFPGATDiErrorCount(); // TODO remove these and do not check in the new persistent alarm - readCount = (U32)getFPGATDiReadCount(); // TODO remove these and do not check in the new persistent alarm + errorCount = (U32)getFPGATDiErrorCount(); + readCount = (U32)getFPGATDiReadCount(); + + checkFPGAPersistentAlarms( TDI_ADC_TEMP_SENSORS, errorCount, readCount ); processTempSnsrsADCRead( TEMPSENSORS_INLET_DIALYSATE, getFPGATDiTemp(), errorCount, readCount, TRUE ); errorCount = (U32)getFPGAPrimaryHeaterFlags(); // TODO remove these and do not check in the new persistent alarm @@ -1029,6 +1038,8 @@ U08 i; F32 temperature = 0.0; BOOL isTemperatureOutOfRange = FALSE; + F32 alarmTemperature = 0.0; + U08 alarmIndex = 0; for ( i = 0; i < NUM_OF_TEMPERATURE_SENSORS; i++ ) { @@ -1056,6 +1067,8 @@ ( getCurrentOperationMode() != DG_MODE_INIT ) ) { isTemperatureOutOfRange |= TRUE; + alarmIndex = i; + alarmTemperature = temperature; } break; @@ -1066,7 +1079,7 @@ } - checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSOR_OUT_OF_RANGE, isTemperatureOutOfRange, i, temperature ); + checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSOR_OUT_OF_RANGE, isTemperatureOutOfRange, alarmIndex, alarmTemperature ); } }