- Posts: 3410
- Thank you received: 0
LUT5
The truth table seems to only show the "and" part
I tried making sense of the hex to binary conversion but that doesn't make sense either.
So then I went to look at the code in the comp and that didn't make much sense either.
The man page hints that the lut5 component is magical and has three types of functions 'and', 'or', and 'xor' but the truth table only shows the 'and' I think as the or function uses 0xfffffffe and that number is not in the truth table. Some experimentation shows that you can combine and and xor in some ways so that is confusing too.
I know Peter has been trying to explain this to me in another thread but I didn't want to hijack that thread any more. I suspect that bit shifting plays a part in this with the pattern between the truth table and a straight binary conversion of the hex number.the man page wrote: A 5-input and function is TRUE only when all the inputs are true, so the correct value for function is 0x80000000.
A 5-input or function is TRUE whenever any of the inputs are true, so the correct value for function is 0xfffffffe.
A 2-input xor function is TRUE whenever exactly one of the inputs is true, so the correct value for function is 0x6. Only in-0 and in-1 should be connected to signals, because if any other bit is TRUE then the output will be FALSE.
Thanks
John
Please Log in to join the conversation.
John
Please Log in to join the conversation.
- mhaberler
- New Member
-
- Thank you received: 0
logical functions of 5 inputs so AND,OR,NAND,NOR,XOR
and every other combinatorial function is possible.
I think its easier to not look at it as a logical function generator
but rather as a lookup table. When looked at this way it becomes
simple to generate any logical function of 5 inputs.
Heres how:
write all the input states down (32 for all 5 inputs 16 for 4 inputs , 8 for 3 inputs. 4 for 2 inputs ) with the weight and the desired output state:
Inputs Weight Output
0 0 0 0 0 1 0
0 0 0 0 1 2 1
0 0 0 1 0 4 1
0 0 0 1 1 8 0
When done, add the weights of all the rows with a '1' output together and voila you have the function value for your desired logic. (6 in this case or 2 input XOR)
This could be done with a spreadsheet/python widget fairly easily
Please Log in to join the conversation.
mhaberler wrote: see here: wiki.linuxcnc.org/cgi-bin/wiki.pl?Lut5
-m
The program is flawed, it only seems to work for all 5 inputs. For example if I put :
but the real answer is 0x8.
If I put
which is correct.
Darn it!
John
Please Log in to join the conversation.
- mhaberler
- New Member
-
- Thank you received: 0
BigJohnT wrote:
mhaberler wrote: see here: wiki.linuxcnc.org/cgi-bin/wiki.pl?Lut5
-m
The program is flawed, it only seems to work for all 5 inputs. For example if I put :
Code:./lut5.py 'i0 & i1' # expression = i0 & i1 ... # setp lut5.N.function 0x88888888
but the real answer is 0x8.
No it isnt, go try in HAL
your expression implies 'ignore i2,i3,i4' and the right thing happens with 0x88888888 - the output reacts only to i0 and i1
with 0x8000000 all of i0-i4 must be true which is not reflected in your expression
-m
If I put
Code:./lut5.py 'i0 & i1 & i2 & i3 & i4' # expression = i0 & i1 & i2 & i3 & i4 ... # setp lut5.N.function 0x80000000
which is correct.
Darn it!
John
Please Log in to join the conversation.
PCW wrote: Note that LUT5 will generate any of the 4,294,967,296
logical functions of 5 inputs so AND,OR,NAND,NOR,XOR
and every other combinatorial function is possible.
I think its easier to not look at it as a logical function generator
but rather as a lookup table. When looked at this way it becomes
simple to generate any logical function of 5 inputs.
Heres how:
write all the input states down (32 for all 5 inputs 16 for 4 inputs , 8 for 3 inputs. 4 for 2 inputs ) with the weight and the desired output state:
Inputs Weight Output
0 0 0 0 0 1 0
0 0 0 0 1 2 1
0 0 0 1 0 4 1
0 0 0 1 1 8 0
When done, add the weights of all the rows with a '1' output together and voilĂ you have the function value for your desired logic. (6 in this case or 2 input XOR)
This could be done with a spreadsheet/python widget fairly easily
Now I finally understand.... for a 5 input or function it is all of them but one! I finally can make this work in my head... now to try and put this in layman's terms for the docs.
Thanks guys for taking the time to beat this in between my ears.
John
Please Log in to join the conversation.
