⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 any_div.vhd

📁 在quartus开发环境下
💻 VHD
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity any_div is
generic(n:integer:=4);------------设置分频系数
port(clk: in std_logic;-----------时钟
	 clkdiv:out std_logic);----分频信号
end;
architecture a of any_div is
	signal cnt1:integer:=0;----计数器1
	signal cnt2:integer:=0;----计数器2
	signal clk_temp:std_logic;---脉冲控制信号
	signal clkdiv1: std_logic;
begin
-------------------------------上升沿触发的计数器进程
process(clk)
begin
if clk'event and clk='1'then
	if cnt1=n-1 then
	cnt1<=0;
	else
	cnt1<=cnt1+1;
	end if;
end if;
end process;
-------------------------------下降沿触发的计数器进程
process(clk)
begin
if clk'event and clk='0'then
	if cnt2=n-1 then
	cnt2<=0;
	else 
	cnt2<=cnt2+1;
	end if;
end if;
end process;
-------------------------------判断分频系数n是否为奇数,并分别控制计数器的计数
process(cnt1,cnt2 )
begin
if ((n mod 2)=1) then------n为奇数的情况
	if cnt1=1 then
		if cnt2=0 then
		clk_temp<='1';
		else clk_temp<='0';
		end if;
	elsif cnt1=(n+1)/2 then
		if cnt2=(n+1)/2 then
		clk_temp<='1';
		else clk_temp<='0';
		end if;
	else
		clk_temp<='0';
	end if;
else-----------------------n为偶数的情况
	if cnt1=1 then
		clk_temp<='1';
	elsif (cnt1=(n/2+1)) then
		clk_temp<='1';
	else
		clk_temp<='0';
	end if;
end if;
end process;
--------讨论n=1和2的情况,并通过脉冲控制信号的上升沿来控制分频信号的输出
process(clk_temp,clk)
begin
if((n/=2) and (n/=1)) then
	if clk_temp'event and clk_temp='1' then
	clkdiv1<=not clkdiv1;
	end if;
elsif(n=2) then
	if clk'event and clk='1' then
	clkdiv1<=not clkdiv1;
	end if;
else
	clkdiv1<=clk;
	end if;
	end process;
	clkdiv<=clkdiv1;
end ;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -