Look-Up Tables Tutorial

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

Please rate this article out of 5: (1 being the worst and 5 being the best)

1
0
No votes
2
0
No votes
3
0
No votes
4
4
22%
5
14
78%
 
Total votes: 18

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: Look-Up Tables Tutorial

Post by brandonb »

martin, which file name are you refering to on the c1

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Look-Up Tables Tutorial

Post by medelec35 »

Just referring to your final application.

Reason being @4MHz MOD function takes about 1ms to complete and divide by 100 takes about 270us to complete so this would add to total loop time

If running at 19.66MHz then MOD function takes about 205us to complete and divide by 100 takes about 54us to complete.

So just looking at better ways for you.
I do have a couple of ideas to try, one of which involve using 2 LUT and all data values is in us.
so for 18.3ms ms will be 18300us
Luckily I have an excel sheet that automatically creates the LUT for supplementary code window, which I created just for this.
I will post it when im happy with how tables are created.

Martin
Martin

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: Look-Up Tables Tutorial

Post by brandonb »

martin, i changed a couple things on this to where it makes sense to me, can you look over it and tell me what you think......first of all i deleted the capitolization of the c code variables, i put a good amount of lut table numbers and put them in and intentionally didnt fill it to 255, then below in the loop i intentionally made the count higher until resets to 0 than the amount of look up table values that are written in the table---> observation was it works fine, when ever the count exceeded the number of values in the look up table the look uptable wrapped around back to zero and went through the whole thing again...this begs the question can i just leave as many values in the look up table as i want and when i link count to the c code variable can i control the look up table with count directly instead of filling it up with zeros or doing the weird calculation you did with the adc if its not needed...... another thing i was wondering is when the program starts should i create a c code block and put the c code table variable in in and initialize it to zero as good practice..... does the c command which links flowcode DELAY_MS to c variable delay_one which is derived from flowcode variable COUNT all ways go at the beginning of loop, basicly it has to be somewhere before the count right, it cant before the loop because then it would only connect the process once right? ...... CAN YOU SHOW ME HOW TO DO A 16 BIT LUT.... thanks man :D i gotta say the snippit below is way cool
You need the us after since if you have 183
ms = 18
us = 300

You can use ms = LUT/10 to retrieve the 18 for ms

You can use the mod function to retrieve the 3 from 183 then * 100
E.g us = (LUT MOD 10 )* 100


So you only need 1 decision branch

Martin
another Q, suppose i have 2 look up tables and i want to make the numbers as one since they are both linked to the same count varible, in one table i have a value of 3 and in the other table for the same count value i have a value of 45, how can i put these numbers together to make 345 so i can use this in a microsecond delay directly by using another variable = lut1 and lut2 combined
Attachments
lut.fcf
(12.5 KiB) Downloaded 671 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Look-Up Tables Tutorial

Post by medelec35 »

brandonb wrote: i gotta say the snippit below is way cool
Hi Brandon.
I have implemented that method for you.
So if you use 5 in LUT then delay = 500us
If you use 18 then delay should be 1.8ms
183 = 18.3ms etc.
If you want precision , then you will need to do two things.
1) Use the fastest oscillator speed as possible E.g. consider 19.66MHz as absolute minimum. This will reduce overhead times for e.g. Decisions branches & calculations (especially MOD) etc.
2) Use a Crystal or resonator for better accuracy.

If you are sticking to internal osc, it may be a better idea to use a device that uses PLL along with internal oscillator for oscillator speeds of 32MHz with the newer 16F. With 18F devices you can get up to 48MHz. not sure if that option is available with internal osc or not as I have not looked into that option yet.

Martin
Attachments
lut2.fcf
(9.5 KiB) Downloaded 675 times
Martin

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: Look-Up Tables Tutorial

Post by brandonb »

nah you misunderstood me, i was playing with that last night with another flowcode and it worked great..... the thing i was wondering is you said you can combine two tables to get 16 bit numbers....and i was asking if i have two different tables synched with the same variable can i put the table numbers together to make one number....suppose i have 3 in one table and 45 in another table how could i make the number 345...........technically why can the lut only do 255 as a max? couldnt it use multiple registers (curious)

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Look-Up Tables Tutorial

Post by Benj »

Hello Brandon,

A Byte is a 8-bit memory location which is capable of storing a number between 0 and 255 i.e. there are 256 different combinations of unique states from the 8 on/off bits.

You could use a 16-bit INT array though this will limit you to a maximum of 128 locations rather then 256. There is a maximum number of locations due to PICs using pages of 256 bytes in the flash.

Or you could use two byte arrays and populate the data like this.

345 in binary looks like this - 00000001 01011001

LUTlow[0] = 0b01011001 or 0x59 or 89
LUThigh[0] = 0b00000001 or 0x01 or 1

To combine into a 16-bit int variable

INTvar = LUTlow[0] + ( LUThigh[0] << 8 )

This would allow you to store any number between 0 and 65535.

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: Look-Up Tables Tutorial

Post by brandonb »

im gonna play with this some and post some files when i get off work..... but there is no way to make a 6 and a 8 become 68?

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Look-Up Tables Tutorial

Post by medelec35 »

brandonb wrote:im gonna play with this some and post some files when i get off work..... but there is no way to make a 6 and a 8 become 68?
Yes that should be fairly straight forward
If LUT1 = 6 and LUT2 is = 8
Then Result = LUT1 * 10 + LUT2
=68
Likewise for numbers >99
if LUT1 = 6 and LUT2 is = 8 & LUT3 = 2
Then Result = LUT1 * 100 + LUT2*10 + LUT3
= 682
Etc.

This may seem obvious but can be over looked: if result will ever be greater then 255, then you must make sure Result variable is an Int or UInt etc
Martin

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: Look-Up Tables Tutorial

Post by brandonb »

wow martin that is simple!, dont tell anyone but i though about how to solve that way too long last night :lol: that kind of stuff dont come to me quickly since im not used to doing it,

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Look-Up Tables Tutorial

Post by medelec35 »

brandonb wrote:dont tell anyone but i though about how to solve that way too long last night :lol:
Don't worry bud, your secret is safe with me! :wink:
Martin

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: Look-Up Tables Tutorial

Post by brandonb »

To combine into a 16-bit int variable

INTvar = LUTlow[0] + ( LUThigh[0] << 8 )

This would allow you to store any number between 0 and 65535.
i was playing around with this last night from martins comments on bens post of the excell lut, but how do i do anything with this like use count+1 scheme and such.... by the way martin your lower solution works with same result as top solution..........below is a working lut i did last night messing around, works great on hardware, the odd numbers are subtracting the values like 47 actually gives me 50*10=500u/s(real quick to do)
Attachments
lut.fcf
combining ms and us
(10 KiB) Downloaded 605 times

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: Look-Up Tables Tutorial

Post by brandonb »

martin, i used your calculations in this one to get the hang of it and to use it for lcd readout, works great on hardware :D
Attachments
v2 with offtime adj 0-255 lut flow.fcf
(43.81 KiB) Downloaded 621 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Look-Up Tables Tutorial

Post by medelec35 »

Hi Brandon,
Well done!
Your flowchart is impressive.
So much better and efficient to the one which used decision branches.
That's why it's good to perceiver, learning and keep getting better.
The final results speak for themselves.

Martin
Martin

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: Look-Up Tables Tutorial

Post by brandonb »

check it out martin, got my pwm working... right now it only goes up in counts but is actually quite stable for frequency at 920hz on hardware
Attachments
lut pwm.fcf
lut based pwm 920hz
(11 KiB) Downloaded 538 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Look-Up Tables Tutorial

Post by medelec35 »

brandonb wrote:check it out martin, got my pwm working...
Nice one! Just tried it and yes it works very well.
Martin

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: Look-Up Tables Tutorial

Post by brandonb »

thanks martin, heres a working version.. switches are--> up - down - fast scroll - pwm on - pwm off/exit from freq set screen,... to reset frequency press pwm on & pwm off at same time, ......for fast scroll press up or down while holding fast scroll, i didnt know if you wanted to play with this one in the variable version, it does loose resolution at higher speeds by a few %... im gonna add some interrupts and do general clean up on it later to make it better,.... its a version 1 :lol:
Attachments
lut variable pwm.fcf
look up table variable pwm
(37.83 KiB) Downloaded 558 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Look-Up Tables Tutorial

Post by medelec35 »

Hi Brandon
How may LUT's :?: ....... Something tells me you have got the hang of them :wink: :lol:
Your Flowchats just get better and better! :D
Funny you should mention interrupts, I was going to suggest tackling them next.

Since Microcontroller coding can usually be created with Delays, i/p's, o/p's, decisions. interrupts (timing and port) and lut's
Master off of then and you should have no trouble in creating your own flowcharts.

Look forward to seeing the interrupt version.

Martin
Martin

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: Look-Up Tables Tutorial

Post by brandonb »

to make it easy to calculate table values for 16 bit luts based on martins calculations http://www.matrixmultimedia.com/mmforum ... igh#p20779 .... change int value and resimulate for high / low bit answers..... yea its easier for me at least,
Attachments
16 bit to 2 table lut values.fcf
(9.5 KiB) Downloaded 570 times

poweronhand
Posts: 21
Joined: Mon Sep 07, 2009 7:09 am
Has thanked: 3 times
Been thanked: 1 time
Contact:

Re: Look-Up Tables Tutorial

Post by poweronhand »

medelec35 wrote:I thought I would put together a basic tutorial on Look-up tables.
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
As you can see there is no direct formula you can use to derive correct delay time from ADC_Val
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:
LUT Tut1.png

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
  };
Look – up tables in Flowcode will always be in the format of:

Code: Select all

rom char* Name_Of_Variable_Storing_Data 
 {
  number0,number1,number2,……………last_number
 } ;
Notice first number has to be preceded with an open brace {
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'
Lut2.png
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];
Notice how all variable names after FCV_ must be in upper case since these are how Normal Flowcode variables assigned in C

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.
And you want to use a specific one then looping though a set of 4 numbers will not be too bad. what about finding a value from 200 numbers. e'g what is the value of MY_Variable180?
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.
Than in C:
rom char* MY_Variable =
{
7,10,12,16 etc
};




Any questions or comments are most welcome.

Thank you

Martin

Hi Martin, Thanks so much for this tutorial , can u tell me what if I have 2 or 3 set of tables? and if 1/3 of the table i need to display negative # do i put them in the supplementary code with different variable name ? can u show me an example?
thank in advance
Roger

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Look-Up Tables Tutorial

Post by medelec35 »

Hi poweronhand,
Your welcome, so long as its helped. :)
Here i have posted a flowchart with 3LUT's
http://wwww.matrixmultimedia.com/mmforu ... 21&#p34830

& this flowchart places postive and negative numbers in 8bit EEPROM so should help you a lot:
http://www.matrixmultimedia.com/mmforum ... 05&#p29124

It should be fairly easy to implement LUT's so positive and negative numbers are retrieved.
If you look at the flowchart and see if you can follow how it works, then you can modify LUT with your data.

If you get stuck, post the data you want to store within LUT''s and I will create flowchart for you.

Martin
Martin

vonskyes
Posts: 7
Joined: Sun Apr 27, 2014 11:20 pm
Has thanked: 1 time
Been thanked: 1 time
Contact:

Re: Look-Up Tables Tutorial

Post by vonskyes »

poweronhand wrote:
medelec35 wrote:I thought I would put together a basic tutorial on Look-up tables.
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
As you can see there is no direct formula you can use to derive correct delay time from ADC_Val
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:
LUT Tut1.png

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
  };
Look – up tables in Flowcode will always be in the format of:

Code: Select all

rom char* Name_Of_Variable_Storing_Data 
 {
  number0,number1,number2,……………last_number
 } ;
Notice first number has to be preceded with an open brace {
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'
Lut2.png
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];
Notice how all variable names after FCV_ must be in upper case since these are how Normal Flowcode variables assigned in C

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.
And you want to use a specific one then looping though a set of 4 numbers will not be too bad. what about finding a value from 200 numbers. e'g what is the value of MY_Variable180?
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.
Than in C:
rom char* MY_Variable =
{
7,10,12,16 etc
};




Any questions or comments are most welcome.

Thank you

Martin

Hi martin i found this very helpful. however i still have a problems in getting my LUT to work. I need to create two diff LUTs withing the same program because is couldn't come up with an equation to solve my problems. i am using flowcode v5 to write a flowcode for a voltage monitor. i need to compare decimal values 0-7 with a set of voltage values (150,160,170,180,190,200,210) for undervoltage and i need to do the same for over voltage values too. what do i need to do? Thank you
Best Regards
vonskyes

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Look-Up Tables Tutorial

Post by medelec35 »

Hi vonskyes,
If you post what you have done so far, then I will have a look at you Flowchart, and let you know where your going wrong.

Maritn
Martin

vonskyes
Posts: 7
Joined: Sun Apr 27, 2014 11:20 pm
Has thanked: 1 time
Been thanked: 1 time
Contact:

Re: Look-Up Tables Tutorial

Post by vonskyes »

medelec35 wrote:Hi vonskyes,
If you post what you have done so far, then I will have a look at you Flowchart, and let you know where your going wrong.

Maritn
Hi martin, sorry for my late reply have been tied up at work. I will post my flowchart later today so u can have a look at what I have done so far. Thanks.

vonskyes
Posts: 7
Joined: Sun Apr 27, 2014 11:20 pm
Has thanked: 1 time
Been thanked: 1 time
Contact:

Re: Look-Up Tables Tutorial

Post by vonskyes »

vonskyes wrote:
medelec35 wrote:Hi vonskyes,
If you post what you have done so far, then I will have a look at you Flowchart, and let you know where your going wrong.

Maritn
Hi martin, sorry for my late reply have been tied up at work. I will post my flowchart later today so u can have a look at what I have done so far. Thanks.
I have put in the c code in the supplementary code window. its two tables of values. the first compares undervoltage (UV) against decimal equivalent and the second one is overvoltage (OV) against decimal equivalent. when i set the switches it reads it in as binary and then coverts it to decimal. the first three switches sets undervoltage level while the last three sets for over voltage level. so that when i set the switch it coverts it to a decimal value and that decimal value is matched to a corresponding value in the table. I hope you can understand what the code is all about with the explanation i have given. Pls let me know it there is any question. Thank you so much for your help. Earnestly waiting for you response.
Attachments
mainsmonitor.fcf
(24.32 KiB) Downloaded 376 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Look-Up Tables Tutorial

Post by medelec35 »

So SW_ST1 & SW_ST1 will have a value e.g 10, so you want to retrieve the 10th number within the look-up table?

One thing I have noticed is you have a calculation like this: SW_ST1 = (SW_A * 4) + (SW_B * 2) + (SW_C)
You will have errors if SW_A, SW_B or SW_C are Bool.
You will need to change Bool to Bytes.

To be honest I'm not following your explanation, but it could be the time of night.

Can you give examples what you want each LUT to retrieve as that will make it easier for me.

Martin
Martin

Post Reply