三分频程序设计及任意奇数分(频占空比50%)
三分频程序设计及任意奇数分(频占空比50%)
实现一个3分频程序,程序如下:
library ieee;
use ieee.std_logic_1164.all;
entity fenpin3 is
port(clock:in std_logic;
clk:out std_logic);
end;
architecture devider of fenpin3 is
signal counter:integer range 0 to 2;
signal temp1,temp2:std_logic;
begin
process(clock)
begin
if rising_edge(clock) then
if counter=2 then
counter<=0;
temp1<=not temp1;
else
counter<=counter+1;
end if;
end if;
if falling_edge(clock) then
if counter=1 then
temp2<=not temp2;
end if;
end if;
end process;
clk<=temp1 xor temp2;
end;
此程序中只使用了一个进程,利用了一个计数器counter,并且使temp1在上升沿计数,rising_edg计到2时翻转,temp2在下降沿计数,当falling_edge计到1时翻转,这样temp1与temp2的相位正好相差180度,以此方法可以实现任意奇数分频,方法当分频数n为奇数时,上面的这条语句改为
signal counter:integer range 0 to (n-1);