Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 0.76 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. entity test2 is
  5.     port(
  6.         clk             : in std_logic;
  7.         rst             : in std_logic;
  8.         load            : in std_logic;
  9.         ena             : in std_logic;
  10.         data_bus    : in std_logic_vector(3 downto 0);
  11.         value       : out std_logic_vector(3 downto 0)
  12.     );
  13. end test2;
  14.  
  15. architecture data_flow of test2 is
  16.     signal cnt_reg, cnt_next : unsigned(3 downto 0);
  17. begin
  18.         process (clk, rst)
  19.             begin
  20.                 if (rst = '1') then
  21.                     cnt_reg <= (others => '0');
  22.                 elsif (rising_edge(clk)) then
  23.                     cnt_reg <= cnt_next;
  24.                 end if;
  25.         end process;
  26.            
  27.         cnt_next <= unsigned(data_bus) when load = '1' else
  28.                         cnt_reg + 1 when ena = '1' else
  29.                         cnt_reg;
  30.                        
  31.                        
  32.         value <= std_logic_vector(cnt_reg);
  33. end data_flow;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement