Go Down

Topic: Look-up Table (Read 996 times) previous topic - next topic

Badr0ck

Hello,

can someone explain me the basics how to make a look-up table for a sensor.
I have no problems with wiring.
I only have no clue how to make the software part.
Thanks

mem

There are many ways to do it. It will be easier giving you an answer if you could say a little about your project and the purpose and size of your table.

Badr0ck

Okay i try to.
I will creat a look-up table for 2 sensors. the first one is a KTY81-200 and the second will be a selfmade Aenometer.
I use the analog Inputs from the Duemilanove Board (10bit).
If it is possible the table shouldn`t be stored in the Ram.
Is it possible to store it in the flash memory?
My first idea is making an arry for the analog values(0-1023), if this is the wrong way please correct me.
But in this case i have to store 1024 values is there any better way to do this?

mem

#3
Mar 17, 2009, 06:57 pm Last Edit: Mar 17, 2009, 06:58 pm by mem Reason: 1
There are two parts to the task. One is how you design the table, the other is how you store and retrieve the data. You are correct that flash would be needed to store a table of 1024 values but it may not be necessary to have that many values.

For example if the temperature sensor is only accurate to 1% and you are measuring a temperature range of less than 100 degrees C then you may only need 100 integer values.
But rather than us guessing what you want to do, why not say a little more about the data you expect to get and what you want the table to do.

Badr0ck

temperature range will be between 0-50°C.
i don`t know the values of the Aneometer first i have to build it :)
I want to to compare the Analog input with the look-up table and get the real temperature back.
So the look-up table have to store the analoginput value and the "real" temperature value.
For example:    500(analoginput value)=30°C.
i haven`t decide if i take the whole 1024 for 0-50°C or not.
i'm interessted in the basics how to make such a look-up table.

mem

One way is to have an array of raw values for each of the temperatures in the range of  0-50°C.  To make things simple, lets say that you store the 51 expected values from anlaogRead for each of the degrees within the range.

Your sketch would then get the actual value from analogRead and search through the array until it found an entry that was equal to or greater than the value.  If the value is exactly the same, you can use this directly. But if the value is between two array entries, you could interpolate the temperature. (you should find lots of info on how to do that if you need fractional temps)

I hope that helps.

Go Up