## 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
2
0
3
0
4
4
24%
5
13
76%

medelec35
Valued Contributor
Posts: 8597
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2468 times
Been thanked: 3555 times
Contact:

### Look-Up Tables Tutorial

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:
viewtopic.php?f=26&t=3543&#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          71          102          123          164          205          236          257          528          559          6110         6311         6612         7013         7214         8015         8516         9117         9818         10019         11520         13021         14622         15123         15524         16025         16826         17127         18028         18529         19130         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 (131.43 KiB) Viewed 27179 times

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 (13.7 KiB) Viewed 26992 times

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.
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= 7MY_Variable2= 10MY_Variable3= 12MY_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]= 7MY_Variable[1]= 10MY_Variable[2]= 12MY_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
Attachments
LUT_Tut FC4 V4.fcf
Last edited by medelec35 on Sun Jan 22, 2012 6:55 pm, edited 3 times in total.
These users thanked the author medelec35 for the post (total 11):
JohnCrow (Fri Jan 20, 2012 8:55 am) • Steve (Fri Jan 20, 2012 9:42 am) • DavidA (Fri Jan 20, 2012 9:46 am) • Benj (Fri Jan 20, 2012 12:13 pm) • Spanish_dude (Fri Jan 20, 2012 2:45 pm) • JonnyW (Fri Jan 20, 2012 10:15 pm) • Steve001 (Sat Jan 21, 2012 1:50 pm) • Werner (Sat Jan 21, 2012 7:22 pm) • brandonb (Sun Jan 22, 2012 6:57 am) • davehindmarsh (Sun Feb 17, 2013 7:56 pm) and one more user
Rating: 55%

Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

JohnCrow
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 381 times
Been thanked: 716 times
Contact:

### Re: Look-Up Tables Tutorial

Hi Martin

Nice tutorial.

Just noticed a slight error in the flowchart. You have missed one of the variables from the LUT, 185.
Just added that and it works fine.

Also as you point out, FC cannot simulate LUTs, but using the generated hex code in Real Pic Simulator does allow it to be simulated.
Attachments
LUT_Tut FC4 V2.fcf
These users thanked the author JohnCrow for the post:
medelec35 (Fri Jan 20, 2012 8:18 pm)
Rating: 5%

1 in 10 people understand binary, the other one doesn't !

medelec35
Valued Contributor
Posts: 8597
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2468 times
Been thanked: 3555 times
Contact:

### Re: Look-Up Tables Tutorial

Thanks for the spot John,
Reason I decided to create a tutorial is because Brandon created a large macro, and I mentioned that it could be greatly reduced using LUT.
As it happens he did mention that he was interested in LUT as its the type of things he plans to do.

I have corrected the flowchart.
Yes you are indeed correct about simulator that uses hex will work.
For people who don't know about the simulator I have posted about it here:
viewtopic.php?f=29&t=8430&p=24998#p24998

Cheers

Martin
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Steve001
Valued Contributor
Posts: 1106
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 454 times
Been thanked: 507 times
Contact:

### Re: Look-Up Tables Tutorial

Thanks very usefull topic

steve
These users thanked the author Steve001 for the post:
medelec35 (Sun Jan 22, 2012 1:54 am)
Rating: 5%

Success always occurs in private and failure in full view.

medelec35
Valued Contributor
Posts: 8597
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2468 times
Been thanked: 3555 times
Contact:

### Re: Look-Up Tables Tutorial

Thanks Steve.
Just need a volunteer who does not know about LUT's and wants to learn.
Then let me know how they found the tutorial.
That way I can tweek it if necessary.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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

martin i cant give up on this its not in my nature, so get ready for the questions shouldnt the adc read adc_val*30/255 instead of *3/25..... this is the part obviously as you guessed that im totally screwed on
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 called Delay_ms and 8bit variable called ADC_Val
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.
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

Notice how all variable names after FCV_ must be in upper case since these are 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..

i think you did a very good job explaining this process but im just not up to the level of understanding the basics of some of the finer points of flowcode yet, you must have infinite patience... what is an array? gonna work through understanding this in a series of mods if you dont mind
Last edited by brandonb on Sun Jan 22, 2012 7:40 am, edited 1 time in total.

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

i changed the file around to make it work in a way i could understand it better, checked it on hardware (all is well) could you set up another look up table (just the basic stuff) so i could adapt it like this with micro second values, then i could have time delays like 2.35 m/s, i have a game plan
Attachments
trying to figure lut.fcf

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

here is my take of trying to create a extra table in the same fashion, i dont think i did it right, the adc does something funny at the extreme position, i would not normally use this with an adc, but rather with a count=count+1 scheme, no clue how to do it with that
Attachments
trying two tables.fcf

Steve001
Valued Contributor
Posts: 1106
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 454 times
Been thanked: 507 times
Contact:

### Re: Look-Up Tables Tutorial

medelec35 wrote:Thanks Steve.
Just need a volunteer who does not know about LUT's and wants to learn.
Then let me know how they found the tutorial.
That way I can tweek it if necessary.

count me in on that
Success always occurs in private and failure in full view.

medelec35
Valued Contributor
Posts: 8597
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2468 times
Been thanked: 3555 times
Contact:

### Re: Look-Up Tables Tutorial

brandonb wrote:martin i cant give up on this its not in my nature, so get ready for the questions

Hi Brandon,
Glad you have decided to give this a go thanks for that. Just bear in mind this is like any subject tackled for the fist time, it will see a bit daunting at first, then it will all fall into place with coaching in the right direction.
I will answer your questions best I can (no matter how many you have got) so here goes:
brandonb wrote: shouldnt the adc read adc_val*30/255 instead of *3/25..... this is the part obviously as you guessed that im totally screwed on

Either will work just as well as each other. The object was to convert a range of numbers produced by ADC ( 0 to 255) to just a range of 31 numbers ( 0 to 30)
You can use all 0 to 255 but at the time I was manually typing in the numbers so I reduced the range so save time. < a bit lazy sometimes

here are the results rounded to 2 decimal places for both equations. Note in PIC maths the number is always rounded down to the nearest whole number. So 59.99 = 59 in PIC maths not 60!

Code: Select all

`ADC   ADC*3/25  ADC*30/2550      0.00      0.001      0.12      0.122      0.24      0.243      0.36      0.354      0.48      0.475      0.60      0.596      0.72      0.717      0.84      0.828      0.96      0.949      1.08      1.0610      1.20      1.1811      1.32      1.2912      1.44      1.4113      1.56      1.5314      1.68      1.6515      1.80      1.7616      1.92      1.8817      2.04      2.0018      2.16      2.1219      2.28      2.2420      2.40      2.3521      2.52      2.4722      2.64      2.5923      2.76      2.7124      2.88      2.8225      3.00      2.9426      3.12      3.0627      3.24      3.1828      3.36      3.2929      3.48      3.4130      3.60      3.5331      3.72      3.6532      3.84      3.7633      3.96      3.8834      4.08      4.0035      4.20      4.1236      4.32      4.2437      4.44      4.3538      4.56      4.4739      4.68      4.5940      4.80      4.7141      4.92      4.8242      5.04      4.9443      5.16      5.0644      5.28      5.1845      5.40      5.2946      5.52      5.4147      5.64      5.5348      5.76      5.6549      5.88      5.7650      6.00      5.8851      6.12      6.0052      6.24      6.1253      6.36      6.2454      6.48      6.3555      6.60      6.4756      6.72      6.5957      6.84      6.7158      6.96      6.8259      7.08      6.9460      7.20      7.0661      7.32      7.1862      7.44      7.2963      7.56      7.4164      7.68      7.5365      7.80      7.6566      7.92      7.7667      8.04      7.8868      8.16      8.0069      8.28      8.1270      8.40      8.2471      8.52      8.3572      8.64      8.4773      8.76      8.5974      8.88      8.7175      9.00      8.8276      9.12      8.9477      9.24      9.0678      9.36      9.1879      9.48      9.2980      9.60      9.4181      9.72      9.5382      9.84      9.6583      9.96      9.7684      10.08      9.8885      10.20      10.0086      10.32      10.1287      10.44      10.2488      10.56      10.3589      10.68      10.4790      10.80      10.5991      10.92      10.7192      11.04      10.8293      11.16      10.9494      11.28      11.0695      11.40      11.1896      11.52      11.2997      11.64      11.4198      11.76      11.5399      11.88      11.65100      12.00      11.76101      12.12      11.88102      12.24      12.00103      12.36      12.12104      12.48      12.24105      12.60      12.35106      12.72      12.47107      12.84      12.59108      12.96      12.71109      13.08      12.82110      13.20      12.94111      13.32      13.06112      13.44      13.18113      13.56      13.29114      13.68      13.41115      13.80      13.53116      13.92      13.65117      14.04      13.76118      14.16      13.88119      14.28      14.00120      14.40      14.12121      14.52      14.24122      14.64      14.35123      14.76      14.47124      14.88      14.59125      15.00      14.71126      15.12      14.82127      15.24      14.94128      15.36      15.06129      15.48      15.18130      15.60      15.29131      15.72      15.41132      15.84      15.53133      15.96      15.65134      16.08      15.76135      16.20      15.88136      16.32      16.00137      16.44      16.12138      16.56      16.24139      16.68      16.35140      16.80      16.47141      16.92      16.59142      17.04      16.71143      17.16      16.82144      17.28      16.94145      17.40      17.06146      17.52      17.18147      17.64      17.29148      17.76      17.41149      17.88      17.53150      18.00      17.65151      18.12      17.76152      18.24      17.88153      18.36      18.00154      18.48      18.12155      18.60      18.24156      18.72      18.35157      18.84      18.47158      18.96      18.59159      19.08      18.71160      19.20      18.82161      19.32      18.94162      19.44      19.06163      19.56      19.18164      19.68      19.29165      19.80      19.41166      19.92      19.53167      20.04      19.65168      20.16      19.76169      20.28      19.88170      20.40      20.00171      20.52      20.12172      20.64      20.24173      20.76      20.35174      20.88      20.47175      21.00      20.59176      21.12      20.71177      21.24      20.82178      21.36      20.94179      21.48      21.06180      21.60      21.18181      21.72      21.29182      21.84      21.41183      21.96      21.53184      22.08      21.65185      22.20      21.76186      22.32      21.88187      22.44      22.00188      22.56      22.12189      22.68      22.24190      22.80      22.35191      22.92      22.47192      23.04      22.59193      23.16      22.71194      23.28      22.82195      23.40      22.94196      23.52      23.06197      23.64      23.18198      23.76      23.29199      23.88      23.41200      24.00      23.53201      24.12      23.65202      24.24      23.76203      24.36      23.88204      24.48      24.00205      24.60      24.12206      24.72      24.24207      24.84      24.35208      24.96      24.47209      25.08      24.59210      25.20      24.71211      25.32      24.82212      25.44      24.94213      25.56      25.06214      25.68      25.18215      25.80      25.29216      25.92      25.41217      26.04      25.53218      26.16      25.65219      26.28      25.76220      26.40      25.88221      26.52      26.00222      26.64      26.12223      26.76      26.24224      26.88      26.35225      27.00      26.47226      27.12      26.59227      27.24      26.71228      27.36      26.82229      27.48      26.94230      27.60      27.06231      27.72      27.18232      27.84      27.29233      27.96      27.41234      28.08      27.53235      28.20      27.65236      28.32      27.76237      28.44      27.88238      28.56      28.00239      28.68      28.12240      28.80      28.24241      28.92      28.35242      29.04      28.47243      29.16      28.59244      29.28      28.71245      29.40      28.82246      29.52      28.94247      29.64      29.06248      29.76      29.18249      29.88      29.29250      30.00      29.41251      30.12      29.53252      30.24      29.65253      30.36      29.76254      30.48      29.88255      30.60      30.00`

Since whole numbers 0 to 30 are required either formula is suitable.
How ever with *30/255 you will only get a result of 30 when ADC hits 255.

brandonb wrote: what is an array? gonna work through understanding this in a series of mods if you dont mind

No don't mind at all
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= 7MY_Variable2= 10MY_Variable3= 12MY_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]= 7MY_Variable[1]= 10MY_Variable[2]= 12MY_Variable[3]= 16 etc.`

Than in C:
rom char* MY_Variable =
{
7,10,12,16 etc
};
Last edited by medelec35 on Sun Jan 22, 2012 12:52 pm, edited 1 time in total.
These users thanked the author medelec35 for the post (total 2):
brandonb (Sun Jan 22, 2012 12:20 pm) • Werner (Mon Jan 23, 2012 12:47 am)
Rating: 10%

Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

medelec35
Valued Contributor
Posts: 8597
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2468 times
Been thanked: 3555 times
Contact:

### Re: Look-Up Tables Tutorial

brandonb wrote:here is my take of trying to create a extra table in the same fashion, i dont think i did it right, the adc does something funny at the extreme position,

I have tried your 'trying two tables.fcf' Flowchart with 18F4455 (since that's what I have currently got plugged into EB006) and using ICD and is working 100% spot on!. All values retrieved are correct. So well done! You have sucsesfully done it!
But not with just 1 but 2 LUT's!

You can also use 2 LUTs to retreive 10bit numbers.
-32768 to 32767 with FC4
or
-32768 to 32767
&
0 to 65535 with FC5 since the addition of Unsigned int

I Think I will extend tutorial (Part 2) to work with retrieving integers rather than leaving it at bytes.

brandonb wrote:i would not normally use this with an adc, but rather with a count=count+1 scheme, no clue how to do it with that

I only used ADC as a way of altering a value so I can retrieve the 1st Delay_Val or 5th Delay_Val etc.
you can easily use any variable.
e.g

Code: Select all

`Count=Count + 1`

Code: Select all

`FCV_DELAY_MS=Delay_Value[FCV_ADC_COUNT];`

in other words

Code: Select all

`Any_Var_Name_Created_In_Flowcode=Any_Var_Name_Created_In_Flowcode+1`

Code: Select all

`FCV_DELAY_MS=Delay_Value[FCV_ANY_VAR_NAME_CREATED_IN_FLOWCODE];`

@Steve that's great thanks, the more the merrier!

Martin
Last edited by medelec35 on Sun Jan 22, 2012 12:55 pm, edited 1 time in total.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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

this is messing with me
where does FCV_DELAY_MS come from? its the special c commanded variable thats not part of flowcode right? can you say the above c command to sound like a english sentence

medelec35
Valued Contributor
Posts: 8597
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2468 times
Been thanked: 3555 times
Contact:

### Re: Look-Up Tables Tutorial

brandonb wrote:where does FCV_DELAY_MS come from? its the special c commanded variable thats not part of flowcode right? can you say the above c command to sound like a english sentence

Ah, I can see where that could lead to confusion since in C you can have a command:
delay_ms( 10 )
So I will alter that in the tutorial.
Thanks for bringing that to my attention.

In this case no the _MS I just used short for MilliSecond

I could of equally used

Code: Select all

`FCV_DELAY_MILLISECOND`

or

Code: Select all

`FCV_DELAYMILLISECOND`

the part after FCV_
is just a name of a variable that you have created within Flowcode using the variables manager
FCV_ just means FlowCode Variable

Martin.
These users thanked the author medelec35 for the post:
brandonb (Sun Jan 22, 2012 1:38 pm)
Rating: 5%

Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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

no i knew the MS was milliseconds the FCV threw me for a loop, i would have never guessed and if i read that it didnt click, i thought it was some kind of register value previously(oops).... but the C statement
should read flowcode variable --> delay_ms now has the same value as "delay value" (which is a C variable) and is calculated from --> flowcode variable adc_value..... is that the right way of saying it? i know that may have sounded a bit retarded, but ohh well
These users thanked the author brandonb for the post:
medelec35 (Sun Jan 22, 2012 1:36 pm)
Rating: 5%

medelec35
Valued Contributor
Posts: 8597
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2468 times
Been thanked: 3555 times
Contact:

### Re: Look-Up Tables Tutorial

brandonb wrote: i know that may have sounded a bit retarded, but ohh well

Not at all! That bit is the most trickiest and does take reading a few times to get the hang of it.

brandonb wrote:should read flowcode variable --> delay_ms now has the same value as "delay value" (which is a C variable) and is calculated from --> flowcode variable adc_value..... is that the right way of saying it?

Yep, this looks like a way of summing it up. That bit is fairly difficult to summing-up without confusing.

Well done!
I will see if I can place wording to that effect in the tutorial.
Martin
These users thanked the author medelec35 for the post:
brandonb (Sun Jan 22, 2012 1:38 pm)
Rating: 5%

Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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

here is my count=count+1 routine, the last part about what FCV calculation allowed me to see it for what it was, thanks for sharing this, using these tables the chip is still about the same amount of memory as new, its amazing how much memory this saves, im sure im gonna have some questions here and there about this but i do feel that i learned enough to get good results in various programs, i can use calculations also to command look up values directly by defining the count variable with the count being in the brackets [ ] because as you say in this case delay_one is the result of whatever variable is within the brackets[ ] which is the count variable, that completely makes sense, i was serious about me trying to learn C, if you know of a good course please advise, i need to learn C code even though it messes with me, its something i have to do because my head is stuck on it now
Attachments
trying count tables.fcf

medelec35
Valued Contributor
Posts: 8597
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2468 times
Been thanked: 3555 times
Contact:

### Re: Look-Up Tables Tutorial

No problem.
I have just looked at your count routine, and its also spot on.
You have definitely got the hang of it now

brandonb wrote: i was serious about me trying to learn C, if you know of a good course please advise, i need to learn C code even though it messes with me, its something i have to do because my head is stuck on it now

I know Matrix sell a C course that's tailored to BoostC which is compiler that's used in Flowcode:
http://www.matrixmultimedia.com/product ... d=EL543ST4

There are other sites I'm sure you can get a C course from but what makes the courses available form Matrix would be the support that will be given....Priceless.

Martin
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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

hey martin, that c course look like what i need, im gonna order it if the money currency is not an issue (i hope not), can you think of anything else i should order that would help me in this quest to learn the impossible ..... on the look up tables i can use LUT's with adc,count+1, calculations commands,ect.... but in the engine controller project i have 200 pulsewidths that are 0-20m/s in 100u/s increments, in the engine controller i labeled them in an easy to use flow which simply looking at at any of the pulsewidth number desisions i can easily know which one is which like --> if i am programming the base fuel calculations for a block and map i would want a pulsewidht of 14.7m/s then the number count number would be 147, straight forward......but now if i remove all the 200 pulsewidths and put 2 look up tables i would have one for milliseconds and one for micro seconds, this would not allow the fuel trims to increment or decrement 100u/s counts if the oxegen sensor trim is lean or rich, how would i accomplish this with decisions? ..... the way i would think would be to leave the numbering system and somw how if it said 147 which means 14.7m/s then i could make the m/s LUT go to 14 and make the U/s LUT go to 7 which is 700 micro seconds, i just dont see how i could do this efficiently with out a whole bunch of decisions and calculations, what are your thoughts on this? if you want on monday after work i could draw up a simple flowcode with just this part in it and took up tables so you could see what im talking about, thanks man your awesome

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

i have another post before this also... to simpliy the variable delays in the tables i figured i would simplify the whole concept to make sure my thoughts are gonna work before i go through setting up the LUT's, unfortunatly this fcf does not work on u/s on or u/s off variables, i dont understand why if it reads the integer correctly for both millisecond delays but doesnot read it correctly for the micro second delays, is there some kind of laws im not familiar with?
Attachments
completely variable delays.fcf

medelec35
Valued Contributor
Posts: 8597
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2468 times
Been thanked: 3555 times
Contact:

### Re: Look-Up Tables Tutorial

Hi Brandon,
This post may apply to you.
viewtopic.php?f=29&t=6792&p=15633

Since the delay you are using is greater than 255 microseconds.
I know the post refers to issue with ms, but I'm guessing its the same with us.

Martin
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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

i can have 255 values in the look up tables, but whats the largest number i can have for values? do you still plan on doing a second part to this.... on a side note i ordered the c couse

medelec35
Valued Contributor
Posts: 8597
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2468 times
Been thanked: 3555 times
Contact:

### Re: Look-Up Tables Tutorial

Hi Brandon,

brandonb wrote: but whats the largest number i can have for values?

Since LUT uses bytes, largest number is also 255.

If you want numbers larger say 400 to 600 then you could use LUT_Value=LUT_Value+400
so if retrieved value = 100 then applying LUT_Value=LUT_Value+400 the final value = 500

If you want a range covering 0 to 32767 (still only a maximum quantaty of 256l) for example then you will need to do a 10bit LUT.
I have briefly covered that here:
viewtopic.php?f=26&t=3543&#p20774

brandonb wrote: do you still plan on doing a second part to this

Yes I do and I will include a Flowchart just like 8 bit version did.
That should help to understand 10Bit LUT a bit better.

Nice one!
Hope you enjoy your C course.
It looks like I will be the one asking you questions when you finish
If you have any problems with installing or running the course then take a look here first:
http://www.matrixmultimedia.com/support ... 60683e5e00

Martin
Last edited by medelec35 on Tue Jan 24, 2012 6:34 pm, edited 1 time in total.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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

It looks like I will be the one asking you questions when you finish
your a funny guy!!! im a long way from getting a diploma from the school of martin .... thanks for the links im gonna go through those after work

medelec35
Valued Contributor
Posts: 8597
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2468 times
Been thanked: 3555 times
Contact:

### Re: Look-Up Tables Tutorial

Hi Brandon,
brandonb wrote: i have 200 pulsewidths that are 0-20m/s in 100u/s increments, in the engine controller i labeled them in an easy to use flow which simply looking at at any of the pulsewidth number desisions i can easily know which one is which like --> if i am programming the base fuel calculations for a block and map i would want a pulsewidht of 14.7m/s then the number count number would be 147, straight forward......but now if i remove all the 200 pulsewidths and put 2 look up tables i would have one for milliseconds and one for micro seconds, this would not allow the fuel trims to increment or decrement 100u/s counts if the oxegen sensor trim is lean or rich, how would i accomplish this with decisions? .....

LUT is the value of LUT thats been retrieved

count number 1 - 9 = 100's uS so you will have 100 to 900 us of trim

Count number 10 - 200 = 1.0ms to 20.0ms

Then you have a decision
If <10 then delay is count us
else
delay is LUT ms + LUT us * 100

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
These users thanked the author medelec35 for the post:
brandonb (Thu Mar 01, 2012 5:46 am)
Rating: 5%

Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

medelec35
Valued Contributor
Posts: 8597
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2468 times
Been thanked: 3555 times
Contact:

### Re: Look-Up Tables Tutorial

Hi Brandon.
Question for you.

is the C1 on: delay :C1 off
in a continuous loop?

Eg

Start:C1 on: delay determined by Count:C1 off: delay determined by Count: goto Start.

Martin
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.