This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

A temperature issue TM4C123GH6PM

I'm using the internal temperature ADC channel, my atmosphere temperature is 24 degree C,
but actually my conversion and calculation result is 16 degree C, i'm wondering what's wrong with my code,
Below is my code:

void Int_Temp_Sensor_Init(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1);
ADCSequenceConfigure(ADC1_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC1_BASE, 1, 0, ADC_CTL_TS);
ADCSequenceStepConfigure(ADC1_BASE, 1, 1, ADC_CTL_TS);
ADCSequenceStepConfigure(ADC1_BASE, 1, 2, ADC_CTL_TS);
ADCSequenceStepConfigure(ADC1_BASE, 1, 3, ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END);
}


uint32_t readSysTemp(void)
{
uint32_t ui32ADC1TempValue[4];
uint32_t ui32TempAvg;
uint32_t ui32TempValueC;

ADCSequenceEnable(ADC1_BASE, 1);

ADCIntClear(ADC1_BASE, 1);
ADCProcessorTrigger(ADC1_BASE, 1);
while(!ADCIntStatus(ADC1_BASE, 1, false))
{
}
ADCSequenceDataGet(ADC1_BASE, 1, ui32ADC1TempValue);

ui32TempAvg = (ui32ADC1TempValue[0] + ui32ADC1TempValue[1] + ui32ADC1TempValue[2] + ui32ADC1TempValue[3] + 2)/4;
// TEMP = 147.5 – ((75 * (VREFP – VREFN) * ADCVALUE) / 4096)
// (VREFP – VREFN) is Vdd or 3.3 volts
ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096)/10;

ADCSequenceDisable(ADC1_BASE, 1);

return ui32TempValueC;
}


Have any issue in my code?thanks.

Ashley

  • Hello Ashley

    In the computation of ui32TempAvg what is the "+ 2" for?

    The next thing is the ADC Reference voltage : Is it 3.3V or 3.0V on the board (if it is a custom board)?

    Regards
    Amit
  • Would it not be useful for poster to supply a listing of many bare, "ADC conversion results" - free from her "ADC values to Temp" conversions?
     
    Issue may lie w/in:

    a) the actual ADC conversion and/or MCU reference levels
    b) the "ADC value to Temperature formula" and/or math implementation

    May be one or both - yet "Kitchen Sink" approach provides zero insight as to "where" the issue lurks.   And occurs here - far too often!

    KISS (not much promoted here) Rules - and eliminates such "What now?" confusion & issues...

  • The errata on the internal temperature sense channel may come into play as well.

    Robert
  • Indeed - yet KISS stresses, "Simplify, divide & conquer, and perhaps (sometimes) read the device's errata."

    One notes that, "item A" under the suggested procedure, has the best chance of quickly/easily identifying "errant" ADC readings.   (i.e. before they are "drowned" w/in the "Value to Temperature" code-flow...)

    Reporting - and apparently (only) looking @ "end results" - buries & obscures the vital "intermediate measures" - which so often shine bright light upon an (otherwise) dark corner...

  • Indeed, getting the raw values is paramount. Whether the errata effect is strong enough to produce what is being reported is questionable.

    Robert
  • @Robert,

    Dawns that a "quick/dirty" test (our favorite) would see the "expected/predicted" 25° C room ambient converted (calculated manually) to ADC counts.   Armed w/that - poster's, "ADC count/value to Temp" code block can be easily tested.  

    And - this method achieves the (always desirable) "single rock - two birds" outcome - as the ADC's (possible) deviation from the 25° calculated value - can be immediately identified.   Thus - one "back of (used) envelope" math exercise should solve poster's issue - clearly ID the source of her problem...