Forum Discussion
LUT help!!!
I have wrote this code for implementing a neural network.What it does is to take some values(inputs) and some weights and computes the SUM(values*weigths).What i want to do is to check if the total sum(values*weights)< threshold and correct the weights in order to sum(values*weights)>=threshold.I think that i have to store the weights on a look up table and change the values in order to sum(values*weights)>=threshold.How i can do this?.My code is :
LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; USE IEEE.STD_LOGIC_ARITH.ALL; USE IEEE.STD_LOGIC_UNSIGNED.ALL; USE IEEE.STD_LOGIC_SIGNED.ALL; ENTITY ANN IS GENERIC ( m : INTEGER := 4; -- Number of inputs or weights b : INTEGER := 8); --Number of bits per input or weight PORT ( x1,x2,x3,x4: IN UNSIGNED(b-1 DOWNTO 0); w : IN UNSIGNED(b-1 DOWNTO 0); clk: IN STD_LOGIC; y : buffer UNSIGNED(2*b-1 DOWNTO 0); id : buffer bit); END ANN; ARCHITECTURE NEURAL OF ANN IS TYPE weights IS ARRAY (1 TO m) OF UNSIGNED(b-1 DOWNTO 0); TYPE inputs IS ARRAY (1 TO m) OF UNSIGNED(b-1 DOWNTO 0); BEGIN PROCESS(clk,w,x1,x2,x3,x4) VARIABLE weight : weights; VARIABLE input : inputs; VARIABLE prod,acc : UNSIGNED(2*b-1 DOWNTO 0); VARIABLE sub : UNSIGNED(2*b-1 DOWNTO 0); BEGIN IF (clk'EVENT AND CLK='1') THEN weight:=w&weight(1 TO m-1); END IF; input(1):=x1; input(2):=x2; input(3):=x3; input(4):=x4; acc:=(OTHERS=>'0'); FOR j IN 1 TO m LOOP prod:=input(j)*weight(j); acc:=acc+prod; END LOOP; y<=acc; END IF; END PROCESS; END NEURAL;70 Replies
- Altera_Forum
Honored Contributor
A LUT is a Look Up Table.
It can be implemented in many ways, but using an array (or arrays) is the most common way. - Altera_Forum
Honored Contributor
Can you please explain me(simply) what exactly is a LUT?I think that a lut is a "place" in which there are stored values(or values to be stored) so we can say that it can be implemented as an array.Am i right?Thanks
- Altera_Forum
Honored Contributor
Ok,so i suppose i am totally wrong.Thanks for your help again.
- Altera_Forum
Honored Contributor
No.
VHDL allows you to do alot of things, most of which will not work on a real circuit, but will work in simulation. So this is why you need to understand digital electronics. - Altera_Forum
Honored Contributor
I think that the key is to describe what i want from the circuit to do,its behavior.Am i right?
- Altera_Forum
Honored Contributor
How do you expect to write a description language, if you dont understand what you're describing?
- Altera_Forum
Honored Contributor
I am aware that the solution i described to the problem is not good from the point of digital logic.But as i said i read in many books that in vhdl you can describe how your circuit want to behave and that's what i did.There are many examples in books that did the same thing so i think i am not wrong at all.Can you please give an idea of how to implement it?Thanks
- Altera_Forum
Honored Contributor
Please go and learn digital electronics.
- Altera_Forum
Honored Contributor
Yes as i said the key is to work.But if there is a more efficient way to implement it it will be good to hear it.I think that maybe it will be implemented with a buffer.Is this right?
- Altera_Forum
Honored Contributor
Without any specific problems, its difficult to give help. If it works - then whats the problem? You already said you dont care how it's coded.