VHDL奇分频偶分频

一、用VHDL写一个20分频程序

Entity div20 is
Port(rst,clk:in_std_logic;
		 div:out_std_logic);
end div20;
Architecture behavior of div20 is
signal cnt10:std_logic_vector(3 downto 0);
signal divt:std_logic;
begin
process(clk,rst)
begin
if rst='0' then
	cnt10<="0000";
	divt<='0';
elsif rising_edge(clk) then
	if cnt10=9 then
		divt<=not divt;
		cnt10<="0000";
	else
		cnt10<=cnt10+1;
	end if;
end if;
end process;
div<=divt;
end behavior;
--如有错误,望指出;

二、用VHDL写一个15分频

Entity div15 is
Port(clk,rst:in std_logic;
		 div:out std_logic);
end div15;
Architecture behavior of div15 is
signal cnt15:std_logic_vector(3 downto 0);
signal clk1,clk2:std_logic;
begin
process(clk,rst)
begin
if rst='0' then
	cnt15<="0000";
	clk1<='0';
elsif rising_edge(clk) then
	if cnt15=14 then
		cnt15<="0000";
		clk1<=not clk1;
	else
		cnt15<=cnt15+1;
	end if;
end if;
end process;

process(clk,rst)
begin
if rst='0' then
	clk2<='0';
elsif falling_edge(clk) then
	if cnt15=7 then
		clk2<=not clk2;
	end if;
end if;
end process;
div<=clk1 xor clk2;
end behavior;
--上述代码如有不理解的地方,可留言。
--如有错,望指出。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值