Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Thermocouple interface with PIC

Status
Not open for further replies.
With a single 5v supply on the AD595, 380K resistance is needed between T+ and 5v to achieve a ~1.454v increase.

Edit: Nevermind, I'll try again with 5v instead of 8v.

Edit 2: My 78M05 is giving 7.8v. WTF o_O
 
Last edited:
Nice, well take your output voltage, divide by 247.3 then subtract 11uv, and you have your original thermocouple output voltage.
 
200K with a proper single 5v supply :)

I have to take off 1.454v though first. So my output is 1700mV, I take 1454mV = 246mV. Divide by 247.3 = 0.99474mV. Minus 0.011mV = 0.98374mV. Which, according to the table, is around 24.5c, which is exactly what my mercury thermometer is reading :) So now I am going to incoporate those calculations into my PIC's firmware and I shall test it when my USB programmer arrives (hopefully in the next couple of hours).
 
Yes, you got it. You can do it any order you want. That way or get the thermocouple voltage first then add it to the -200c value.
 
I've got the circuit working well, assuming the AD595's output is linear. However I'm unsure how to go about implementing a lookup table. The only way I can think of doing it is an array of 500 bytes...And thinking about it that wouldn't even work o_O
 
I've got the circuit working well, assuming the AD595's output is linear. However I'm unsure how to go about implementing a lookup table. The only way I can think of doing it is an array of 500 bytes...And thinking about it that wouldn't even work o_O

hi,
Look at this thermocouple calculator.
**broken link removed**

If you cannot use a full -200C to +50C lookup table, consider a 'chorded' lookup table.

Out of curiosity why do you need to go down to -200C.??? are you liquefying gases.?
 
It will be used with cryogenics. Of which liquid nitrogen will be the coldest substance at -196c. I think I will assume the output is linear between the temperatures of 0c to 50c as it almost is anyway. And accuracy in that range needn't be very high.

Thanks for the link. But I'm still unsure of how to implement a lookup table using the data.
 
Something I've just noticed: the numbers on the LCD after the decimal place jump around a bit. What I mean is, the temperature reads 25.2c, then I touch the probe with me finger an it will go up in steps, 25.4c then 25.7c then 25.9c. It never shows 25.3c for example. Here is my firmware.

Code:
#define samples 256

signed long temp;
char print;

void readadc(int channel){

    temp = 0;

    // Take specified number of samples
    for(i = 0; i < samples; i++){
          temp += Adc_Read(channel);
    }

    temp /= samples;
    temp = (temp * multi) >> 10;

    temp -= 1454;

     if (temp < 0) LCD_Chr(1,5,'_'); else LCD_Chr(1,5,' '); // Display minus sign if negative temp

     print = abs(temp / 1000);
     WriteTallNum(print, 6);
     
     print = abs(temp / 100)%10;
     WriteTallNum(print, 7);
     
     print = abs(temp / 10)%10;
     WriteTallNum(print, 8);
     
     LCD_Chr(2, 9, '.');
     
     print = abs(temp % 10);
     WriteTallNum(print, 10);

}

WriteTallNum simply writes the specified digit to the display but with double the height. I'm compiling with MikroC.
 
It will be used with cryogenics. Of which liquid nitrogen will be the coldest substance at -196c. I think I will assume the output is linear between the temperatures of 0c to 50c as it almost is anyway. And accuracy in that range needn't be very high.

Thanks for the link. But I'm still unsure of how to implement a lookup table using the data.

Hi,
Which programming language and assembler/compiler are you using.?
EDIT: you answered while I was asking...:)

For the chord type Table, you could assume 0C thru +50C is linear as you suggest, so the -200C thru 0C could be a Table, say for every 5C or 10C step, that would shorten the Table length.

Have you finalised the -200C thru +50C as 0V thru +5V as the adc input range.?

EDIT:
I use assembler, not 'C' , other members will step forward I expect.
 
Last edited:
I understand how the table might work. I just don't know how to implement it in software. I don't understand how the ADC reading could map exactly onto the K type voltage either.

I have not changed the gain on the amp. But I have added an offset of +1.454v so -200c should read 0v (I don't have anything at the moment to test that). Therefore the output at 50c should be ~1.96v. At the moment I am using a 2.5v reference using a potential divider on my breadboard. But I will most likely convert to a 2v reference when I make the PCB.
 
I understand how the table might work. I just don't know how to implement it in software. I don't understand how the ADC reading could map exactly onto the K type voltage either.

I have not changed the gain on the amp. But I have added an offset of +1.454v so -200c should read 0v (I don't have anything at the moment to test that). Therefore the output at 50c should be ~1.96v. At the moment I am using a 2.5v reference using a potential divider on my breadboard. But I will most likely convert to a 2v reference when I make the PCB.

hi,
If you used a stable 2.5V ref IC, you could set the PIC's +Vref to 2.5V.
This would mean that the PICs 10bit adc would give a count of [1.96/2.5]/1023 == 802 counts.
If you increase the gain so that you get just under 2.5Vout, this would use the 0 to 1000 range of the adc when using a 2.5Vref.

So that would be 1000counts/250Cdeg, which would become your Table address, equiv to 4 adc counts per 1C step.
 
I have the PIC's +vref at 1.98v now, using a potential divider.

Can anyone explain why I have funny jumps in temperature?
 
I have the PIC's +vref at 1.98v now, using a potential divider.

Can anyone explain why I have funny jumps in temperature?

One reason could be that the 1.98V is not stable as its derived from +5V using a simple resistive divider.

Can you explain 'funny jumps'.?? is there any pattern to it.?
 
Something I've just noticed: the numbers on the LCD after the decimal place jump around a bit. What I mean is, the temperature reads 25.2c, then I touch the probe with me finger an it will go up in steps, 25.4c then 25.7c then 25.9c. It never shows 25.3c for example. Here is my firmware.

...Here...
 
As for your funny jumps, the pic only has 10-bit resolution. That is 1024 steps. Between -200 and 50, at 1/10 degree resolution, you have 2500 steps. As you can see, your pic cannot possible determine the temp at every 1/10 a degree, it does not have the resolution.

Your reference should be set at full scale, the lowest output is zero at -200, the highest output is 1.957V, so the ref you chose is pretty good.

Let's say you decide that your confident in the linearity between each 32 ADC step. You would make your look-up table for each 32 interval then interpolate in between. 32 is a good number because it's easy for your little PIC16 with no hardware multiplier to work with and it means youll only need to store 32 int's. I will do the first five terms. Odviously, if your ADC reports 0, the real temp is -200. so that one is easy.

0: -200

moving on, 32, what real life voltage does 32 correspond to? (1.98 / 1024) * 32 = .0619V

now let's put that through the transfer function: (0.0619 / 247.3) - .000011 = 239.3 uV. Now we add that to your chosen cold point of -200.

239.3 uV + -5.891mV = -5.652mV

No, ill take a peak at the lookup table at: https://www.electro-tech-online.com/custompdfs/2010/09/Type_K_Thermocouple_Reference_Table.pdf

i can see -174 is closest to that value so we have our next value.

32: -174

at 64 well have -5.402mV

64: -168

and moving on.

96: -160
128: -150
160: -139

ill continue this is a fresh post
 
So now wee have our data, lets make an array

Code:
int TEMP_TABLE[32] = {-200,-174,-168,-160,-150,-139,...,...,...,..};
now, how do we use that? let's say we got our ADC value and its in a var call result.

Code:
char short_result = result >> 5; //get whichever 32 step it corresponds to
char result_diff = result - short_result; //how much larger than the 32 is it.
char span = TEMP_TABLE[short_result + 1] - TEMP_TABLE[short_result]; //span between this 32 val and the next.
int temp_diff = (result_diff / 32) * span; //This will not work since result_diff /32, will always return 0, you need to use fixed point or floating point or however you want to implement it. this is for illustration only.
int myTempRightNow = TEMP_TABLE[short_result] + temp_diff; //yayy!!
Hopefully that clears up some stuff. I can't write your program for you (unless you pay me of course), so your going to have to use your imagination and creativity for finding coding solutions to various things.

I am attaching the spreadsheet I used for those first 5 values for you.
 

Attachments

  • thermocouple.zip
    5.9 KB · Views: 197
Last edited:
I took a gander at the datasheet for 16F819 since Eric mentioned the stability of the ref. The ADC ref input current is 500uA during acquisition. Unless the resistors are very low values, that is probably too much draw, so you need to buffer that with an op-amp in a voltage follower configuration. If you take conversions intermittently enough, you could get away with just a capacitor for stability. The other thing is the minimum Vref is listed as 2.2V. So, you may want to bump that up. Sorry I told you otherwise.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top