Index: firmware/App/Controllers/TemperatureSensors.c =================================================================== diff -u -r2666279eebfdc11eb611219cb03ba2549f86e381 -r611e805a6547ac922154e623a9d79adeae128e81 --- firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 2666279eebfdc11eb611219cb03ba2549f86e381) +++ firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 611e805a6547ac922154e623a9d79adeae128e81) @@ -164,7 +164,6 @@ static F32 getADC2TempConversion ( F32 avgADC, U32 gain, U32 refResistance, U32 zeroDegResistance, F32 adcConversionCoeff ); static void getHeaterInternalTemp ( U32 TCIndex, U32 CJIndex ); -static void processADCRead_old ( U32 sensorIndex, U32 adc, U32 fpgaError, U32 fpgaCount ); //TODO remove static void processTempSnsrsADCRead ( U32 sensorIndex, U32 adc, U32 fpgaError, U32 fpgaCount ); static void processHtrsTempSnsrsADCRead ( U32 sensorIndex, U32 adc, U32 fpgaError, U32 fpgaCount ); @@ -603,145 +602,6 @@ temperatureValues [ sensorIndex ].data = temperature; } - -// TODO remove this function -static void processADCRead_old (U32 sensorIndex, U32 adc, U32 fpgaError, U32 fpgaCount ) -{ - U32 error; - BOOL isADCValid = TRUE; - F32 temperature; - S32 convertedADC; - - /* - * check if the index is not the heaters - * Mask the values accordingly - * if error is 0x80 for the external sensors, increment - * if count has not changed, update the previous count, increment the internal error count - * if the internal error count is above the threshold, set alarm, set the bool avGCalc to false - * if count is greater than previous, update the previous and reset the internal count - * set the avgCalc to true - * if the avgCalc in true, calculate all the steps and immediately convert to temperature - */ - //TODO clean up - if ( sensorIndex != TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE_TEMP_SENSOR && - sensorIndex != TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE_TEMP_SENSOR && - sensorIndex != TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION_TEMP_SENSOR && - sensorIndex != TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION_TEMP_SENSOR ) - { - error = 0; //TODO non-zero error - convertedADC = (S32)(adc & MASK_OFF_U32_MSB); - /* - * what if the fpga channel error is not zero? - * what if the fpga channel error is zero but the individual is not? - */ - - if ( fpgaError != 0 ) - { - if ( error == EXTERNAL_TEMP_SENSORS_ERROR_VALUE ) - { - // TODO: alarm? - } - //isADCValid = FALSE; - } - if ( error == EXTERNAL_TEMP_SENSORS_ERROR_VALUE ) - { - //tODO: FILL UP - //isADCValid = FALSE; - } - } - // It is a heaters temperature sensor - else if ( sensorIndex == TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE_TEMP_SENSOR || - sensorIndex == TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE_TEMP_SENSOR ) - { - // Cast the adc from U32 to U16 and shit it to left by 2 - U16 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; - } - else if ( sensorIndex == TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION_TEMP_SENSOR || - sensorIndex == TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION_TEMP_SENSOR ) - { - // Cast the adc from U32 to U16 and shift it by 4 - U16 rawADC = ( (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)rawADC ) >> SHIFT_BITS_BY_4; - } - - U32 previousReadCount = readAndErrorCounts [ sensorIndex ] [ READ_AND_ERROR_PREV_FPGA_COUNT_INDEX ]; - if ( fpgaCount == previousReadCount ) - { - U32 internalErrorCount = readAndErrorCounts [ sensorIndex ] [ READ_AND_ERROR_INTERNAL_ERROR_COUNT_INDEX ]; - if ( internalErrorCount > MAX_ALLOWED_UNCHANGED_ADC_READS ) - { - // TODO alarm - } - else - { - readAndErrorCounts [ sensorIndex ] [ READ_AND_ERROR_PREV_FPGA_COUNT_INDEX ] = fpgaCount; - readAndErrorCounts [ sensorIndex ] [ READ_AND_ERROR_INTERNAL_ERROR_COUNT_INDEX ] = internalErrorCount++; - } - //isADCValid = FALSE; - } - else if ( fpgaCount > previousReadCount ) - { - readAndErrorCounts [ sensorIndex ] [ READ_AND_ERROR_PREV_FPGA_COUNT_INDEX ] = fpgaCount; - readAndErrorCounts [ sensorIndex ] [ READ_AND_ERROR_INTERNAL_ERROR_COUNT_INDEX ] = 0; - isADCValid = TRUE; - } - - if ( isADCValid ) - { - // Update the values in the folders - U32 index = runningSumAndIndex [ sensorIndex ] [ ADC_READ_NEXT_INDEX_INDEX ]; - S32 runningSum = runningSumAndIndex [ sensorIndex ] [ ADC_READ_RUNNING_SUM_INDEX ]; - S32 indexValue = rawADCReads [ sensorIndex ] [ index ]; - U32 nextIndex = INC_WRAP( index, ADC_READ_FIRST_READ_INDEX, MAX_NUM_OF_RAW_ADC_SAMPLES - 1 ); - runningSum = runningSum - indexValue + convertedADC; - - rawADCReads [ sensorIndex ] [ index ] = convertedADC; - runningSumAndIndex [ sensorIndex ] [ ADC_READ_NEXT_INDEX_INDEX ] = nextIndex; - runningSumAndIndex [ sensorIndex ] [ ADC_READ_RUNNING_SUM_INDEX ] = runningSum; - - // If the buffer array is being filled for the first time, the number of samples - // are changing. When the array is filled up completely, max number of samples are used - if ( sampleCount < MAX_NUM_OF_RAW_ADC_SAMPLES ) - { - sampleCount++; - } - else - { - sampleCount = MAX_NUM_OF_RAW_ADC_SAMPLES; - } - // Calculate average - F32 avgADCReads = runningSum / sampleCount; - - // The external temperature sensors have gain and other parameters for temperature - // calculations. The heaters internal temperature sensors do not have any parameters - // this is used to decide whether to call the quadratic equation or not - if ( tempSensorsConstants [ sensorIndex ] [ ADC_READ_GAIN_INDEX ] != 0 ) - { - temperature = getADC2TempConversion ( avgADCReads, - tempSensorsConstants [ sensorIndex ] [ ADC_READ_GAIN_INDEX ], - tempSensorsConstants [ sensorIndex ] [ ADC_READ_REF_RESISTANCE_INDEX ], - tempSensorsConstants [ sensorIndex ] [ ADC_READ_0_DEG_RESISTANCE_INDEX ], 0 ); - } - if ( sensorIndex == TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE_TEMP_SENSOR || - sensorIndex == TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE_TEMP_SENSOR ) - { - temperature = avgADCReads * HEATERS_INTERNAL_TC_ADC_TO_TEMP_CONVERSION_COEFF; - } - if ( sensorIndex == TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION_TEMP_SENSOR || - sensorIndex == TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION_TEMP_SENSOR ) - { - temperature = avgADCReads * HEATERS_COLD_JUNCTION_ADC_TO_TEMP_CONVERSION_COEFF; - } - temperatureValues [ sensorIndex ].data = temperature; - } -} -//TODO remove this function - /************************************************************************* * @brief * The handleSelfTestStart function transitions the self test state to