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.

Problem with getting the internal temperature of CC1110F32

Normal 0 21 false false false MicrosoftInternetExplorer4

Hello everyone I’m new to microcontroller programming and the CC1110F32.

I try to get the value of the internal temperature sensor of the CC1110 via the ADC, Ive done everything like it was said in the Datasheet of the CC1110F32 and the Design Note DN102 but I got a problem when I want the return value of the function getTemp().

 

Normal 0 21 false false false MicrosoftInternetExplorer4

Here is my source code:

 

  #define SAMPLE_TEMP_SENSOR(v) \

  do { \

  ADCCON2 = 0x3E; \

  ADCCON1 = 0x73; \

//The ADC Registers are set like in the Design Note DN102

  while(!(ADCCON1 & 0x80)); \

  v = ADCL; \

  v |= (((unsigned int)ADCH) << 8); \

  } while(0)

   

 

  #define CONST 0.61065

// typical output voltage [mV] at 0°C

#define OFFSET_DATASHEET 755

// offset measuered at 25°C due to 1-point calibration

#define OFFSET_MEASURED_AT_25_DEGREES_CELCIUS 16

// calculate overall offset

#define OFFSET (OFFSET_DATASHEET + OFFSET_MEASURED_AT_25_DEGREES_CELCIUS)

// temperatur coeffizient

#define TEMP_COEFF 2.47

//coefficients like in Design Note DN102 with slightly diffrent values

 

 

  float getTemp(void)

    {

    unsigned int adcValue;

    float outputVoltage;

    SAMPLE_TEMP_SENSOR(adcValue);

    // Note that the conversion result always resides in MSB section of ADCH:ADCL

    adcValue >>= 4; // Shift 4 due to 12 bits resolution

    outputVoltage = adcValue * CONST;

    return ((outputVoltage - OFFSET) / TEMP_COEFF);

    }

 

 

I wrote in my main function:

 

float testtemperature;

testtemperature=getTemp();

 

But I get a warning that says:

 

Warning[Pe550]: variable "testtemperature" was set but never used

 

I don’t understand what is wrong with my code or what I have forgotten. When I'm right the function “getTemp” should have a return value of the type float like testtemperature.

 

Thanks in advance

  • I dont know why but it seems my browser addet "Normal 0 21 false false false MicrosoftInternetExplorer4"in the text. Sorry about that

  • The compiler warning is saying that there is no code after "testtemperature=getTemp();" that uses the value in "testtemperature" -- it's sort of wondering "Why bother getting the value from getTemp() if no-one is going to use it".

  • Normal 0 21 false false false MicrosoftInternetExplorer4

    Thanks for your answer xyzzy that was quick and helped me understand the problem.

    I added some code that is using testtemperature underneath:

    test=testtemperature/2;
     
     if (test>1000){
         P1=0x33;
     
     }

     else{
      P1=0x73;
     
     }

    test declared as float in the right section of the sourcecode.

    The warning is gone now just like you said.

    But when I want to look at the value of test or testtemperature in the Watch window of the debug modus using the CC Debugger it says at the column Value <unavailable>. How can I check the value of testtemperature? I want to check if everything I have done is right before I do further steps in my project.

    Thanks in advance

  • Sometimes the optimizer makes it difficult to observe register values at a line after it's done with a variable. First, I would put a breakpoint on the "test=testtemperature/2;" line and see if you can observe the value of "testtemperature" before single-stepping off that line. After single-stepping, you should be able to see the value of "test". Another option to try as a last resort: disable the optimizer - even though you're not testing the same code (compared to optimizer ON). you can check whether your logic seems to be OK.

  • Thanks a lot that helped me out just perfectly. I have turned off the opzimizer in the options and now everything is fine.