Altera_Forum
Honored Contributor
16 years agocounte various value
i have a array with 16 values each with 12 bits i want to count the no of trailingones(1 or -1) maxmim is 3 ,and total no of non zero values and total zeros .
i wrote the program ,it compile successfully but i m unable to get the simulation result. can any one help. library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; use ieee.numeric_std.ALL; entity rom1 is port(CLK:in std_logic; totalcoeffs,totalzeros:out std_logic_vector(4 downto 0); trailingones:out std_logic_vector(1 downto 0)); end rom1; architecture rom of rom1 is signal etotalcoeffs : std_logic_vector(4 downto 0) := b"00000"; signal etotalzeros : std_logic_vector(4 downto 0) := b"00000"; signal etrailingones : std_logic_vector(1 downto 0) := b"00"; signal ecgt1 : std_logic := '0'; signal vin:std_logic_vector(11 downto 0); type vector_array is array (0 to 15) of std_logic_vector(11 downto 0); constant memory:vector_array := ("111111111111","111111111111","000100000011","000000000100", "000000000101","000000000110","000000000111","000000001000", "000000001001","000000001010","000000001011","000100001000", "000100000001","000100000010","000100001000","000100001000" ); begin process(CLK) begin if CLK'event and CLK = '1' then --data <= memory(addr); --end if; x2:for i in 1 to 16 loop vin <= memory(i-1); if vin /= 0 then etotalcoeffs <= etotalcoeffs + 1; elsif vin = 1 or vin = x"FFF" then etrailingones <= etrailingones +1; else etotalzeros <= etotalzeros + 1; end if; end if; end loop x2; if (etrailingones > 3) then trailingones <= b"11"; else trailingones <= etrailingones; totalzeros <= etotalzeros; totalcoeffs <= etotalcoeffs; end if; end if; end process; end rom;