Advertisement
thibthibaut

TP3 Level4

Nov 28th, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.03 KB | None | 0 0
  1.  ----------------------------------------------------------------------------------
  2.  -- Company:
  3.  -- Engineer:
  4.  --
  5.  -- Create Date:    09:55:25 11/21/2014
  6.  -- Design Name:
  7.  -- Module Name:    Counter - Behavioral
  8.  -- Project Name:
  9.  -- Target Devices:
  10.  -- Tool versions:
  11.  -- Description:
  12.  --
  13.  -- Dependencies:
  14.  --
  15.  -- Revision:
  16.  -- Revision 0.01 - File Created
  17.  -- Additional Comments:
  18.  --
  19.  ----------------------------------------------------------------------------------
  20.  library IEEE;
  21.  use IEEE.STD_LOGIC_1164.ALL;
  22.  use ieee.std_logic_unsigned.all;
  23.  
  24.  -- Uncomment the following library declaration if using
  25.  -- arithmetic functions with Signed or Unsigned values
  26.  use IEEE.NUMERIC_STD.ALL;
  27.  
  28.  -- Uncomment the following library declaration if instantiating
  29.  -- any Xilinx primitives in this code.
  30.  --library UNISIM;
  31.  --use UNISIM.VComponents.all;
  32.  
  33.  entity Counter is
  34.       Port ( Reset : in  STD_LOGIC;
  35.                 CLK : in  STD_LOGIC;
  36.                 S1, S2 : out  STD_LOGIC_VECTOR(25 downto 0));
  37.  end Counter;
  38.  
  39.  architecture Behavioral of Counter is
  40.  
  41.  signal Add1, Add2 : STD_LOGIC_VECTOR(25 downto 0);
  42.  signal Reg1, Reg2 : STD_LOGIC_VECTOR(25 downto 0);
  43.  signal Mux1, Mux2 : STD_LOGIC_VECTOR(25 downto 0);
  44.  signal Cmp1, Cmp2 : STD_LOGIC;
  45.  
  46.  begin
  47.  
  48.  Add1 <= Reg1 + "0000000000000000000000001";
  49.  
  50.  Mux1 <= Add1 when Cmp1 = '0' else "00000000000000000000000000" when Cmp1 = '1';
  51.  
  52.  Cmp1 <= '1' when Add1 > "0000000000000000000001000" else '0';
  53.  
  54.  Reg1 <= "00000000000000000000000000" when Reset = '0' else Mux1 when rising_edge(CLK);
  55.  
  56. -----------------------------------------
  57.  
  58.  Add2 <= Reg2 + "0000000000000000000000001";
  59.  
  60.  Mux2 <= "00000000000000000000000000" when Cmp2 = '1' and Cmp1='1' else
  61.          Add2 when Cmp2 = '0' and Cmp1 = '1' else
  62.             Reg2;
  63.  
  64.  Cmp2 <= '1' when Add2 > "0000000000000000000000100" else '0';
  65.  
  66.  Reg2 <= "00000000000000000000000000" when Reset = '0' else Mux2 when rising_edge(CLK);
  67.  
  68. -----------------------------------------
  69.  
  70. S1 <= Reg1;
  71.  
  72. S2 <= Reg2;
  73.  
  74.  end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement