PDA

View Full Version : Lookup Tables



shawn
- 21st November 2010, 00:32
Hello
More dumb questions.
First, If i create a constant mice CON 3 where is that stored? Is it in eprom, ram, or flash program space. I assume it is stored in the flash program memory.

Second, if that constant is stored in the flash program memory then in theory I could make constants untill the device flash program memory is full.

What I am trying to do is make a look up table to read a thermistor. Yes I know use a lm34 or lm35 temp sensor. I've done that and they are awesome, but I am looking for cheap and not real accurate.

I have a chart made for a 10K thermistor that shows what adc value correlates to what temp. I have a 1024 different values and I am trying to figure out if a lookup table would work.

Third, if your still reading. How do I create a table in PBP? The book is pretty short and I can not find a darn thing in the forum.
Thanks
Nick

mackrackit
- 21st November 2010, 11:09
I have a 1024 different values
That is doable with an 18Fxxx chip.


How do I create a table in PBP?
Not sue what you mean? By typing?
Here is an example


'Lets say
TXI = 255
GOSUB D_INDEX
' Now TXIU will hold the value 2500

D_INDEX:
'THERMO TEMPERATURES
LOOKUP2 TXI,[2500,2490,2480,2470,2460,2450,2440,2430,2420,2410, 2400,2390,2380,2370,_
2360,2350,2340,2330,2320,2310,2300,2290,2280,2270, 2260,2250,2240,2230,2220,2210,2200,_
2190,2180,2170,2160,2150,2140,2130,2120,2110,2100, 2090,2080,2070,2060,2050,2040,2030,_
2020,2010,2000,1990,1980,1970,1960,1950,1940,1930, 1920,1910,1900,1890,1880,1870,1860,_
1850,1840,1830,1820,1810,1800,1790,1780,1770,1760, 1750,1740,1730,1720,1710,1700,1690,_
1680,1670,1660,1650,1640,1630,1620,1610,1600,1590, 1580,1570,1560,1550,1540,1530,1520,_
1510,1500,1490,1480,1470,1460,1450,1440,1430,1420, 1410,1400,1390,1380,1370,1360,1350,_
1340,1330,1320,1310,1300,1290,1280,1270,1260,1250, 1240,1230,1220,1210,1200,1190,1180,_
1170,1160,1150,1140,1130,1120,1110,1100,1090,1080, 1070,1060,1050,1040,1030,1020,1010,_
1000,990,980,970,960,950,940,930,920,910,900,890,8 80,870,860,850,840,830,820,810,800,_
790,780,770,760,750,740,730,720,710,700,690,680,67 0,660,650,640,630,620,610,600,590,_
580,570,560,550,540,530,520,510,_
500],TXIU
RETURN

aratti
- 21st November 2010, 16:35
Dave, is it with the last version of PBP that you can use 1024 variables in lookup2 table?
With mine I am limited to 256 for 18fxxxx

Since your table is linear, with these two lines of code you can do without the rather large table:

If TXI > 200 Then TXI = 0
TXIU = 2500 - (TXI * 10)


Checking the regression of your data, most of the time you discover that you can do without the lookup table.

Nick, post your thermistor table convertion and I will check if it is feasible.

Cheers

Al.

mackrackit
- 21st November 2010, 17:16
I can not remember if 2.50 had 1024 constants. I have not used all 1024 but around 500 or so works with 2.60.



Since your table is linear,
Thanks for pointing that out, it may save someone some confusion.
That probably was not the best example.. Grabbed it from a piece of code that had a non-liner LOOKDOWN feeding the LOOKUP. I was playing with a "K" thermocouple and the reference/junction temperature..


LOOKDOWN2 TX,>[898,895,892,889,886,883,879,876,873,870,867,863,86 0,857,854,850,_
847,844,841,838,835,832,828,825,822,819,815,812,80 9,805,802,799,795,792,788,785,_
782,778,775,772,769,765,762,758,755,751,748,744,74 1,737,734,731,727,724,721,717,_
713,710,706,703,699,696,692,689,685,682,678,675,67 1,667,664,660,656,653,650,646,_
643,639,635,632,628,624,620,617,614,610,606,603,59 9,595,592,588,584,580,577,573,_
570,566,562,558,555,551,547,544,540,536,532,529,52 5,521,517,513,509,506,502,498,_
495,491,487,483,479,475,471,468,464,460,456,453,44 9,445,441,437,433,429,426,422,_
418,414,410,406,402,398,395,391,387,383,379,375,37 1,367,363,360,356,352,348,344,_
340,336,332,328,324,321,317,313,309,305,301,297,29 3,290,286,282,278,274,270,267,_
263,259,255,252,248,244,240,236,232,229,224,221,21 7,213,209,206,202,198,194,190,_
187,183,180,176,173],TXI

BH_epuk
- 21st November 2010, 20:18
Have you considered the MCP9700 temp sensor from Microchip.
About to use one on a project myself, Cheap £0.22 @10off in farnell and hopefuly a lot less coding than a Thermistor.

shawn
- 22nd November 2010, 02:28
Thanks guys for posting.
That helped me understand the lookup table.
Would it be faster and take up less code if I placed the table inside of an eeprom. Also to get the resolution I want over the temp. range I want, I think I am going to switch to a mcp 3202 12bit ad chip.

Another question for ya all. If I am reading a temp of 70.8 is it possible to store that in a 1 byte memory location. How I handle this now is to put the 70 in the high byte of a word variable and I put the .8 in the low byte.This works very well but doubles the memory requirments.

Thanks to You all
Nick

mackrackit
- 22nd November 2010, 04:16
A correction to my not so good example

'Lets say
TXI = 0
GOSUB D_INDEX
' Now TXIU will hold the value 2500
" If Index is zero, Var is set to the first Value."


Would it be faster and take up less code if I placed the table inside of an eeprom.
Faster-- No, it takes time to read the EEPROM. Less code-- Probably yes.


If I am reading a temp of 70.8 is it possible to store that in a 1 byte memory location.
Not that I can think of.

Darrel Taylor
- 22nd November 2010, 14:33
Storing 1024 WORD values in LOOKUP2 statements would take over 8K words of program space.

But using the technique described here ... http://www.picbasic.co.uk/forum/showthread.php?t=3891#LAB
You can do it with just over 1K.

Faster, smaller, no external parts.