Index: firmware/App/Monitors/Conductivity.c =================================================================== diff -u -r313fa2d93236d6aa9de1a7e8e65c8c908e6b0c59 -rde5e503e4adc38658ac9d15cdad2b755a3ce566b --- firmware/App/Monitors/Conductivity.c (.../Conductivity.c) (revision 313fa2d93236d6aa9de1a7e8e65c8c908e6b0c59) +++ firmware/App/Monitors/Conductivity.c (.../Conductivity.c) (revision de5e503e4adc38658ac9d15cdad2b755a3ce566b) @@ -40,9 +40,8 @@ #define FP_CONDUCTIVITY_DATA_PUBLISH_COUNTER_START_COUNT 41 ///< FP Conductivity data publish counter start count. #define RO_DATA_PUBLISH_COUNTER_START_COUNT 42 ///< FP RO Data publish counter start count. #define RESISTANCE_DATA_PUBLISH_COUNTER_START_COUNT 43 ///< DD Resistance data publish counter start count. -#define CONDUCTIVITY_SAMPLE_FILTER_MS ( 70 ) ///< Filter conductivity data for given time. Currently set to have 5 samples over 3.5s ( 700ms sample rate ) #define CONDUCTIVITY_TEMP_SAMPLE_FILTER_MS ( 30 ) ///< Filter conductivity temperature data for given time. Currently set to have 5 samples over 3.5s ( 700ms sample rate ) -#define SIZE_OF_COND_ROLLING_AVG ( CONDUCTIVITY_SAMPLE_FILTER_MS / TASK_PRIORITY_INTERVAL ) ///< Filtered conductivity moving average sample count. +#define FILTER_SIZE_MULTIPLIER ( 7 ) ///< Conductivity filter size multiplier. #define SIZE_OF_COND_TEMP_ROLLING_AVG ( CONDUCTIVITY_TEMP_SAMPLE_FILTER_MS / TASK_PRIORITY_INTERVAL ) ///< Filtered conductivity temprature moving average sample count. #define RO_RR_MOVING_AVG_NUM_OF_SAMPLES 30 ///< RO rejection ratio moving average number of samples. #define FRACTION_TO_PERCENT_CONVERSION_FACTOR 100.0F ///< RO rejection ratio factor to percentage conversion factor value @@ -51,7 +50,7 @@ /// Filter conductivity readings record. typedef struct { - F32 conductivityReadings[ SIZE_OF_COND_ROLLING_AVG ]; ///< Holds conductivity sample rolling average. + F32 conductivityReadings[ FILTER_SIZE_MULTIPLIER ]; ///< Holds conductivity sample rolling average. U32 conductivityReadingsIdx; ///< Index for next sample in rolling average array. F32 conductivityReadingsTotal; ///< Rolling total - used to calc average. U32 conductivityReadingsCount; ///< Number of samples in rolling average buffer @@ -134,6 +133,7 @@ roRRAvg.ovInitData = 0.0F; roRRAvg.override = OVERRIDE_RESET; roRRSampleIntervalCounter = 0; + conductivityFilterSize = 0; memset( &roRRSamples, 0, sizeof( roRRSamples ) ); @@ -328,25 +328,16 @@ static U32 getConductivityFilterSize( void ) { F32 tdDialysateFlowRate = getTDDialysateFlowrate(); - U32 result = SIZE_OF_COND_ROLLING_AVG; + U32 result = FILTER_SIZE_MULTIPLIER; if ( tdDialysateFlowRate > NEARLY_ZERO ) { F32 balChamberSwitchingFreq = tdDialysateFlowRate / BAL_CHAMBER_FILL_VOLUME_ML; F32 balChamberSwitchingPeriod = (F32)SEC_PER_MIN / balChamberSwitchingFreq; - result = (U32)( (F32)SIZE_OF_COND_ROLLING_AVG * balChamberSwitchingPeriod ); + result = (U32)( (F32)FILTER_SIZE_MULTIPLIER * balChamberSwitchingPeriod ); } - if ( result < 1 ) - { - result = 1; - } - else if ( result > SIZE_OF_COND_ROLLING_AVG ) - { - result = SIZE_OF_COND_ROLLING_AVG; - } - return result; } @@ -366,7 +357,7 @@ { U32 readingIndex; - for ( readingIndex = 0; readingIndex < SIZE_OF_COND_ROLLING_AVG; readingIndex++ ) + for ( readingIndex = 0; readingIndex < FILTER_SIZE_MULTIPLIER; readingIndex++ ) { filteredConductivityReadings[ sensor ].conductivityReadings[ readingIndex ] = 0.0F; }