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

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: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
Hello martin,
thank you so much for helping me out with this and please forgive my late replies. I have explained in details what the program is about and what i want to achieve with the look up table in the word document attached to this post. I hope you find my explanations clear enough and if there's any part that isn't clear please let me know so i can make it clear. thanks again.
Attachments
Look Up table sample_Matrix forum.doc
(48.5 KiB) Downloaded 517 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 can follow the document just fine.
I have simplified flowchart and cheated a bit.

LUT values on 8 bit chips are only 8 bit wide
Therefore only numbers 0 to 255 can be used.
On the over voltage side you wanted 260,265,270,275 & 280
So what I did was subtract 50 from each number, then added the 50 back on after the lut number has been retrieved by using:

Code: Select all

FCV_OVERVOLTAGE=OV_Eqv[7-(FCV_READDIPSWITCHES>>3)]+50;
The 7- is used because the switches or active low and not active high.
>> just bit shift by 3 so if all switches connected to B3,B4 & B5 are all closed, pulling 5V down to 0V the value will be 7
This is the same as if switches connected to B0,B1 & B2 are all closed, pulling 5V down to 0V the value will also be 7

Just remember that C code is not simulated, so the only way of confirming all is working is by either using a 3rd part simulator, or on hardware.

Martin
Attachments
mainsmonitor V2.fcf
(20.5 KiB) Downloaded 509 times
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:No problem.
I can follow the document just fine.
I have simplified flowchart and cheated a bit.

LUT values on 8 bit chips are only 8 bit wide
Therefore only numbers 0 to 255 can be used.
On the over voltage side you wanted 260,265,270,275 & 280
So what I did was subtract 50 from each number, then added the 50 back on after the lut number has been retrieved by using:

Code: Select all

FCV_OVERVOLTAGE=OV_Eqv[7-(FCV_READDIPSWITCHES>>3)]+50;
The 7- is used because the switches or active low and not active high.
>> just bit shift by 3 so if all switches connected to B3,B4 & B5 are all closed, pulling 5V down to 0V the value will be 7
This is the same as if switches connected to B0,B1 & B2 are all closed, pulling 5V down to 0V the value will also be 7

Just remember that C code is not simulated, so the only way of confirming all is working is by either using a 3rd part simulator, or on hardware.

Martin

Hello Martin,
Thanks for the program, there are somethings you did in there that are new to me so i want to take time to study it for better understanding before i proceed to load it on my hardware. I appreciate your help greatly, what will my programming career be without people like you :) . I will give you feedback when i am done. Best Regards.

Post Reply