Index: firmware/App/Monitors/Conductivity.c =================================================================== diff -u -r145fd716a856f864f39fb0f9884865f6e45b9256 -r44d7a987b5c6b91396ddb2cc8163b36c21f59bde --- firmware/App/Monitors/Conductivity.c (.../Conductivity.c) (revision 145fd716a856f864f39fb0f9884865f6e45b9256) +++ firmware/App/Monitors/Conductivity.c (.../Conductivity.c) (revision 44d7a987b5c6b91396ddb2cc8163b36c21f59bde) @@ -69,6 +69,8 @@ static U08 condPrevReadCount[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< Previous read count for conductivity per sensor static U08 condTempPrevReadCount[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< Previous read count for temperature per sensor. static FILTER_CONDUCTIVITY_READINGS_T filteredConductivityReadings[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< Filtered conductivity reading for conductivity sensors. +static FILTER_CONDUCTIVITY_READINGS_T filteredUConductivityReadings[ NUM_OF_CONDUCTIVITY_SENSORS ]; +static OVERRIDE_F32_T filteredcurrentUConductivityReadings[ NUM_OF_CONDUCTIVITY_SENSORS ]; static OVERRIDE_F32_T filteredcurrentConductivityReadings[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< filtered current conductivity sensor conductivity readings (overrideable). static FILTER_CONDUCTIVITY_TEMPERATURE_READINGS_T filteredConductivityTemperatureReadings[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< Filtered temperature reading for conductivity sensors. static OVERRIDE_F32_T filteredcurrentTemperatureReadings[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< filtered current conductivity sensor temperature readings (overrideable). @@ -135,6 +137,15 @@ // Initialize override structures for each conductivity sensor for ( sensor = FIRST_DD_COND_SENSOR; sensor < NUM_OF_CONDUCTIVITY_SENSORS; sensor++ ) { + filteredcurrentUConductivityReadings[ sensor ].data = 0.0F; + filteredcurrentUConductivityReadings[ sensor ].ovData = 0.0F; + filteredcurrentUConductivityReadings[ sensor ].ovInitData = 0.0F; + filteredcurrentUConductivityReadings[ sensor ].override = OVERRIDE_RESET; + + filteredUConductivityReadings[ sensor ].conductivityReadingsIdx = 0; + filteredUConductivityReadings[ sensor ].conductivityReadingsTotal = 0.0F; + filteredUConductivityReadings[ sensor ].conductivityReadingsCount = 0; + filteredcurrentConductivityReadings[ sensor ].data = 0.0F; filteredcurrentConductivityReadings[ sensor ].ovData = 0.0F; filteredcurrentConductivityReadings[ sensor ].ovInitData = 0.0F; @@ -259,6 +270,7 @@ { CONDUCTIVITY_SENSORS_T sensor; F32 calculatedConductivity = 0.0F; + F32 uncompenstatedConductivity = 0.0F; BOOL freshData = FALSE; for ( sensor = FIRST_DD_COND_SENSOR; sensor < NUM_OF_CONDUCTIVITY_SENSORS; sensor++ ) @@ -282,6 +294,7 @@ if ( condPrevReadCount[ sensor ] != getConductivityReadCount( sensor ) ) { calculatedConductivity = getConductivity( sensor ); + uncompenstatedConductivity = getUncompensatedConductivity( sensor ); condPrevReadCount[ sensor ] = getConductivityReadCount( sensor ); freshData = TRUE; } @@ -301,6 +314,17 @@ filteredConductivityReadings[ sensor ].conductivityReadingsIdx = INC_WRAP( filteredConductivityReadings[ sensor ].conductivityReadingsIdx, 0, SIZE_OF_COND_ROLLING_AVG - 1 ); filteredConductivityReadings[ sensor ].conductivityReadingsCount = INC_CAP( filteredConductivityReadings[ sensor ].conductivityReadingsCount, SIZE_OF_COND_ROLLING_AVG ); filteredcurrentConductivityReadings[ sensor ].data = filteredConductivityReadings[ sensor ].conductivityReadingsTotal / (F32)filteredConductivityReadings[ sensor ].conductivityReadingsCount; + + if ( filteredUConductivityReadings[ sensor ].conductivityReadingsCount >= SIZE_OF_COND_ROLLING_AVG ) + { + filteredUConductivityReadings[ sensor ].conductivityReadingsTotal -= filteredUConductivityReadings[ sensor ].conductivityReadings[ filteredUConductivityReadings[ sensor ].conductivityReadingsIdx ]; + } + filteredUConductivityReadings[ sensor ].conductivityReadings[ filteredUConductivityReadings[ sensor ].conductivityReadingsIdx ] = uncompenstatedConductivity; + filteredUConductivityReadings[ sensor ].conductivityReadingsTotal += uncompenstatedConductivity; + filteredUConductivityReadings[ sensor ].conductivityReadingsIdx = INC_WRAP( filteredUConductivityReadings[ sensor ].conductivityReadingsIdx, 0, SIZE_OF_COND_ROLLING_AVG - 1 ); + filteredUConductivityReadings[ sensor ].conductivityReadingsCount = INC_CAP( filteredUConductivityReadings[ sensor ].conductivityReadingsCount, SIZE_OF_COND_ROLLING_AVG ); + filteredcurrentUConductivityReadings[ sensor ].data = filteredUConductivityReadings[ sensor ].conductivityReadingsTotal / (F32)filteredUConductivityReadings[ sensor ].conductivityReadingsCount; + } } }