Altera_Forum
Honored Contributor
13 years agoVHDL waveform simulation problems
Hello everyone, this is my first post here.
Thanks in advance for reading my problem. Well, I have to create a vhdl code for a 2bit counter, which receives 8bits, and adds 1 to the counter for every '1' inside those 8bits To do so, I used a shifter for A within a loop. And designed it to add counter by 1 when A(0) = '1' It compiled succesfully, but when I tried to simulate it with a waveform file, for every clock pulse the "count" was added by 1, and after 3 clock cycles, the "count" reached its limit (11) and reseted. The value of "count" didnt even obeyed the reset or enable values. Maybe the code isn't proper for what I want, cause I'm a beginner trying to learn by myself. Or maybe I'm simulating it wrongly, also because I'm a beginner, haha. hope someone help me :). Vhdl code: library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity contador_acertos is port (clock, reset, enable : in std_logic; acertos : in std_logic_vector(7 downto 0); contador : out std_logic_vector(1 downto 0) ); end contador_acertos; architecture behavior_contagem of contador_acertos is signal count : std_logic_vector(1 downto 0); signal A : std_logic_vector(7 downto 0); begin process (clock, acertos, enable) begin if (reset = '1') then count <= "00"; elsif (clock'event and clock = '1') then if (enable <= '1') then A <= acertos; count <= "00"; oito : for i in 7 downto 0 loop if (A(0) <= '1') then count <= count + 1; A(6 downto 0) <= A(7 downto 1); else A(6 downto 0) <= A(7 downto 1); end if; end loop oito; end if; end if; end process; contador <= count; end behavior_contagem; Thank you!