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.

TM4C123x 内部温度传感器 精度问题

Other Parts Discussed in Thread: TM4C1231D5PZ, EK-TM4C123GXL

  使用TM4C1231D5PZ内部温度传感器对-20~70℃的环境进行测量,测得的温度始终比实际环境温度低4~11℃不等;使用LM3S9B92(内部温度传感器)进行同样的测量结果好一些(低3~6℃不等)。想请问:

1、按理来说,芯片在运行时其内部温度应比环境温度高,为何TM4C123x测得的温度比实际温度低?而且LM3S也有相同的现象?

2、有什么方法可以提高TM4C1231D5PZ内部温度传感器的测量精度?(±3℃以内)

原始数据如下:

Sequence

Environment Temp(℃)

LM3S real temp

TM4C real temp

1

-25

-28.01

-28.58

2

-20.1

-22.95

-23.56

3

-15.1

-17.68

-18.49

4

-10

-12.84

-14.44

5

-5

-8.00

-8.15

6

0

-3.38

-4.53

7

5

1.24

-0.90

8

10

5.86

3.75

9

15

11.36

9.37

10

20

15.98

13.72

11

25

20.59

18.25

12

30

27.63

26.59

13

35

30.71

27.80

14

40

35.33

31.97

15

45.4

40.39

35.90

16

50.3

45.45

40.85

17

55.1

49.19

44.23

18

60.3

55.12

50.94

19

65.2

59.52

55.17

20

70

64.14

59.28

 ——>以上数据是在温度试验箱内测得,每个温度点都经过足够保温时间,确保芯片温度与环境温度一致。

 ——>以上两个芯片的测量温度都是使用各自datasheet的内部温度传感器计算公式算得。

 

  • 请问您是否有尝试使用TI的示例代码测试呢?您现在的时钟是怎样的?是否有使用PLL?
  • 我在办公室测试了一下,官网的例程配合EK-TM4C123GXL

    结果还算稳定,23度上下

    代码如下

    //*****************************************************************************
    //
    // temperature_sensor.c - Example demonstrating the internal ADC temperature
    //                        sensor.
    //
    // Copyright (c) 2010-2017 Texas Instruments Incorporated.  All rights reserved.
    // Software License Agreement
    // 
    //   Redistribution and use in source and binary forms, with or without
    //   modification, are permitted provided that the following conditions
    //   are met:
    // 
    //   Redistributions of source code must retain the above copyright
    //   notice, this list of conditions and the following disclaimer.
    // 
    //   Redistributions in binary form must reproduce the above copyright
    //   notice, this list of conditions and the following disclaimer in the
    //   documentation and/or other materials provided with the  
    //   distribution.
    // 
    //   Neither the name of Texas Instruments Incorporated nor the names of
    //   its contributors may be used to endorse or promote products derived
    //   from this software without specific prior written permission.
    // 
    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    // 
    // This is part of revision 2.1.4.178 of the Tiva Firmware Development Package.
    //
    //*****************************************************************************
    
    #include <stdbool.h>
    #include <stdint.h>
    #include "inc/hw_memmap.h"
    #include "driverlib/adc.h"
    #include "driverlib/gpio.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/uart.h"
    #include "utils/uartstdio.h"
    
    //*****************************************************************************
    //
    //! \addtogroup adc_examples_list
    //! <h1>ADC Temperature Sensor (temperature_sensor)</h1>
    //!
    //! This example shows how to setup ADC0 to read the internal temperature
    //! sensor.
    //!
    //! NOTE: The internal temperature sensor is not calibrated.  This example
    //! just takes the raw temperature sensor sample and converts it using the
    //! equation found in the LM3S9B96 datasheet.
    //!
    //! This example uses the following peripherals and I/O signals.  You must
    //! review these and change as needed for your own board:
    //! - ADC0 peripheral
    //!
    //! The following UART signals are configured only for displaying console
    //! messages for this example.  These are not required for operation of the
    //! ADC.
    //! - UART0 peripheral
    //! - GPIO Port A peripheral (for UART0 pins)
    //! - UART0RX - PA0
    //! - UART0TX - PA1
    //!
    //! This example uses the following interrupt handlers.  To use this example
    //! in your own application you must add these interrupt handlers to your
    //! vector table.
    //! - None.
    //
    //*****************************************************************************
    
    //*****************************************************************************
    //
    // This function sets up UART0 to be used for a console to display information
    // as the example is running.
    //
    //*****************************************************************************
    void
    InitConsole(void)
    {
        //
        // Enable GPIO port A which is used for UART0 pins.
        // TODO: change this to whichever GPIO port you are using.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    
        //
        // Configure the pin muxing for UART0 functions on port A0 and A1.
        // This step is not necessary if your part does not support pin muxing.
        // TODO: change this to select the port/pin you are using.
        //
        GPIOPinConfigure(GPIO_PA0_U0RX);
        GPIOPinConfigure(GPIO_PA1_U0TX);
    
        //
        // Enable UART0 so that we can configure the clock.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    
        //
        // Use the internal 16MHz oscillator as the UART clock source.
        //
        UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
    
        //
        // Select the alternate (UART) function for these pins.
        // TODO: change this to select the port/pin you are using.
        //
        GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
        //
        // Initialize the UART for console I/O.
        //
        UARTStdioConfig(0, 115200, 16000000);
    }
    
    //*****************************************************************************
    //
    // Configure ADC0 for the temperature sensor input with a single sample.  Once
    // the sample is done, an interrupt flag will be set, and the data will be
    // read then displayed on the console via UART0.
    //
    //*****************************************************************************
    int
    main(void)
    {
    #if defined(TARGET_IS_TM4C129_RA0) ||                                         \
        defined(TARGET_IS_TM4C129_RA1) ||                                         \
        defined(TARGET_IS_TM4C129_RA2)
        uint32_t ui32SysClock;
    #endif
    
        //
        // This array is used for storing the data read from the ADC FIFO. It
        // must be as large as the FIFO for the sequencer in use.  This example
        // uses sequence 3 which has a FIFO depth of 1.  If another sequence
        // was used with a deeper FIFO, then the array size must be changed.
        //
        uint32_t pui32ADC0Value[1];
    
        //
        // These variables are used to store the temperature conversions for
        // Celsius and Fahrenheit.
        //
        uint32_t ui32TempValueC;
        uint32_t ui32TempValueF;
    
        //
        // Set the clocking to run at 20 MHz (200 MHz / 10) using the PLL.  When
        // using the ADC, you must either use the PLL or supply a 16 MHz clock
        // source.
        // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
        // crystal on your board.
        //
    #if defined(TARGET_IS_TM4C129_RA0) ||                                         \
        defined(TARGET_IS_TM4C129_RA1) ||                                         \
        defined(TARGET_IS_TM4C129_RA2)
        ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                           SYSCTL_OSC_MAIN |
                                           SYSCTL_USE_PLL |
                                           SYSCTL_CFG_VCO_480), 20000000);
    #else
        SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);
    #endif
    
        //
        // Set up the serial console to use for displaying messages.  This is just
        // for this example program and is not needed for ADC operation.
        //
        InitConsole();
    
        //
        // Display the setup on the console.
        //
        UARTprintf("ADC ->\n");
        UARTprintf("  Type: Internal Temperature Sensor\n");
        UARTprintf("  Samples: One\n");
        UARTprintf("  Update Rate: 250ms\n");
        UARTprintf("  Input Pin: Internal temperature sensor\n\n");
    
        //
        // The ADC0 peripheral must be enabled for use.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    
        //
        // Enable sample sequence 3 with a processor signal trigger.  Sequence 3
        // will do a single sample when the processor sends a singal to start the
        // conversion.  Each ADC module has 4 programmable sequences, sequence 0
        // to sequence 3.  This example is arbitrarily using sequence 3.
        //
        ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
    
        //
        // Configure step 0 on sequence 3.  Sample the temperature sensor
        // (ADC_CTL_TS) and configure the interrupt flag (ADC_CTL_IE) to be set
        // when the sample is done.  Tell the ADC logic that this is the last
        // conversion on sequence 3 (ADC_CTL_END).  Sequence 3 has only one
        // programmable step.  Sequence 1 and 2 have 4 steps, and sequence 0 has
        // 8 programmable steps.  Since we are only doing a single conversion using
        // sequence 3 we will only configure step 0.  For more information on the
        // ADC sequences and steps, reference the datasheet.
        //
        ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_TS | ADC_CTL_IE |
                                 ADC_CTL_END);
    
        //
        // Since sample sequence 3 is now configured, it must be enabled.
        //
        ADCSequenceEnable(ADC0_BASE, 3);
    
        //
        // Clear the interrupt status flag.  This is done to make sure the
        // interrupt flag is cleared before we sample.
        //
        ADCIntClear(ADC0_BASE, 3);
    
        //
        // Sample the temperature sensor forever.  Display the value on the
        // console.
        //
        while(1)
        {
            //
            // Trigger the ADC conversion.
            //
            ADCProcessorTrigger(ADC0_BASE, 3);
    
            //
            // Wait for conversion to be completed.
            //
            while(!ADCIntStatus(ADC0_BASE, 3, false))
            {
            }
    
            //
            // Clear the ADC interrupt flag.
            //
            ADCIntClear(ADC0_BASE, 3);
    
            //
            // Read ADC Value.
            //
            ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value);
    
            //
            // Use non-calibrated conversion provided in the data sheet.  Make
            // sure you divide last to avoid dropout.
            //
            ui32TempValueC = ((1475 * 1023) - (2250 * pui32ADC0Value[0])) / 10230;
    
            //
            // Get Fahrenheit value.  Make sure you divide last to avoid dropout.
            //
            ui32TempValueF = ((ui32TempValueC * 9) + 160) / 5;
    
            //
            // Display the temperature value on the console.
            //
            UARTprintf("Temperature = %3d*C or %3d*F\r", ui32TempValueC,
                       ui32TempValueF);
    
            //
            // This function provides a means of generating a constant length
            // delay.  The function delay (in cycles) = 3 * parameter.  Delay
            // 250ms arbitrarily.
            //
    #if defined(TARGET_IS_TM4C129_RA0) ||                                         \
        defined(TARGET_IS_TM4C129_RA1) ||                                         \
        defined(TARGET_IS_TM4C129_RA2)
            SysCtlDelay(ui32SysClock / 12);
    #else
            SysCtlDelay(SysCtlClockGet() / 12);
    #endif
        }
    }
    

  • 可以通过手工校准来提高测量精度
  • 不知道你的办公室室温是多少?我也用这个官方例程配合EK-TM4C123GXL试过,稳定在22、23℃,但我的室温是29℃。
  • 1、没有使用TI示例代码,但也差不多;时钟使用PLL,4分频,即50Hz;

    2、用TI示例代码配合EK-TM4C123GXL得到的温度(23)也比实际室温(29)低6℃左右;

    TM4C1231D5PZ具体代码如下结构;

    首先初始化:

    ROM_SysCtlClockSet( SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_25MHZ );

    ROM_SysCtlPeripheralEnable( SYSCTL_PERIPH_ADC0 );

    /* configure internal ADC ONLY used for internal temperature */

    ROM_ADCSequenceConfigure( ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0 );  /* ADC module 0, sequence 0 ,processor trigger, highest priority */

    ROM_ADCHardwareOversampleConfigure( ADC0_BASE, 64 );    /*set 64x hardware oversampling */

    ROM_ADCSequenceStepConfigure( ADC0_BASE, 0, 0, ADC_CTL_END | ADC_CTL_TS ); 

    ROM_ADCSequenceEnable( ADC0_BASE, 0 ); /*  enable sequence */

     

    然后在主循环中触发和读取:

    While(1)

    {

    xxxxxxxxxxxxxxxxxxxxxxxxxx

    xxxxxxxxxxxxxxxxxxxxxxxxxx

    ul_loop_count++;

    If(ul_loop_count >= 10000)

    {

    ul_loop_count = 0;

    }

    switch( ul_loop_count )

    {

    case 1:

    ROM_ADCProcessorTrigger( ADC0_BASE, 0 );

    break;

    case 200:

    xxxxxxxxxxxxxxxxxxxxxxxxxx

    xxxxxxxxxxxxxxxxxxxxxxxxxx

    break;

    case 500:

    xxxxxxxxxxxxxxxxxxxxxxxxxx

    xxxxxxxxxxxxxxxxxxxxxxxxxx

    break;

    case 700:

    ROM_ADCSequenceDataGet( ADC0_BASE, 0, &ul_ADC0_values[ 0 ] );

    break;

    case 1000:

    xxxxxxxxxxxxxxxxxxxxxxxxxx

    xxxxxxxxxxxxxxxxxxxxxxxxxx

    break;

    }

    xxxxxxxxxxxxxxxxxxxxxxxxxx

    Xxxxxxxxxxxxxxxxxxxxxxxxxx

    }

     

  • 没别的办法话只能通过我测出来的曲线去校准了。。
  • 本来就是测芯片温度的,用这个测环境温度还是算了。