Author Topic: RTD interfacing with PIC and eeprom lookup table.  (Read 17911 times)

0 Members and 1 Guest are viewing this topic.

Offline HexureusTopic starter

  • Contributor
  • Posts: 24
  • Country: pt
RTD interfacing with PIC and eeprom lookup table.
« on: January 03, 2014, 08:48:09 pm »
Hello,
I am trying to develop a project to be able to take a measurement of a platinum RTD, compare the value obtained (resistance) do a look up on an eeprom (Local or external) and then output the value to an LCD.
Any advice's or tips are very welcome.
Since the RTD does not have a linear resistance and I want the measurement to be as precise as possible id like to know if its possible to store a complete table, lets say an array of 2x350 where column 0 is for the resistance and column 1 is for the given temperature. When the resistance value is calculated from the RTD by the PIC ADC and stored in a variable, would then do a look up of that value in the array column 0 (or the closest value) and output the respective value from column 1.


Thank you.
Carlos Lucas
 

Offline mazurov

  • Frequent Contributor
  • **
  • Posts: 526
  • Country: us
    • nerpa
Re: RTD interfacing with PIC and eeprom lookup table.
« Reply #1 on: January 04, 2014, 12:37:36 am »
Platinum RTD can be linearized with a simple polynomial equation, typically given in the datasheet (or here -> http://www.analog.com/static/imported-files/application_notes/AN709_0.pdf , or google "RTD linearization"). 
With sufficient thrust, pigs fly just fine - RFC1925
 

Offline HexureusTopic starter

  • Contributor
  • Posts: 24
  • Country: pt
Re: RTD interfacing with PIC and eeprom lookup table.
« Reply #2 on: January 04, 2014, 12:48:37 am »
Thank you for the reply.
Even if I can use RTD linearization, is it still possible to to "table" look ups?
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: RTD interfacing with PIC and eeprom lookup table.
« Reply #3 on: January 04, 2014, 12:53:44 am »
Quote
if its possible to store a complete table

Yes, assuming you have sufficient space.

================================
https://dannyelectronics.wordpress.com/
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: RTD interfacing with PIC and eeprom lookup table.
« Reply #4 on: January 04, 2014, 12:55:13 am »
Quote
a simple polynomial equation

Math is a lot faster in a table.
================================
https://dannyelectronics.wordpress.com/
 

Offline HexureusTopic starter

  • Contributor
  • Posts: 24
  • Country: pt
Re: RTD interfacing with PIC and eeprom lookup table.
« Reply #5 on: January 04, 2014, 12:59:44 am »
I know, but the problem is the RTD has a range of about -200ºC to +600ºC. The mid curve of the temperature/resistance is where its less linear and is the exact range that I need (0º-300º) and I need very precise readings. The table I would need would be to store the resistance-temperature value in between those values degree by degree.
 

Offline Rufus

  • Super Contributor
  • ***
  • Posts: 2095
Re: RTD interfacing with PIC and eeprom lookup table.
« Reply #6 on: January 04, 2014, 02:18:33 am »
I know, but the problem is the RTD has a range of about -200ºC to +600ºC. The mid curve of the temperature/resistance is where its less linear and is the exact range that I need (0º-300º) and I need very precise readings.
Then you shouldn't be using a PIC ADC and the rest of your analog electronics will have to be very precise.  Linearization by look up table or calculation is a small part of the overall problem.

The difference in resistance change from say 100 to 110C and 110 to 120C is about 1 part in 7000 pretty meaningless when a 12 bit ADC covering 0 to 300C is only going to give you about 1 part in 140 over a similar 10 degree range (and with a 12 bit PIC ADC 7 or 8 of those parts could be error or noise). 
 

Offline HexureusTopic starter

  • Contributor
  • Posts: 24
  • Country: pt
Re: RTD interfacing with PIC and eeprom lookup table.
« Reply #7 on: January 04, 2014, 02:34:48 am »
The difference in resistance between 100º and 110º is 37.87ohm's.
What else should I use? i suggested using a pic because I need to interface an LCD and control SSR's depending on the reading's of the temperature's, and follow a predetermined temperature profile.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: RTD interfacing with PIC and eeprom lookup table.
« Reply #8 on: January 04, 2014, 02:35:03 am »
Quote
I need very precise readings.

Well, the answer depends on which version of "very precise" it is.

Quote
The table I would need would be to store the resistance-temperature value in between those values degree by degree.

sounds like a table of 300 values.

================================
https://dannyelectronics.wordpress.com/
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: RTD interfacing with PIC and eeprom lookup table.
« Reply #9 on: January 04, 2014, 02:36:42 am »
Quote
The difference in resistance between 100º and 110º is 37.87ohm's.

With a 10-bit adc, you have at most 1024 unique values. Just map them to temperature readings.
================================
https://dannyelectronics.wordpress.com/
 

Offline HexureusTopic starter

  • Contributor
  • Posts: 24
  • Country: pt
Re: RTD interfacing with PIC and eeprom lookup table.
« Reply #10 on: January 04, 2014, 02:40:30 am »
I need it to be 1º precise  :D
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 29543
  • Country: nl
    • NCT Developments
Re: RTD interfacing with PIC and eeprom lookup table.
« Reply #11 on: January 04, 2014, 02:51:52 am »
A thermocouple might be a better option. Anyway, if you use a PT1000 RTD you'd get more range from the ADC. Feeding it with a resistor (around 2k Ohm) undoes much of the polynomal equation. You can fiddle a bit with Excel to see what your error is and determine a lookup table.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline HexureusTopic starter

  • Contributor
  • Posts: 24
  • Country: pt
Re: RTD interfacing with PIC and eeprom lookup table.
« Reply #12 on: January 04, 2014, 03:02:46 am »
Thermocouple does not have the precision I need, since a variation of 2 degrees could be enough to ruin the process. I already have a table with temperature-resistance value of the RTD that the company maker provided me.
My major question is, where and how am I going to store this table? It is only going to be read so no write operation is needed and I read somewhere that eeprom was the right place to store the table.
The second question is how am I going to implement in circuit a way to measure the resistance of the RTD and have that value in the microcontroller for analysis and processing.

Thank you for all the help.
 

Offline Maxlor

  • Frequent Contributor
  • **
  • Posts: 565
  • Country: ch
Re: RTD interfacing with PIC and eeprom lookup table.
« Reply #13 on: January 04, 2014, 03:37:36 am »
One of the advantages of an RTD is a linear increase in resistance, which is easy to calculate. But hey, if you feel you must use a table lookup, continue reading.

I've used table lookups for an NTC based thermometer. A table was given in the NTC datasheet with temperature->resistance values in 5K increments. I converted the resistance values to expected ADC values, then stored those in the EEPROM. I only stored the ADC values, not the temperatures themselves, because they can be trivially reconstructed:

adcValues[0] = ADC value for -55°C
adcValues[1] = ADC value for -50°C
adcValues[2] = ADC value for -45°C
...
adcValues[41] = ADC value for 150°C

You get the idea.

The code then searches through the eeprom values for an interval where the measured ADC value is in between two values in the table, then does a linear interpolation between them, using this code:
Code: [Select]
        for (i = 0; i < (ADC_VALUES_SIZE - 1); ++i, temperature += 50) {
                int16_t a = adcValues[i];
                int16_t b = adcValues[i + 1];
                if (adcMeasurement == a) { return temperature; }
                if (adcMeasurement < b) {
                        return temperature + 50 * (adcMeasurement - a) / (b - a);
                }
        }
Note 1: I use 50 instead of 5 because I'm working with tenths of a degree.
Note 2: The comparison is < b because an NTC's resistance drops with increasing temperature; for an RTD it's the other way round.
 

Offline Jay_Diddy_B

  • Super Contributor
  • ***
  • Posts: 2933
  • Country: ca
Re: RTD interfacing with PIC and eeprom lookup table.
« Reply #14 on: January 04, 2014, 03:44:56 am »
Hi,

Here is a circuit that will get you more resolution than you know what to do with:




The circuit has an interesting feature that the ADC and the drive for the RTD use the same voltage source. This makes the circuit ratio-metric. The absolute value and the drift of the reference don't matter. What does matter is the ratio match of the resistors.

More information can be found in Linear Technology Application note AN84.

Link: http://cds.linear.com/docs/en/application-note/an78fs.pdf

You can scale the resistors to R1, R2 and R3 90.9K,  R4 should be 1K, so the circuit works with a 1000 Ohm RTD.

The decimator in the LTC2400 will reject either 50 Hz and its harmonics or 60 Hz and its harmonics.
 

Regards,

Jay_Diddy_B
« Last Edit: January 04, 2014, 03:49:27 am by Jay_Diddy_B »
 

Offline Rufus

  • Super Contributor
  • ***
  • Posts: 2095
Re: RTD interfacing with PIC and eeprom lookup table.
« Reply #15 on: January 04, 2014, 04:25:44 am »
Here is a circuit that will get you more resolution than you know what to do with:

The LT1028 isn't going to be very happy at 300C so the RTD is going to be on the end of a cable and you are into 3 wire or 4 wire compensation schemes which is another can of worms the OP probably hasn't considered.

I don't know what the OPs project is but he might be better of buying at PT100 to 4..20mA converter for like $10 on ebay although I would be a bit dubious about cheap and Chinese accuracy and stability.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: RTD interfacing with PIC and eeprom lookup table.
« Reply #16 on: January 04, 2014, 01:03:39 pm »
Quote
I need it to be 1º precise 

Very simple: calculate the corresponding temperature for adc values from 0 to 1023.

That would be the best precision / resolution you will ever get.
================================
https://dannyelectronics.wordpress.com/
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 29543
  • Country: nl
    • NCT Developments
Re: RTD interfacing with PIC and eeprom lookup table.
« Reply #17 on: January 04, 2014, 01:29:55 pm »
Thermocouple does not have the precision I need, since a variation of 2 degrees could be enough to ruin the process. I already have a table with temperature-resistance value of the RTD that the company maker provided me.
My major question is, where and how am I going to store this table? It is only going to be read so no write operation is needed and I read somewhere that eeprom was the right place to store the table.
Quote
Calculate the table using fixed point math and store like this:
const int rtd_table[1024]={1,2,3,4,5,....};
This tells the compiler to put the rtd_table in flash memory together with the program.
The second question is how am I going to implement in circuit a way to measure the resistance of the RTD and have that value in the microcontroller for analysis and processing.
You need an A/D converter. Using a PT1000 element is much simpler than a PT100 because a PT1000 can be read directly by an ADC. This projects needs a mathematical approach to determine how much error and resolution you get from a certain solution and wether you need 4 wire compensation or not.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline itdontgo

  • Regular Contributor
  • *
  • Posts: 167
  • Country: gb
    • IoT Manufacturer
Re: RTD interfacing with PIC and eeprom lookup table.
« Reply #18 on: January 04, 2014, 01:59:40 pm »
Instead of telling you you don't know what you're doing I'll answer your question.  Yes you can store an awful lot of data in a PIC.  Use a PIC16F1 for this application.  Then use the moviw command to get the data from your program memory.  One command and really easy.  If you need more space/precision you can use the flash memory read routines to get both the high and low parts of the program memory word.

In our GSM products we store the telephone numbers in the program memory starting at 0x1800.  Our test program has these numbers in it:

      org      0x1800

      DATA   0x0F57
      DATA   0x0F56
      DATA   0x0F66
      DATA   0x0F03

      DATA   0x1857
      DATA   0x1756
      DATA   0x1066
      DATA   0x1F03

      DATA   0x2857
      DATA   0x2756
      DATA   0x2066
      DATA   0x2F03

To get the lower byte you simply write the memory location to the FSR so for example to get the data from the first word you need the following code:

movlw 0x18  ;you should really wite 0x98 as you need to set bit 7 of the FSRxH for a PM read but the assembler will do this for you

movlw 0x18
movwf FSR0H
movlw 0x00
movwf FSR0L

then to get the data in the WREG:

moviw FSR0++ 

puts 0x57 in the WREG

This also post increments the FSR so

moviw FSR0++

puts 0x56 in the WREG from 0x1801 and so on

For the high byte at each address you would need to call a flash memory read such as this

      bcf      EECON1,CFGS
      bsf      EECON1,EEPGD
      bcf      INTCON,GIE
      bsf      EECON1,RD
      nop
      nop
      bsf      INTCON,GIE
      bcf      EECON1,EEPGD
      movf   EEDATH,0
      movlb   0
   return

So it's easier just to use the lower byte unless you have to.  Unfortunately we have to for our program but it's no big deal

Offline Niklas

  • Frequent Contributor
  • **
  • Posts: 425
  • Country: se
Re: RTD interfacing with PIC and eeprom lookup table.
« Reply #19 on: January 10, 2014, 12:17:42 am »
One approach I have used for temperature conversion of NTCs, PtXXX and silicon sensors as the KTY-series is to split the temperature range in several, piecewise linear regions. Each region is treated as linear and then linked together with the next region.
y = k * x + M, where k is a constant, x is the ADC value and M is a constant
k is normally a non integer value but it could be rewritten as a quotient A/B where A and B are integers. Some values of B might even be equal or close enough to 2^n, ie correspond to a right shift instruction. The selection of region is a simple if-elseif-elseif-else to test the ADC value against the range of each region.
 

Offline jerry507

  • Regular Contributor
  • *
  • Posts: 248
Re: RTD interfacing with PIC and eeprom lookup table.
« Reply #20 on: January 10, 2014, 02:29:21 am »
Here is a circuit that will get you more resolution than you know what to do with:

The LT1028 isn't going to be very happy at 300C so the RTD is going to be on the end of a cable and you are into 3 wire or 4 wire compensation schemes which is another can of worms the OP probably hasn't considered.

I don't know what the OPs project is but he might be better of buying at PT100 to 4..20mA converter for like $10 on ebay although I would be a bit dubious about cheap and Chinese accuracy and stability.

The great thing about RTD's is that you're measuring resistance. Cable resistance is both small and doesn't change as much over temperature. Calibrating this out is extremely simple. Simply set up your system and in place of the RTD place high precision resistors. If you're calculating resistance value from the ADC value, you can subtract the known value from the result to find cable resistance.

Because the table given to the OP by the manufacturer is resistance vs temperature, it is probably easier to approach the problem as accurately measuring resistance. The circuit given in Linear's AN78 does exactly this and will do it with enough precision for the OP. Calibration needs to be done with high precision resistors. Once you have accurate resistance measurements, you can put your table into your code and use that.
 

Offline HexureusTopic starter

  • Contributor
  • Posts: 24
  • Country: pt
Re: RTD interfacing with PIC and eeprom lookup table.
« Reply #21 on: January 14, 2014, 05:19:37 pm »
Hello, Thank you every one for your reply.
I have been doing some calculations and i think a 10 bit ADC should have enough steps for the precision I need.
My project will be using a PIC18F4550.
I am now facing another problem. I need a way to create a constant current source of 0.5 milliamps. I have been doing some simulation with an LM317 and from the simulation it went as expected. I did breadboard it and for some reason I am getting over 1 milliamp of constant current (not so constant) on the output. The amperage is varying with the load connected to the output.
I have been googling for a way to do it for this small current but with no success.
Any advice?

Thank you.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: RTD interfacing with PIC and eeprom lookup table.
« Reply #22 on: January 14, 2014, 06:37:20 pm »
Quote
Any advice?

Read the datasheet to make sure that you aren't pushing the device out of its specs - you did.

There are plenty of alternatives - which one works depends on your particular application.
================================
https://dannyelectronics.wordpress.com/
 

Offline HexureusTopic starter

  • Contributor
  • Posts: 24
  • Country: pt
Re: RTD interfacing with PIC and eeprom lookup table.
« Reply #23 on: January 14, 2014, 07:52:53 pm »
I'm trying to use 0.5 milliamps to power the rtd for measurement.
 

Offline qno

  • Frequent Contributor
  • **
  • Posts: 422
  • Country: nl
Re: RTD interfacing with PIC and eeprom lookup table.
« Reply #24 on: January 14, 2014, 09:45:03 pm »
You can also use a compensated measurement.
Put the RTD in one leg of a bridge configuration and control the other part with a selected number of resistors to tune the bridge back to zero.
Depending on the number of resistors you use you can choose the resolution.

With 9 resistors you can cover the range of 0 to 300°C. with almost 0.5°C resolution.
Why spend money I don't have on things I don't need to impress people I don't like?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf