Index: firmware/App/Controllers/TemperatureSensors.c =================================================================== diff -u -r61e5717c3410c16144d49351e727fae0992e45d2 -rc38c6d64b5f4df1fe08e2daabb37d3a7a483a4be --- firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 61e5717c3410c16144d49351e727fae0992e45d2) +++ firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision c38c6d64b5f4df1fe08e2daabb37d3a7a483a4be) @@ -39,17 +39,19 @@ #define PRIMARY_HEATER_EXT_TEMP_SENSORS_GAIN 8U ///< Primary heater external temperature sensors gain. #define PRIMARY_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE 20000 ///< Primary heater external temperature sensors reference resistance. #define PRIMARY_HEATER_EXT_TEMP_SENSORS_0_DEGREE_RESISTANCE 1000U ///< Primary heater external temperature sensors zero degree resistance. +#define PRIMARY_HEATER_EXT_TEMP_SENSORS_V3_REF_RESISTANCE 19600 ///< Primary heater external temperature sensors V3 reference resistance. #define COND_SENSORS_TEMP_SENSOR_GAIN 8U ///< Temperature sensor for conductivity gain. #define COND_SENSORS_TEMP_SENSOR_REF_RESISTANCE 20000 ///< Temperature sensor for conductivity reference resistance. #define COND_SENSORS_TEMP_SENSOR_0_DEGREE_RESISTANCE 1000U ///< Temperature sensor for conductivity zero degree resistance. +#define COND_SENSORS_TEMP_SENSOR_V3_REF_RESISTANCE 19600 ///< Temperature sensor for conductivity V3 reference resistance. #define TRIMMER_HEATER_EXT_TEMP_SENSORS_GAIN 32U ///< Trimmer heater external temperature sensors gain. -#define TRIMMER_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE 4990U ///< Trimmer heater external temperature sensors reference resistance. +#define TRIMMER_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE 4990 ///< Trimmer heater external temperature sensors reference resistance. #define TRIMMER_HEATER_EXT_TEMP_SENSORS_0_DEGREE_RESISTANCE 100U ///< Trimmer heater external temperature sensors zero degree resistance. +#define TRIMMER_HEATER_EXT_TEMP_SENSORS_V3_REF_RESISTANCE 5110 ///< Trimmer heater external temperature sensors V3 reference resistance. #define TEMP_SENSORS_ADC_BITS 24U ///< External temperature sensors ADC bits. - #define ADC_FPGA_READ_DELAY 30U ///< Delay in ms before reading the ADC values from FPGA. #define MAX_NUM_OF_RAW_ADC_SAMPLES 4U ///< Number of ADC reads for moving average calculations. #define MAX_ALLOWED_TEMP_DELTA_BETWEEN_SENSORS 2U ///< Maximum allowed temperature delta between sensors. @@ -87,6 +89,7 @@ #define TEMP_SENSORS_MIN_ALLOWED_DEGREE_C 0.0F ///< Temperature sensors minimum allowed temperature in C. #define TEMP_SENSORS_MAX_ALLOWED_DEGREE_C 120.0F ///< Temperature sensors maximum allowed temperature in C. +#define HEATERS_INTERNAL_TEMP_SENSORS_MAX_ALLOWED_DEGREE_C 200.0F ///< Heaters' internal temperature sensors maximum allowed temperature in C. #define NON_FLUID_PATH_TEMP_SENSORS_MAX_ALLOWED_DEGREE_C 80.0F ///< Non fluid temperature sensors path maximum allowed temperature in C. #define TEMP_SENSORS_OUT_OF_RANGE_TIME_OUT_MS ( 5 * MS_PER_SECOND ) ///< Temperature sensor out of range persistent period in milliseconds. #define DATA_PUBLISH_COUNTER_START_COUNT 30 ///< Data publish counter start count. @@ -139,7 +142,6 @@ static OVERRIDE_U32_T tempSensorsPublishInterval = { TEMP_SENSORS_DATA_PUBLISH_INTERVAL, TEMP_SENSORS_DATA_PUBLISH_INTERVAL, 0, 0 }; ///< Temperature sensors publish time interval override. static DG_TEMP_SENSORS_CAL_RECORD_T tempSensorCalRecord; ///< Temperature sensors calibration record. -static BOOL hasTempSensorsRefRBeenSet; ///< Temperature sensors reference resistance been set. static const F32 POSITIVE_TC_EXP_A0 = 0.118597600000E0; ///< K TC positive temperature exponent coefficient A0. static const F32 POSITIVE_TC_EXP_A1 = -0.118343200000E-3; ///< K TC positive temperature exponent coefficient A1. static const F32 POSITIVE_TC_EXP_A2 = 0.126968600000E3; ///< K TC positive temperature exponent coefficient A2. @@ -175,15 +177,16 @@ static BOOL isADCReadValid( U32 sensorIndex, U32 fpgaError, U32 fpgaCount ); static void processADCRead( U32 sensorIndex, S32 adc ); static void publishTemperatureSensorsData( void ); -static void monitorTemperatureSnsrs( U32 sensorIndex ); +static void monitorTemperatureSenors( void ); +static void adjustTemperatureSensorsV3DVTRefResistance( void ); /*********************************************************************//** * @brief * The initTemperatureSensors function initializes the module. * @details Inputs: none * @details Outputs: tempSensorsSelfTestState, tempSensorsExecState, * elapsedTime, internalHeatersConversionTimer, dataPublicationTimerCounter, - * tempSensors, fpgaRawADCReadInterval, hasTempSensorsRefRBeenSet + * tempSensors, fpgaRawADCReadInterval * @return none *************************************************************************/ void initTemperatureSensors( void ) @@ -195,7 +198,6 @@ internalHeatersConversionTimer = 0; dataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; fpgaRawADCReadInterval = 0; - hasTempSensorsRefRBeenSet = FALSE; /* NOTE: The temperature sensors do not have conversion coefficient. * The conversion coefficients are used for the heaters internal temperature sensors and @@ -251,21 +253,25 @@ // Initialize the heaters internal thermocouples constants tempSensors[ TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE ].conversionCoeff = HEATERS_INTERNAL_TC_ADC_TO_TEMP_CONVERSION_COEFF; - tempSensors[ TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE ].maxAllowedTemp = TEMP_SENSORS_MAX_ALLOWED_DEGREE_C; + tempSensors[ TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE ].maxAllowedTemp = HEATERS_INTERNAL_TEMP_SENSORS_MAX_ALLOWED_DEGREE_C; tempSensors[ TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE ].conversionCoeff = HEATERS_INTERNAL_TC_ADC_TO_TEMP_CONVERSION_COEFF; - tempSensors[ TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE ].maxAllowedTemp = TEMP_SENSORS_MAX_ALLOWED_DEGREE_C; + tempSensors[ TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE ].maxAllowedTemp = HEATERS_INTERNAL_TEMP_SENSORS_MAX_ALLOWED_DEGREE_C; // Initialize the heaters cold junction constants tempSensors[ TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION ].conversionCoeff = HEATERS_COLD_JUNCTION_ADC_TO_TEMP_CONVERSION_COEFF; tempSensors[ TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION ].maxAllowedTemp = TEMP_SENSORS_MAX_ALLOWED_DEGREE_C; tempSensors[ TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION ].conversionCoeff = HEATERS_COLD_JUNCTION_ADC_TO_TEMP_CONVERSION_COEFF; tempSensors[ TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION ].maxAllowedTemp = TEMP_SENSORS_MAX_ALLOWED_DEGREE_C; + // Initialize the heaters internal temperature sensors + tempSensors[ TEMPSENSORS_PRIMARY_HEATER_INTERNAL ].maxAllowedTemp = HEATERS_INTERNAL_TEMP_SENSORS_MAX_ALLOWED_DEGREE_C; + tempSensors[ TEMPSENSORS_TRIMMER_HEATER_INTERNAL ].maxAllowedTemp = HEATERS_INTERNAL_TEMP_SENSORS_MAX_ALLOWED_DEGREE_C; + // FPGA board temperature conversion coefficient tempSensors[ TEMPSENSORS_FPGA_BOARD_SENSOR ].conversionCoeff = 503.975 / (F32)TWELVE_BIT_RESOLUTION; tempSensors[ TEMPSENSORS_FPGA_BOARD_SENSOR ].maxAllowedTemp = NON_FLUID_PATH_TEMP_SENSORS_MAX_ALLOWED_DEGREE_C; - F32 const conversionCoeff = 1.0 / 13584.0; + F32 conversionCoeff = 1.0 / 13584.0; // Board temperature sensors conversion coefficient tempSensors[ TEMPSENSORS_LOAD_CELL_A1_B1 ].conversionCoeff = conversionCoeff; tempSensors[ TEMPSENSORS_LOAD_CELL_A1_B1 ].maxAllowedTemp = NON_FLUID_PATH_TEMP_SENSORS_MAX_ALLOWED_DEGREE_C; @@ -344,20 +350,8 @@ *************************************************************************/ void execTemperatureSensors( void ) { - if ( ( getCurrentOperationMode() != DG_MODE_INIT ) && ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_ENABLE_V3_SYSTEM ) ) && - ( FALSE == hasTempSensorsRefRBeenSet ) ) - { - U32 primaryAndCondSensorsRefResistance = 19600; - U32 externalTempSesnorsRefResitance = 5110; - hasTempSensorsRefRBeenSet = TRUE; - tempSensors[ TEMPSENSORS_INLET_PRIMARY_HEATER ].refResistance = primaryAndCondSensorsRefResistance; - tempSensors[ TEMPSENSORS_OUTLET_PRIMARY_HEATER ].refResistance = primaryAndCondSensorsRefResistance; - tempSensors[ TEMPSENSORS_CONDUCTIVITY_SENSOR_1 ].refResistance = primaryAndCondSensorsRefResistance; - tempSensors[ TEMPSENSORS_CONDUCTIVITY_SENSOR_2 ].refResistance = primaryAndCondSensorsRefResistance; - tempSensors[ TEMPSENSORS_HEAT_DISINFECT ].refResistance = externalTempSesnorsRefResitance; - tempSensors[ TEMPSENSORS_OUTLET_REDUNDANT ].refResistance = externalTempSesnorsRefResitance; - tempSensors[ TEMPSENSORS_INLET_DIALYSATE ].refResistance = externalTempSesnorsRefResitance; - } + // Check the status of the software configuration + adjustTemperatureSensorsV3DVTRefResistance(); // Read the sensors all the time switch ( tempSensorsExecState ) @@ -376,6 +370,9 @@ break; } + // Monitor the temperature values + monitorTemperatureSenors(); + // Publish the data publishTemperatureSensorsData(); } @@ -438,30 +435,15 @@ if ( sensorIndex < NUM_OF_TEMPERATURE_SENSORS ) { - //temperature = tempSensors[ sensorIndex ].temperatureValues.data; - - if ( OVERRIDE_KEY == tempSensors[ sensorIndex ].temperatureValues.override ) + temperature = getF32OverrideValue( &tempSensors[ sensorIndex ].temperatureValues ); + // If the system is V3 and THd or its ADC internal temperature is requested, return TRo instead. V3 does not have + // the electrical connection of THd sensor. + if ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_ENABLE_V3_SYSTEM ) ) { - temperature = tempSensors[ sensorIndex ].temperatureValues.ovData; - } - //else if ( ) - - else - { -#ifdef THD_USING_TRO_CONNECTOR - // In V3 THd is connected to TRo - // In V3 TDi represents TRo since they are very close to each other - if ( TEMPSENSORS_HEAT_DISINFECT == sensorIndex ) + if ( ( TEMPSENSORS_HEAT_DISINFECT == sensorIndex ) || ( TEMPSENSORS_INTERNAL_THD_RTD == sensorIndex ) ) { - temperature = tempSensors[ TEMPSENSORS_OUTLET_REDUNDANT ].temperatureValues.data; + temperature = getF32OverrideValue( &tempSensors[ TEMPSENSORS_OUTLET_REDUNDANT ].temperatureValues ); } - else - { - temperature = tempSensors[ sensorIndex ].temperatureValues.data; - } -#else - temperature = tempSensors[ sensorIndex ].temperatureValues.data; -#endif } } else @@ -794,17 +776,14 @@ case TEMPSENSORS_LOAD_CELL_A2_B2: case TEMPSENSORS_INTERNAL_TRO_RTD: case TEMPSENSORS_INTERNAL_TDI_RTD: + case TEMPSENSORS_INTERNAL_THD_RTD: case TEMPSENSORS_INTERNAL_COND_TEMP_SENSOR: // Temperature(C) = ((ADC - 0x800000)/13584) - 272.5 // The value 1/13584 has been calculated and stored in the conversion coefficient variable of the structure temperature = ( ( avgADCReads - ADC_BOARD_TEMP_SENSORS_CONST ) * tempSensors[ sensorIndex ].conversionCoeff ) - ADC_BOARD_TEMP_SENSORS_CONVERSION_CONST; break; - case TEMPSENSORS_INTERNAL_THD_RTD: - temperature = 25.0; - break; - case TEMPSENSORS_BAROMETRIC_TEMP_SENSOR: temperature = 30.0; break; @@ -819,9 +798,6 @@ // Update the temperature tempSensors[ sensorIndex ].temperatureValues.data = temperature; - - // Monitor the temperature value - monitorTemperatureSnsrs( sensorIndex ); } /*********************************************************************//** @@ -980,26 +956,64 @@ * for more than the specified time. * @details Inputs: tempSensors * @details Outputs: tempSensors - * @param sensorIndex the index of the temperature sensor * @return none *************************************************************************/ -static void monitorTemperatureSnsrs( U32 sensorIndex ) +static void monitorTemperatureSenors( void ) { #ifndef _RELEASE_ if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_TEMPERATURE_SENSORS_ALARM ) != SW_CONFIG_ENABLE_VALUE ) #endif { - F32 temperature = getTemperatureValue( sensorIndex ); - // Check both temperature and to be in range - if ( ( ( temperature < TEMP_SENSORS_MIN_ALLOWED_DEGREE_C ) || ( temperature > tempSensors[ sensorIndex ].maxAllowedTemp ) ) && - ( getCurrentOperationMode() != DG_MODE_INIT ) ) + U08 i; + F32 temperature = 0.0; + BOOL isTemperatureOutOfRange = FALSE; + + for ( i = 0; i < NUM_OF_TEMPERATURE_SENSORS; i++ ) { - checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSOR_OUT_OF_RANGE, TRUE, sensorIndex, temperature ); + temperature = getTemperatureValue( i ); + + // Check both temperature and to be in range + if ( ( ( temperature < TEMP_SENSORS_MIN_ALLOWED_DEGREE_C ) || ( temperature > tempSensors[ i ].maxAllowedTemp ) ) && + ( getCurrentOperationMode() != DG_MODE_INIT ) ) + { + isTemperatureOutOfRange |= TRUE; + } } + + //checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSOR_OUT_OF_RANGE, isTemperatureOutOfRange, i, temperature ); } } +/*********************************************************************//** + * @brief + * The adjustTemperatureSensorsV3DVTRefResistance function adjusts the temperature + * sensors V3 or DVT reference resistance values. + * @details Inputs: tempSensors + * @details Outputs: tempSensors + * @return none + *************************************************************************/ +static void adjustTemperatureSensorsV3DVTRefResistance( void ) +{ + // The default are DVT changes + U32 primaryAndCondSensorsRefResistance = PRIMARY_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE; + U32 externalTempSesnorsRefResitance = TRIMMER_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE; + if ( ( getCurrentOperationMode() != DG_MODE_INIT ) && ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_ENABLE_V3_SYSTEM ) ) ) + { + primaryAndCondSensorsRefResistance = PRIMARY_HEATER_EXT_TEMP_SENSORS_V3_REF_RESISTANCE; + externalTempSesnorsRefResitance = TRIMMER_HEATER_EXT_TEMP_SENSORS_V3_REF_RESISTANCE; + } + + tempSensors[ TEMPSENSORS_INLET_PRIMARY_HEATER ].refResistance = primaryAndCondSensorsRefResistance; + tempSensors[ TEMPSENSORS_OUTLET_PRIMARY_HEATER ].refResistance = primaryAndCondSensorsRefResistance; + tempSensors[ TEMPSENSORS_CONDUCTIVITY_SENSOR_1 ].refResistance = primaryAndCondSensorsRefResistance; + tempSensors[ TEMPSENSORS_CONDUCTIVITY_SENSOR_2 ].refResistance = primaryAndCondSensorsRefResistance; + tempSensors[ TEMPSENSORS_HEAT_DISINFECT ].refResistance = externalTempSesnorsRefResitance; + tempSensors[ TEMPSENSORS_OUTLET_REDUNDANT ].refResistance = externalTempSesnorsRefResitance; + tempSensors[ TEMPSENSORS_INLET_DIALYSATE ].refResistance = externalTempSesnorsRefResitance; +} + + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/