Butterfly A/D Code for Temp Sensor

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey Kas, Thanks for your reply.

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.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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:

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not if your Vcc is greater than 3V (minus a diode drop) at all times. Which includes startup, so first Vcc should be connected, then the 3V to the ADC.

Stealing Proteus doesn't make you an engineer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Turns out i had a bad connection and didn't know how to wire a pot correctly.