Forum: FPGA, VHDL & Verilog VHDL simulation waveform problems

von Rousseau (Guest)

Rate this post
0 useful
not useful
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 (where only 3 of them are '1'), and adds 1 to the counter for 
every '1' inside those 8bits

I created another signal, "conta", and assigned the variable count to it 
inside the process, and so assigned "conta" to the output "contador" 
outside the process

Now the "contador" isn't adding when A(i) <= '1'.
I guess there may be a problem the way I attached the signals and 
variable inside/outside the process.

Maybe the code isn't proper for what I want, cause I'm a beginner trying 
to learn by myself.

If my question is too basic, I would appreciate a link where I could 
understand it thoroughly. I got to send a project next friday.
Right now the code is like:

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 A : std_logic_vector(7 downto 0);
signal conta : std_logic_vector(1 downto 0);
A <= acertos;
process (clock, acertos, enable, reset)
variable count : std_logic_vector(1 downto 0);
  if (reset = '1') then
  count := "00";
    elsif (clock'event and clock = '1') then
    if (enable <= '1') then

      count := "00";

      oito : for i in 7 downto 0 loop
      if (A(i) <= '1') then
      count := count + 1;
      end if;
      end loop oito;

end if;
end if;
conta <= count;
end process;
contador <= conta;
end behavior_contagem;

von Lothar M. (lkmiller) (Moderator)

Rate this post
0 useful
not useful
> if (A(i) <= '1') then
This means: one element from the vector A is a std_logic. And if this 
elements value is less or equal '1', then increment count.

And now answer the questions: what would you expect from that operation? 
Is a operation less-equal defined for a single std_logic element at 

> and adds 1 to the counter for every '1' inside those 8bits
I would try it this way:
  if (A(i) = '1') then
    count := count + 1;
  end if;


Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.