Index: firmware/App/Drivers/ConductivitySensors.c =================================================================== diff -u -re9a789e5cf3e0da840ccd0227fdd482ab5ed338d -r0ad3c0f2ae387408c3ec608c0ac186c801591ee2 --- firmware/App/Drivers/ConductivitySensors.c (.../ConductivitySensors.c) (revision e9a789e5cf3e0da840ccd0227fdd482ab5ed338d) +++ firmware/App/Drivers/ConductivitySensors.c (.../ConductivitySensors.c) (revision 0ad3c0f2ae387408c3ec608c0ac186c801591ee2) @@ -126,6 +126,7 @@ static U32 getTemperatureSensorErrorCount( CONDUCTIVITY_SENSORS_T sensor ); static BOOL monitorCalDataReads( CONDUCTIVITY_SENSORS_T sensorId ); static BOOL checkConductivityCoefficientRanges( CONDUCTIVITY_SENSORS_T sensorId ); +static void calculateConductivityUpdatedStandard( CONDUCTIVITY_SENSORS_T sensorNum, BOOL isFPSensor ); static void calculateConductivityUpdatedStandardTempCompensated( CONDUCTIVITY_SENSORS_T sensorNum, BOOL isFPSensor ); static void calculateTemperature( CONDUCTIVITY_SENSORS_T sensorNum ); static void calculateResistance( CONDUCTIVITY_SENSORS_T sensorNum, BOOL isFPSensor ); @@ -557,6 +558,7 @@ { isFPSensor = TRUE; } + calculateConductivityUpdatedStandard( sensor, isFPSensor ); calculateConductivityUpdatedStandardTempCompensated( sensor, isFPSensor ); } @@ -1002,6 +1004,40 @@ /*********************************************************************//** * @brief + * The calculateConductivityUpdatedStandard function calculates the conductivity value. + * @details \b Inputs: conductivitySensorCoefficients - Conductivity Coefficients + * @details \b Inputs: conductivitySensorStatus - Raw measurement values + * @details \b Outputs: conductivitySensorStatus - calculated conductivity value + * @param sensorNum - Conductivity sensor index value. + * @param isFPSensor - T/F if sensor is on FP hardware. + * @return + *************************************************************************/ +static void calculateConductivityUpdatedStandard( CONDUCTIVITY_SENSORS_T sensorNum, BOOL isFPSensor ) +{ + F64 calculatedConductivity = 0.0; + F64 alpha = 0.0; + F64 k = 0.0; + + if ( TRUE == isFPSensor ) + { + alpha = conductivitySensorCoefficients[ sensorNum ].alpha_low; + k = conductivitySensorCoefficients[ sensorNum ].K_low; + } + else + { + alpha = conductivitySensorCoefficients[ sensorNum ].alpha_high; + k = conductivitySensorCoefficients[ sensorNum ].K_high; + } + calculateResistance( sensorNum, isFPSensor ); + calculateTemperature( sensorNum ); + + calculatedConductivity = ( ( k / conductivitySensorStatus[ sensorNum ].calculatedResistance ) * + ( 1 + ( alpha * ( COND_TEMP_OFFSET - conductivitySensorStatus[ sensorNum ].calculatedTemperature ) ) ) ); + currentConductivityReadings[ sensorNum ].data = calculatedConductivity * SIEMENS_TO_MICROSIEMENS_CONVERSION; +} + +/*********************************************************************//** + * @brief * The calculateConductivityUpdatedStandardTempCompensated function calculates the conductivity value with temperature compensation. * @details \b Inputs: conductivitySensorCoefficients - Conductivity Coefficients * @details \b Inputs: conductivitySensorStatus - Raw measurement values Index: firmware/App/Monitors/Conductivity.c =================================================================== diff -u -r14277e7c55fbb8407612572aca191ffae0835796 -r0ad3c0f2ae387408c3ec608c0ac186c801591ee2 --- firmware/App/Monitors/Conductivity.c (.../Conductivity.c) (revision 14277e7c55fbb8407612572aca191ffae0835796) +++ firmware/App/Monitors/Conductivity.c (.../Conductivity.c) (revision 0ad3c0f2ae387408c3ec608c0ac186c801591ee2) @@ -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). @@ -87,6 +89,8 @@ 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. // ********** private function prototypes ********** @@ -96,6 +100,7 @@ static void filterConductivitySensorTemperatureReadings( void ); static void calcRORejectionRatio( void ); static void filterRORejectionRatioReadings( void ); +static void broadcastResistanceData( void ); /*********************************************************************//** * @brief @@ -114,6 +119,7 @@ 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; @@ -131,7 +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; @@ -169,6 +183,11 @@ 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; + } /*********************************************************************//** @@ -275,6 +294,7 @@ if ( condPrevReadCount[ sensor ] != getConductivityReadCount( sensor ) ) { calculatedConductivity = getConductivity( sensor ); + uncompenstatedConductivity = getUncompensatedConductivity( sensor ); condPrevReadCount[ sensor ] = getConductivityReadCount( sensor ); freshData = TRUE; } @@ -295,6 +315,16 @@ 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; + } } }