Index: firmware/App/Monitors/Pressures.c =================================================================== diff -u -r234249ae228096a2351d478f784e754298da6628 -r57c5e32b2e155d728405b33ddcffb7efa440c1e8 --- firmware/App/Monitors/Pressures.c (.../Pressures.c) (revision 234249ae228096a2351d478f784e754298da6628) +++ firmware/App/Monitors/Pressures.c (.../Pressures.c) (revision 57c5e32b2e155d728405b33ddcffb7efa440c1e8) @@ -101,10 +101,12 @@ #define SIZE_OF_LONG_ART_ROLLING_AVG ( ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) * 10 ) /// Measured arterial pressure is filtered w/ 1 second moving average for inline pressure. #define SIZE_OF_SHORT_ART_ROLLING_AVG ( ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) * 1 ) -/// Measured arterial pressure is filtered w/ 10 second moving average for pressure compensation of flow. +/// Measured venous pressure is filtered w/ 10 second moving average for pressure compensation of flow. #define SIZE_OF_LONG_VEN_ROLLING_AVG ( ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) * 10 ) /// Measured venous pressure is filtered w/ 1 second moving average for inline pressure and unfiltered for occlusion detection. #define SIZE_OF_SHORT_VEN_ROLLING_AVG ( ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) * 1 ) +/// Measured trans-membrane pressure is filtered w/ 10 second moving average for pressure compensation of flow. +#define SIZE_OF_LONG_TMP_ROLLING_AVG ( ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) * 10 ) #define DATA_PUBLISH_COUNTER_START_COUNT 5 ///< Data publish counter start count. @@ -160,6 +162,7 @@ static OVERRIDE_F32_T shortFilteredArterialPressure; ///< Measured arterial pressure after short (1 s) filter (in mmHg). static F32 longFilteredVenousPressure; ///< Measured venous pressure after long (10 s) filter (in mmHg). static OVERRIDE_F32_T shortFilteredVenousPressure; ///< Measured venous pressure after short (1 s) filter (in mmHg). +static F32 longFilteredTmpPressure; ///< Measured trans-membrane pressure after long (10 s) filter (in mmHg). static OVERRIDE_F32_T tmpPressure; ///< Calculated trans-membrane pressure (in mmHg). static STABILIZATION_PERIODS_T pressureStabilizeTime; ///< Pressure stabilization time based on system events such as airpump, treatment param changes etc., static BOOL resetFillExemptPeriod; ///< Flag to reset the exempt period after defined time expire. @@ -191,6 +194,11 @@ static U32 venPressureReadingsShortCount; ///< Number of samples in flow rolling average buffer. static BARO_MOVING_AVG_DATA_T baroMovingAvg; ///< Barometric sensor moving average. +static F32 tmpPressureReadingsLong[ SIZE_OF_LONG_TMP_ROLLING_AVG ]; ///< Holds flow samples for long trans-membrane pressure rolling average. +static U32 tmpPressureReadingsLongIdx; ///< Index for next sample in rolling average array. +static F32 tmpPressureReadingsLongTotal; ///< Rolling total - used to calc average. +static U32 tmpPressureReadingsLongCount; ///< Number of samples in flow rolling average buffer. + static PRESSURE_SELF_TEST_STATE_T pressurePostState; ///< Pressure self test post state. //static HD_PRESSURE_SENSORS_CAL_RECORD_T pressureSensorsCalRecord; ///< Pressure sensors calibration record. @@ -204,7 +212,7 @@ static void checkTmpPressureInRange( void ); static void publishPressureData( void ); static void determineArtVenPressureLimits( void ); -static void filterInlinePressureReadings( F32 artPres, F32 venPres ); +static void filterInlinePressureReadings( F32 artPres, F32 venPres, F32 tmpPres ); static void filterBaroPressureReadings( F32 baroPresPSI ); /*********************************************************************//** @@ -286,6 +294,10 @@ venPressureReadingsShortTotal = 0.0F; venPressureReadingsShortCount = 0; + tmpPressureReadingsLongIdx = 0; + tmpPressureReadingsLongTotal = 0.0F; + tmpPressureReadingsLongCount = 0; + baroMovingAvg.baroAvgPSI.data = 0.0F; baroMovingAvg.baroAvgPSI.ovData = 0.0F; baroMovingAvg.baroAvgPSI.ovInitData = 0.0F; @@ -575,16 +587,14 @@ PRESSURE_STATE_T result = PRESSURE_CONTINUOUS_READ_STATE; F32 fpgaArtPres = getPressure( H2_PRES ) - arterialPressureOffset; F32 fpgaVenPres = getPressure( H14_PRES ) - venousPressureOffset; + F32 tmpPres = fpgaVenPres - ( getDialysatePressure() * PSI_TO_MMHG ); F32 fpgaBaroPresPSI = getPressure( H23_PRES ); // Filter inline pressure readings - filterInlinePressureReadings( fpgaArtPres, fpgaVenPres ); + filterInlinePressureReadings( fpgaArtPres, fpgaVenPres, tmpPres); // Filter the baro pressure filterBaroPressureReadings( fpgaBaroPresPSI ); - // Get latest dialysate pressure so we can calculate TMP - tmpPressure.data = getFilteredVenousPressure() - ( getDialysatePressure() * PSI_TO_MMHG ); - // Handle pressure limits state machine execPressureLimits(); @@ -595,6 +605,7 @@ #ifndef TEST_NO_PRESSURE_CHECKS checkArterialPressureInRange(); checkVenousPressureInRange(); + checkTMPPressureInRange(); #endif return result; @@ -977,6 +988,19 @@ /*********************************************************************//** * @brief + * The getLongFilteredTMPPressure function gets the current long filtered + * trans-membrane pressure. + * @details \b Inputs: longFilteredTmpPressure + * @details \b Outputs: none + * @return the current long filtered trans-membrane pressure (in mmHg). + *************************************************************************/ +F32 getLongFilteredTMPPressure( void ) +{ + return longFilteredTmpPressure; +} + +/*********************************************************************//** + * @brief * The getBaroPressurePSI function gets the averaged barometric pressure in psi. * @details \b Inputs: baroMovingAvg.baroAvgPS * @details \b Outputs: none @@ -989,18 +1013,20 @@ /*********************************************************************//** * @brief - * The filterInlinePressureReadings function adds a new arterial and venous - * pressure sample to the filters. + * The filterInlinePressureReadings function adds a new arterial, venous and + * trans-membrane pressure sample to the filters. * @details \b Inputs: none * @details \b Outputs: artPressureReadingsLong[], artPressureReadingsLongIdx, artPressureReadingsLongTotal, artPressureReadingsLongCount, * artPressureReadingsShort, artPressureReadingsShortIdx, artPressureReadingsShortTotal, artPressureReadingsShortCount, * venPressureReadingsShort, venPressureReadingsShortIdx, venPressureReadingsShortTotal, venPressureReadingsShortCount, - * longFilteredArterialPressure, shortFilteredArterialPressure, shortFilteredVenousPressure + * longFilteredArterialPressure, shortFilteredArterialPressure, shortFilteredVenousPressure, + * tmpPressureReadingsLong[], tmpPressureReadingsLongIdx, tmpPressureReadingsLongTotal, tmpPressureReadingsLongCount * @param artPres newest arterial pressure sample to add to filters * @param venPres newest venous pressure sample to add to filter + * @param tmpPres newest trans-membrane pressure sample to add to filter * @return none *************************************************************************/ -static void filterInlinePressureReadings( F32 artPres, F32 venPres ) +static void filterInlinePressureReadings( F32 artPres, F32 venPres, F32 tmpPres ) { // Long filter for arterial pressure. if ( artPressureReadingsLongCount >= SIZE_OF_LONG_ART_ROLLING_AVG ) @@ -1045,6 +1071,18 @@ venPressureReadingsShortIdx = INC_WRAP( venPressureReadingsShortIdx, 0, SIZE_OF_SHORT_VEN_ROLLING_AVG - 1 ); venPressureReadingsShortCount = INC_CAP( artPressureReadingsShortCount, SIZE_OF_SHORT_VEN_ROLLING_AVG ); shortFilteredVenousPressure.data = venPressureReadingsShortTotal / (F32)venPressureReadingsShortCount; + + // Long filter for trans-membrane pressure + if ( tmpPressureReadingsLongCount >= SIZE_OF_LONG_TMP_ROLLING_AVG ) + { + tmpPressureReadingsLongTotal -= tmpPressureReadingsLong[ tmpPressureReadingsLongIdx ]; + } + tmpPressureReadingsLong[ tmpPressureReadingsLongIdx ] = tmpPres; + tmpPressureReadingsLongTotal += tmpPres; + tmpPressureReadingsLongIdx = INC_WRAP( tmpPressureReadingsLongIdx, 0, SIZE_OF_LONG_TMP_ROLLING_AVG - 1 ); + tmpPressureReadingsLongCount = INC_CAP( tmpPressureReadingsLongCount, SIZE_OF_LONG_TMP_ROLLING_AVG ); + longFilteredTmpPressure = tmpPressureReadingsLongTotal / (F32)tmpPressureReadingsLongCount; + tmpPressure.data = tmpPres; } /*********************************************************************//** Index: firmware/App/TDCommon.h =================================================================== diff -u -r51ef627266bf3c95d2294ce19161d0ac3d1a0cf4 -r57c5e32b2e155d728405b33ddcffb7efa440c1e8 --- firmware/App/TDCommon.h (.../TDCommon.h) (revision 51ef627266bf3c95d2294ce19161d0ac3d1a0cf4) +++ firmware/App/TDCommon.h (.../TDCommon.h) (revision 57c5e32b2e155d728405b33ddcffb7efa440c1e8) @@ -25,7 +25,7 @@ #define TD_VERSION_MAJOR 0 #define TD_VERSION_MINOR 0 #define TD_VERSION_MICRO 0 -#define TD_VERSION_BUILD 26 +#define TD_VERSION_BUILD 37 // ********** development build switches ********** @@ -36,7 +36,7 @@ // #define TEST_PINCH_VALVES 1 // Alpha unit pinch valve testing // #define TEST_DEBUGGER 1 // Testing with debugger - prevents FPGA comm alarms caused by breakpoints // #define TEST_PROCESS_TASKS_WO_UI 1 // Allow task processing even when UI not connected -// #define TEST_UI_ONLY 1 // Alpha test with TD and UI only - no DD + #define TEST_UI_ONLY 1 // Alpha test with TD and UI only - no DD // #define TEST_USE_OFF_AS_STOP_BUTTON 1 // Alpha test re-purposing off button as a stop button #define TEST_NO_PRESSURE_CHECKS 1 // Alpha test with no pressure sensor checks // #define TEST_NO_STOP_CONSUME_CHECK 1 // Alpha test with no check for stop button timeout