LucaSkywalker

Counter.vhd

Nov 21st, 2020
627
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.39 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.std_logic_1164.all;
  3. use IEEE.std_logic_arith.all;
  4. use IEEE.std_logic_misc.all;
  5. use IEEE.std_logic_unsigned.all;
  6.  
  7. entity Counter is
  8.     Port (  Clk_in: IN STD_LOGIC;
  9.                 async_rst: IN STD_LOGIC;
  10.                 pData_in: IN STD_LOGIC_VECTOR(3 DOWNTO 0);
  11.                 pData_en_in: IN STD_LOGIC;
  12.                 BCD_mode_in: IN STD_LOGIC;
  13.                 CNTR_en_in: IN STD_LOGIC;
  14.                 CNTR_out: OUT STD_LOGIC_VECTOR(3 DOWNTO 0);
  15.                 Carry_out: OUT STD_LOGIC);
  16. end Counter;
  17.  
  18. architecture Behavioral of Counter is
  19.     begin
  20.     Main: process(Clk_in, async_rst)
  21.     variable count : STD_LOGIC_VECTOR(3 DOWNTO 0) := "0000";
  22.      variable countMax : STD_LOGIC_VECTOR(3 DOWNTO 0) := "0000";
  23.         begin
  24.             if async_rst = '1' then
  25.                 count := "0000";
  26.                 countMax := "0000";
  27.                 CNTR_out <= "0000";
  28.                 Carry_out <= '0';
  29.             elsif Rising_Edge(Clk_in) then
  30.                 if bcd_mode_in = '1' then
  31.                     countMax := "1001";
  32.                 else
  33.                     countMax := "1111";
  34.                 end if;
  35.                 if CNTR_en_in = '1' then
  36.                     if count = countMax then
  37.                         Carry_out <= '1';
  38.                     else                           
  39.                         count := count + 1;
  40.                         Carry_out <= '0';
  41.                     end if;
  42.                     CNTR_out <= count;
  43.                 end if;
  44.                 if pData_en_in = '1' then
  45.                     count := pData_in;
  46.                     if count >= countMax then
  47.                         Carry_out <= '1';
  48.                     else
  49.                         Carry_out <= '0';
  50.                     end if;
  51.                     CNTR_out <= pData_in;
  52.                 end if;
  53.             end if;
  54.         end process Main;
  55. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment