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

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:

Look-Up Tables Tutorial

Post by medelec35 »

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
(131.43 KiB) Downloaded 27597 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) Downloaded 27410 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.
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
Attachments
LUT_Tut FC4 V4.fcf
(8 KiB) Downloaded 909 times
Last edited by medelec35 on Sun Jan 22, 2012 6:55 pm, edited 3 times in total.
Martin

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

Re: Look-Up Tables Tutorial

Post by JohnCrow »

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
(8 KiB) Downloaded 958 times
1 in 10 people understand binary, the other one doesn't !

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 »

Thanks for the spot John,
Glad you like it.
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:
http://www.matrixmultimedia.com/mmforum ... 998#p24998

Cheers

Martin
Martin

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: Look-Up Tables Tutorial

Post by Steve001 »

Thanks very usefull topic

steve
Success always occurs in private and failure in full view.

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 »

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

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 cant give up on this its not in my nature, so get ready for the questions :lol: 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.
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_MS=Delay_Val[FCV_ADC_VAL];

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

Post by brandonb »

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 :lol:
Attachments
trying to figure lut.fcf
(5 KiB) Downloaded 869 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 »

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
(7 KiB) Downloaded 875 times

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: Look-Up Tables Tutorial

Post by Steve001 »

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 :D
Success always occurs in private and failure in full view.

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:martin i cant give up on this its not in my nature, so get ready for the questions :lol:

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 :lol:

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/255
0		0.00		0.00
1		0.12		0.12
2		0.24		0.24
3		0.36		0.35
4		0.48		0.47
5		0.60		0.59
6		0.72		0.71
7		0.84		0.82
8		0.96		0.94
9		1.08		1.06
10		1.20		1.18
11		1.32		1.29
12		1.44		1.41
13		1.56		1.53
14		1.68		1.65
15		1.80		1.76
16		1.92		1.88
17		2.04		2.00
18		2.16		2.12
19		2.28		2.24
20		2.40		2.35
21		2.52		2.47
22		2.64		2.59
23		2.76		2.71
24		2.88		2.82
25		3.00		2.94
26		3.12		3.06
27		3.24		3.18
28		3.36		3.29
29		3.48		3.41
30		3.60		3.53
31		3.72		3.65
32		3.84		3.76
33		3.96		3.88
34		4.08		4.00
35		4.20		4.12
36		4.32		4.24
37		4.44		4.35
38		4.56		4.47
39		4.68		4.59
40		4.80		4.71
41		4.92		4.82
42		5.04		4.94
43		5.16		5.06
44		5.28		5.18
45		5.40		5.29
46		5.52		5.41
47		5.64		5.53
48		5.76		5.65
49		5.88		5.76
50		6.00		5.88
51		6.12		6.00
52		6.24		6.12
53		6.36		6.24
54		6.48		6.35
55		6.60		6.47
56		6.72		6.59
57		6.84		6.71
58		6.96		6.82
59		7.08		6.94
60		7.20		7.06
61		7.32		7.18
62		7.44		7.29
63		7.56		7.41
64		7.68		7.53
65		7.80		7.65
66		7.92		7.76
67		8.04		7.88
68		8.16		8.00
69		8.28		8.12
70		8.40		8.24
71		8.52		8.35
72		8.64		8.47
73		8.76		8.59
74		8.88		8.71
75		9.00		8.82
76		9.12		8.94
77		9.24		9.06
78		9.36		9.18
79		9.48		9.29
80		9.60		9.41
81		9.72		9.53
82		9.84		9.65
83		9.96		9.76
84		10.08		9.88
85		10.20		10.00
86		10.32		10.12
87		10.44		10.24
88		10.56		10.35
89		10.68		10.47
90		10.80		10.59
91		10.92		10.71
92		11.04		10.82
93		11.16		10.94
94		11.28		11.06
95		11.40		11.18
96		11.52		11.29
97		11.64		11.41
98		11.76		11.53
99		11.88		11.65
100		12.00		11.76
101		12.12		11.88
102		12.24		12.00
103		12.36		12.12
104		12.48		12.24
105		12.60		12.35
106		12.72		12.47
107		12.84		12.59
108		12.96		12.71
109		13.08		12.82
110		13.20		12.94
111		13.32		13.06
112		13.44		13.18
113		13.56		13.29
114		13.68		13.41
115		13.80		13.53
116		13.92		13.65
117		14.04		13.76
118		14.16		13.88
119		14.28		14.00
120		14.40		14.12
121		14.52		14.24
122		14.64		14.35
123		14.76		14.47
124		14.88		14.59
125		15.00		14.71
126		15.12		14.82
127		15.24		14.94
128		15.36		15.06
129		15.48		15.18
130		15.60		15.29
131		15.72		15.41
132		15.84		15.53
133		15.96		15.65
134		16.08		15.76
135		16.20		15.88
136		16.32		16.00
137		16.44		16.12
138		16.56		16.24
139		16.68		16.35
140		16.80		16.47
141		16.92		16.59
142		17.04		16.71
143		17.16		16.82
144		17.28		16.94
145		17.40		17.06
146		17.52		17.18
147		17.64		17.29
148		17.76		17.41
149		17.88		17.53
150		18.00		17.65
151		18.12		17.76
152		18.24		17.88
153		18.36		18.00
154		18.48		18.12
155		18.60		18.24
156		18.72		18.35
157		18.84		18.47
158		18.96		18.59
159		19.08		18.71
160		19.20		18.82
161		19.32		18.94
162		19.44		19.06
163		19.56		19.18
164		19.68		19.29
165		19.80		19.41
166		19.92		19.53
167		20.04		19.65
168		20.16		19.76
169		20.28		19.88
170		20.40		20.00
171		20.52		20.12
172		20.64		20.24
173		20.76		20.35
174		20.88		20.47
175		21.00		20.59
176		21.12		20.71
177		21.24		20.82
178		21.36		20.94
179		21.48		21.06
180		21.60		21.18
181		21.72		21.29
182		21.84		21.41
183		21.96		21.53
184		22.08		21.65
185		22.20		21.76
186		22.32		21.88
187		22.44		22.00
188		22.56		22.12
189		22.68		22.24
190		22.80		22.35
191		22.92		22.47
192		23.04		22.59
193		23.16		22.71
194		23.28		22.82
195		23.40		22.94
196		23.52		23.06
197		23.64		23.18
198		23.76		23.29
199		23.88		23.41
200		24.00		23.53
201		24.12		23.65
202		24.24		23.76
203		24.36		23.88
204		24.48		24.00
205		24.60		24.12
206		24.72		24.24
207		24.84		24.35
208		24.96		24.47
209		25.08		24.59
210		25.20		24.71
211		25.32		24.82
212		25.44		24.94
213		25.56		25.06
214		25.68		25.18
215		25.80		25.29
216		25.92		25.41
217		26.04		25.53
218		26.16		25.65
219		26.28		25.76
220		26.40		25.88
221		26.52		26.00
222		26.64		26.12
223		26.76		26.24
224		26.88		26.35
225		27.00		26.47
226		27.12		26.59
227		27.24		26.71
228		27.36		26.82
229		27.48		26.94
230		27.60		27.06
231		27.72		27.18
232		27.84		27.29
233		27.96		27.41
234		28.08		27.53
235		28.20		27.65
236		28.32		27.76
237		28.44		27.88
238		28.56		28.00
239		28.68		28.12
240		28.80		28.24
241		28.92		28.35
242		29.04		28.47
243		29.16		28.59
244		29.28		28.71
245		29.40		28.82
246		29.52		28.94
247		29.64		29.06
248		29.76		29.18
249		29.88		29.29
250		30.00		29.41
251		30.12		29.53
252		30.24		29.65
253		30.36		29.76
254		30.48		29.88
255		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= 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
};
Last edited by medelec35 on Sun Jan 22, 2012 12:52 pm, edited 1 time in total.
Martin

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: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

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 »

this is messing with me
FCV_DELAY_MS=Delay_Val[FCV_ADC_VAL];
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
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: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.
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 »

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
FCV_DELAY_MS=Delay_Val[FCV_ADC_VAL];
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 :lol:

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 know that may have sounded a bit retarded, but ohh well :lol:
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
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 »

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
(6 KiB) Downloaded 751 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 »

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

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 »

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 :lol: ..... 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

Post by brandonb »

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
(5.5 KiB) Downloaded 763 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,
This post may apply to you.
http://www.matrixmultimedia.com/mmforum ... 92&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

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 »

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
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,
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:
http://www.matrixmultimedia.com/mmforum ... 43&#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 :lol:
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

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 »

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 :lol: .... thanks for the links im gonna go through those after work

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,
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? .....
How about this:
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
Martin

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.
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

Post Reply