简体   繁体   English

在C中串联32位整数

[英]Concatenating 32 bit integers in C

I am currently working on a project that will use a thermister as a temperature sensor and displaying this information among other things onto a gui using the raspberry pi. 我目前正在进行一个项目,该项目将使用热敏电阻作为温度传感器,并使用树莓派将这些信息显示在gui上。 However I am currently stuck on the Analog to digital conversion. 但是,我目前仍停留在模数转换上。 Using the sample code from the waveshare ad board I am using I manage to get the voltage to display, however I then need to use this vout in my voltage divider equation to get the resistance of my thermister and I can't figure out how to actually use the 32 bit integer iTemp variable and properly convert it so thats its the actual number displayed on the console. 使用我正在使用的waveshare广告板上的示例代码,设法获得要显示的电压,但是随后我需要在分压器方程式中使用此vout来获得热敏电阻的电阻,因此我不知道该怎么做。实际上使用32位整数iTemp变量并将其正确转换,以便其在控制台上显示的实际数字。 Currently the 2 print lines with itemp print out numbers like (1.186 391 V). 当前,带有itemp的2条打印行打印出的数字为(1.186 391 V)。 which is correct but I need to convert that into a actual number that I can then plug into my voltage divider equation. 是正确的,但我需要将其转换为实际数字,然后将其插入我的分压器方程式。 Ps: I included the part of the code with the print statements. 附:我在打印语句中包括了部分代码。 Any help would be greatly appreaciated. 任何帮助将不胜感激。

Code: 码:

 while((ADS1256_Scan() == 0));
        for (i = 0; i < ch_num; i++)
        {
            adc[i] = ADS1256_GetAdc(i);
                 volt[i] = (adc[i] * 100) / 167;    
        }

        for (i = 0; i < ch_num; i++)
        {
                    buf[0] = ((uint32_t)adc[i] >> 16) & 0xFF;
                    buf[1] = ((uint32_t)adc[i] >> 8) & 0xFF;
                    buf[2] = ((uint32_t)adc[i] >> 0) & 0xFF;
                    printf("%d=%02X%02X%02X, %8ld", (int)i, (int)buf[0], 
                           (int)buf[1], (int)buf[2], (long)adc[i]);                

                    iTemp = volt[i];    /* uV  */
                    if (iTemp < 0)
                    {
                        iTemp = -iTemp;
                                printf(" (-%ld.%03ld %03ld V) \r\n", iTemp /1000000, (iTemp%1000000)/1000, iTemp%1000);
                    }
                    else
                    {
                                    printf(" ( %ld.%03ld %03ld V) \r\n", iTemp /1000000, (iTemp%1000000)/1000, iTemp%1000);                   
                    }

        }
            //printf("\33[%dA", (int)ch_num);  
        bsp_DelayUS(100000);    
            }   
    bcm2835_spi_end();
    bcm2835_close();

    return 0;
}

According to your comment: iTemp = volt[i]; /* uV */ 根据您的评论: iTemp = volt[i]; /* uV */ iTemp = volt[i]; /* uV */ , iTemp read is in micro-volts. iTemp = volt[i]; /* uV */ ,iTemp读数以微伏为单位。 In order to use it in your equation, all you need to do is convert it to volts (convert it to double or float and multiply by (1.0/1000000.0)). 为了在方程式中使用它,您所需要做的就是将其转换为伏特(将其转换为doublefloat并乘以(1.0 / 1000000.0))。

double iTempV = (double)iTemp*1.0e-6;

or: 要么:

float iTempV = (float)iTemp*1.0e-6f;

I assume the following formula converts A2D raw sample value to micro-voltage: 我假设以下公式将A2D原始样本值转换为微电压:

adc[i] = ADS1256_GetAdc(i);
volt[i] = (adc[i] * 100) / 167;

I found the following project in GitHub: https://github.com/ecao1/SEADS-Rpi/blob/master/test_ver1.c to support my claim. 我在GitHub上找到了以下项目: https : //github.com/ecao1/SEADS-Rpi/blob/master/test_ver1.c支持我的主张。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM