 # Need help with programming a cross reference table

Hello, I am new to programming Arduino. I am trying to build a refrigeration monitor. I am using a 0-5 vdc pressure sensor on analog input 0. I need to read the pressure input, find the two values in the table that the reading falls between and call out the temperature reading. The table is basically a pressure to temperature table. find pressure reading in chart and cross over to find corresponding temperature. I was going to do calculations, but the formula is way to complex and involved, hence the cross reference table. I have the analogRead mapped from 0-1023 to 0-500 PSI. I am having trouble taking the value, say 34.7 and getting the temperature from the table. 34.7-35.6 is the range for a cross reference of 1 deg. I would need to get the value, scan the table to find out where it falls between the two values (interpolate ?) and then retrieve the temperature value for further processing. Thanks in advance for any help, Nik

P.S. I have attached the pressure to temperature chart for reference.

Maybe put the table into EXCEL and use the LINEST function to see if you can come up with a simplified formula.

Then see if the formula can be easily used in an Arduino sketch.

.

Maybe if you post the chart somebody will see a simple way to implement it?

How many temperature steps do you need to deal with? I the number is not too large (say 50 or so) you could create an array and map the values from analogRead() to index into the array.

...R

I posted the chart with my initial post (Advantage engineering.pdf)

I took the Value from the sensor via analogRead (A0) as an int.

Then i made a float (voltage) = sensorValue * (500.0/1023.0) to get it as a decimal number.

Now I need to figure out how to take that value (34.8 for example) and figure out how to scan the table under the R404A column to see where it falls so I can get the temperature value from the left column. I will probably need only 51 values in the table (0-50 degrees.) I do not think an array index can be a float variable.

Thank, Nik

I was going to do calculations, but the formula is way to complex and involved,

I doubt that. If you post the formula for the pressure-temperature relationship (or a link to it), I'll be happy to write the one or two lines to compute it.

You haven't told us how quickly you need to find the values. If just monitoring something and don't need to do something in the next 5 milliseconds, just search the table linearly.

Paul

The link to the formula is as follows:

The resulting pressure to temperature table is as follows:

The formula is complex, I think that is why all hvac technicians use the cross reference charts.

nikbatten: I posted the chart with my initial post (Advantage engineering.pdf)

I don't think you have said what refrigerant you are using so I will assume R-22 which is the first column.

The range of pressures is from 0.6 to 50. If I pick a pressure - say 15.2 I can read off a temperature of -24.4C, and 16.5 gives me -23.3. Am I interpreting the table properly?

You have not told us how the analogRead() values 0-1023 relate to those pressure values. Knowing that seems to be essential. I don't see any value in using floating point values - they are less precise and the calculations are a lot slower.

Can you produce a graph from the table for your chosen refrigerant and post a picture of it. That will illustrate the relationship more clearly. The PDF you posted is just an image and I cannot extract the numbers from it.

...R

Robin2:
I don’t think you have said what refrigerant you are using so I will assume R-22 which is the first column.

In Reply 3 he said it is R-404a. Because I am really nice (or really bored, you guys can pick), I graphed the R-404a column. As you can see, the trendline is almost perfect with a third order polynomial:

y = 0.0002x^3 + 0.0336x^2 + 2.7693x + 73.666

I don’t know how well Arduino does with powers but surely this calculation shouldn’t take too long… saximus: In Reply 3 he said it is R-404a.

I seem to be missing everything in this Thread :)

...R

Are you sure that the calculations are of any worth to your project? IMO a pressure difference is related to a temperature difference, so that you'll have to measure absolute temperatures as well?

Yep, 3rd order polynomial. I did this last night but couldn’t log in to post. Simplified table found elsewhere.

``````float P = 3.23E-5*T*T*T + 0.00747*T*T + 0.953*T + 32.2; //T in degrees F, R-404a P in PSIG
float T = 4.14E-6*P*P*P - 0.00344*P*P + 1.17*P - 37.3;
`````` Thanks for the help everyone. I think i'm on my way. I will post my code once its done to share with everyone. :)

I'm having trouble with the formula. Sorry math is not a strong subject with me.

Am i doing this right ?

i used a pressure reading of 33.7:

float T = 0.00000414 x 33.7 x 33.7 x 33.7 - 0.00344 x 33.7 x 33.7 + 1.17 x 33.7 - 37.3

i came up with T = -1.61932440258 on my calculator. I must not be doing something right.

i came up with T = -1.61932440258 on my calculator

That result is correct according to the graph in reply #12, for T in degrees F and pressure in PSIG. I would round it off to T = -2 degrees, though.

It also agrees with your first post:

getting the temperature from the table. 34.7-35.6 is the range for a cross reference of 1 deg.

Then i made a float (voltage) = sensorValue * (500.0/1023.0) to get it as a decimal number.

You are assuming exactly 5V reference voltage and 1023 steps.

The first will probably be wrong (run via USB it will be much less), the second is definitely wrong, there are 1024 steps.

nikbatten: I posted the chart with my initial post (Advantage engineering.pdf)

I took the Value from the sensor via analogRead (A0) as an int.

Then i made a float (voltage) = sensorValue * (500.0/1023.0) to get it as a decimal number.

Now I need to figure out how to take that value (34.8 for example) and figure out how to scan the table under the R404A column to see where it falls so I can get the temperature value from the left column. I will probably need only 51 values in the table (0-50 degrees.) I do not think an array index can be a float variable.

Thank, Nik

You can only get 1 of 1024 readings from analog and every one of those has a corresponding pressure. So all you need is an array with 1 value for every possible read in order, the pressure value will be in the read value position.

There is no need to compare and interpolate when you use the analog read value directly as an array index, answer is right there!

Now you need to learn about PROGMEM to store and read table values from flash memory unless your Arduino has 8K RAM or more. PROGMEM learning will pay for itself, an Uno/Nano/Micro/Mini has 32K of flash and most programs don't fill 8K of that... put all your constant text and data there and you can write "bigger" sketches.

Thanks for the info GoForSmoke. I really appreciate everyones help. I will post my code once i have all working.