I have Benj to thanks as I first read about LUT here:
http://www.matrixmultimedia.com/mmforum ... 543&#p5509
I thought I would try and write a tutorial form a different perspective.
Thanks werner for spotting my typical spelling errors before posting tutorial on here.
I have added a bit more since so hopefully not too many more have crept in

LOOK–UP TABLES (LUT) TUTORIAL
Equipment:
EB006 programmer with 16F88 microcontroller.
EB003 Sensor board (using pot at pin2) connected to port A
EB005 LCD Board connected to port B
Problem: I have a variable called ADC_Val which can have a range of 0 - 30
For each value I need a precise delay in milliseconds (or it could be a value of thermistor for a corresponding temperature) e.g.
Code: Select all
ADC_Val Delay_Val
0 7
1 10
2 12
3 16
4 20
5 23
6 25
7 52
8 55
9 61
10 63
11 66
12 70
13 72
14 80
15 85
16 91
17 98
18 100
19 115
20 130
21 146
22 151
23 155
24 160
25 168
26 171
27 180
28 185
29 191
30 203
You can create a flowchart using decision branches but I’m sure you can imagine how large flowchart would be after all 31 values are used. What about if there were 256 different values!
Here is the Flowchart with just 3 out of 31 values:
The most efficient way to solve this is by use of a look-up table.
Basically all the values of delay required are placed in the supplementary code window separated by a comer after the name of LUT variable that is declared. Don’t worry I will showing a completed LUT.
In Flowcode V4 supplementary code window is found by ‘View’ menu, ‘Project Options’
In V5 it’s Build menu, ‘Project Options’ Don’t forget to tick the “Use Supplementary code’ which enables Supplementary code button.
This is how the code in the supplementary code window will look:
Code: Select all
rom char* Delay_Val =
{
7,10,12,16,20,23,25,52,55,61,63,66,70,72,80,
85,91,98,100,115,130,146,151,155,160,168,171,180,191,203
};
Code: Select all
rom char* Name_Of_Variable_Storing_Data
{
number0,number1,number2,……………last_number
} ;
There are comers after every number except the last number which has a close brace and a semicolon.
NOTE: Don't forget the semicolon!.
If you do you will get a general error that gives the wrong line number . Try it just so you will recognise the error if it does occur.
It Does not matter how many lines you have so long as you don't exceed the maximum quantity of 256 numbers and don't exceed the value of 255 since LUT are 8 Bit.
E.g. for a total 31 you could have 2 rows of 10 numbers + 1 row of 11
Or
1 row of 15, and 1 row of 16 etc.
If you want to use numbers greater than 255 then you will have to use 2 sets of 8 bit LUTs.
Other important things are don't allow the number which will be used to retrieve the LUT value to exceed the quantity of LUT data values.
E.g since I have 31 data items, then ADC_Val can't be higher than 31-1 = 30
If it is, a variable not related to LUT data will be retrieved instead!
Also if the minimum number which will be used to retrieve the LUT value is greater than 0, say 35.
Then you either do 0,0,0,0,0,0 …34 times then 1st data value or an easier way could be ADC_Val = ADC_Val – 35 which is my preferred method
The Name_Of_Variable used e.g. Delay_Val is not created within in normal flowchart variables since it's declared by rom char*
Now the LUT has been created in the supplementary code window we need to create a flowchart in the main work area.
You will need to create a 8bit variable E.g called Delay_Milliseconds and 8bit variable called ADC_Val. These can be created using Variables Manager. One way is 'Edit' menu and select 'Variables' Basically here is how the look-up table system will work.
Think of each value of Delay as an array* so:
Delay_Val(0)=7,
Delay_Val (1)=10………Delay(30)=203 etc.
So you could say Delay_Val=(ADC_Val)
The way to retrieve correct LUT value on flowchart is by using a C Code block.
In this example code block will have:
Code: Select all
FCV_DELAY_MILLISECONDS=Delay_Val[FCV_ADC_VAL];
Variable that’s declared in supplementary code window in this example * Delay_Val
Is case sensitive so you must have the capitals D and V
You don't need the underscore so DelayVal is also valid. But same as variable rules … no spaces etc..
Attached is a Flowchart that has the example LUT incorporated so you can see how the example looks in Flowchart form.
You will need to test it out on your hardware to see the LUT Value display correctly as LUT uses C, FLOWCODE SIMULATION WON'T display LUT Value!
Only 0 will be displayed in simulator.
What I usually do is use EB006 programming board and enable ICD ('Edit', ''Project Options' in the flowchart. Or use LCD to display both number that is use for retrieval & value of LUT that's retrieved.
*For anyone who don't know about arrays:
An array:
Starting with variables: is just a storage area which can sore numbers and text, but a variable will hold only one value at a time.
E.g a byte (8 bits) type variable called MY_Variable1 = 25
If you have a list of numbers e.g:
Code: Select all
MY_Variable1= 7
MY_Variable2= 10
MY_Variable3= 12
MY_Variable4= 16 etc.
To have 200 variables with 200 different names will be very tedious to do and difficult to find. So in programming like basic. C or even in flowcharts that's where arrays are very useful.
An array are just separate storage areas set aside for a variable. The number of separate storage areas are set by square brackets [ ]
So to set aside MY_Variable which could have 200 separate values at the same time, is created by MY_Variable[200] this is created in the variable manager and not C box.
Then using a calulation box, a variable can be retrieved by either
Required_Value=MY_Variable[180]
or
Var=180 < assigned anywhere so long as its assigned before you would like to retrieve contents of MY_Variable
Required_Value=MY_Variable[Var]
Reason why LUT's are used instead of assigning MY_Variable with 200 numbers at the start is because it will take much longer to do:
Code: Select all
MY_Variable[0]= 7
MY_Variable[1]= 10
MY_Variable[2]= 12
MY_Variable[3]= 16 etc.
rom char* MY_Variable =
{
7,10,12,16 etc
};
Any questions or comments are most welcome.
Thank you
Martin