Index: firmware/App/Monitors/Temperature.c =================================================================== diff -u -r268b3f1b55eda9eb47ab3cb8b3a364ff8eb9d502 -r9ad8a0724b0afdfc455312b4293e1255f6fb9532 --- firmware/App/Monitors/Temperature.c (.../Temperature.c) (revision 268b3f1b55eda9eb47ab3cb8b3a364ff8eb9d502) +++ firmware/App/Monitors/Temperature.c (.../Temperature.c) (revision 9ad8a0724b0afdfc455312b4293e1255f6fb9532) @@ -41,9 +41,8 @@ #define TEMP_SENSORS_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Temperature sensors publish data time interval. #define TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Temperature sensors FPGA error timeout in milliseconds. -#define D4_TEMP_MOVING_AVG_NUM_OF_SAMPLES 50 ///< D4 temperature sensor moving average number of samples //TODO Not a fixed sample +#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 25 ///< D50 temperature sensor moving average number of samples ( 250ms filter ). -//TODO for D99 the sample size will be defined as needed #define D99_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. @@ -106,6 +105,7 @@ static F32 d99TempSamplesC[ D99_TEMP_MOVING_AVG_NUM_OF_SAMPLES ]; ///< D99 temperature samples array in C. static U32 d99TempSamplesNextIndex; ///< D99 temperature sample next index number. static U32 d99TempCount; ///< D99 Number of samples in average buffer. +static U32 d99TempSampleIntervalCounter; ///< D99 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. @@ -147,6 +147,7 @@ d99TempSamplesNextIndex = 0; d99TempCount = 0; d4TempSampleIntervalCounter = 0; + d99TempSampleIntervalCounter = 0; tempDataColTimeInterval = 0; tempDriftEventCheck = FALSE; @@ -294,7 +295,7 @@ * @brief * The filterTemperatureReadings function adds a new temperature sensor * sample to the filters. - * @details \b Inputs: D4 and D50 Temperature + * @details \b Inputs: D4, D50 and D99 Temperature * @details \b Outputs: d4TempSamplesC[], d4TempSamplesNextIndex, d4TempRunningSumC, * d4TempCount, d4TempAvgC, d50TempSamplesC, d50TempRunningSumC, d50TempSamplesNextIndex, * d50TempCount, d50TempAvgC, d99TempSamplesC, d99TempRunningSumC, d99TempSamplesNextIndex, @@ -334,19 +335,25 @@ d50TempCount = INC_CAP( d50TempCount, D50_TEMP_MOVING_AVG_NUM_OF_SAMPLES ); d50TempAvgC = d50TempRunningSumC / (F32)d50TempCount; - // Filter D99 Temperature for fresh dialysate temperature - if ( d99TempCount >= D99_TEMP_MOVING_AVG_NUM_OF_SAMPLES ) + + // Moving average sample collection interval varies based on the dialysate flow rate + if ( ++d99TempSampleIntervalCounter >= tempDataColTimeInterval ) { - d99TempRunningSumC -= d99TempSamplesC[ d99TempSamplesNextIndex ]; - } - F32 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; + // Filter D99 Temperature for fresh dialysate temperature + if ( d99TempCount >= D99_TEMP_MOVING_AVG_NUM_OF_SAMPLES ) + { + d99TempRunningSumC -= d99TempSamplesC[ d99TempSamplesNextIndex ]; + } + F32 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; + } + // dailysate temperature moving average filterDialTemperatureReadings(); }