- 电池中默认都会带有一个热敏电阻, 如果要换算温度,需要通过计算阻值来转换成温度
2. 常用的电路图如下:
分压后,算出电流,然后再用采的电压/电流,算出阻值 ,核心算出在R241上加的电流, 然后通过采集的BATT_NTC的电压值来计算出NTC上的阻值 ,进而转成相应的温度
计算公式如下:
/* (ADC code * R_PULLUP (100Kohm)) / (full_scale_code – ADC code)*/
ADC / (1.8-ADC / 10k )
/**
struct vadc_map_pt - Map the graph representation for ADC channel
@x: Represent the ADC digitized code.
@y: Represent the physical data which can be temperature, voltage,
resistance.
*/
struct vadc_map_pt {
s32 x;
s32 y;
}; /*
Resistance to temperature table for 10k pull up for NCP15XH103.
*/
static const struct vadc_map_pt adcmap7_10k[] = {
{ 195652, -40960 },
{ 186155, -39936 },
{ 176659, -38912 },
{ 167163, -37888 },
{ 157667, -36864 },
{ 148171, -35840 },
{ 141206, -34816 },
{ 134242, -33792 },
{ 127278, -32768 },
{ 120314, -31744 },
{ 113347, -30720 },
{ 108190, -29696 },
{ 103033, -28672 },
{ 97876, -27648 },
{ 92719, -26624 },
{ 87559, -25600 },
{ 83694, -24576 },
{ 79830, -23552 },
{ 75966, -22528 },
{ 72102, -21504 },
{ 68237, -20480 },
{ 65319, -19456 },
{ 62402, -18432 },
{ 59485, -17408 },
{ 56568, -16384 },
{ 53650, -15360 },
{ 51420, -14336 },
{ 49191, -13312 },
{ 46962, -12288 },
{ 44733, -11264 },
{ 42506, -10240 }, { 40784, -9216 },
{ 39062, -8192 },
{ 37340, -7168 },
{ 35618, -6144 },
{ 33892, -5120 }, { 32557, -4096 },
{ 31222, -3072 },
{ 29887, -2048 },
{ 28552, -1024 },
{ 27219, 0 }, { 26179, 1024 },
{ 25140, 2048 },
{ 24101, 3072 },
{ 23062, 4096 },
{ 22021, 5120 }, { 21202, 6144 },
{ 20383, 7168 },
{ 19564, 8192 },
{ 18745, 9216 },
{ 17926, 10240 }, { 17275, 11264 },
{ 16625, 12288 },
{ 15975, 13312 },
{ 15325, 14336 },
{ 14674, 15360 }, { 14155, 16384 },
{ 13637, 17408 },
{ 13119, 18432 },
{ 12601, 19456 },
{ 12081, 20480 }, { 11664, 21504 },
{ 11248, 22528 },
{ 10832, 23552 },
{ 10416, 24576 },
{ 10000, 25600 }, { 9662, 26624 },
{ 9325, 27648 },
{ 8909, 28672 },
{ 8493, 29696 },
{ 8315, 30720 }, { 8042, 31744 },
{ 7769, 32768 },
{ 7495, 33792 },
{ 7223, 34816 },
{ 6948, 35840 }, { 6725, 36864 },
{ 6502, 37888 },
{ 6279, 38912 },
{ 6056, 39936 },
{ 5834, 40960 }, { 5650, 41984 },
{ 5406, 43008 },
{ 5162, 44032 },
{ 4917, 45056 }, { 4765, 46080 },
{ 4614, 47104 },
{ 4463, 48128 },
{ 4312, 49152 },
{ 4161, 50176 }, { 4035, 51200 },
{ 3910, 52224 },
{ 3785, 53248 },
{ 3660, 54272 },
{ 3535, 55296 }, { 3430, 56320 },
{ 3326, 57344 },
{ 3222, 58368 },
{ 3118, 59392 },
{ 3014, 60416 }, { 2928, 61440 },
{ 2842, 62464 },
{ 2756, 63488 },
{ 2670, 64512 },
{ 2586, 65536 }, { 2515, 66560 },
{ 2443, 67584 },
{ 2372, 68608 },
{ 2301, 69632 },
{ 2228, 70656 }, { 2168, 71680 },
{ 2108, 72704 },
{ 2048, 73728 },
{ 1988, 74752 },
{ 1925, 75776 }, { 1874, 76800 },
{ 1823, 77824 },
{ 1772, 78848 },
{ 1721, 79872 },
{ 1669, 80896 }, { 1626, 81920 },
{ 1583, 82944 },
{ 1540, 83968 },
{ 1497, 84992 },
{ 1452, 86016 }, { 1402, 87040 },
{ 1352, 88064 },
{ 1302, 89088 },
{ 1268, 90112 }, { 1236, 91136 },
{ 1204, 92160 },
{ 1172, 93184 },
{ 1140, 94208 },
{ 1110, 95232 }, { 1083, 96256 },
{ 1056, 97280 },
{ 1029, 98304 },
{ 1002, 99328 },
{ 974, 100352 }, { 951, 101376 },
{ 928, 102400 },
{ 905, 103424 },
{ 882, 104448 },
{ 858, 105472 }, { 838, 106496 },
{ 818, 107520 },
{ 798, 108544 },
{ 778, 109568 },
{ 758, 110592 }, { 741, 111616 },
{ 724, 112640 },
{ 707, 113664 },
{ 690, 114688 },
{ 672, 115712 }, { 657, 116736 },
{ 632, 117760 },
{ 617, 118784 },
{ 602, 119808 },
{ 596, 120832 }, { 590, 121856 },
{ 582, 122880 },
{ 572, 123904 },
{ 562, 124928 },
{ 531, 125952 }, { 490, 126976 },
{ 450, 128000 },
{ 410, 129024 },
{ 400, 130048 }
};
static int qcom_vadc_map_voltage_temp(const struct vadc_map_pt *pts,
u32 tablesize, s32 input, int *output)
{
bool descending = 1;
u32 i = 0;
if (!pts)
return -EINVAL;
/* Check if table is descending or ascending */
if (tablesize > 1) {
if (pts[0].x < pts[1].x)
descending = 0;
}
while (i < tablesize) {
if ((descending) && (pts[i].x < input)) {
/* table entry is less than measured*/
/* value and table is descending, stop */
break;
} else if ((!descending) &&
(pts[i].x > input)) {
/* table entry is greater than measured*/
/*value and table is ascending, stop */
break;
}
i++;
}
if (i == 0) {
*output = pts[0].y;
} else if (i == tablesize) {
*output = pts[tablesize - 1].y;
} else {
/* result is between search_index and search_index-1 */
/* interpolate linearly */
*output = (((s32)((pts[i].y - pts[i - 1].y) *
(input - pts[i - 1].x)) /
(pts[i].x - pts[i - 1].x)) +
pts[i - 1].y);
}
return 0;
}
近期评论