Index: firmware/App/Drivers/ConductivitySensors.c =================================================================== diff -u -r1d9be2f5baf7d1416ef8a79c2ed93a279738f97a -r6bccc0b74d3d04fd702709aec11632cacdc5b98e --- firmware/App/Drivers/ConductivitySensors.c (.../ConductivitySensors.c) (revision 1d9be2f5baf7d1416ef8a79c2ed93a279738f97a) +++ firmware/App/Drivers/ConductivitySensors.c (.../ConductivitySensors.c) (revision 6bccc0b74d3d04fd702709aec11632cacdc5b98e) @@ -67,7 +67,7 @@ #define BICARB_SENSORS_ALPHA_LOW 0.0211F ///< Temp compensated low alpha value for D17 and D74. #define BICARB_SENSORS_ALPHA_HIGH 0.0228F ///< Temp compensated high alpha value for D17 and D74. #define RO_SENSORS_ALPHA 0.02F ///< Temp compensated alpha value for P9, P18 with RO water. -#define TEMP_COMP_LINEAR(slope, intercept, temp) ( ( slope * temp ) + intercept ) ///< Line equation for temp +#define TEMP_COMP_LINEAR(slope, intercept, temp) ( ( slope * temp ) + intercept ) ///< Line equation for temp #define COND_TEMP_OFFSET 25 ///< Temperature offset constant used in RTD calculations. #define SIEMENS_TO_MICROSIEMENS_CONVERSION 1000000.0F ///< Siemens to microSiemens conversion factor. @@ -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 @@ -1033,23 +1069,22 @@ { conductivitySensorStatus[ sensorNum ].currentAlphaValue = BICARB_SENSORS_ALPHA_LOW; } - else if( conductivitySensorStatus[ sensorNum ].calculatedTemperature > COND_TEMP_COMP_LOW_BOUNDS ) + else if ( conductivitySensorStatus[ sensorNum ].calculatedTemperature > COND_TEMP_COMP_LOW_BOUNDS ) { conductivitySensorStatus[ sensorNum ].currentAlphaValue = BICARB_SENSORS_ALPHA_HIGH; } else { conductivitySensorStatus[ sensorNum ].currentAlphaValue = TEMP_COMP_LINEAR( BICARB_SENSORS_ALPHA_SLOPE, BICARB_SENSORS_ALPHA_INTERCEPT, conductivitySensorStatus[ sensorNum ].calculatedTemperature ); } - break; default: // check temp range and apply alpha if ( conductivitySensorStatus[ sensorNum ].calculatedTemperature < COND_TEMP_COMP_LOW_BOUNDS ) { conductivitySensorStatus[ sensorNum ].currentAlphaValue = DIALYSATE_SENSORS_ALPHA_LOW; } - else if( conductivitySensorStatus[ sensorNum ].calculatedTemperature > COND_TEMP_COMP_LOW_BOUNDS ) + else if ( conductivitySensorStatus[ sensorNum ].calculatedTemperature > COND_TEMP_COMP_LOW_BOUNDS ) { conductivitySensorStatus[ sensorNum ].currentAlphaValue = DIALYSATE_SENSORS_ALPHA_HIGH; } Index: firmware/App/Monitors/Conductivity.c =================================================================== diff -u -r1d9be2f5baf7d1416ef8a79c2ed93a279738f97a -r6bccc0b74d3d04fd702709aec11632cacdc5b98e --- firmware/App/Monitors/Conductivity.c (.../Conductivity.c) (revision 1d9be2f5baf7d1416ef8a79c2ed93a279738f97a) +++ firmware/App/Monitors/Conductivity.c (.../Conductivity.c) (revision 6bccc0b74d3d04fd702709aec11632cacdc5b98e) @@ -68,27 +68,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 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. static U32 conductivityFilterSize; ///< Active conductivity filter sample count. // ********** private function prototypes ********** @@ -137,7 +139,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; @@ -174,7 +184,6 @@ roRRDataPublishInterval.ovData = COND_SENSOR_REPORT_PERIOD; roRRDataPublishInterval.ovInitData = 0; roRRDataPublishInterval.override = OVERRIDE_RESET; - } /*********************************************************************//** @@ -247,6 +256,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[] @@ -287,6 +325,7 @@ if ( condPrevReadCount[ sensor ] != getConductivityReadCount( sensor ) ) { calculatedConductivity = getConductivity( sensor ); + uncompenstatedConductivity = getUncompensatedConductivity( sensor ); condPrevReadCount[ sensor ] = getConductivityReadCount( sensor ); freshData = TRUE; } @@ -307,6 +346,16 @@ filteredConductivityReadings[ sensor ].conductivityReadingsCount = INC_CAP( filteredConductivityReadings[ sensor ].conductivityReadingsCount, conductivityFilterSize ); 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; + } } } @@ -604,16 +653,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.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 ) ); @@ -626,10 +681,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.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 ) ); @@ -649,9 +706,9 @@ broadcastData( MSG_ID_FP_RO_REJECTION_RATIO_DATA, COMM_BUFFER_OUT_CAN_FP_BROADCAST, (U08*)&data, sizeof( RO_REJECTION_RATIO_DATA_T ) ); } - } + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/