Hi,
I am trying to allocate my A-D value which goes from 0-1023 to precalculated values. I tried this approach first because the calculation is pretty complex. So once I had my precalculated values, I tried storing them into the EEPROM like this:
DATA @1023,-782
DATA @1022,-696
DATA @1021,-633
DATA @1020,-594
.
.
.
DATA @3,3797
DATA @2,4126
DATA @1,4725
DATA @0,4730
Read these values from EEPROM:
FOR index0 = 0 to 1023
read index0,tem0[index0]
next index0
Then allocated precalulated stored values to A-D value:
ADCIN 2,pot_value
temperature = tem0[pot_value]
However, I think the EEPROM can only store bytes rather than words, thus I cannot store the value I wanted. I tried using lookup tables as well, but the maximum you can store in a lookup table are 256 values, I need 1023.
So, I thought about actually doing the math in the PIC itself. The equation I need to calculate is:
temperature = (80.8321*( (-1*LN( (2490*(Pot_value*(4096/1024)))/(40960-10000*(Pot_value*(4096/1024))))) + ( SQRT( (LN( (2490*pot_value)/(40960-10000*pot_value)) + 7.4063)^2 + 68.2415) -7.4063))) - 273.15
I have got an algorithm for the Ln but I will need to do all this in floating point math. Can someone please suggest what I can do?
Bookmarks