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 :
int ADC_read(void) { char i; int ADC_temp; int ADC = 0; // 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); sbi(ADCSRA, ADEN); // Enable the ADC //do a dummy readout first ADCSRA |= (1<<ADSC); // do single conversion while(!(ADCSRA & 0x10)); // wait for conversion done, ADIF flag active for(i=0;i<8;i++) // do the ADC conversion 8 times for better accuracy { ADCSRA |= (1<<ADSC); // do single conversion while(!(ADCSRA & 0x10)); // wait for conversion done, ADIF flag active ADC_temp = ADCL; // read out ADCL register ADC_temp += (ADCH << 8); // read out ADCH register ADC += ADC_temp; // accumulate result (8 samples) for later averaging } ADC = ADC >> 3; // average the 8 samples cbi(PORTF, PORTF3); // disable the VCP cbi(DDRF, PORTF3); cbi(ADCSRA, ADEN); // disable the ADC return ADC; }
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!