BJ-EPM CPLD開發(fā)板:VHDL入門例程1

2012年05月16日 10:22 來源:本站整理 作者:秩名 我要評論(0)




  -- Filename ﹕ CLKDIV.vhd

  -- Author ﹕ wuhouhang

  -- Description ﹕ 分頻計數(shù)器,50MHz時鐘做分頻后的50%占空比方波驅(qū)動蜂鳴器發(fā)聲

  library IEEE;

  use IEEE.std_logic_1164.all;

  use IEEE.std_logic_arith.all;

  use IEEE.std_logic_unsigned.all;

  entity CLKDIV is

  port (

  Clk : in STD_LOGIC; --50MHz輸入時鐘

  Rst_n : in STD_LOGIC; --低電平復(fù)位信號

  Clk_div : out STD_LOGIC --分頻信號,連接到蜂鳴器

  );

  end entity CLKDIV;

  --20bit計數(shù)器循環(huán)計數(shù)

  architecture COUNTER OF CLKDIV is

  signal cnt20b : STD_LOGIC_VECTOR (19 downto 0); --20bit計數(shù)器

  begin

  process (Clk,Rst_n)

  begin

  if Rst_n = '0' then

  cnt20b <= x"00000";

  elsif Clk'event AND Clk = '1' then

  cnt20b <= cnt20b+"1"; --分頻計數(shù)

  end if;

  end process;

  Clk_div <= cnt20b(19); --分頻賦值

  end architecture COUNTER;