Index: firmware/App/Monitors/Temperature.c =================================================================== diff -u -r1781335a8c1833fad17b275bf44c7f6675e68423 -r2e89a75592087ba15cae7070a92173e9f1efa8fe --- firmware/App/Monitors/Temperature.c (.../Temperature.c) (revision 1781335a8c1833fad17b275bf44c7f6675e68423) +++ firmware/App/Monitors/Temperature.c (.../Temperature.c) (revision 2e89a75592087ba15cae7070a92173e9f1efa8fe) @@ -47,7 +47,7 @@ #define D28_D30_TEMP_SENSORS_MAX_DEVIATION_IN_HEAT_DIS_C 5.0F ///< Dialysate temperature sensors maximum allowed deviation in heat disinfect in C. /// Dialysate temperature sensors enums -typedef enum Dial_Temps_Sensors +typedef enum dial_Temps_Sensors { DIAL_TEMP_D28 = 0, ///< Dialysate temperature D28. DIAL_TEMP_FIRST = DIAL_TEMP_D28, ///< Dialysate temperature first. @@ -86,8 +86,8 @@ static F32 d4TempSamplesC[ D4_TEMP_MOVING_AVG_NUM_OF_SAMPLES ]; ///< D4 temperature samples array in C. static U32 d4TempSamplesNextIndex; ///< D4 temperature sample next index number. static U32 d4TempCount; ///< D4 Number of samples in average buffer. -static U32 tempDataColStartTimeMS; ///< Temperature data collection start time in milliseconds. static U32 tempDataColTimeInterval; ///< Temperature data collection time interval in milliseconds. +static U32 d4TempSampleIntervalCounter; ///< D4 temperature sensor sample collection timer counter. static F32 d50TempAvgC; ///< D50 temperature average in C. static F32 d50TempRunningSumC; ///< D50 temperature running sum in C. @@ -117,8 +117,6 @@ *************************************************************************/ void initTemperature( void ) { - DIAL_TEMPERATURE_SENSORS_T j; - startTime = 0; tempSensorsExecState = TEMPSENSORS_EXEC_STATE_START; dataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; @@ -130,21 +128,13 @@ d50TempAvgC = 0.0F; d50TempSamplesNextIndex = 0; d50TempCount = 0; - tempDataColStartTimeMS = 0; + d4TempSampleIntervalCounter = 0; tempDataColTimeInterval = 0; tempDriftEventCheck = FALSE; - for ( j = DIAL_TEMP_FIRST; j < NUM_OF_DIAL_TEMPS; j++ ) - { - dialTempMovingAvgData[ j ].dialTempAvgC = 0.0F; - dialTempMovingAvgData[ j ].dialTempColHasTimerBeenSet = FALSE; - dialTempMovingAvgData[ j ].dialTempRunningSumC = 0.0F; - dialTempMovingAvgData[ j ].dialTempSamplesNextIndex = 0; - dialTempMovingAvgData[ j ].dialTempDataColStartTimeMS = getMSTimerCount(); + dialTempMovingAvgData[ DIAL_TEMP_D28 ].dialTempColHasTimerBeenSet = FALSE; + dialTempMovingAvgData[ DIAL_TEMP_D30 ].dialTempColHasTimerBeenSet = FALSE; - memset( dialTempMovingAvgData[ j ].dialTempSamplesC, 0.0F, sizeof( F32 ) * DIAL_TEMP_MOVING_AVG_NUM_OF_SAMPLES ); - } - // Initialize the temperature sensors initTemperatureSensors(); @@ -286,31 +276,29 @@ static void filterTemperatureReadings( void ) { // Moving average sample collection interval varies based on the dialysate flow rate - if ( 0 == tempDataColStartTimeMS ) + if ( ++d4TempSampleIntervalCounter >= tempDataColTimeInterval ) { - tempDataColStartTimeMS = getMSTimerCount(); - } - else if ( TRUE == didTimeout( tempDataColStartTimeMS , tempDataColTimeInterval ) ) - { // Filter D4 Temperature for AC heater if ( d4TempCount >= D4_TEMP_MOVING_AVG_NUM_OF_SAMPLES ) { d4TempRunningSumC -= d4TempSamplesC[ d4TempSamplesNextIndex ]; } + F32 d4Temp = getTemperatureValue( D4_TEMP ); d4TempSamplesC[ d4TempSamplesNextIndex ] = d4Temp; d4TempRunningSumC += d4Temp; d4TempSamplesNextIndex = INC_WRAP( d4TempSamplesNextIndex, 0, D4_TEMP_MOVING_AVG_NUM_OF_SAMPLES - 1 ); d4TempCount = INC_CAP( d4TempCount, D4_TEMP_MOVING_AVG_NUM_OF_SAMPLES ); d4TempAvgC = d4TempRunningSumC / (F32)d4TempCount; - tempDataColStartTimeMS = getMSTimerCount(); + d4TempSampleIntervalCounter = 0; } // Filter D50 Temperature ( 250 ms filter ) for trimmer heater if ( d50TempCount >= D50_TEMP_MOVING_AVG_NUM_OF_SAMPLES ) { d50TempRunningSumC -= d50TempSamplesC[ d50TempSamplesNextIndex ]; } + F32 d50Temp = getTemperatureValue( D50_TEMP ); d50TempSamplesC[ d50TempSamplesNextIndex ] = d50Temp; d50TempRunningSumC += d50Temp; @@ -427,13 +415,15 @@ * to find the average value. * @details \b Inputs: dialysate flow rate * @details \b Outputs: none - * @return the temperature interval for sample collection + * @return the temperature interval for sample collection in task interval *************************************************************************/ static void getTempMovingAverageTimeInterval( void ) { F32 period = (F32)SEC_PER_MIN / ( getTDDialysateFlowrate() / BAL_CHAMBER_FILL_VOLUME_ML ) ; - tempDataColTimeInterval = (U32)( ( period / (F32)D4_TEMP_MOVING_AVG_NUM_OF_SAMPLES ) * MS_PER_SECOND ); + U32 sampleInterval = (U32)( ( period / (F32)D4_TEMP_MOVING_AVG_NUM_OF_SAMPLES ) * MS_PER_SECOND ); + + tempDataColTimeInterval = (U32) ( sampleInterval / TASK_PRIORITY_INTERVAL ); } /*********************************************************************//**