Index: firmware/App/Controllers/TemperatureSensors.c =================================================================== diff -u -rc38c6d64b5f4df1fe08e2daabb37d3a7a483a4be -r544e9782a1b8d444224f41efef38a5204c262722 --- firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision c38c6d64b5f4df1fe08e2daabb37d3a7a483a4be) +++ firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 544e9782a1b8d444224f41efef38a5204c262722) @@ -93,6 +93,7 @@ #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. +#define BARO_SENSOR_REFERENCE_TEMP_C 2000 ///< Barometric sensor reference temperature in C. // The count cannot be within 0.1V of the rail on both sides therefore: // ADC count = ((2^12) - 1 / ref voltage) * voltage @@ -128,16 +129,24 @@ U08 sensorErrorBitStatus; ///< Temperature sensor error bit status BOOL fpgaErrorStatus; ///< Temperature sensor FPGA error status BOOL adcErrorStatus; ///< Temperature sensor ADC error status + S32 baroTempSnsrDiff; ///< Barometric sensor temperature difference } TEMP_SENSOR_T; +/// Barometric sensor temperature conversion +typedef struct +{ + U16 refTemperature; ///< Barometric sensor reference temperature. + U16 temperatureCoeff; ///< Barometric sensor temperature coefficient. +} BARO_SENSOR_CONSTS_T; + // ********** private data ********** static TEMPSENSORS_EXEC_STATES_T tempSensorsExecState; ///< TemperatureSensor exec state. static TEMP_SENSOR_T tempSensors [ NUM_OF_TEMPERATURE_SENSORS ]; ///< Temperature sensors' data structure. static U32 fpgaRawADCReadInterval; ///< FPGA raw ADC read interval count. static U32 elapsedTime; ///< Elapsed time variable. static U32 internalHeatersConversionTimer; ///< Conversion timer variable to calculate the heaters internal temperature. - +static BARO_SENSOR_CONSTS_T baroConvConsts; ///< Barometric sensor conversion constants. static U32 dataPublicationTimerCounter; ///< Temperature sensors data publish timer counter. static OVERRIDE_U32_T tempSensorsPublishInterval = { TEMP_SENSORS_DATA_PUBLISH_INTERVAL, TEMP_SENSORS_DATA_PUBLISH_INTERVAL, 0, 0 }; ///< Temperature sensors publish time interval override. @@ -162,8 +171,10 @@ }; ///< Thermocouple inverse coefficient for positive cold junction temperature. static const U32 TEMP_EQUATION_RESISTOR_CALC = 1 << ( TEMP_SENSORS_ADC_BITS - 1 ); ///< Temperature sensors resistor calculation (2^(24 - 1)). -static const F32 TEMP_EQUATION_COEFF_A = 3.9083E-3; ///< ADC to temperature conversion coefficient A. -static const F32 TEMP_EQUATION_COEFF_B = -5.775E-7; ///< ADC to temperature conversion coefficient B. +static const F32 TEMP_EQUATION_COEFF_A = 3.9083E-3; ///< ADC to temperature conversion coefficient A. +static const F32 TEMP_EQUATION_COEFF_B = -5.775E-7; ///< ADC to temperature conversion coefficient B. +static const U32 TWO_TO_POWER_OF_8 = ( 1 << 8 ); ///< 2^8. +static const U32 TWO_TO_POWER_OF_23 = ( 1 << 23 ); ///< 2^23. // ********** private function prototypes ********** @@ -186,7 +197,7 @@ * @details Inputs: none * @details Outputs: tempSensorsSelfTestState, tempSensorsExecState, * elapsedTime, internalHeatersConversionTimer, dataPublicationTimerCounter, - * tempSensors, fpgaRawADCReadInterval + * tempSensors, fpgaRawADCReadInterval, baroConvConsts * @return none *************************************************************************/ void initTemperatureSensors( void ) @@ -213,6 +224,9 @@ benignPolynomialCalRecord( &tempSensorCalRecord.tempSensors[ i ] ); } + // Initialize the barometric sensor's temperature conversion constants + memset( &baroConvConsts, 0x0, sizeof( BARO_SENSOR_CONSTS_T ) ); + // Initialize TPi, THd, and TPo constants tempSensors[ TEMPSENSORS_INLET_PRIMARY_HEATER ].gain = PRIMARY_HEATER_EXT_TEMP_SENSORS_GAIN; tempSensors[ TEMPSENSORS_INLET_PRIMARY_HEATER ].refResistance = PRIMARY_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE; @@ -457,6 +471,19 @@ /*********************************************************************//** * @brief + * The getBaroSensorTemperatureDiff function returns the barometric pressure + * sensor's temperature difference. + * @details Inputs: tempSensors + * @details Outputs: none + * @return barometric pressure sensor temperature difference + *************************************************************************/ +S32 getBaroSensorTemperatureDiff( void ) +{ + return tempSensors[ TEMPSENSORS_BAROMETRIC_TEMP_SENSOR ].baroTempSnsrDiff; +} + +/*********************************************************************//** + * @brief * The getADC2TempConversion function calculates the temperature from the * moving average ADC samples. * @details Inputs: tempEquationCoeffA, tempEquationCoeffB @@ -769,7 +796,7 @@ case TEMPSENSORS_FPGA_BOARD_SENSOR: // Temperature(C) = ((ADC x 503.975) / 4096) - 273.15 // The value of 503.975/4096 has been calculated and stored in the conversion coefficient variable of the structure - temperature = ( avgADCReads * tempSensors[ sensorIndex ].conversionCoeff ) - CELSIUS_TO_KELVIN_CONVERSION; + temperature = ( avgADCReads * tempSensors[ sensorIndex ].conversionCoeff ) - CELSIUS_TO_KELVIN_CONVERSION; break; case TEMPSENSORS_LOAD_CELL_A1_B1: @@ -785,7 +812,12 @@ break; case TEMPSENSORS_BAROMETRIC_TEMP_SENSOR: - temperature = 30.0; + { + tempSensors[ sensorIndex ].baroTempSnsrDiff = (S32)avgADCReads - ( baroConvConsts.refTemperature * TWO_TO_POWER_OF_8 ); + U64 baroSnsrTemperature = BARO_SENSOR_REFERENCE_TEMP_C + ( ( tempSensors[ sensorIndex ].baroTempSnsrDiff * + baroConvConsts.temperatureCoeff ) / TWO_TO_POWER_OF_23 ); + temperature = (F32)( (U32)( baroSnsrTemperature ) / 100 ); + } break; default: @@ -819,8 +851,11 @@ // A delay to let FPGA to boot up else if ( TRUE == didTimeout( elapsedTime, ADC_FPGA_READ_DELAY ) ) { - elapsedTime = 0; - state = TEMPSENSORS_EXEC_STATE_GET_ADC_VALUES; + // Once FPGA is ready get the barometric sensor's temperature conversion constants + baroConvConsts.refTemperature = getFPGABaroReferenceTemperature(); + baroConvConsts.temperatureCoeff = getFPGABaroTempCoeffOfTemperature(); + elapsedTime = 0; + state = TEMPSENSORS_EXEC_STATE_GET_ADC_VALUES; } return state; @@ -859,6 +894,10 @@ readCount = (U32)getFPGATHdReadCount(); processTempSnsrsADCRead( TEMPSENSORS_HEAT_DISINFECT, getFPGATHdTemp(), errorCount, readCount, TRUE ); processTempSnsrsADCRead( TEMPSENSORS_INTERNAL_THD_RTD, getFPGATHdInternalTemp(), errorCount, readCount, FALSE ); + + errorCount = getFPGABaroErrorCount(); + readCount = getFPGABaroReadCount(); + processTempSnsrsADCRead( TEMPSENSORS_BAROMETRIC_TEMP_SENSOR, getFPGABaroTemperature(), errorCount, readCount, TRUE ); } errorCount = (U32)getFPGATRoErrorCount(); @@ -980,7 +1019,7 @@ } } - //checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSOR_OUT_OF_RANGE, isTemperatureOutOfRange, i, temperature ); + //checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSOR_OUT_OF_RANGE, isTemperatureOutOfRange, i, temperature ); // TODO DEBUG_DENALI } } @@ -994,7 +1033,7 @@ *************************************************************************/ static void adjustTemperatureSensorsV3DVTRefResistance( void ) { - // The default are DVT changes + // The defaults are DVT values U32 primaryAndCondSensorsRefResistance = PRIMARY_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE; U32 externalTempSesnorsRefResitance = TRIMMER_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE;