library ieee
use ieee.std_logic_arith.all
use ieee.std_logic_1164.all
use ieee.std_logic_unsigned.all
entity fenpin is
port(clk: in std_logic
clk_div4: out std_logic)
end fenpin
architecture art of fenpin is
signal count : std_logic_vector(15 downto 0)
begin
process(clk)
begin
if(clk'event and clk='斗搜1') then
if(count = "空基历1111111111111111") then
count<=(others=>锋陪'0')
else
count<= count + 1
end if
end if
end process
clk_div4<= count(15)
end art
module clkgen(clk,cout)
input clk 镇则 --clk为频率输入,用于被分频
reg[24:0] q --定义一个变量用于计数
output reg cout --频率输出
always @(posedge clk) --此进程每次在clk的上升沿被触发
begin
if(q==20000000-1) --q为计数器, 当clk上升沿到来的时候加一,若计数达到
--(20000000-1)则清零再薯旅态重新计数
q=0
else
数源 q=q+1
if(q==20000000-1) --当q计满(20000000-1)时,cout输出一个clk的高电平,
--其余时间均为低电平
cout=1
else
cout=0
end
endmodule
相当于一个(20000000-1)分频的分频器,输出波形示意图如下:
字字手打,望楼主采纳!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)