Counter

  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Counter as PDF for free.

More details

  • Words: 147
  • Pages: 2
---------------------------------------------------------------------------------library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; ---- Uncomment the following library declaration if instantiating ---- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all; entity counter is Port ( clk : in STD_LOGIC; rst : in STD_LOGIC; din : in STD_LOGIC_VECTOR (3 downto 0); dout : out STD_LOGIC_VECTOR (3 downto 0); up_dn : in STD_LOGIC; load : in STD_LOGIC); end counter; architecture Behavioral of counter is signal cnt: STD_LOGIC_VECTOR (3 downto 0); signal scale: STD_LOGIC_VECTOR (22 downto 0); signal clk_s: std_logic; begin ----------- clock down scaling -----------process(clk, rst) begin if rst='1' then scale<=(others=>'0'); elsif clk'event and clk='1' then scale<= scale+1; end if ; end process; clk_s<= scale(22); -------------- counter ---------process(clk_s, rst) begin if rst='1' then cnt<=(others=>'0'); elsif clk_s'event and clk_s='1' then if load='1' then cnt<= din; elsif up_dn='0' then cnt<= cnt-1; else cnt<= cnt+1; end if; end if;

end process; dout<= cnt; end Behavioral;

Related Documents

Counter
November 2019 52
Counter
November 2019 43
Counter
November 2019 48
Counter
October 2019 52
Counter
November 2019 48
Counter
June 2020 33