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.

TMS320F28377D: readings of internal temperature sensor of TMS320f28377D

Part Number: TMS320F28377D
Other Parts Discussed in Thread: C2000WARE

Tool/software:

hi am using TMS320F28377D microcontroller to access the internal temperature i have used below code but the reading always showing 4095(in decimal) as i want to do polling method instead of interrupt i did not used temperature sensor code in drvierlib 

the function that i have used:-

SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_ADCA);

ADC_setPrescaler(ADCA_BASE, ADC_CLK_DIV_4_0);

ADC_setupSOC(ADCA_BASE, ADC_SOC_NUMBER0, ADC_TRIGGER_SW_ONLY, ADC_CH_ADCIN13, 140); // 140 clock cycles @ 200 MHz = 700ns time period to allow temp sensor enough time to acquire data

ADC_setInterruptSOCTrigger(ADCA_BASE, ADC_SOC_NUMBER0, ADC_INT_SOC_TRIGGER_ADCINT1);

ADC_setInterruptSource(ADCA_BASE, ADC_INT_NUMBER1, ADC_SOC_NUMBER0);

ADC_enableContinuousMode(ADCA_BASE, ADC_INT_NUMBER1);

ADC_enableInterrupt(ADCA_BASE, ADC_INT_NUMBER1);

ADC_clearInterruptStatus(ADCA_BASE, ADC_INT_NUMBER1);

ADC_forceSOC(ADCA_BASE, ADC_SOC_NUMBER0);

ADC_enableConverter(ADCA_BASE);

ASysCtl_enableTemperatureSensor();
DEVICE_DELAY_US(1000);

// Read ADC result
sensorSample = ADC_readResult(ADCARESULT_BASE, ADC_SOC_NUMBER0);

// Convert to temperature (Celsius)
sensorTemp = ADC_getTemperatureC(sensorSample, 3.0f); // assuming 3.0V reference

please let me know if am missing something 

regards

J.Muniniteesh

  • Part Number: TMS320F28377D

    Tool/software:

    hi, am using TMS320F28377D microcontroller and used the example from D:\TI\C2000Ware_4_02_00_00\driverlib\f2837xd\examples\cpu1\adc\adc_ex3_temp_sensor.c but am not getting proper output as below below 

    it is showing always zero for sample sensor data which will be returned from ADC_readResult() function for ur reference i have copy pasted the example code that i used 

    //#############################################################################
    //
    // 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 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.
    //
    //#############################################################################
    //
    // $Release Date: $
    // $Copyright:
    // Copyright (C) 2013-2022 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"
    /*Inclusion of Header Files*/
    #include <Inc/DMM_APPLICATION/DMM_App_SerialDebug.h>
    #include <Inc/DMM_APPLICATION/DMM_App_Main.h>
    // Globals
    //
    uint16_t sensorSample;
    int16_t sensorTemp;
    int16_t buff[120];
    //
    // Function Prototypes
    //
    void initADC(void);
    void initEPWM(void);
    void initADCSOC(void);
    __interrupt void adcA1ISR(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_ADCA1, &adcA1ISR);

    //
    // 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_ADCA1);

    //
    // 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 ADCA.
    //
    void initADC(void)
    {

    //
    // Set ADCDLK divider to /4
    //
    ADC_setPrescaler(ADCA_BASE, ADC_CLK_DIV_4_0);

    //
    // Set resolution and signal mode (see #defines above) and load
    // corresponding trims.
    //
    ADC_setMode(ADCA_BASE, ADC_RESOLUTION_12BIT, ADC_MODE_SINGLE_ENDED);

    //
    // Set pulse positions to late
    //
    ADC_setInterruptPulseMode(ADCA_BASE, ADC_PULSE_END_OF_CONV);

    //
    // Power up the ADC and then delay for 1 ms
    //
    ADC_enableConverter(ADCA_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 1000 and the period to 1999
    // Assuming ePWM clock is 100MHz, this would give 50kHz sampling
    // 50MHz ePWM clock would give 25kHz sampling, etc.
    // The sample rate can also be modulated by changing the ePWM period
    // directly (ensure that the compare A value is less than the period).
    //
    EPWM_setCounterCompareValue(EPWM1_BASE, EPWM_COUNTER_COMPARE_A, 1000);
    EPWM_setTimeBasePeriod(EPWM1_BASE, 1999);

    //
    // Set the local ePWM module clock divider to /1
    //
    EPWM_setClockPrescaler(EPWM1_BASE,
    EPWM_CLOCK_DIVIDER_1,
    EPWM_HSCLOCK_DIVIDER_1);

    //
    // Freeze the counter
    //
    EPWM_setTimeBaseCounterMode(EPWM1_BASE, EPWM_COUNTER_MODE_STOP_FREEZE);
    }

    //
    // initADCSOC - Function to configure ADCA's SOC0 to be triggered by ePWM1.
    //
    void initADCSOC(void)
    {
    //
    // Configure SOC0. The temperature sensor is internally connected to A13
    // and requires an acquisition time of at least 700 ns.
    //
    ADC_setupSOC(ADCA_BASE, ADC_SOC_NUMBER0, ADC_TRIGGER_EPWM1_SOCA,
    ADC_CH_ADCIN13, 140);

    //
    // Set SOC0 to set the interrupt 1 flag. Enable the interrupt and make
    // sure its flag is cleared.
    //
    ADC_setInterruptSource(ADCA_BASE, ADC_INT_NUMBER1, ADC_SOC_NUMBER0);
    ADC_enableInterrupt(ADCA_BASE, ADC_INT_NUMBER1);
    ADC_clearInterruptStatus(ADCA_BASE, ADC_INT_NUMBER1);
    }

    //
    // adcA1ISR - ADC A Interrupt 1 ISR
    //
    __interrupt void adcA1ISR(void)
    {
    DMM_App_Serial_Print("\n\r temperature measurement started \n\r");
    //
    // Read the raw result
    //
    sensorSample = ADC_readResult(ADCARESULT_BASE, ADC_SOC_NUMBER0);

    //
    // Convert the result to a temperature in degrees C
    //
    sensorTemp = ADC_getTemperatureC(sensorSample, 3.0f);

    snprintf(buff,sizeof(buff),"the temperature is %d \n",sensorTemp);
    DMM_App_Serial_Print(buff);
    //
    // Clear the interrupt flag
    //
    ADC_clearInterruptStatus(ADCA_BASE, ADC_INT_NUMBER1);

    //
    // Check if overflow has occurred
    //
    if(true == ADC_getInterruptOverflowStatus(ADCA_BASE, ADC_INT_NUMBER1))
    {
    ADC_clearInterruptOverflowStatus(ADCA_BASE, ADC_INT_NUMBER1);
    ADC_clearInterruptStatus(ADCA_BASE, ADC_INT_NUMBER1);
    }

    //
    // Acknowledge the interrupt
    //
    Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP1);
    }

    please help me to get the proper output to read the temperature 

    regards

    J.Muniniteesh

  • Hello,

    Even though you want to poll vs INT, I would still look at the initADC() function in the adc_ex3_temp_sensor pjt. Looking at your code above it appears that you are missing this function call

    ADC_setMode(ADCA_BASE, ADC_RESOLUTION_12BIT, ADC_MODE_SINGLE_ENDED);

    Since you are getting 4095, I suspect that the ADC reference is not on, which would make any conversion look like FSR = 4095.  Try to add the above function call, if that doesn't work, I would recommend stepping through that example to see if there is another function that is missing.

    Best,

    Matthew

  • hi matthew, 

    when used the temperature example code on EVM board of TMS320f28377D it is working fine but if i used on my custom board the values are not coming can u please help me out

    Device_init();

    Device_initGPIO();

    Interrupt_initModule();

    Interrupt_initVectorTable();

    Interrupt_register(INT_ADCA1, &adcA1ISR);

    initADC();
    initEPWM();
    initADCSOC();

    ASysCtl_enableTemperatureSensor();
    DEVICE_DELAY_US(500);

    Interrupt_enable(INT_ADCA1);

    EINT;
    ERTM;

    EPWM_enableADCTrigger(EPWM1_BASE, EPWM_SOC_A);
    EPWM_setTimeBaseCounterMode(EPWM1_BASE, EPWM_COUNTER_MODE_UP);

    while(1)
    {
    ;
    }

    }

    void initADC(void)
    {

    ADC_setPrescaler(ADCA_BASE, ADC_CLK_DIV_4_0);

    ADC_setMode(ADCA_BASE, ADC_RESOLUTION_12BIT, ADC_MODE_SINGLE_ENDED);
    ADC_setInterruptPulseMode(ADCA_BASE, ADC_PULSE_END_OF_CONV);

    ADC_enableConverter(ADCA_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);


    EPWM_setCounterCompareValue(EPWM1_BASE, EPWM_COUNTER_COMPARE_A, 1000);
    EPWM_setTimeBasePeriod(EPWM1_BASE, 1999);

    //
    // Set the local ePWM module clock divider to /1
    //
    EPWM_setClockPrescaler(EPWM1_BASE,
    EPWM_CLOCK_DIVIDER_1,
    EPWM_HSCLOCK_DIVIDER_1);

    //
    // Freeze the counter
    //
    EPWM_setTimeBaseCounterMode(EPWM1_BASE, EPWM_COUNTER_MODE_STOP_FREEZE);
    }

    //
    // initADCSOC - Function to configure ADCA's SOC0 to be triggered by ePWM1.
    //
    void initADCSOC(void)
    {
    //
    // Configure SOC0. The temperature sensor is internally connected to A13
    // and requires an acquisition time of at least 700 ns.
    //
    ADC_setupSOC(ADCA_BASE, ADC_SOC_NUMBER0, ADC_TRIGGER_EPWM1_SOCA,
    ADC_CH_ADCIN13, 140);

    //
    // Set SOC0 to set the interrupt 1 flag. Enable the interrupt and make
    // sure its flag is cleared.
    //
    ADC_setInterruptSource(ADCA_BASE, ADC_INT_NUMBER1, ADC_SOC_NUMBER0);
    ADC_enableInterrupt(ADCA_BASE, ADC_INT_NUMBER1);
    ADC_clearInterruptStatus(ADCA_BASE, ADC_INT_NUMBER1);
    }

    //
    // adcA1ISR - ADC A Interrupt 1 ISR
    //
    __interrupt void adcA1ISR(void)
    {
    DMM_App_Serial_Print("\n\r temperature measurement started \n\r");
    //
    // Read the raw result
    //
    sensorSample = ADC_readResult(ADCARESULT_BASE, ADC_SOC_NUMBER0);

    snprintf(buff,sizeof(buff),"the ADC sample is %d \n",sensorSample);
    DMM_App_Serial_Print(buff);
    //
    // Convert the result to a temperature in degrees C
    //
    sensorTemp = ADC_getTemperatureC(sensorSample, 3.0f);

    snprintf(buff,sizeof(buff),"the temperature is %d \n",sensorTemp);
    DMM_App_Serial_Print(buff);
    //
    // Clear the interrupt flag
    //
    ADC_clearInterruptStatus(ADCA_BASE, ADC_INT_NUMBER1);

    //
    // Check if overflow has occurred
    //
    if(true == ADC_getInterruptOverflowStatus(ADCA_BASE, ADC_INT_NUMBER1))
    {
    ADC_clearInterruptOverflowStatus(ADCA_BASE, ADC_INT_NUMBER1);
    ADC_clearInterruptStatus(ADCA_BASE, ADC_INT_NUMBER1);
    }

    //
    // Acknowledge the interrupt
    //
    Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP1);
    }

    do i miss something to add 

    regards

    J.Muniniteesh

  • Muniniteesh,

    If you use the TI example code on your board(as is), does this work?  I'm trying to understand if there is a HW issue in play with your PCB or not.  If our example code also works on your PCB, then we can focus on the FW.

    Best,

    Matthew

  • hi matthew,

     TI example code is working on EVM board (evaluation board) but on our custom made PCB with TMS320f28377D microcontroller is not working am continuously getting 4095(in decimal) as output of ADC_readResult function 

    regards

    J.Muniniteesh

  • Muniniteesh,

    Thanks for the update.  Can you comment on what is connected to the VREFHI/VREFLO pins(please see below from the DS)?

    We are expecting an exteranal precision reference to drive these pins.  If these are floating or grounded it may explain why you are seeing 4095 all the time.

    Best,

    Matthew 

  • Matthew, 

    thanks for your reply. in our design we did not connected any source to drive those pins that is the reason why am getting 4095 

    regards

    J.Muniniteesh