Using a graph in an MCU

I have a graph of values
0.399 203.9
0.6736 192.2
0.716 188.06
0.7422 185.54
0.7705 183.38
0.7948 180.86
0.8036 180.14
0.8189 178.7
0.8365 177.26
0.8609 175.64
0.8628 175.46
0.8753 174.74
0.9015 173.732
0.9206 172.832
0.9648 172.67

the 2nd column is temp in F. the value in the 1st column is the one that I want displayed. There is no known (to me) formula to calculate the 1st column from the 2nd.

what would be an appropriate way to store (variable) and display this information? what if my temp sensor shows 176?

Are they all the values that you have or are there more ?

what would be an appropriate way to store (variable) and display this information?

It depends on a number of factors, like

  • how precise do you need them?
  • how quickly do you need to access them?
  • how many do you need to store?

this is all I have. and the highest, and lowest value is the full range that I want.

example would be temp = x. if X is below 172.67, y= 0. if x = 172.67, then y = 0.9648. if x= 204, y=0

  • how precise do you need them? 3 decimal places
  • how quickly do you need to access them? I dont know how to quantify this. the mcu is doing a bunch of other stuff, so as quickly as I can.
  • how many do you need to store? this is the exhaustive list of values that I have.

Try a 2D array of floats

Report back.

Is there a requirement to interpolate between values and if not then what should happen if say a temperature of 177.90 is to be translated ?

float aeTable[15][15] = {
  {0.399, 0.6736, 0.716, 0.7422, 0.7705, 0.7948, 0.8036, 0.8189, 0.8365, 0.8609, 0.8628, 0.8753, 0.9015, 0.9206, 0.9648},
  {203.9, 192.2, 188.06, 185.54, 183.38, 180.86, 180.14, 178.7, 177.26, 175.64, 175.46, 174.74, 173.732, 172.832, 172.67}
};

I can devise a way to get the aetable[x][y] where y is given, but if the temp sensor gets a value that isnt in this list... that's where I am stuck at the moment.

so if the temp sensor reads 177.9, i "think i can" get the value of the 2 closest ones, and somehow get an inbetween value based on how close to the upper or lower value the temp value is? i think my brain just broke.

float aeTable[15][15] Why 15x15?
Why not 15x2?

theskaz:

  • how precise do you need them? 3 decimal places

Do you mean 3 significant figures? That's one part out of 1000 or 0.1%. Kind of ambitious in my opinion. Your gonna have to do some kind of interpolation or curve fitting.

I assume the numbers come from some sort of (secret to you) physical process. Why not start by plotting your data on a piece of paper? Then look for some of the typical relationships you might expect: linear, quadratic, logarithmic, exponential, etc. You can curve fit to those.

Baring any other plan, go with linear interpolation between samples. Extrapolation outside the range is kind of dicey.

AWOL:
float aeTable[15][15] Why 15x15?
Why not 15x2?

cause i'm special. typo.

gfvalvo:
Do you mean 3 significant figures? That's one part out of 1000 or 0.1%. Kind of ambitious in my opinion. Your gonna have to do some kind of interpolation or curve fitting.

I assume the numbers come from some sort of (secret to you) physical process. Why not start by plotting your data on a piece of paper? Then look for some of the typical relationships you might expect: linear, quadratic, logarithmic, exponential, etc. You can curve fit to those.

Baring any other plan, go with linear interpolation between samples. Extrapolation outside the range is kind of dicey.

before coming to this forum, i went to https://mycurvefit.com/ to attempt to figure out the maths. I cant really say that I understand it very well:

y = 168.6714 + (204.0255 - 168.6714)/(1 + (x/0.7339429)^8.497811)

i threw that in excel to test, and they all came back "7". i went back and came up with this quartic Regression method:
y = 1741.346 - 36.26593x + 0.2829009x^2 - 0.0009788492x^3 + 0.000001266937x^4

its pretty accurate after 173

Another quartic fit

fit.png

fit.png

Nice curve. If were my data I'd either:

  1. Do a linear regression, slap down a straight line, and call it a day ;D

  2. Do linear interpolation between the samples.

#2 was the way that i was going to go, but jremington's curve is tight enough to make me happy. and I dont have to keep a 2d array. just an if statement to keep it within bounds.