Index: firmware/App/Monitors/Temperature.c =================================================================== diff -u -rd748813399d38ef5b71d760e327e368cc82d7a38 -r3ebcff44116a7853d2011c7b2f1eb38c1f37ba2a --- firmware/App/Monitors/Temperature.c (.../Temperature.c) (revision d748813399d38ef5b71d760e327e368cc82d7a38) +++ firmware/App/Monitors/Temperature.c (.../Temperature.c) (revision 3ebcff44116a7853d2011c7b2f1eb38c1f37ba2a) @@ -48,6 +48,7 @@ #define D4_TEMP_MOVING_AVG_NUM_OF_SAMPLES 50 ///< D4 temperature sensor moving average number of samples. #define D50_TEMP_MOVING_AVG_NUM_OF_SAMPLES 50 ///< D50 temperature sensor moving average number of samples. #define D99_TEMP_MOVING_AVG_NUM_OF_SAMPLES 50 ///< D99 temperature sensor moving average number of samples +#define D78_TEMP_MOVING_AVG_NUM_OF_SAMPLES 50 ///< D99 temperature sensor moving average number of samples #define DATA_PUBLISH_COUNTER_START_COUNT 30 ///< Data publish counter start count. #define DIAL_TEMP_MOVING_AVG_NUM_OF_SAMPLES 30 ///< Dialysate temperature sensors moving average number of samples. #define D28_D30_DATA_COLLECTION_TIME_MS ( 1 * MS_PER_SECOND ) ///< Dialysate temperature sensors data collection time in milliseconds. @@ -112,6 +113,13 @@ static U32 d99TempCount; ///< D99 Number of samples in average buffer. static U32 d99TempSampleIntervalCounter; ///< D99 temperature sensor sample collection timer counter. +static F32 d78TempAvgC; ///< D78 temperature average in C. +static F32 d78TempRunningSumC; ///< D78 temperature running sum in C. +static F32 d78TempSamplesC[ D99_TEMP_MOVING_AVG_NUM_OF_SAMPLES ]; ///< D78 temperature samples array in C. +static U32 d78TempSamplesNextIndex; ///< D78 temperature sample next index number. +static U32 d78TempCount; ///< D78 Number of samples in average buffer. +static U32 d78TempSampleIntervalCounter; ///< D78 temperature sensor sample collection timer counter. + static U32 ddTempDataPublicationTimerCounter; ///< DD Temperature sensors data publish timer counter. static U32 fpTempDataPublicationTimerCounter; ///< FP Temperature sensors data publish timer counter. static OVERRIDE_U32_T ddTempSensorsPublishInterval; ///< DD Temperature sensors publish time interval override. @@ -151,9 +159,14 @@ d99TempAvgC = 0.0F; d99TempSamplesNextIndex = 0; d99TempCount = 0; + d78TempRunningSumC = 0.0F; + d78TempAvgC = 0.0F; + d78TempSamplesNextIndex = 0; + d78TempCount = 0; d4TempSampleIntervalCounter = 0; d50TempSampleIntervalCounter = 0; d99TempSampleIntervalCounter = 0; + d78TempSampleIntervalCounter = 0; tempDataCollectionTimeInterval = 0; tempDriftEventCheck = FALSE; @@ -301,15 +314,20 @@ * @brief * The filterTemperatureReadings function adds a new temperature sensor * sample to the filters. - * @details \b Inputs: D4, D50 and D99 Temperature + * @details \b Inputs: D4, D50,D78 and D99 Temperature * @details \b Outputs: d4TempSamplesC[], d4TempSamplesNextIndex, d4TempRunningSumC, * d4TempCount, d4TempAvgC, d50TempSamplesC, d50TempRunningSumC, d50TempSamplesNextIndex, * d50TempCount, d50TempAvgC, d99TempSamplesC, d99TempRunningSumC, d99TempSamplesNextIndex, - * d99TempCount, d99TempAvgC + * d99TempCount, d99TempAvgC, * @return none *************************************************************************/ static void filterTemperatureReadings( void ) { + F32 d4Temp = 0.0F; + F32 d50Temp = 0.0F; + F32 d99Temp = 0.0F; + F32 d78Temp = 0.0F; + // Moving average sample collection interval varies based on the dialysate flow rate if ( ++d4TempSampleIntervalCounter >= tempDataCollectionTimeInterval ) { @@ -319,7 +337,7 @@ d4TempRunningSumC -= d4TempSamplesC[ d4TempSamplesNextIndex ]; } - F32 d4Temp = getTemperatureValue( D4_TEMP ); + d4Temp = getTemperatureValue( D4_TEMP ); d4TempSamplesC[ d4TempSamplesNextIndex ] = d4Temp; d4TempRunningSumC += d4Temp; d4TempSamplesNextIndex = INC_WRAP( d4TempSamplesNextIndex, 0, D4_TEMP_MOVING_AVG_NUM_OF_SAMPLES - 1 ); @@ -336,7 +354,7 @@ d50TempRunningSumC -= d50TempSamplesC[ d50TempSamplesNextIndex ]; } - F32 d50Temp = getTemperatureValue( D50_TEMP ); + d50Temp = getTemperatureValue( D50_TEMP ); d50TempSamplesC[ d50TempSamplesNextIndex ] = d50Temp; d50TempRunningSumC += d50Temp; d50TempSamplesNextIndex = INC_WRAP( d50TempSamplesNextIndex, 0, D50_TEMP_MOVING_AVG_NUM_OF_SAMPLES - 1 ); @@ -356,14 +374,32 @@ d99TempRunningSumC -= d99TempSamplesC[ d99TempSamplesNextIndex ]; } - F32 d99Temp = getTemperatureValue( D99_TEMP ); + d99Temp = getTemperatureValue( D99_TEMP ); d99TempSamplesC[ d99TempSamplesNextIndex ] = d99Temp; d99TempRunningSumC += d99Temp; d99TempSamplesNextIndex = INC_WRAP( d99TempSamplesNextIndex, 0, D99_TEMP_MOVING_AVG_NUM_OF_SAMPLES - 1 ); d99TempCount = INC_CAP( d99TempCount, D99_TEMP_MOVING_AVG_NUM_OF_SAMPLES ); d99TempAvgC = d99TempRunningSumC / (F32)d99TempCount; } + // Moving average sample collection interval varies based on the dialysate flow rate + if ( ++d78TempSampleIntervalCounter >= tempDataCollectionTimeInterval ) + { + + // Filter D78 Temperature for fresh dialysate temperature + if ( d78TempCount >= D78_TEMP_MOVING_AVG_NUM_OF_SAMPLES ) + { + d78TempRunningSumC -= d78TempSamplesC[ d78TempSamplesNextIndex ]; + } + + d78Temp = getTemperatureValue( D78_TEMP ); + d78TempSamplesC[ d78TempSamplesNextIndex ] = d78Temp; + d78TempRunningSumC += d78Temp; + d78TempSamplesNextIndex = INC_WRAP( d78TempSamplesNextIndex, 0, D78_TEMP_MOVING_AVG_NUM_OF_SAMPLES - 1 ); + d78TempCount = INC_CAP( d78TempCount, D78_TEMP_MOVING_AVG_NUM_OF_SAMPLES ); + d78TempAvgC = d78TempRunningSumC / (F32)d78TempCount; + } + // dailysate temperature moving average filterDialTemperatureReadings(); } @@ -485,6 +521,19 @@ /*********************************************************************//** * @brief + * The getD78AverageTemperature function returns the average temperature + * for D78 temperature sensor. + * @details \b Inputs: none + * @details \b Outputs: none + * @return the D78 average temperature + *************************************************************************/ +F32 getD78AverageTemperature( void ) +{ + return d78TempAvgC; +} + +/*********************************************************************//** + * @brief * The getTempMovingAverageTimeInterval function calculates the temperature * interval used for sample collection based on the dialysate flow rate, * to find the average value. @@ -543,6 +592,7 @@ data.d99AvgTemp = getD99AverageTemperature(); data.d28AvgTemp = dialTempMovingAvgData[ DIAL_TEMP_D28 ].dialTempAvgC; data.d30AvgTemp = dialTempMovingAvgData[ DIAL_TEMP_D30 ].dialTempAvgC; + data.d78AvgTemp = getD78AverageTemperature(); data.d9PresTemp = getFilteredPressureSensorTemperature( D9_PRES ); data.d66PresTemp = getFilteredPressureSensorTemperature( D66_PRES ); data.d51PresTemp = getFilteredPressureSensorTemperature( D51_PRES );