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.

CCS/CC2640R2F: Lm335 temperature sensor with CC2640R2

Part Number: CC2640R2F
Other Parts Discussed in Thread: LM335

Tool/software: Code Composer Studio

Hello

I'm doing a little project in which i use a CC2640R2 with a LM335 to measure the ambient temperature. 

tempy = (((adcValue0 * 3.3 * 100 ) /4096));
Temp_final =  tempy >> 10;

But my output is not right. I connect the lm335 to 5 V and my measure is    ADC Raw: 2775 and Vout= 2.98V.

Did i miss anything ? 

Best regards

  • Does that mean you can get a voltage higher than VDDS on the input of CC2640R2 since you are powering the LM335 with 5 V? If that is the case, revise the design.

    Are you using the same functions as used in dev.ti.com/.../README.html to calculate the voltage value? It's a bit difficult to see based on the the code you have posted.
  • Yes, i'm using adcsinglechannel example. Inicially i used 3.3V but after reading the lm335 datasheet, i change to 5V.
  • Did you change R accordingly to about 2000 ohms?

    What makes you think that 2.98 is incorrect? Room temperature in K is about 293 K, which makes your 2.98 about 5 deg C higher.

    The LM335 outputs 10mV/K so at 293 K you should read 2.93 V.
  • My R is 1K. I did a test with a lighter to check and the value stayed the same
  • What does your DVM do?
  • Please post all the ADC related code.
  • *  ======== adcsinglechannel.c ========
     */
    #include <stdint.h>
    #include <stddef.h>
    
    /* POSIX Header files */
    #include <pthread.h>
    #include "sys/types.h"
    /* Driver Header files */
    #include <ti/drivers/ADC.h>
    #include <ti/display/Display.h>
    #include <ti/drivers/GPIO.h>
    
    /* Example/Board Header files */
    #include "Board.h"
    
    /* ADC sample count */
    #define ADC_SAMPLE_COUNT  (10)
    
    #define THREADSTACKSIZE   (768)
    
    /* ADC conversion result variables */
    uint16_t  estado;
    uint16_t adcValue0;
    uint32_t adcValue0MicroVolt;
    uint16_t adcValue1[ADC_SAMPLE_COUNT];
    uint32_t adcValue1MicroVolt[ADC_SAMPLE_COUNT];
    
    static Display_Handle display;
    
    * ======== threadFxn0 ========
     * Open an ADC instance and get a sampling result from a one-shot conversion.
     */
    
    void *threadFxn0(void *arg0)
    {
        ADC_Handle   adc;
        ADC_Params   params;
        int_fast16_t res;
        
        int_fast16_t tempy;
        float temperatura;
    
    
    
        ADC_Params_init(&params);
    
        while(1)
        {
        adc = ADC_open(Board_ADC0, &params); // inicia conversão para canal DIO23
        
    
        if (adc == NULL) {
            Display_printf(display, 0, 0, "Error initializing ADC channel 0\n");
            while (1);
        }
    
        // Blocking mode conversion  //users have to wait the current sampling finished before starting another sampling.
        res = ADC_convert(adc, &adcValue0);
    
    
        if (res == ADC_STATUS_SUCCESS) {
    
            adcValue0MicroVolt = ADC_convertRawToMicroVolts(adc, adcValue0); // utiliza funcao pre definida da biblioteca do ADC
    
            
    		tempy = (((adcValue0 * 3.3 * 100 ) /4096));
    		Temp_final =  tempy >> 10;
    
            Display_printf(display, 0, 0, "ADC channel 0 raw result: %d\n", adcValue0);
            Display_printf(display, 0, 0, "ADC: %d\n", resultado);
    
            Display_printf(display, 0, 0, "Temperatura: %d\n",temperatura);
            Display_printf(display, 0, 0, "ADC channel 0 convert result: %d uV\n",
                adcValue0MicroVolt);
           // estado = GPIO_read (Board_GPIO_BUTTON0);
    
        }
        else {
            Display_printf(display, 0, 0, "ADC channel 0 convert failed\n");
        }
    
        ADC_close(adc); // desabilita conversao
    
       
        sleep(3); //funciona como delay
        }
        }
        return (NULL);
    }
     *  ======== mainThread ========
     */
    void *mainThread(void *arg0)
    {
        pthread_t           thread0, thread1;
        pthread_attr_t      attrs;
        struct sched_param  priParam;
        int                 retc;
        int                 detachState;
    
    
        /* Call driver init functions */
        ADC_init();
        GPIO_init();
        Display_init();
    
        /* Open the display for output */
        display = Display_open(Display_Type_UART, NULL);
        if (display == NULL)
        {
            /* Failed to open display driver */
            while (1);
        }
    
        Display_printf(display, 0, 0, "Exemplo:\n");
    //************************ ***************************  Iniciar led e botoes
        /* Create application threads */
           pthread_attr_init(&attrs);
    
           detachState = PTHREAD_CREATE_DETACHED;
           /* Set priority and stack size attributes */
           retc = pthread_attr_setdetachstate(&attrs, detachState);
           if (retc != 0) {
               /* pthread_attr_setdetachstate() failed */
               while (1);
           }
    
           retc |= pthread_attr_setstacksize(&attrs, THREADSTACKSIZE);
           if (retc != 0) {
               /* pthread_attr_setstacksize() failed */
               while (1);
           }
    
           /* Create threadFxn0 thread */
           priParam.sched_priority = 1;
           pthread_attr_setschedparam(&attrs, &priParam);
    
           retc = pthread_create(&thread0, &attrs, threadFxn0, NULL);
           if (retc != 0) {
               /* pthread_create() failed */
               while (1);
           }
    
           /* Create threadFxn1 thread */
        //   retc = pthread_create(&thread1, &attrs, threadFxn1, (void* )0);
          // if (retc != 0) {
               /* pthread_create() failed */
          //     while (1);
         //  }
    
           return (NULL);
       }

  • sorry my ignorance, but what means dvm ?
  • Looking at your code:

    adcValue0MicroVolt = ADC_convertRawToMicroVolts(adc, adcValue0); // utiliza funcao pre definida da biblioteca do ADC

    tempy = (((adcValue0 * 3.3 * 100 ) /4096));
    Temp_final = tempy >> 10;

    adcValue0MicroVolt contains the value in uV which is using calibrated data. But for the calculation you use adcValue0 which is uncalibrated and hence you get an inaccurate result.
  • DVM = Digital Volt Meter.

    Is the LM335 working by itself?

  • It also seems silly to mix floats and ints like that.
  • So, i must use the adcValue0 to calculate the temperature value, right ?
    The algorithm to calculate the value must be this ?


    tempy = (((adcValue0 * 3.3 * 100 ) /4096));
    tempfinal = (tempy -273.15 )>> 10;
  • i only used the float to obtain a decimal value
  • Yes, i think. If using a multimeter, for a supply of 5 V, the output is 2.95/ 2.98 V. The temperature in the room is about 19/20 C
  • As said, adcValue0 is the uncalibrated value, if you use this you will get an inaccurate value.

    How high will the input be if you increase the temperature (compared to VDDS) or are you just interested in measuring room temperature.
  • Which is what you measured on the launchpad. Did you try your lighter test?
  • I changed the LM335 because what I had was not working properly. To add the decimal part to the value, should I use a float variable?
  • I get 3.2v max. My goal is to measure temperatures between 5 and 20º C
  • You either need a float or use fixed point.

    Why are you shifting by 10? I think you want a divide there.
  • So, i need to use:

    resultado = (adcValue0 * 3.3 * 100);
    temperatura = (resultado / 4096);
    resultado2 = (temperatura -273.15);

    and then divide the result in 2 parts and forget the bit shifting ?
  • Diogo: Could you please explain to me why you do

    resultado = (adcValue0 * 3.3 * 100);
    temperatura = (resultado / 4096);

    When ADC_convertRawToMicroVolts returns a value in uV which you can use directly?
  • You're right. It's easier to use the MicroVolts.
    Thanks for all the help