help with binary decoder

M

majmoat_ensan

hi all;

i have this code for a 5-bits binary counter :


LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.numeric_std.all;
ENTITY counter IS
PORT ( count : OUT unsigned (4 DOWNTO 0);
load : IN STD_LOGIC;
pre :IN unsigned (4 DOWNTO 0);
Clk : IN STD_LOGIC);
END counter;
ARCHITECTURE Behavioral OF counter IS
SIGNAL c : unsigned(4 DOWNTO 0) := "00000";

BEGIN
count <= c;
PROCESS(Clk)
BEGIN
IF( rising_edge(Clk) ) THEN
IF(load = '1') THEN
c <= pre;
ELSE
c <= c + 1;
END IF;
END IF;
END PROCESS;
END Behavioral;


I want to connect the output to a binary decoder that shows the state
of the counter
how can i do that?

can any one help me plz
 
Joined
Jan 30, 2009
Messages
42
Reaction score
0
Binary Decoder

Code:
-----------------------------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.NUMERIC_STD.all;
------------------------------------------------------------------------------------------------------
entity decode is

  generic (code_size       : positive := 5;                                       --Code input size
            output_asserted : std_logic := '1';                          --Sets output asserted value
						out_size        : positive  := 32
		 		 );
port (word_in         : in  std_logic_vector(code_size - 1 downto 0);   --Input to be decoded
       decode_ena   : in  std_logic := '1';                                         --If LOW, no decoding
       oe_n              : in  std_logic := '0';                                    --If HIGH, outputs are Hi-Z
       decode_out   : out std_logic_vector(out_size - 1 downto 0));     --Decoder ouput

end decode;
------------------------------------------------------------------------------------------------------
architecture archdecode of decode is

begin

pdecode : process(word_in, oe_n, decode_ena)
  begin
    if oe_n = '1' then
      decode_out <= (others => 'Z');
    elsif decode_ena = '0' then
      decode_out <= (others => not output_asserted);
    else
      for i in decode_out'range loop
        if unsigned(word_in) = i then
          decode_out(i) <= output_asserted;
        else
          decode_out(i) <= not output_asserted;
        end if;
      end loop;
    end if;
  end process pdecode;

end;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top