beautypg.com

Temperature conversion c source code – RoboteQ AX2850 User Manual

Page 69

background image

AX2550 Motor Controller User’s Manual

69

Temperature Conversion C Source Code

Temperature Conversion C Source Code

The code below can be used to convert the analog reading into temperature. It is provided
for reference only. Interpolation table is for the internal thermistors.

int ValToHSTemp(int AnaValue)
{

// Interpolation table. Analog readings at -40 to 150 oC, in 5o intervals

int TempTable[39] ={248, 246, 243, 240, 235, 230, 224, 217, 208, 199, 188, 177,
165, 153, 140, 128, 116, 104,93, 83, 74, 65, 58, 51, 45, 40, 35, 31, 27, 24, 21,
19, 17, 15, 13, 12, 11, 9, 8};

int LoTemp, HiTemp, lobound, hibound, temp, i;

i = 38;

while (TempTable[i] < AnaValue && i > 0)

i--;

if (i < 0)

i = 0;

if (i == 38)

return 150;

else
{

LoTemp = i * 5 - 40;
HiTemp = LoTemp + 5;
lobound = TempTable[i];
hibound = TempTable[i+1];
temp = LoTemp + (5 * ((AnaValue - lobound)*100/ (hibound - lobound)))/100;
return temp;

}

}

0

50

100

150

200

250

300

Reported Analog Value

Temperature in Degrees C

-4

0

-3

0

-2

0

-1

0

0

10

20

30

40

50

60

70

80

90 10

0

11

0

12

0

13

0

14

0

15

0

FIGURE 39. Analog reading by controller vs. internal heat sink temperature