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.

28004x内部温度采样无法找到相关.c文件

Other Parts Discussed in Thread: C2000WARE

13.3.5 Internal Temperature Sensor
The internal temperature sensor measures the junction temperature of the device. The output of the
sensor can be sampled with the ADC through an internal connection. This can be enabled on channel
ADCIN14 on ADCB by setting the ENABLE bit in the TSNSCTL register.
To convert the temperature sensor reading into a temperature, pass the temperature sensor reading to the
GetTemperatureC() function in F28004x_TempSensorConv.c.
Note that this function assumes that the temperature reading was taken with VREFHI = 2.5V. If a different
reference voltage is used, the sample should be scaled appropriately before passing it to the function by
using the below formula.
adjusted sensor reading = raw sensor reading * (VREFHI / 2.5V)

F28004x_TempSensorConv.c没有这个文件,可以参考使用其他型号的么?

  • 您可以参考下

    C:\ti\c2000\C2000Ware_2_00_00_02\driverlib\f28004x\examples\adc

    内的例程
  • //#############################################################################
    //
    // FILE:   adc_ex3_temp_sensor.c
    //
    // TITLE:  Sample temperature sensor and convert to temperature
    //
    //! \addtogroup driver_example_list
    //! <h1>ADC Temperature Sensor Conversion</h1>
    //!
    //! This example sets up the ePWM to periodically trigger the ADC.  The
    //! ADC converts the internal connection to the temperature sensor,
    //! which is then interpreted as a temperature by calling the
    //! ADC_getTemperatureC() function.
    //!
    //! \b External \b Connections \n
    //!  - Connect VREFHI and VREFLO to desired reference voltage. If not 3.3V,
    //!    make sure to adjust the argument to ADC_getTemperatureC() below.
    //!
    //! \b Watch \b Variables \n
    //! - \b sensorSample - The raw reading from the temperature sensor
    //! - \b sensorTemp   - The interpretation of the sensor sample as a temperature
    //!                     in degrees Celsius.
    //
    //#############################################################################
    // $TI Release: F28004x Support Library v1.06.00.00 $
    // $Release Date: Mon May 27 06:42:25 CDT 2019 $
    // $Copyright:
    // Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
    //
    // 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.
    // $
    //#############################################################################
    
    //
    // Included Files
    //
    #include "driverlib.h"
    #include "device.h"
    
    //
    // Globals
    //
    uint16_t sensorSample;
    int16_t sensorTemp;
    
    //
    // Function Prototypes
    //
    void initADC(void);
    void initEPWM(void);
    void initADCSOC(void);
    __interrupt void adcB1ISR(void);
    
    //
    // Main
    //
    void main(void)
    {
        //
        // Initialize device clock and peripherals
        //
        Device_init();
    
        //
        // Disable pin locks and enable internal pullups.
        //
        Device_initGPIO();
    
        //
        // Initialize PIE and clear PIE registers. Disables CPU interrupts.
        //
        Interrupt_initModule();
    
        //
        // Initialize the PIE vector table with pointers to the shell Interrupt
        // Service Routines (ISR).
        //
        Interrupt_initVectorTable();
    
        //
        // Interrupts that are used in this example are re-mapped to ISR functions
        // found within this file.
        //
        Interrupt_register(INT_ADCB1, &adcB1ISR);
    
        //
        // Set up the ADC and the ePWM and initialize the SOC
        //
        initADC();
        initEPWM();
        initADCSOC();
    
        //
        // Enable the temperature sensor and give it 500 us to power up
        //
        ASysCtl_enableTemperatureSensor();
        DEVICE_DELAY_US(500);
    
        //
        // Enable ADC interrupt
        //
        Interrupt_enable(INT_ADCB1);
    
        //
        // Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
        //
        EINT;
        ERTM;
    
        //
        // Start ePWM1, enabling SOCA and putting the counter in up-count mode
        //
        EPWM_enableADCTrigger(EPWM1_BASE, EPWM_SOC_A);
        EPWM_setTimeBaseCounterMode(EPWM1_BASE, EPWM_COUNTER_MODE_UP);
    
        //
        // Loop indefinitely
        //
        while(1)
        {
            ;
        }
    }
    
    //
    // initADC - Function to configure and power up ADCB.
    //
    void initADC(void)
    {
        //
        // Setup VREF as external as required by the temperature sensor. Note that
        // the refVoltage parameter has no effect in this case.
        //
        ADC_setVREF(ADCB_BASE, ADC_REFERENCE_EXTERNAL, ADC_REFERENCE_3_3V);
    
        //
        // Set ADCCLK divider to /4
        //
        ADC_setPrescaler(ADCB_BASE, ADC_CLK_DIV_4_0);
    
        //
        // Set pulse positions to late
        //
        ADC_setInterruptPulseMode(ADCB_BASE, ADC_PULSE_END_OF_CONV);
    
        //
        // Power up the ADC and then delay for 1 ms
        //
        ADC_enableConverter(ADCB_BASE);
        DEVICE_DELAY_US(1000);
    }
    
    //
    // initEPWM - Function to configure ePWM1 to generate the SOC.
    //
    void initEPWM(void)
    {
        //
        // Disable SOCA
        //
        EPWM_disableADCTrigger(EPWM1_BASE, EPWM_SOC_A);
    
        //
        // Configure the SOC to occur on the first up-count event
        //
        EPWM_setADCTriggerSource(EPWM1_BASE, EPWM_SOC_A, EPWM_SOC_TBCTR_U_CMPA);
        EPWM_setADCTriggerEventPrescale(EPWM1_BASE, EPWM_SOC_A, 1);
    
        //
        // Set the compare A value to 2048 and the period to 4096
        //
        EPWM_setCounterCompareValue(EPWM1_BASE, EPWM_COUNTER_COMPARE_A, 0x0800);
        EPWM_setTimeBasePeriod(EPWM1_BASE, 0x1000);
    
        //
        // Freeze the counter
        //
        EPWM_setTimeBaseCounterMode(EPWM1_BASE, EPWM_COUNTER_MODE_STOP_FREEZE);
    }
    
    //
    // initADCSOC - Function to configure ADCB's SOC0 to be triggered by ePWM1.
    //
    void initADCSOC(void)
    {
        //
        // Configure SOC0. The temperature sensor is internally connected to B14
        // and requires an acquisition time of at least 450 ns.
        //
        ADC_setupSOC(ADCB_BASE, ADC_SOC_NUMBER0, ADC_TRIGGER_EPWM1_SOCA,
                     ADC_CH_ADCIN14, 45);
    
        //
        // Set SOC0 to set the interrupt 1 flag. Enable the interrupt and make
        // sure its flag is cleared.
        //
        ADC_setInterruptSource(ADCB_BASE, ADC_INT_NUMBER1, ADC_SOC_NUMBER0);
        ADC_enableInterrupt(ADCB_BASE, ADC_INT_NUMBER1);
        ADC_clearInterruptStatus(ADCB_BASE, ADC_INT_NUMBER1);
    }
    
    //
    // adcB1ISR - ADC B Interrupt 1 ISR
    //
    __interrupt void adcB1ISR(void)
    {
        //
        // Read the raw result
        //
        sensorSample = ADC_readResult(ADCBRESULT_BASE, ADC_SOC_NUMBER0);
    
        //
        // Convert the result to a temperature in degrees C
        //
        sensorTemp = ADC_getTemperatureC(sensorSample, 3.3f);
    
        //
        // Clear the interrupt flag
        //
        ADC_clearInterruptStatus(ADCB_BASE, ADC_INT_NUMBER1);
    
        //
        // Check if overflow has occurred
        //
        if(true == ADC_getInterruptOverflowStatus(ADCB_BASE, ADC_INT_NUMBER1))
        {
            ADC_clearInterruptOverflowStatus(ADCB_BASE, ADC_INT_NUMBER1);
            ADC_clearInterruptStatus(ADCB_BASE, ADC_INT_NUMBER1);
        }
    
        //
        // Acknowledge the interrupt
        //
        Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP1);
    }
    

  • //*****************************************************************************
    //
    //! Converts temperature from sensor reading to degrees C
    //!
    //! \param tempResult is the raw ADC A conversion result from the temp sensor.
    //! \param vref is the reference voltage being used (for example 3.3 for 3.3V).
    //!
    //! This function converts temperature from temp sensor reading to degrees C.
    //! Temp sensor values in production test are derived with 2.5V reference.
    //! The \b vref argument in the function is used to scale the temp sensor
    //! reading accordingly if temp sensor value is read at a different VREF
    //! setting.
    //!
    //! \note Only external reference mode is supported for the temperature sensor.
    //! This function does not set the reference mode. Reference mode can be set
    //! using ADC_setVREF(). using ADC_setVREF().
    //!
    //! \return Returns the temperature sensor reading converted to degrees C.
    //
    //*****************************************************************************
    static inline int16_t
    ADC_getTemperatureC(uint16_t tempResult, float32_t vref)
    {
    float32_t temp;

    //
    // Read temp sensor slope and offset locations from OTP and convert
    //
    temp = (float32_t)tempResult * (vref / 2.5F);
    return((int16_t)((((int32_t)temp - ADC_EXT_REF_TSOFFSET) * 4096) /
    ADC_EXT_REF_TSSLOPE));
    }
    \note Only external reference mode is supported for the temperature sensor.
    是否可以理解为必须外部给AD基准才可以使用这个温度采样?
  • Only external reference mode is supported for the temperature sensor.

    是的