EmbDev.net

Forum: FPGA, VHDL & Verilog VHDL simulation waveform problems


von Rousseau (Guest)


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;

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


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;

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.