Index: firmware/App/Monitors/Conductivity.c =================================================================== diff -u -r145fd716a856f864f39fb0f9884865f6e45b9256 -rd47b9bcbd4796a8c51d9e87436422c5868292ac6 --- firmware/App/Monitors/Conductivity.c (.../Conductivity.c) (revision 145fd716a856f864f39fb0f9884865f6e45b9256) +++ firmware/App/Monitors/Conductivity.c (.../Conductivity.c) (revision d47b9bcbd4796a8c51d9e87436422c5868292ac6) @@ -7,8 +7,8 @@ * * @file Conductivity.c * -* @author (last) Sameer Kalliadan Poyil -* @date (last) 16-Jun-2026 +* @author (last) Michael Garthwaite +* @date (last) 08-Jul-2026 * * @author (original) Vinayakam Mani * @date (original) 13-Sep-2024 @@ -66,29 +66,29 @@ // ********** private data ********** -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 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). -static U32 ddConductivityPublishTimerCounter; ///< DD Conductivity data publication counter. -static OVERRIDE_U32_T ddConductivityDataPublishInterval; ///< DD Conductivity sensors publish time interval override. -static U32 fpConductivityPublishTimerCounter; ///< FP Conductivity data publication counter. -static OVERRIDE_U32_T fpConductivityDataPublishInterval; ///< FP Conductivity sensors publish time interval override. -static F32 roRejectionRatio; ///< All time RO rejection ratio. -static F32 roRejectionRatioTankFill; ///< RO rejection ratio during permeate tank fill state. -static U32 roRRPublishTimerCounter; ///< RO rejection ratio publication counter. -static OVERRIDE_U32_T roRRDataPublishInterval; ///< RO rejection ratio publish time interval override. -static OVERRIDE_F32_T roRRAvg; ///< Average RO rejection ratio. -static F32 roRRRunningSum; ///< RO rejection ratio running sum. -static F32 roRRSamples[ RO_RR_MOVING_AVG_NUM_OF_SAMPLES ]; ///< RO rejection ratio samples array. -static U32 roRRSamplesNextIndex; ///< RO rejection ratio sample next index number. -static U32 roRRCount; ///< RO rejection ratio Number of samples in average buffer. -static F32 roRRTankFillAvg; ///< Average RO rejection ratio during permeate tank fill state. -static U32 roRRSampleIntervalCounter; ///< RO rejection ratio sample collection timer counter. -static U32 conductivityResistancePublishTimerCounter; ///< DD and FP Conductivity data publication counter. -static OVERRIDE_U32_T conductivityResistanceDataPublishInterval; ///< DD and FP Conductivity sensors publish time interval override. +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 ]; ///< Filtered conductivity readings without temperature compensation +static OVERRIDE_F32_T filteredcurrentUConductivityReadings[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< Filtered current conductivity sensor conductivity readings (overrideable). +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). +static U32 ddConductivityPublishTimerCounter; ///< DD Conductivity data publication counter. +static OVERRIDE_U32_T ddConductivityDataPublishInterval; ///< DD Conductivity sensors publish time interval override. +static U32 fpConductivityPublishTimerCounter; ///< FP Conductivity data publication counter. +static OVERRIDE_U32_T fpConductivityDataPublishInterval; ///< FP Conductivity sensors publish time interval override. +static F32 roRejectionRatio; ///< All time RO rejection ratio. +static F32 roRejectionRatioTankFill; ///< RO rejection ratio during permeate tank fill state. +static U32 roRRPublishTimerCounter; ///< RO rejection ratio publication counter. +static OVERRIDE_U32_T roRRDataPublishInterval; ///< RO rejection ratio publish time interval override. +static OVERRIDE_F32_T roRRAvg; ///< Average RO rejection ratio. +static F32 roRRRunningSum; ///< RO rejection ratio running sum. +static F32 roRRSamples[ RO_RR_MOVING_AVG_NUM_OF_SAMPLES ]; ///< RO rejection ratio samples array. +static U32 roRRSamplesNextIndex; ///< RO rejection ratio sample next index number. +static U32 roRRCount; ///< RO rejection ratio Number of samples in average buffer. +static F32 roRRTankFillAvg; ///< Average RO rejection ratio during permeate tank fill state. +static U32 roRRSampleIntervalCounter; ///< RO rejection ratio sample collection timer counter. // ********** private function prototypes ********** @@ -98,7 +98,6 @@ static void filterConductivitySensorTemperatureReadings( void ); static void calcRORejectionRatio( void ); static void filterRORejectionRatioReadings( void ); -static void broadcastResistanceData( void ); /*********************************************************************//** * @brief @@ -117,7 +116,6 @@ ddConductivityPublishTimerCounter = DD_CONDUCTIVITY_DATA_PUBLISH_COUNTER_START_COUNT; fpConductivityPublishTimerCounter = FP_CONDUCTIVITY_DATA_PUBLISH_COUNTER_START_COUNT; roRRPublishTimerCounter = RO_DATA_PUBLISH_COUNTER_START_COUNT; - conductivityResistancePublishTimerCounter = RESISTANCE_DATA_PUBLISH_COUNTER_START_COUNT; roRejectionRatio = 0.0F; roRejectionRatioTankFill = 0.0F; roRRRunningSum = 0.0F; @@ -135,6 +133,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; @@ -171,12 +178,6 @@ roRRDataPublishInterval.ovData = COND_SENSOR_REPORT_PERIOD; roRRDataPublishInterval.ovInitData = 0; roRRDataPublishInterval.override = OVERRIDE_RESET; - - conductivityResistanceDataPublishInterval.data = COND_SENSOR_REPORT_PERIOD; - conductivityResistanceDataPublishInterval.ovData = COND_SENSOR_REPORT_PERIOD; - conductivityResistanceDataPublishInterval.ovInitData = 0; - conductivityResistanceDataPublishInterval.override = OVERRIDE_RESET; - } /*********************************************************************//** @@ -249,6 +250,35 @@ /*********************************************************************//** * @brief + * The getFilteredUConductivity function gets the filtered current conductivity (in uS/cm) + * for a given conductivity sensor. + * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT if given sensor is invalid. + * @details \b Inputs: filteredcurrentConductivityReadings[] + * @details \b Outputs: none + * @param sensor ID of conductivity sensor to get filtered conductivity reading for. + * @return The filtered current conductivity (in uS/cm) for the given conductivity sensor + *************************************************************************/ +F32 getFilteredUConductivity( CONDUCTIVITY_SENSORS_T sensor ) +{ + F32 result = 0.0F; + + if ( sensor < NUM_OF_CONDUCTIVITY_SENSORS ) + { + result = filteredcurrentUConductivityReadings[ sensor ].data; + if ( OVERRIDE_KEY == filteredcurrentUConductivityReadings[ sensor ].override ) + { + result = filteredcurrentUConductivityReadings[ sensor ].ovData; + } + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_FILTERED_CONDUCTIVITY_SENSOR_ID, (U32)sensor ) + } + + return result; +} +/*********************************************************************//** + * @brief * The filterConductivitySensorReadings function filters the conductivity rates for * defined interval to get average conductivity rates. * @details \b Inputs: filteredConductivityReadings[] @@ -259,6 +289,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 +313,7 @@ if ( condPrevReadCount[ sensor ] != getConductivityReadCount( sensor ) ) { calculatedConductivity = getConductivity( sensor ); + uncompenstatedConductivity = getUncompensatedConductivity( sensor ); condPrevReadCount[ sensor ] = getConductivityReadCount( sensor ); freshData = TRUE; } @@ -301,6 +333,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; + } } } @@ -529,6 +572,22 @@ data.d29Cond = getFilteredConductivity( D29_COND ); data.d43Cond = getFilteredConductivity( D43_COND ); data.d74Cond = getFilteredConductivity( D74_COND ); + data.d17CondResist = getConductivityRawResistance( D17_COND ); + data.d27CondResist = getConductivityRawResistance( D27_COND ); + data.d29CondResist = getConductivityRawResistance( D29_COND ); + data.d43CondResist = getConductivityRawResistance( D43_COND ); + data.d74CondResist = getConductivityRawResistance( D74_COND ); + data.d17RTDResist = getConductivityRawRTD( D17_COND ); + data.d27RTDResist = getConductivityRawRTD( D27_COND ); + data.d29RTDResist = getConductivityRawRTD( D29_COND ); + data.d43RTDResist = getConductivityRawRTD( D43_COND ); + data.d74RTDResist = getConductivityRawRTD( D74_COND ); + data.d17CondUncomp = getFilteredUConductivity( D17_COND ); + data.d27CondUncomp = getFilteredUConductivity( D27_COND ); + data.d29CondUncomp = getFilteredUConductivity( D29_COND ); + data.d43CondUncomp = getFilteredUConductivity( D43_COND ); + data.d74CondUncomp = getFilteredUConductivity( D74_COND ); + ddConductivityPublishTimerCounter = 0; broadcastData( MSG_ID_DD_CONDUCTIVITY_DATA, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&data, sizeof( DD_CONDUCTIVITY_DATA_T ) ); @@ -541,6 +600,12 @@ data.p9Conductivity = getFilteredConductivity( P9_COND ); data.p18Conductivity = getFilteredConductivity( P18_COND ); + data.p9CondResist = getConductivityRawResistance( P9_COND ); + data.p18CondResist = getConductivityRawResistance( P18_COND ); + data.p9RTDResist = getConductivityRawRTD( P9_COND ); + data.p18RTDResist = getConductivityRawRTD( P18_COND ); + data.p9CondUncomp = getFilteredUConductivity( P9_COND ); + data.p18CondUncomp = getFilteredUConductivity( P18_COND ); fpConductivityPublishTimerCounter = 0; broadcastData( MSG_ID_FP_CONDUCTIVITY_DATA, COMM_BUFFER_OUT_CAN_FP_BROADCAST, (U08*)&data, sizeof( FP_CONDUCTIVITY_DATA_T ) ); @@ -560,50 +625,9 @@ broadcastData( MSG_ID_FP_RO_REJECTION_RATIO_DATA, COMM_BUFFER_OUT_CAN_FP_BROADCAST, (U08*)&data, sizeof( RO_REJECTION_RATIO_DATA_T ) ); } - - if ( FALSE == getTestConfigStatus( TEST_CONFIG_DD_FP_ENABLE_BETA_1_9_HW ) ) - { - // publish conductivity resistance data on interval - if ( ++conductivityResistancePublishTimerCounter >= getU32OverrideValue( &conductivityResistanceDataPublishInterval ) ) - { - broadcastResistanceData(); - } - } } -/*********************************************************************//** - * @brief - * The broadcastResistanceData function publishes DD resistance data. - * @details \b Inputs: conductivityResistancePublishTimerCounter - * @details \b Outputs: resistance data - * roRRPublishTimerCounter, DD & FP resistance data is sent - * @details \b Message \b Sent: MSG_ID_DD_CONDUCTIVITY_SENSOR_RESISTANCE_DATA to publish DD resistance data. - * @return none - *************************************************************************/ -static void broadcastResistanceData( void ) -{ - CONDUCTIVITY_RESISTANCE_DATA_T data; - data.d17CondResist = getConductivityRawResistance( D17_COND ); - data.d27CondResist = getConductivityRawResistance( D27_COND ); - data.d29CondResist = getConductivityRawResistance( D29_COND ); - data.d43CondResist = getConductivityRawResistance( D43_COND ); - data.d74CondResist = getConductivityRawResistance( D74_COND ); - data.p9CondResist = getConductivityRawResistance( P9_COND ); - data.p18CondResist = getConductivityRawResistance( P18_COND ); - data.d17RTDResist = getConductivityRawRTD( D17_COND ); - data.d27RTDResist = getConductivityRawRTD( D27_COND ); - data.d29RTDResist = getConductivityRawRTD( D29_COND ); - data.d43RTDResist = getConductivityRawRTD( D43_COND ); - data.d74RTDResist = getConductivityRawRTD( D74_COND ); - data.p9RTDResist = getConductivityRawRTD( P9_COND ); - data.p18RTDResist = getConductivityRawRTD( P18_COND ); - conductivityResistancePublishTimerCounter = 0; - - broadcastData( MSG_ID_DD_CONDUCTIVITY_SENSOR_RESISTANCE_DATA, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&data, sizeof( CONDUCTIVITY_RESISTANCE_DATA_T ) ); - -} - /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/