RTD interfacing with PIC and eeprom lookup table. - Page 1
Forum section: electronics / projects

author: Hexureus
author_rank: Contributor
timestamp: January 03, 2014, 08:48:09 pm
content: 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

author: mazurov
author_rank: Frequent Contributor
timestamp: January 04, 2014, 12:37:36 am
content: 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").

author: Hexureus
author_rank: Contributor
timestamp: January 04, 2014, 12:48:37 am
content: Thank you for the reply.Even if I can use RTD linearization, is it still possible to to "table" look ups?

author: dannyf
author_rank: Super Contributor
timestamp: January 04, 2014, 12:53:44 am
content: QuoteYes, assuming you have sufficient space.

author: dannyf
author_rank: Super Contributor
timestamp: January 04, 2014, 12:55:13 am
content: QuoteMath is a lot faster in a table.

author: Hexureus
author_rank: Contributor
timestamp: January 04, 2014, 12:59:44 am
content: 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.

author: Rufus
author_rank: Super Contributor
timestamp: January 04, 2014, 02:18:33 am
content: Quote from: Hexureus on January 04, 2014, 12:59:44 amThen 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).

author: Hexureus
author_rank: Contributor
timestamp: January 04, 2014, 02:34:48 am
content: 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.

author: dannyf
author_rank: Super Contributor
timestamp: January 04, 2014, 02:35:03 am
content: QuoteWell, the answer depends on which version of "very precise" it is.Quotesounds like a table of 300 values.

author: dannyf
author_rank: Super Contributor
timestamp: January 04, 2014, 02:36:42 am
content: QuoteWith a 10-bit adc, you have at most 1024 unique values. Just map them to temperature readings.

author: Hexureus
author_rank: Contributor
timestamp: January 04, 2014, 02:40:30 am
content: I need it to be 1º precise

author: nctnico
author_rank: Super Contributor
timestamp: January 04, 2014, 02:51:52 am
content: 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.

author: Hexureus
author_rank: Contributor
timestamp: January 04, 2014, 03:02:46 am
content: 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.

author: Maxlor
author_rank: Frequent Contributor
timestamp: January 04, 2014, 03:37:36 am
content: 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 = ADC value for -55°CadcValues = ADC value for -50°CadcValues = ADC value for -45°C...adcValues = ADC value for 150°CYou 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:for (i = 0; i < (ADC_VALUES_SIZE - 1); ++i, temperature += 50) {int16_t a = adcValues;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< bbecause an NTC's resistance drops with increasing temperature; for an RTD it's the other way round.

author: Jay_Diddy_B
author_rank: Super Contributor
timestamp: January 04, 2014, 03:44:56 am
content: 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

author: Rufus
author_rank: Super Contributor
timestamp: January 04, 2014, 04:25:44 am
content: Quote from: Jay_Diddy_B on January 04, 2014, 03:44:56 amThe 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.

author: dannyf
author_rank: Super Contributor
timestamp: January 04, 2014, 01:03:39 pm
content: QuoteVery simple: calculate the corresponding temperature for adc values from 0 to 1023.That would be the best precision / resolution you will ever get.

author: nctnico
author_rank: Super Contributor
timestamp: January 04, 2014, 01:29:55 pm
content: Quote from: Hexureus on January 04, 2014, 03:02:46 amYou 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.

author: itdontgo
author_rank: Regular Contributor
timestamp: January 04, 2014, 01:59:40 pm
content: 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 0x1800DATA 0x0F57DATA 0x0F56DATA 0x0F66DATA 0x0F03DATA 0x1857DATA 0x1756DATA 0x1066DATA 0x1F03DATA 0x2857DATA 0x2756DATA 0x2066DATA 0x2F03To 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 youmovlw 0x18movwf FSR0Hmovlw 0x00movwf FSR0Lthen to get the data in the WREG:moviw FSR0++puts 0x57 in the WREGThis also post increments the FSR somoviw FSR0++puts 0x56 in the WREG from 0x1801 and so onFor the high byte at each address you would need to call a flash memory read such as thisbcf EECON1,CFGSbsf EECON1,EEPGDbcf INTCON,GIEbsf EECON1,RDnopnopbsf INTCON,GIEbcf EECON1,EEPGDmovf EEDATH,0movlb 0returnSo 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

author: Niklas
author_rank: Frequent Contributor
timestamp: January 10, 2014, 12:17:42 am
content: 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 constantk 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.

author: jerry507
author_rank: Regular Contributor
timestamp: January 10, 2014, 02:29:21 am
content: Quote from: Rufus on January 04, 2014, 04:25:44 amThe 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.

author: Hexureus
author_rank: Contributor
timestamp: January 14, 2014, 05:19:37 pm
content: 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.

author: dannyf
author_rank: Super Contributor
timestamp: January 14, 2014, 06:37:20 pm
content: QuoteRead 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.

author: Hexureus
author_rank: Contributor
timestamp: January 14, 2014, 07:52:53 pm
content: I'm trying to use 0.5 milliamps to power the rtd for measurement.

author: qno
author_rank: Frequent Contributor
timestamp: January 14, 2014, 09:45:03 pm
content: 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.

author: Hexureus
author_rank: Contributor
timestamp: January 14, 2014, 09:57:12 pm
content: Thank you for your reply.I was re-watching some of Dave's videos and I just came up with an idea.I would have a similar uCurrent circuit to mesure the current on the RTD and instead of using a constant current source to measure the RTD I would use a constant voltage of lets say, 0.8 volts. I would then use 1 of the ADC channels to keep an eye on the voltage across the resistor and other channel for the value of the current on the RTD and then do the calculations on the micro-controller, compare it to the look-up table and then show them on the LCD.Another question,If the micro-controller is working with 5v, can't I define the ADC steps to work with 0-1.5v having the 1024 steps in that range?Thank you.

author: Maxlor
author_rank: Frequent Contributor
timestamp: January 14, 2014, 10:19:33 pm
content: Quote from: Hexureus on January 14, 2014, 09:57:12 pmMost PICs have an internal voltage reference (called FVR in the data sheets) that you can use with the ADC. It's set at fixed values, you can choose from 4.096V, 2.048V and 1.024V. However, if you do use the internal reference, and your RTD/circuit is powered from an external supply, you're opening yourself up to errors caused by fluctuations in the voltage level of that external supply. So make sure that is stable.You could also use a voltage divider and a buffer to reduce Vdd to whatever you want, and use that as reference voltage for the ADC. That way, you can get a range of 0-1.5V which follows fluctuations in Vdd, but you need a couple more parts.

author: Hexureus
author_rank: Contributor
timestamp: January 14, 2014, 10:45:13 pm
content: Thank you for your reply.This project is for a prototype and for learning so amount of parts or cost is not important.I'm really new to electronics but I'm starting to get the hang of it.