How to use a loop statement in VHDL for this code?

Status
Not open for further replies.

triggerman

Newbie level 6
Joined
Dec 6, 2009
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,412
Here is what i want to do.I have 3 inputs each of one has a weight(random).I want to compute the : input1*weight1+input2*weight2+input3*weight3 and if this is greater than a threshold(predetermined) its ok.But if it is less than the threshold i want to fix the weights in order for the sum>threshold.Can anyone know how can i do this?.This is the code i ve written for the first part(the computation of nput1*weight1+input2*weight2+input3*weight3).How can i fix the weights?I suppose that i have to use a loop statement but how?Thanks

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity neuron is
port ( in1,in2,in3,w1,w2,w3 : in unsigned (7 downto 0);
clk : in std_logic;
id : out bit;
output : out unsigned (15 downto 0));
end neuron;

architecture behavioral of neuron is
type inputs is array (1 to 3) of unsigned (7 downto 0);
type weights is array (1 to 3) of unsigned (7 downto 0);
constant threshold : unsigned(15 downto 0):="0000011011100111";
constant sum : unsigned:="1";
begin

process(clk,w1,w2,w3)

variable weight : weights;
variable input : inputs;
variable prod,acc : unsigned (15 downto 0);
begin

if(clk'EVENT AND clk='1') then
input(1):=in1;
input(2):=in2;
input(3):=in3;
weight(1):=w1;
weight(2):=w2;
weight(3):=w3;
acc:=(others=>'0');
end if;
for j in 1 to 3 loop
prod:=input(j)*weight(j);
acc:=acc+prod;
end loop;
if(acc>threshold) then id<='1';
else id<='0';
end if;
output<=acc;
end process;
end behavioral;
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…