VHDL simulation waveform problems

Guest #2728939
Rate this post
• ▲ 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);
begin
A <= acertos;
process (clock, acertos, enable, reset)
variable count : std_logic_vector(1 downto 0);
begin
  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;
Moderator (Company: Titel) #2729462
Rate this post
• ▲ 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 
all?

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

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.