Index: firmware/App/Monitors/Temperature.c =================================================================== diff -u -r2cdff97cc76e7a7b9ec3c087dacf767f2c022b31 -r3f65e4b1e11315bd6ca3a30a80fd4848a9081dda --- firmware/App/Monitors/Temperature.c (.../Temperature.c) (revision 2cdff97cc76e7a7b9ec3c087dacf767f2c022b31) +++ firmware/App/Monitors/Temperature.c (.../Temperature.c) (revision 3f65e4b1e11315bd6ca3a30a80fd4848a9081dda) @@ -42,7 +42,7 @@ #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. -#define D50_TEMP_MOVING_AVG_NUM_OF_SAMPLES 25 ///< D50 temperature sensor moving average number of samples ( 250ms filter ). +#define D50_TEMP_MOVING_AVG_NUM_OF_SAMPLES 50 ///< D50 temperature sensor moving average number of samples ( 250ms filter ). #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. @@ -92,6 +92,7 @@ static U32 d4TempCount; ///< D4 Number of samples in average buffer. static U32 tempDataColTimeInterval; ///< Temperature data collection time interval in milliseconds. static U32 d4TempSampleIntervalCounter; ///< D4 temperature sensor sample collection timer counter. +static U32 d50TempSampleIntervalCounter; ///< D50 temperature sensor sample collection timer counter. static F32 d50TempAvgC; ///< D50 temperature average in C. static F32 d50TempRunningSumC; ///< D50 temperature running sum in C. @@ -135,6 +136,7 @@ d50TempSamplesNextIndex = 0; d50TempCount = 0; d4TempSampleIntervalCounter = 0; + d50TempSampleIntervalCounter = 0; tempDataColTimeInterval = 0; tempDriftEventCheck = FALSE; @@ -308,19 +310,23 @@ d4TempSampleIntervalCounter = 0; } - // Filter D50 Temperature ( 250 ms filter ) for trimmer heater - if ( d50TempCount >= D50_TEMP_MOVING_AVG_NUM_OF_SAMPLES ) + // Moving average sample collection interval varies based on the dialysate flow rate + if ( ++d50TempSampleIntervalCounter >= tempDataColTimeInterval ) { - d50TempRunningSumC -= d50TempSamplesC[ d50TempSamplesNextIndex ]; + if ( d50TempCount >= D50_TEMP_MOVING_AVG_NUM_OF_SAMPLES ) + { + d50TempRunningSumC -= d50TempSamplesC[ d50TempSamplesNextIndex ]; + } + + F32 d50Temp = getTemperatureValue( D50_TEMP ); + d50TempSamplesC[ d50TempSamplesNextIndex ] = d50Temp; + d50TempRunningSumC += d50Temp; + d50TempSamplesNextIndex = INC_WRAP( d50TempSamplesNextIndex, 0, D50_TEMP_MOVING_AVG_NUM_OF_SAMPLES - 1 ); + d50TempCount = INC_CAP( d50TempCount, D50_TEMP_MOVING_AVG_NUM_OF_SAMPLES ); + d50TempAvgC = d50TempRunningSumC / (F32)d50TempCount; + d50TempSampleIntervalCounter = 0; } - F32 d50Temp = getTemperatureValue( D50_TEMP ); - d50TempSamplesC[ d50TempSamplesNextIndex ] = d50Temp; - d50TempRunningSumC += d50Temp; - d50TempSamplesNextIndex = INC_WRAP( d50TempSamplesNextIndex, 0, D50_TEMP_MOVING_AVG_NUM_OF_SAMPLES - 1 ); - d50TempCount = INC_CAP( d50TempCount, D50_TEMP_MOVING_AVG_NUM_OF_SAMPLES ); - d50TempAvgC = d50TempRunningSumC / (F32)d50TempCount; - // dailysate temperature moving average filterDialTemperatureReadings(); }