Code für den Zähler mit Enable und Flankenerkennung

edge.vhd
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
 
-- Edge detection circuit 
 
entity edge is 
  port (
    clk_i:            in std_ulogic;
    reset_ni:         in std_ulogic;
    key_i:            in std_ulogic;  
    rising_edge_o:    out std_ulogic 
  );
end; 
 
architecture rtl of edge is  
  signal key_reg : std_ulogic;
begin
 
  edge_detection_p : process(key_i, key_reg)
  begin
    -- Hier code einfuegen
  end process edge_detection_p;  
 
  -- The sequential process for flipflop instantiation
  -- All signal assignments in this process will result in flipflops.
  key_reg_p : process (clk_i, reset_ni)
  begin
    if reset_ni = '0' then
      -- hier code einfuegen
    elsif rising_edge(clk_i) then
      -- hier code einfuegen
    end if; 
  end process key_reg_p;      
 
end; -- architecture
top.vhd
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
 
entity top is 
  port (
    CLOCK_50:   in  std_ulogic;                    -- 50 MHz Clock input
    SW:         in  std_ulogic_vector(9 downto 0); -- Switches
    KEY:        in  std_ulogic_vector(3 downto 0); -- Keys
    LEDR:       out std_ulogic_vector(9 downto 0); -- Red LEDs above switches
    HEX0:       out std_ulogic_vector(6 downto 0); -- 7 Segment Display
    HEX1:       out std_ulogic_vector(6 downto 0); -- 7 Segment Display
    HEX2:       out std_ulogic_vector(6 downto 0)  -- 7 Segment Display
  );
end; 
 
architecture struct of top is
 
  component bin2seg is 
    port (
      number_i:       in  unsigned(3 downto 0);
      seg_o:          out std_ulogic_vector(6 downto 0)
    );
  end component;
 
  component counter is 
    port (
      clk_i:          in  std_ulogic;
      reset_ni:       in  std_ulogic;
      enable_i:       in  std_ulogic;  
      count_o:        out unsigned(7 downto 0)
    );
  end component;
 
  component edge is 
    port (
      clk_i:          in  std_ulogic;
      reset_ni:       in  std_ulogic;
      key_i:          in  std_ulogic;
      rising_edge_o:   out std_ulogic 
    );
  end component;
 
  signal count : unsigned(7 downto 0);
  signal enable : std_ulogic; 
 
begin
 
  bin2seg_i0 : bin2seg
    port map (
      number_i => count(3 downto 0),
      seg_o    => HEX0);
 
  bin2seg_i1 : bin2seg
    port map (
      number_i => count(7 downto 4),
      seg_o    => HEX1);
 
  counter_i0 : counter
    port map (
      clk_i    => CLOCK_50,
      reset_ni => KEY(1),
      enable_i => 
      count_o  => count);
 
  edge_i0 : edge
    port map (
      clk_i         => 
      reset_ni      => 
      key_i         => 
      rising_edge_o => );
 
  LEDR(7 downto 0) <= std_ulogic_vector(count);
  LEDR(9 downto 8) <= "00"; 
  HEX2 <= "1111111";
 
end; -- architecture
top_tb.vhd
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
 
entity top_tb is
end; 
 
architecture beh of top_tb is
 
  component top 
  port (
    CLOCK_50:   in  std_ulogic;
    SW:         in  std_ulogic_vector(9 downto 0); -- Switches  
    KEY:        in  std_ulogic_vector(3 downto 0);
    LEDR:       out std_ulogic_vector(9 downto 0); -- Red LEDs above switches
    HEX0:       out std_ulogic_vector(6 downto 0); -- 7 Segment Display
    HEX1:       out std_ulogic_vector(6 downto 0); -- 7 Segment Display
    HEX2:       out std_ulogic_vector(6 downto 0)  -- 7 Segment Display
    );
  end component;
 
  signal clk, reset_n : std_ulogic;
  signal inc          : std_ulogic;
 
  signal switch : std_ulogic_vector(9 downto 0);
  signal key    : std_ulogic_vector(3 downto 0);
  signal ledr   : std_ulogic_vector(9 downto 0);
  signal hex0, hex1, hex2 : std_ulogic_vector(6 downto 0); 
 
begin
 
  top_i0 : top
    port map (
      CLOCK_50            => clk,
      SW                  => switch,
      KEY                 => key,
      LEDR                => ledr,
      HEX0                => hex0,
      HEX1                => hex1,
      HEX2                => hex2);
 
  key(0) <= inc;
  key(1) <= reset_n; 
  key(3 downto 2) <= "00"; 
 
 
  clk_p : process
  begin
    clk <= '0';
    wait for 1 us;
    clk <= '1';
    wait for 1 us; 
  end process clk_p;
 
  reset_p : process
  begin
    reset_n <= '0';
    wait for 15500 ns; 
    reset_n <= '1';  
    wait; 
  end process reset_p;
 
  incr_p : process
  begin
    inc <= '1'; 
    wait for 25100 ns;
    for i in 0 to 100 loop
      inc <= '0';
      wait for 5 us;
      inc <= '1';
      wait for 5 us;
    end loop; 
  end process incr_p;
 
 
  switch <= "0000000000";  
 
end; -- architecture
  • dtpr_v3_code_zaehler_mit_enable.txt
  • Last modified: 2010/11/28 20:27
  • by beckmanf