Index: firmware/App/Controllers/TemperatureSensors.c =================================================================== diff -u -r7df1fae66b80c946ff1bcdee4b43afb5ab7a1d4c -r6190a4ad94521b74164f1e1fbd79ed359c7c27fb --- firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 7df1fae66b80c946ff1bcdee4b43afb5ab7a1d4c) +++ firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 6190a4ad94521b74164f1e1fbd79ed359c7c27fb) @@ -53,7 +53,7 @@ #define MAX_ALLOWED_TEMP_DELTA_BETWEEN_SENSORS 2U ///< Maximum allowed temperature delta between sensors. #define SHIFT_BITS_BY_2 2U ///< Shift bits by 2 to create a 4 for averaging 4 samples. #define SHIFT_BITS_BY_2_FOR_AVERAGING 2U ///< Shift the ADCs of the temperature sensors by 2 to average them. -#define INLET_WATER_TEMPERATURE_PERSISTENCE_PERIOD ( 5 * MS_PER_SECOND ) ///< Persistence period for temperature sensors out of range error period. +#define INLET_WATER_TEMPERATURE_PERSISTENCE_PERIOD ( 5 * MS_PER_SECOND ) ///< Persistence period for temperature sensors out of range error period. #define MIN_WATER_INPUT_TEMPERATURE 22U ///< Minimum water input temperature. #define MAX_WATER_INPUT_TEMPERATURE 35U ///< Maximum water input temperature. @@ -77,6 +77,7 @@ #define TEMPERATURE_SENSORS_FPGA_ERROR_PERSISTENT_PERIOD ( 5 * MS_PER_SECOND ) ///< Temperature sensors FPGA error persistent period. #define TEMPERATURE_SENSORS_INTERNAL_ERROR_PERSISTENT_PERIOD ( 3 * MS_PER_SECOND ) ///< Temperature sensors internal error persistent period. #define FPGA_RAW_ADC_READ_INTERVAL_COUNT 8 ///< Time interval in counts to read the raw ADC reads from FPGA. +#define TEMPERATURE_SENSORS_ERROR_FLAG_PERSISTENT_PERIOD ( 5 * MS_PER_SECOND ) ///< Temperature sensors error flag persistent period. /// Temperature sensor self-test states. typedef enum tempSensors_Self_Test_States @@ -253,7 +254,7 @@ initPersistentAlarm( ALARM_ID_INLET_WATER_HIGH_TEMPERATURE, INLET_WATER_TEMPERATURE_PERSISTENCE_PERIOD, INLET_WATER_TEMPERATURE_PERSISTENCE_PERIOD ); initPersistentAlarm( ALARM_ID_INLET_WATER_LOW_TEMPERATURE, INLET_WATER_TEMPERATURE_PERSISTENCE_PERIOD, INLET_WATER_TEMPERATURE_PERSISTENCE_PERIOD ); - // Persistent alarm for temperature sensors internal error + // Persistent alarm for temperature sensors ADC error // When the FPGA read count does not increment for a period of time, it is considered as an internal error of the temperature sensors // driver. This is internal because FPGA does not error out if the FPGA read count does not increment. initPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSORS_ADC_FAULT, TEMPERATURE_SENSORS_FPGA_ERROR_PERSISTENT_PERIOD, TEMPERATURE_SENSORS_FPGA_ERROR_PERSISTENT_PERIOD ); @@ -363,7 +364,20 @@ } 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 ) + { + temperature = tempSensors[ TEMPSENSORS_OUTLET_REDUNDANT ].temperatureValues.data; + } + else + { + temperature = tempSensors[ sensorIndex ].temperatureValues.data; + } +#else temperature = tempSensors[ sensorIndex ].temperatureValues.data; +#endif } } else @@ -494,8 +508,49 @@ { S32 convertedADC = (S32)( adc & MASK_OFF_U32_MSB ); - if ( TRUE == isADCReadValid( sensorIndex, fpgaError, fpgaCount ) ) + // All the sensors have ADC read and count values that have to be checked + BOOL isADCValid = isADCReadValid( sensorIndex, fpgaError, fpgaCount ); + + // Some of the temperature sensors have an MSB bit that is used as an + // error flag. This flag will be a TRUE by default. + BOOL isTemperatureNotValid = FALSE; + + switch( sensorIndex ) { + case TEMPSENSORS_LOAD_CELL_A1_B1: // 267 + case TEMPSENSORS_LOAD_CELL_A2_B2: // 279 + case TEMPSENSORS_CONDUCTIVITY_SENSOR_1: // 283 + case TEMPSENSORS_CONDUCTIVITY_SENSOR_2: // 287 + case TEMPSENSORS_OUTLET_PRIMARY_HEATER: // 291 + case TEMPSENSORS_INLET_PRIMARY_HEATER: // 295 + case TEMPSENSORS_INTERNAL_COND_TEMP_SENSOR: // 299 + case TEMPSENSORS_OUTLET_REDUNDANT: // 303 + case TEMPSENSORS_INTERNAL_THDO_RTD: // 307 + case TEMPSENSORS_INLET_DIALYSATE: // 311 + case TEMPSENSORS_INTERNAL_TDI_RTD: // 315 + { + // The MSB bit of the last byte is the error flag, so that MSB + // is shifted 31 bits to the first bit of the U32 variable. + // If that bit is a 1, there is either CRC error or Status error + // that are ored on top of each other + U32 errorBit = adc >> 31; + isTemperatureNotValid = errorBit > 0; + checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSOR_FAULT, isTemperatureNotValid, sensorIndex, + TEMPERATURE_SENSORS_ERROR_FLAG_PERSISTENT_PERIOD ); + } + break; + + default: + // Do nothing. FPGA board temperature sensor does not have error flag bit + // If a wrong temperature sensor name is picked, the function that converts + // ADC counts to temperature raises an alarm. + break; + } + + // To update the moving average of a temperature sensor, both ADC and internal + // error flags must be valid + if ( ( TRUE == isADCValid ) && ( FALSE == isTemperatureNotValid ) ) + { processADCRead( sensorIndex, convertedADC ); } } @@ -558,7 +613,7 @@ } } - BOOL isThereAnError = !isFPGACountChanging || !isFPGAErrorZero; + BOOL isThereAnError = ( FALSE == isFPGACountChanging ) || ( FALSE == isFPGAErrorZero ); checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSORS_ADC_FAULT, isThereAnError, sensorIndex, TEMPERATURE_SENSORS_FPGA_ERROR_PERSISTENT_PERIOD );