triggerman
Newbie level 6
I wrote this code.What i need to do is to insert 4 values at each clock which i store on a 2-dimensional array and i want to compute the sum of these values.
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
ENTITY test IS
PORT( x1 : IN INTEGER RANGE 0 TO 255;
clk,load : IN STD_LOGIC;
output1 : out INTEGER RANGE 0 TO 1020);
END test;
ARCHITECTURE behavioral OF test IS
TYPE windows IS ARRAY(0 TO 1,0 to 1) OF INTEGER RANGE 0 TO 255;
BEGIN
PROCESS(clk,x1)
VARIABLE window : windows;
VARIABLE sum : INTEGER RANGE 0 TO 1020;
BEGIN
IF(clk'EVENT AND clk='1') THEN
IF(load='1') THEN
FOR i IN 0 TO 1 LOOP
FOR j IN 0 TO 1 LOOP
window(i,j):=x1;
sum:=sum+window(i,j);
END LOOP;
END LOOP;
END IF;
END IF;
output1<=sum;
END PROCESS;
END behavioral;
The code has no problem while compiling but in the simulation the results are wrong!!!.Please help.I set in the simulation for the x1 to take 2 values per clock but the result shows that something is wrong.
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
ENTITY test IS
PORT( x1 : IN INTEGER RANGE 0 TO 255;
clk,load : IN STD_LOGIC;
output1 : out INTEGER RANGE 0 TO 1020);
END test;
ARCHITECTURE behavioral OF test IS
TYPE windows IS ARRAY(0 TO 1,0 to 1) OF INTEGER RANGE 0 TO 255;
BEGIN
PROCESS(clk,x1)
VARIABLE window : windows;
VARIABLE sum : INTEGER RANGE 0 TO 1020;
BEGIN
IF(clk'EVENT AND clk='1') THEN
IF(load='1') THEN
FOR i IN 0 TO 1 LOOP
FOR j IN 0 TO 1 LOOP
window(i,j):=x1;
sum:=sum+window(i,j);
END LOOP;
END LOOP;
END IF;
END IF;
output1<=sum;
END PROCESS;
END behavioral;
The code has no problem while compiling but in the simulation the results are wrong!!!.Please help.I set in the simulation for the x1 to take 2 values per clock but the result shows that something is wrong.