Index: firmware/App/Controllers/TemperatureSensors.c =================================================================== diff -u -rfeb93744f73bc0a3d58841bb02bd05c38357f35d -r2e4afce5a9fd0392b330461ed38322ecadd59aa1 --- firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision feb93744f73bc0a3d58841bb02bd05c38357f35d) +++ firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 2e4afce5a9fd0392b330461ed38322ecadd59aa1) @@ -134,7 +134,7 @@ 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 ] = { @@ -147,10 +147,13 @@ 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. +/// Max FPGA error count limit. static const F32 MAX_FPGA_ERROR_COUNT_LIMIT = TEMPERATURE_SENSORS_FPGA_ERROR_PERSISTENT_PERIOD / - ( FPGA_RAW_ADC_READ_INTERVAL_COUNT * TASK_PRIORITY_INTERVAL ); ///< Max FPGA error count limit. + ( FPGA_RAW_ADC_READ_INTERVAL_COUNT * TASK_PRIORITY_INTERVAL ); + +/// Max internal error count limit. static const F32 MAX_INTERNAL_ERROR_COUNT_LIMIT = TEMPERATURE_SENSORS_INTERNAL_ERROR_PERSISTENT_PERIOD / - ( FPGA_RAW_ADC_READ_INTERVAL_COUNT * TASK_PRIORITY_INTERVAL ); ///< Max internal error count limit. + ( FPGA_RAW_ADC_READ_INTERVAL_COUNT * TASK_PRIORITY_INTERVAL ); // ********** private function prototypes ********** @@ -534,24 +537,24 @@ if ( ( sensorIndex == TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE ) || ( sensorIndex == TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE ) ) { - // Cast the adc from U32 to U16 and shit it to left by 2 + // 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 = ( (S16)adcConv ) >> SHIFT_BITS_BY_2; + convertedADC = ( (S32)adcConv ) >> SHIFT_BITS_BY_2; } 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 = ( (S16)adcConv ) >> SHIFT_BITS_BY_4; + convertedADC = ( (S32)adcConv ) >> SHIFT_BITS_BY_4; } if ( isADCReadValid( sensorIndex, fpgaError, fpgaCount ) ) { - processADCRead( sensorIndex, convertedADC ); + processADCRead( sensorIndex, (S32)convertedADC ); } } @@ -575,23 +578,23 @@ isADCValid = TRUE; // TODO remove this line. Temporary set to true until FPGA error count is fixed //THIS ISSUE HAS BEEN FIXED. TRY IT. #endif - if ( fpgaError == 0 ) + + // Check the status of FPGA error and FPGA count + BOOL isFPGAErrorZero = fpgaError == 0; + BOOL isFPGACountChanging = tempSensors[ sensorIndex ].readCount != fpgaCount; + + if ( isFPGAErrorZero ) { - if ( tempSensors[ sensorIndex ].readCount < fpgaCount ) // it was != rather than > + if ( isFPGACountChanging ) { tempSensors[ sensorIndex ].readCount = fpgaCount; isADCValid = TRUE; } - else - { - checkPersistentAlarm( PERSISTENT_ALARM_TEMP_SENSORS_INTERNAL_ERROR, TRUE, sensorIndex, MAX_INTERNAL_ERROR_COUNT_LIMIT ); - } } - else - { - checkPersistentAlarm( PERSISTENT_ALARM_TEMP_SENSORS_FPGA_ERROR, TRUE, sensorIndex, MAX_FPGA_ERROR_COUNT_LIMIT ); - } + checkPersistentAlarm( PERSISTENT_ALARM_TEMP_SENSORS_INTERNAL_ERROR, !isFPGACountChanging, sensorIndex, MAX_INTERNAL_ERROR_COUNT_LIMIT ); + checkPersistentAlarm( PERSISTENT_ALARM_TEMP_SENSORS_FPGA_ERROR, !isFPGAErrorZero, sensorIndex, MAX_FPGA_ERROR_COUNT_LIMIT ); + return isADCValid; } @@ -771,23 +774,13 @@ // coming from FPGA. It is kept here to do moving average on the values. The supporting functions need to see the FPGA read count // incrementing internally so there will not be any errors. U32 simulatedCounter = tempSensors[ TEMPSENSORS_FPGA_BOARD_SENSOR ].readCount; - processTempSnsrsADCRead( TEMPSENSORS_FPGA_BOARD_SENSOR, getFPGABoardTemp(), 0, ++simulatedCounter ); + processTempSnsrsADCRead( TEMPSENSORS_FPGA_BOARD_SENSOR, getFPGABoardTemp(), 0, ++simulatedCounter ); + processTempSnsrsADCRead( TEMPSENSORS_LOAD_CELL_A1_B1, getFPGALoadCellsA1B1Temp(), getFPGAADC1ErrorCount(), getFPGAADC1ReadCount() ); + processTempSnsrsADCRead( TEMPSENSORS_LOAD_CELL_A2_B2, getFPGALoadCellsA2B2Temp(), getFPGAADC2ErrorCount(), getFPGAADC2ReadCount() ); + processTempSnsrsADCRead( TEMPSENSORS_INTERNAL_THDO_RTD, getFPGATHDoInternalTemp(), getFPGATHDoErrorCount(), getFPGATHDoReadCount() ); + processTempSnsrsADCRead( TEMPSENSORS_INTERNAL_TDI_RTD, getFPGATDiInternalTemp(), getFPGATDiErrorCount(), getFPGATDiReadCount() ); + processTempSnsrsADCRead( TEMPSENSORS_INTERNAL_COND_TEMP_SENSOR, getFPGACondSnsrInternalTemp(), getFPGARTDErrorCount(), getFPGARTDReadCount() ); - processTempSnsrsADCRead( TEMPSENSORS_LOAD_CELL_A1_B1, getFPGALoadCellsA1B1Temp(), getFPGAADC1ErrorCount(), - getFPGAADC1ReadCount() ); - - processTempSnsrsADCRead( TEMPSENSORS_LOAD_CELL_A2_B2, getFPGALoadCellsA2B2Temp(), getFPGAADC2ErrorCount(), - getFPGAADC2ReadCount() ); - - processTempSnsrsADCRead( TEMPSENSORS_INTERNAL_THDO_RTD, getFPGATHDoInternalTemp(), getFPGATHDoErrorCount(), - getFPGATHDoReadCount() ); - - processTempSnsrsADCRead( TEMPSENSORS_INTERNAL_TDI_RTD, getFPGATDiInternalTemp(), getFPGATDiErrorCount(), - getFPGATDiReadCount() ); - - processTempSnsrsADCRead( TEMPSENSORS_INTERNAL_COND_TEMP_SENSOR, getFPGACondSnsrInternalTemp(), getFPGARTDErrorCount(), - getFPGARTDReadCount() ); - // Check if time has elapsed to calculate the internal temperature of the heaters if ( ++internalHeatersConversionTimer >= HEATERS_INTERNAL_TEMPERTURE_CALCULATION_INTERVAL ) {