Index: firmware/App/Drivers/ConductivitySensors.c =================================================================== diff -u -r99e330b5b872f68fdf2d842bd0597e54044d9ba9 -r1d9be2f5baf7d1416ef8a79c2ed93a279738f97a --- firmware/App/Drivers/ConductivitySensors.c (.../ConductivitySensors.c) (revision 99e330b5b872f68fdf2d842bd0597e54044d9ba9) +++ firmware/App/Drivers/ConductivitySensors.c (.../ConductivitySensors.c) (revision 1d9be2f5baf7d1416ef8a79c2ed93a279738f97a) @@ -56,6 +56,19 @@ #define COND_SENSORS_FPGA_ERROR_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Conductivity sensors FPGA error timeout in milliseconds. #define COND_SENSORS_READ_ERR_MAX_CNT 255 ///< Conductivity sensors read and error count max value. +#define COND_TEMP_COMP_LOW_BOUNDS 25.0F ///< Low temperature range for temperature compensation +#define COND_TEMP_COMP_HIGH_BOUNDS 42.0F ///< High temperature range for temperature compensation +#define DIALYSATE_SENSORS_ALPHA_LOW 0.02F ///< Temp compensated low alpha value for D27, D29, D43. +#define DIALYSATE_SENSORS_ALPHA_HIGH 0.0213F ///< Temp compensated high alpha value for D27, D29, D43. +#define DIALYSATE_SENSORS_ALPHA_SLOPE 0.00007647F ///< Calculated linear slope between temp and alpha range for dialysate sensors +#define DIALYSATE_SENSORS_ALPHA_INTERCEPT 0.01808824F ///< Calculated linear intercept between temp and alpha range for dialysate sensors +#define BICARB_SENSORS_ALPHA_SLOPE 0.0001F ///< Calculated linear slope between temp and alpha range for bicarb sensors +#define BICARB_SENSORS_ALPHA_INTERCEPT 0.0186F ///< Calculated linear intercept between temp and alpha range for bicarb sensors +#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 COND_TEMP_OFFSET 25 ///< Temperature offset constant used in RTD calculations. #define SIEMENS_TO_MICROSIEMENS_CONVERSION 1000000.0F ///< Siemens to microSiemens conversion factor. #define KOHMS_TO_OHMS 1000.0F ///< Kilo ohms to ohms conversion factor. @@ -75,6 +88,7 @@ F32 rawResistance; ///< Raw Resistance in kOhms from the conductivity sensor. F32 calculatedTemperature; ///< Calculated temperature in C. F32 calculatedResistance; ///< Calculated resistance in Ohms. + F32 currentAlphaValue; ///< Last used alpha value in temperature compensation. U08 condReadCount; ///< Last conductivity read count. U08 condErrorCount; ///< Last conductivity error count. U08 tempReadCount; ///< Last temperature read count. @@ -90,6 +104,7 @@ // ********** private data ********** static CONDUCTIVITY_STATE_T currentConductivityState; ///< Current conductivity sensor state. +static OVERRIDE_F32_T currentUncompenstatedConductivityReadings[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< TODO: Get Vinay or Sean to tell me to remove this debug array in CR. static OVERRIDE_F32_T currentConductivityReadings[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< Current conductivity sensor conductivity readings (overrideable). static OVERRIDE_F32_T currentTemperatureReadings[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< Current conductivity sensor temperature readings (overrideable). static OVERRIDE_U32_T lastConductivityReadCounter[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< Last conductivity sensor read count (Overrideable). @@ -111,7 +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 ); @@ -130,6 +145,11 @@ // Initialize override structures for each conductivity sensor for ( sensor = FIRST_DD_COND_SENSOR; sensor < NUM_OF_CONDUCTIVITY_SENSORS; sensor++ ) { + currentUncompenstatedConductivityReadings[ sensor ].data = 0.0F; + currentUncompenstatedConductivityReadings[ sensor ].ovData = 0.0F; + currentUncompenstatedConductivityReadings[ sensor ].ovInitData = 0.0F; + currentUncompenstatedConductivityReadings[ sensor ].override = OVERRIDE_RESET; + currentConductivityReadings[ sensor ].data = 0.0F; currentConductivityReadings[ sensor ].ovData = 0.0F; currentConductivityReadings[ sensor ].ovInitData = 0.0F; @@ -537,8 +557,7 @@ { isFPSensor = TRUE; } - - calculateConductivityUpdatedStandard( sensor, isFPSensor ); + calculateConductivityUpdatedStandardTempCompensated( sensor, isFPSensor ); } return state; @@ -872,6 +891,35 @@ /*********************************************************************//** * @brief + * The getUncompensatedConductivity function gets the conductivity + * value for a given conductivity sensor id. + * @details \b Inputs: currentUncompenstatedConductivityReadings[] + * @details \b Outputs: none + * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT if given sensor is invalid. + * @param sensorId conductivity sensor id + * @return conductivity value + *************************************************************************/ +F32 getUncompensatedConductivity( CONDUCTIVITY_SENSORS_T sensor ) +{ + F32 result = 0.0F; + + if ( sensor < NUM_OF_CONDUCTIVITY_SENSORS ) + { + result = currentUncompenstatedConductivityReadings[ sensor ].data; + if ( OVERRIDE_KEY == currentUncompenstatedConductivityReadings[ sensor ].override ) + { + result = currentUncompenstatedConductivityReadings[ sensor ].ovData; + } + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_CONDUCTIVITY_SENSOR_ID, sensor ) + } + + return result; +} +/*********************************************************************//** + * @brief * The getConductivityTemperatureValue function gets the temperature * value for a given conductivity sensor id. * @details \b Inputs: currentTemperatureReadings[] @@ -954,36 +1002,70 @@ /*********************************************************************//** * @brief - * The calculateConductivityUpdatedStandard function calculates the conductivity value. + * The calculateConductivityUpdatedStandardTempCompensated function calculates the conductivity value with temperature compensation. * @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 ) +static void calculateConductivityUpdatedStandardTempCompensated( 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; + conductivitySensorStatus[ sensorNum ].currentAlphaValue = RO_SENSORS_ALPHA; } else { - alpha = conductivitySensorCoefficients[ sensorNum ].alpha_high; k = conductivitySensorCoefficients[ sensorNum ].K_high; + + switch ( sensorNum ) + { + case D74_COND: + case D17_COND: + // check temp range and apply alpha + if ( conductivitySensorStatus[ sensorNum ].calculatedTemperature < COND_TEMP_COMP_LOW_BOUNDS ) + { + conductivitySensorStatus[ sensorNum ].currentAlphaValue = BICARB_SENSORS_ALPHA_LOW; + } + 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 ) + { + conductivitySensorStatus[ sensorNum ].currentAlphaValue = DIALYSATE_SENSORS_ALPHA_HIGH; + } + else + { + conductivitySensorStatus[ sensorNum ].currentAlphaValue = TEMP_COMP_LINEAR( DIALYSATE_SENSORS_ALPHA_SLOPE, DIALYSATE_SENSORS_ALPHA_INTERCEPT, conductivitySensorStatus[ sensorNum ].calculatedTemperature ); + } + break; + } } calculateResistance( sensorNum, isFPSensor ); calculateTemperature( sensorNum ); calculatedConductivity = ( ( k / conductivitySensorStatus[ sensorNum ].calculatedResistance ) * - ( 1 + ( alpha * ( COND_TEMP_OFFSET - conductivitySensorStatus[ sensorNum ].calculatedTemperature ) ) ) ); + ( 1 + ( conductivitySensorStatus[ sensorNum ].currentAlphaValue * ( COND_TEMP_OFFSET - conductivitySensorStatus[ sensorNum ].calculatedTemperature ) ) ) ); currentConductivityReadings[ sensorNum ].data = calculatedConductivity * SIEMENS_TO_MICROSIEMENS_CONVERSION; } Index: firmware/App/Monitors/Conductivity.c =================================================================== diff -u -rdfbd800e10847db992bd6a9981c26d1f8d763c6f -r1d9be2f5baf7d1416ef8a79c2ed93a279738f97a --- firmware/App/Monitors/Conductivity.c (.../Conductivity.c) (revision dfbd800e10847db992bd6a9981c26d1f8d763c6f) +++ firmware/App/Monitors/Conductivity.c (.../Conductivity.c) (revision 1d9be2f5baf7d1416ef8a79c2ed93a279738f97a) @@ -89,9 +89,7 @@ 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 U32 conductivityFilterSize; ///< Active conductivity filter sample count. -static OVERRIDE_U32_T conductivityResistanceDataPublishInterval; ///< DD and FP Conductivity sensors publish time interval override. // ********** private function prototypes ********** @@ -101,7 +99,6 @@ static void filterConductivitySensorTemperatureReadings( void ); static void calcRORejectionRatio( void ); static void filterRORejectionRatioReadings( void ); -static void broadcastResistanceData( void ); static U32 getConductivityFilterSize( void ); static void resetConductivityFilterReadings( void ); @@ -122,7 +119,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; @@ -141,6 +137,7 @@ // Initialize override structures for each conductivity sensor for ( sensor = FIRST_DD_COND_SENSOR; sensor < NUM_OF_CONDUCTIVITY_SENSORS; sensor++ ) { + filteredcurrentConductivityReadings[ sensor ].data = 0.0F; filteredcurrentConductivityReadings[ sensor ].ovData = 0.0F; filteredcurrentConductivityReadings[ sensor ].ovInitData = 0.0F; @@ -178,11 +175,6 @@ 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; - } /*********************************************************************//** @@ -314,6 +306,7 @@ filteredConductivityReadings[ sensor ].conductivityReadingsIdx = INC_WRAP( filteredConductivityReadings[ sensor ].conductivityReadingsIdx, 0, conductivityFilterSize - 1 ); filteredConductivityReadings[ sensor ].conductivityReadingsCount = INC_CAP( filteredConductivityReadings[ sensor ].conductivityReadingsCount, conductivityFilterSize ); filteredcurrentConductivityReadings[ sensor ].data = filteredConductivityReadings[ sensor ].conductivityReadingsTotal / (F32)filteredConductivityReadings[ sensor ].conductivityReadingsCount; + } } } @@ -611,6 +604,16 @@ 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 ); ddConductivityPublishTimerCounter = 0; broadcastData( MSG_ID_DD_CONDUCTIVITY_DATA, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&data, sizeof( DD_CONDUCTIVITY_DATA_T ) ); @@ -623,6 +626,10 @@ 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 ); fpConductivityPublishTimerCounter = 0; broadcastData( MSG_ID_FP_CONDUCTIVITY_DATA, COMM_BUFFER_OUT_CAN_FP_BROADCAST, (U08*)&data, sizeof( FP_CONDUCTIVITY_DATA_T ) ); @@ -643,49 +650,8 @@ 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 *************************************************************************/