三分频器的设计
时钟输入端(clkin)首先反向和不反向分别接到两个D触发器的时钟输入端,两个D触发器的输出接到一个二输入或非门的输入端,或非门的输出反馈到前面两个D触发器的D输入端,并且或非门的输出后面接一二分频器,得到占空比为50%的三分频波形。
图1:图形设计
VHDL程序:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity fen3 is
port
(clkin : in std_logic; --时钟输入
qout1 : buffer std_logic;
qout2 : buffer std_logic;
qout3 : buffer std_logic;
clkout : out std_logic --占空比为1/2的三分频输出
);
end fen3;
architecture behave of fen3 is
begin
qout3<=qout1 nor qout2;
process(clkin)
begin
if clkin'event and clkin='1' then --在上升沿触发
qout1<=qout3;
end if;
end process;
process(clkin)
begin
if clkin'event and clkin='0' then --在下降沿触发
qout2<=qout3;
end if;
end process;
process(qout3)
variable tem:std_logic;
begin
if qout3'event and qout3='1' then --二分频tem:=not tem;
end if;
clkout<=tem;
end process;
end behave;
图3:仿真结果
方法二:
设计两个占空比为1/3的三分频器,分别在时钟输入端的上升沿和下降沿触发,然后两个分频器的输出接一个或门,得到占空比为50%的三分频波形。
图4:图形设计
VHDL程序:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity fen3 is
port
(clkin : in std_logic; --时钟输入
qout1 : buffer std_logic;
qout2 : buffer std_logic;
clkout : out std_logic --占空比为1/2的三分频输出
);
end fen3;
architecture behave of fen3 is
begin
clkout<=qout1 or qout2;
process(clkin) --占空比为1/3的三分频
variable cnt:integer range 0 to 2;
begin
if clkin'event and clkin='1' then --在上升沿触发
if cnt=2 then
cnt:=0;
qout1<='1';
else
cnt:=cnt+1;
qout1<='0';
end if;
end if;
end process;
process(clkin)
variable cnt:integer range 0 to 2; --占空比为1/3的三分频 begin
if clkin'event and clkin='0' then --在下降沿触发
if cnt=2 then
cnt:=0;
qout2<='1';
else
cnt:=cnt+1;
qout2<='0';
end if;
end if;
end process;
end behave;
图5:编译结果
图6:仿真结果
方法三:
设计一个占空比为50%的四分频器,四分频器的时钟输入端是由四分频器的输出端和时钟输入相异或后驱动的,四分频器的时钟输出端就是占空比为50%的三分频波形输出。
图:图形设计
VHDL程序:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity fen3 is
port
(clkin : in std_logic; --时钟输入
qout1 : buffer std_logic;
clkout : out std_logic --占空比为1/2的三分频输出
);
end fen3;
architecture behave of fen3 is
constant counter_len:integer:=3; --设置计数器的模
signal clk_tem:std_logic;
begin
qout1<=clkin xor clk_tem; --反馈
process(qout1) --四分频
variable cnt:integer range 0 to counter_len;
begin
if qout1'event and qout1='1' then --在上升沿触发
if cnt=counter_len then
cnt:=0;
else
cnt:=cnt+1;
end if;
if cnt<=1 then
clk_tem<='0';
clkout<='0';
else
clk_tem<='1';
clkout<='1';
end if;
end if;
end process;
end behave;
编译结果
以上介绍了三种设计50%占空比三分频器的方法,由以上看出,第三种设计方法,程序最简洁,占用宏单元最少,而且可以举一反三,很容易设计出其他奇数分频占空比为50%的分频器。