## Butterfly A/D Code for Temp Sensor

6 posts / 0 new
Author
Message

I am trying to figure out how the math / circuitry works for the temperature sensor onboard the butterfly. The A/D values for temperatures from 0 to 140 F are defined as follows:

```__flash int TEMP_Farenheit_pos[] =  // Positive Farenheit temperatures (ADC-value)
{                           // from 0 to 140 degrees
938, 935, 932, 929, 926, 923, 920, 916, 913, 909, 906, 902, 898,
894, 891, 887, 882, 878, 874, 870, 865, 861, 856, 851, 847, 842,
837, 832, 827, 822, 816, 811, 806, 800, 795, 789, 783, 778, 772,
766, 760, 754, 748, 742, 735, 729, 723, 716, 710, 703, 697, 690,
684, 677, 670, 663, 657, 650, 643, 636, 629, 622, 616, 609, 602,
595, 588, 581, 574, 567, 560, 553, 546, 539, 533, 526, 519, 512,
505, 498, 492, 485, 478, 472, 465, 459, 452, 446, 439, 433, 426,
420, 414, 408, 402, 396, 390, 384, 378, 372, 366, 360, 355, 349,
344, 338, 333, 327, 322, 317, 312, 307, 302, 297, 292, 287, 282,
277, 273, 268, 264, 259, 255, 251, 246, 242, 238, 234, 230, 226,
222, 219, 215, 211, 207, 204, 200, 197, 194, 190, 187,
};
```

A reading is done through the A/D using this code :

```
{
char i;

// To save power, the voltage over the LDR and the NTC is turned off when not used
// This is done by controlling the voltage from a I/O-pin (PORTF3)

sbi(PORTF, PORTF3);     // Enable the VCP (VC-peripheral)
sbi(DDRF, PORTF3);

for(i=0;i<8;i++)            // do the ADC conversion 8 times for better accuracy
{

}

cbi(PORTF, PORTF3);     // disable the VCP
cbi(DDRF, PORTF3);

}

```

If the max value can be 8191 after it is shifted 3 bits, how is the max value for the temp sensor at 938?

I looked at the circuitry for the temp sensor, but i don't know how to analyze it.

[/img][img]

PF0 is the A/D channel and VCP is activated as an ouput to 3 V? i think. If i had to guess then this would be a voltage divider, but even with that info I don't know how to go about trying to understand these values. Do i measure the current, then calculate Voltages?

Any help in the right direction would be awesome!

thanks!

seasick,

from the beginning: R208 and R211 form a voltage divider that is measured by ADC. IMHO it's reference is the same as VCP, thus the actual VCP value does not matters much.
ADC_read returns a value that is processed afterward. Please see the rest of the code for this. Anyway the result of this after-processing is used as a pointer to flash int TEMP_Farenheit_pos[] array. See it has 141 values for 0F to 140F interval. The contents (constant) is obviously displayed, it's three digit without leading zeroes and no decimal point neither fractions.
Well may did some wrong guesses but it's something I managed to dig from BF. And with big kudos for freaks, for sure.

best regards
kp

Quote:
it's three digit without leading zeroes and no decimal point neither fractions.

This is what i am having a hard time with. I am going to single step through the code to see what values are outputted, which is what i should have done in the first place. it just didn't occur to me.

i'm doing some ADC debugging and i'm afraid i might have blown something up.

Is it possible to trash the ADC circuity by wiring 3v with no resistor?

:oops: