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.

HDC2010: Temperature measurement with Single digit after decimal point

Part Number: HDC2010

Hello,

 

1) As per below link, for 11-bits whether 5 LSB bits are zero. I don’t think so. Even I am seeing values in 5 LSB bits. Please confirm.

   https://e2e.ti.com/support/sensors/f/1023/p/787156/2910923?tisearch=e2e-quicksearch&keymatch=HDC2010%20single%20digit%20accuracy#2910923

 

2) I am fine with single digit after decimal point and if want to store the value read from Temperature register [0:15] whether below approach will be fine.

 

              a) Do Sampling with 14-bit resolution.

              b) Right shift upper 11-bits of Temperature[0:15] register by 5 bits.

              c) Store 11-bit and whenever required use below math to compute actual temperature value.

 

                             ((11-bit temperature value) / 2 ^ 11) *165) - 40

              Where 2 ^ 11 is 2048

 

I want single digit accuracy after decimal point. (Ex: 12.1)

Thanks & Regards

Vishnu Beema

  • Dear Vishnu - 

    the resolution for which the part is configured for (in register 0x0E) is the output of the HDC2010 ADC. There is but one formula for converting that to %RH. 

    page 18 of the datasheet, you don't have to do any more calculation other than that one. 

    then if you don't want the digits of precision out past first decimal point, you could truncate it before you store it, but float to int would cause loss of all the decimal part of the number, so would using the trunc() function. so it probably should be stored as a float - if you want to print it this would just use printf conversion, using %.1f, as you would want to go for putting out a float, with just the one character after decimal point

     

  • The source code for HDC2010METER-EVM might be useful. It's available here: http://www.ti.com/tool/HDC2010METER-EVM

    Specifically, tmp-decode.c is an example of converting the two byte response from HDC2010 to humidity in string data type with one digit of precision. 

    char* humstring(unsigned char HiByte, unsigned char LoByte){
        long ih;
        float fh;
    
        //combine 2 bytes
        ih = (long) (HiByte & 0xFF) << 8 | (LoByte & 0xFF);
        fh = (float) ih / 65536;
        fh *= 100;
        sprintf(sh, "%6.1f", fh);
        return sh;
    }

    I had originally written a version that avoided the use of float data type as well as printf library. It was not pretty. It was scrapped because it actually used more CPU cycles than the above code with float & printf.

    char* humstring(unsigned char HiByte, unsigned char LoByte){
        char i;
        unsigned long it;
    
        //combine 2 bytes
        it = (unsigned long) HiByte << 8 | (LoByte & 0xFF);
        //LSB
            it *= 15258; //2^-16*100*1e7
            sh[st_char_len-1] = '%';
        #ifdef DEBUG
        printf("it: %lli i: %i\n",it,i);
        #endif
        //sign
    //    if (it<0) {
    //        sh[0] = 0x2D;
    //        it *= -1;
    //    }
    //    else
        sh[0] = 0x20;
        //decimal
        sh[4] = 0x2E;
        for(i=st_char_len-2;i > 0;i--){
            #ifdef DEBUG
            printf("it: %lli i: %i\n",it,i);
            #endif
            if (i!=4){
                sh[i] = it % 10 + 0x30;
                it /= 10;
            }
        }
        //fix leading zeroes
        for (i=1; i < 3; i++){
            //if equals zero
            if (sh[i]==0x30) {
                //if previous equals minus
                if (sh[i-1]==0x2D) {
                    sh[i] = 0x2D;
                    sh[i-1] = 0x20;
                }
                //else if previous equals space
                else if (sh[i-1]==0x20)
                sh[i] = 0x20;
            }
            else break;
        }
        return sh;
    }

    Ren

  • Hello,

     

    Thank you for your inputs. I have gone through the example code. Let me give more details about my requirement.

     

    1) We want to store Temperature & Humidity data into Non-Volatile memory (Ex: Flash). We have a very stringent requirement for Flash space remaining.

    2) So we don't want to store converted values in float format into Flash which will take 4 bytes for Temperature and 4 bytes for Humidity.

    3) With respect to Temperature we want to store only 11-bits (Take MSB 11-bits and then right *** by 5) of register data into Flash. For Humidity only 8-bits (Take MSB 8 bits and then right shift by 8). With this will be using only 19 bits (11-bits for Temperature and 8-bits for Humidity) into Flash rather than 32-bit (16-bit register values of Temperature and Humidity).

    4) While communicating the Sensor values, read those values from Flash and then apply below formula and transmit over communication port.

    Formula:

    Temperature :     (((MSB 11-bit temperature value + 5 LSBit as 0) / 2 ^ 11) *165) - 40;

                               Where 2 ^ 11 is 2048

    Humidity: ((MSB 8-bit Humidity value + 8 LSBit as 0) / 2 ^ 8) *100;

                               Where 2 ^ 8 is 256

     

    Is above approach is fine or is there any alternate and better approach.            

     

    Thanks & Regards

    Vishnu Beema

  • Vishnu - 

    without knowing what MCU you are using, etc. or redesigning whatever you are making for you, I can't comment specifically on what to do about your possibly perceived data handling issue. Here are some ideas. 

    1. You could use half precision float (see IEEE 754) - this would cut each value to occupying 2 bytes. which is what i think you are asking for. 

    2. You could try using an MCU with FRAM, that way you are free to partition as you see fit (FRAM is executable, RAM and non-volatile storage) - see any of the MSP430FR series devices - 

    3. use RAM instead of Flash for the temporary storage before sending over wire or antenna.