-
RTD interfacing with PIC and eeprom lookup table.
Posted by
Hexureus
on 03 Jan, 2014 20:48
-
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
-
#1 Reply
Posted by
mazurov
on 04 Jan, 2014 00:37
-
-
#2 Reply
Posted by
Hexureus
on 04 Jan, 2014 00:48
-
Thank you for the reply.
Even if I can use RTD linearization, is it still possible to to "table" look ups?
-
#3 Reply
Posted by
dannyf
on 04 Jan, 2014 00:53
-
if its possible to store a complete table
Yes, assuming you have sufficient space.
-
#4 Reply
Posted by
dannyf
on 04 Jan, 2014 00:55
-
a simple polynomial equation
Math is a lot faster in a table.
-
#5 Reply
Posted by
Hexureus
on 04 Jan, 2014 00:59
-
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.
-
#6 Reply
Posted by
Rufus
on 04 Jan, 2014 02:18
-
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).
-
#7 Reply
Posted by
Hexureus
on 04 Jan, 2014 02:34
-
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.
-
#8 Reply
Posted by
dannyf
on 04 Jan, 2014 02:35
-
I need very precise readings.
Well, the answer depends on which version of "very precise" it is.
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.
-
#9 Reply
Posted by
dannyf
on 04 Jan, 2014 02:36
-
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.
-
#10 Reply
Posted by
Hexureus
on 04 Jan, 2014 02:40
-
I need it to be 1º precise
-
#11 Reply
Posted by
nctnico
on 04 Jan, 2014 02:51
-
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.
-
#12 Reply
Posted by
Hexureus
on 04 Jan, 2014 03:02
-
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.
-
#13 Reply
Posted by
Maxlor
on 04 Jan, 2014 03:37
-
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:
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.
-
-
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.pdfYou 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
-
#15 Reply
Posted by
Rufus
on 04 Jan, 2014 04:25
-
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.
-
#16 Reply
Posted by
dannyf
on 04 Jan, 2014 13:03
-
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.
-
#17 Reply
Posted by
nctnico
on 04 Jan, 2014 13:29
-
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.
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.
-
#18 Reply
Posted by
itdontgo
on 04 Jan, 2014 13:59
-
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
-
#19 Reply
Posted by
Niklas
on 10 Jan, 2014 00:17
-
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.
-
#20 Reply
Posted by
jerry507
on 10 Jan, 2014 02:29
-
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.
-
#21 Reply
Posted by
Hexureus
on 14 Jan, 2014 17:19
-
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.
-
#22 Reply
Posted by
dannyf
on 14 Jan, 2014 18:37
-
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.
-
#23 Reply
Posted by
Hexureus
on 14 Jan, 2014 19:52
-
I'm trying to use 0.5 milliamps to power the rtd for measurement.
-
#24 Reply
Posted by
qno
on 14 Jan, 2014 21:45
-
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.