Index: firmware/App/Controllers/TemperatureSensors.c =================================================================== diff -u -re6dc73b45ec3d0df4c9a03673625862b71acd608 -rebbb1f85550a1f9b8f946655f7b2b63f76fbf67d --- firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision e6dc73b45ec3d0df4c9a03673625862b71acd608) +++ firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision ebbb1f85550a1f9b8f946655f7b2b63f76fbf67d) @@ -32,11 +32,11 @@ // ********** private definitions ********** -#define PRIMARY_HEATER_EXT_TEMP_SENSORS_GAIN 16U ///< Primary heater external temperature sensors gain. +#define PRIMARY_HEATER_EXT_TEMP_SENSORS_GAIN 8U ///< Primary heater external temperature sensors gain. #define PRIMARY_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE 19600U ///< 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 COND_SENSORS_TEMP_SENSOR_GAIN 16U ///< Temperature sensor for conductivity gain. +#define COND_SENSORS_TEMP_SENSOR_GAIN 8U ///< Temperature sensor for conductivity gain. #define COND_SENSORS_TEMP_SENSOR_REF_RESISTANCE 19600U ///< Temperature sensor for conductivity reference resistance. #define COND_SENSORS_TEMP_SENSOR_0_DEGREE_RESISTANCE 1000U ///< Temperature sensor for conductivity zero degree resistance. @@ -76,56 +76,55 @@ #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. - /// Temperature sensor self-test states. typedef enum tempSensors_Self_Test_States { - TEMPSENSORS_SELF_TEST_START = 0, ///< Temperature sensors self-test start - TEMPSENSORS_SELF_TEST_ADC_CHECK, ///< Temperature sensors self ADC check - TEMPSENSORS_SELF_TEST_COMPLETE, ///< Temperature sensors self-test complete - NUM_OF_TEMPSENSORS_SELF_TEST_STATES ///< Total number of self-test states + TEMPSENSORS_SELF_TEST_START = 0, ///< Temperature sensors self-test start + TEMPSENSORS_SELF_TEST_ADC_CHECK, ///< Temperature sensors self ADC check + TEMPSENSORS_SELF_TEST_COMPLETE, ///< Temperature sensors self-test complete + NUM_OF_TEMPSENSORS_SELF_TEST_STATES ///< Total number of self-test states } TEMPSENSORS_SELF_TEST_STATES_T; /// Temperature sensor exec states. typedef enum tempSensors_Exec_States { - TEMPSENSORS_EXEC_STATE_START = 0, ///< Temperature sensors exec start - TEMPSENSORS_EXEC_STATE_GET_ADC_VALUES, ///< Temperature sensors exec get ADC values - NUM_OF_TEMPSENSORS_EXEC_STATES, ///< Total number of exec states + TEMPSENSORS_EXEC_STATE_START = 0, ///< Temperature sensors exec start + TEMPSENSORS_EXEC_STATE_GET_ADC_VALUES, ///< Temperature sensors exec get ADC values + NUM_OF_TEMPSENSORS_EXEC_STATES, ///< Total number of exec states } TEMPSENSORS_EXEC_STATES_T; /// Temperature sensor struct. typedef struct { - F32 gain; ///< ADC gain - F32 refResistance; ///< ADC reference resistance - F32 conversionCoeff; ///< ADC conversion coefficient - F32 zeroDegreeResistance; ///< ADC zero degree resistance - S32 rawADCReads[ MAX_NUM_OF_RAW_ADC_SAMPLES ]; ///< Raw ADC reads array - S32 adcNextIndex; ///< Next ADC read index - S32 adcRunningSum; ///< ADC running sum - U32 readCount; ///< Read counts from FPGA - OVERRIDE_F32_T temperatureValues; ///< Temperature values with override + F32 gain; ///< ADC gain + F32 refResistance; ///< ADC reference resistance + F32 conversionCoeff; ///< ADC conversion coefficient + F32 zeroDegreeResistance; ///< ADC zero degree resistance + S32 rawADCReads[ MAX_NUM_OF_RAW_ADC_SAMPLES ]; ///< Raw ADC reads array + S32 adcNextIndex; ///< Next ADC read index + S32 adcRunningSum; ///< ADC running sum + U32 readCount; ///< Read counts from FPGA + OVERRIDE_F32_T temperatureValues; ///< Temperature values with override } TEMP_SENSOR_T; // ********** private data ********** -static SELF_TEST_STATUS_T tempSensorsSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; ///< Self-test result of the TemperatureSensors module. -static TEMPSENSORS_SELF_TEST_STATES_T tempSensorsSelfTestState; ///< TemperatureSensor self-test state. -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 = 0; ///< FPGA raw ADC read interval count. -static U32 elapsedTime = 0; ///< Elapsed time variable. -static U32 internalHeatersConversionTimer = 0; ///< Conversion timer variable to calculate the heaters internal temperature. +static SELF_TEST_STATUS_T tempSensorsSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; ///< Self-test result of the TemperatureSensors module. +static TEMPSENSORS_SELF_TEST_STATES_T tempSensorsSelfTestState; ///< TemperatureSensor self-test state. +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 = 0; ///< FPGA raw ADC read interval count. +static U32 elapsedTime = 0; ///< Elapsed time variable. +static U32 internalHeatersConversionTimer = 0; ///< Conversion timer variable to calculate the heaters internal temperature. -static F32 tempValuesForPublication [ NUM_OF_TEMPERATURE_SENSORS ]; ///< Temperature sensors data publication array. -static U32 dataPublicationTimerCounter; ///< Temperature sensors data publish timer counter. +static F32 tempValuesForPublication [ NUM_OF_TEMPERATURE_SENSORS ]; ///< Temperature sensors data publication array. +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. + TEMP_SENSORS_DATA_PUBLISH_INTERVAL, 0, 0 }; ///< Temperature sensors publish time interval override. -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. +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. static const F32 POSITIVE_TC_COEFFS [ SIZE_OF_THERMOCOUPLE_COEFFICIENTS ] = { @@ -134,18 +133,18 @@ 0.318409457190E-9, -0.560728448890E-12, 0.560750590590E-15,-0.320207200030E-18, 0.971511471520E-22,-0.121047212750E-25 -}; ///< Thermocouple correction coefficients for positive cold junction temperature. +}; ///< Thermocouple correction coefficients for positive cold junction temperature. static const F32 POSITIVE_TC_INVERSER_COEFFS [ SIZE_OF_THERMOCOUPLE_COEFFICIENTS ] = { 0.0, 2.508355E1, 7.860106E-2, -2.503131E-1, 8.315270E-2, -1.228034E-2, 9.804036E-4, -4.413030E-5, 1.057734E-6, -1.052755E-8 -}; ///< Thermocouple inverse coefficient for positive cold junction temperature. +}; ///< Thermocouple inverse coefficient for positive cold junction temperature. -static const U32 TEMP_SENSORS_ADC_MAX_COUNT = ( 1 << TEMP_SENSORS_ADC_BITS ) - 1; ///< ADC 24 bit max count which is (2^24 - 1). -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 U32 TEMP_SENSORS_ADC_MAX_COUNT = ( 1 << TEMP_SENSORS_ADC_BITS ) - 1; ///< ADC 24 bit max count which is (2^24 - 1). +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. // ********** private function prototypes ********** @@ -159,7 +158,7 @@ static void getHeaterInternalTemp( U32 TCIndex, U32 CJIndex ); static void processTempSnsrsADCRead( U32 sensorIndex, U32 adc, U32 fpgaError, U32 fpgaCount ); -static void processHtrsTempSnsrsADCRead( U32 sensorIndex, U32 adc, U32 fpgaError, U32 fpgaCount ); +static void processHtrsTempSnsrsADCRead( U32 sensorIndex, U16 adc, U32 fpgaError, U32 fpgaCount ); static BOOL isADCReadValid( U32 sensorIndex, U32 fpgaError, U32 fpgaCount ); static void processADCRead( U32 sensorIndex, S32 adc ); static void publishTemperatureSensorsData( void ); @@ -398,7 +397,7 @@ // R(RTD) = R(ref) * ( adc – 2^(N - 1) ) / ( G * 2^(N - 1) ); F32 resistance = ( refResistance * ( avgADC - TEMP_EQUATION_RESISTOR_CALC ) ) / ( gain * TEMP_EQUATION_RESISTOR_CALC ); // T = (-A + √( A^2 - 4B * ( 1 - R_T / R_0 ) ) ) / 2B - F32 secondSqrtPart = 4 * TEMP_EQUATION_COEFF_B * (1 - ( resistance / zeroDegResistance ) ); + F32 secondSqrtPart = 4 * TEMP_EQUATION_COEFF_B * ( 1 - ( resistance / zeroDegResistance ) ); temperature = ( -TEMP_EQUATION_COEFF_A + sqrt( pow( TEMP_EQUATION_COEFF_A, 2 ) - secondSqrtPart ) ) / ( 2 * TEMP_EQUATION_COEFF_B ); } else @@ -467,7 +466,7 @@ } // Check which heater's internal temperature is being calculated - if ( TCIndex == TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE ) + if ( TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE == TCIndex ) { tempSensors[ TEMPSENSORS_PRIMARY_HEATER_INTERNAL ].temperatureValues.data = temperature; } @@ -495,7 +494,7 @@ { S32 convertedADC = (S32)( adc & MASK_OFF_U32_MSB ); - if ( isADCReadValid( sensorIndex, fpgaError, fpgaCount ) ) + if ( TRUE == isADCReadValid( sensorIndex, fpgaError, fpgaCount ) ) { processADCRead( sensorIndex, convertedADC ); } @@ -516,32 +515,12 @@ * @param fpgaCount reported read count by FPGA * @return none *************************************************************************/ -static void processHtrsTempSnsrsADCRead( U32 sensorIndex, U32 adc, U32 fpgaError, U32 fpgaCount ) +static void processHtrsTempSnsrsADCRead( U32 sensorIndex, U16 adc, U32 fpgaError, U32 fpgaCount ) { - U16 adcConv = 0; - S16 convertedADC = 0; - - if ( ( sensorIndex == TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE ) || ( sensorIndex == TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE ) ) + if ( TRUE == isADCReadValid( sensorIndex, fpgaError, fpgaCount ) ) { - // Cast the adc from U32 to U16 and shift it to left by 2 - adcConv = ( (U16)adc ) << SHIFT_BITS_BY_2; - // Cast from U16 to S16 and shift the bits to right by 2 - // so if the sign bit is 1, the sign bit is extended - convertedADC = ( (S32)adcConv ) >> SHIFT_BITS_BY_2; + processADCRead( sensorIndex, (S32)adc ); } - else if ( ( sensorIndex == TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION ) || ( sensorIndex == TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION ) ) - { - // Cast the adc from U32 to U16 and shift it by 4 - adcConv = ( (U16)adc ) << SHIFT_BITS_BY_4; - // Cast from U16 to S16 and shift the bits to right by 4 - // so if the sign bit is 1, the sign bit is extended - convertedADC = ( (S32)adcConv ) >> SHIFT_BITS_BY_4; - } - - if ( isADCReadValid( sensorIndex, fpgaError, fpgaCount ) ) - { - processADCRead( sensorIndex, (S32)convertedADC ); - } } /*********************************************************************//** @@ -578,8 +557,10 @@ } } - checkPersistentAlarm( ALARM_ID_TEMPERATURE_SENSORS_FAULT, !isFPGACountChanging || !isFPGAErrorZero, sensorIndex, TEMPERATURE_SENSORS_FPGA_ERROR_PERSISTENT_PERIOD ); + BOOL isThereAnError = !isFPGACountChanging || !isFPGAErrorZero; + checkPersistentAlarm( ALARM_ID_TEMPERATURE_SENSORS_FAULT, isThereAnError, sensorIndex, TEMPERATURE_SENSORS_FPGA_ERROR_PERSISTENT_PERIOD ); + return isADCValid; }