|
偶数分频和奇数分频器设计
(1)偶数分频
对时钟进行偶数分频比较简单,如占空比为50%的时钟信号只要使用一个计数器,在前半段时间内高电平后半段电平内低电平这样分频出来的信号就是占空比为50%的时钟信号。废话不多说上段程序。
---------------------------偶数分频VHDL代码
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity clkdiv is
generic (n:integer:=8); ---偶数分频,分频数可任意更改
port(clk:in std_logic;
outclk:out std_logic
);
end clkdiv;
architecture u1 of clkdiv is
signal count:integer;
begin
process(clk)
begin
if(clk'event and clk='1')
then
if(count=n-1)then --计数周期
count<=0;
else count<=count+1;
if count<(integer(n/2))
then
outclk<='0';
else
outclk<='1';
end if;
end if;
end if;
end process;
end u1;
(2)奇数分频
奇数分频相对偶数分频来说,如果不要求占空比的话是一样的,但是如果要求占空比为50%的话则计数分频必偶数分频要复杂些。其中需要使用些技巧。可以先对输入时钟的上升沿进行计数,然后让一个内部信号在前一半段时间内为低电平,后一半段时间内为高电平。同时对输入时钟的下降沿进行计数,让另一个内部信号在前半段时间内为高电平,在后半段时间内为低电平。然后让两个内部信号进行相与,得到了半个时钟的一个高电平,在让这个信号和第一个内部信号相或,就得到了占空比为50%的时钟信号了~~~
-----奇数分频VHDL代码------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity clkdiv is
generic (n:integer:=7); ---偶数分频,分频数可任意更改
port(clk:in std_logic;
outclk:out std_logic
);
end clkdiv;
architecture u1 of clkdiv is
signal count1,count2:integer;
signal q,outclk1,outclk2:std_logic;
begin
q<=outclk1 and outclk2;----两个内部信号相与
outclk<=q or outclk1; ----第一个信号和Q信号相或
process(clk)
begin
if(clk'event and clk='1')
then
if(count1=n-1)then --计数周期
count1<=0;
else count1<=count1+1;
if count<(integer(n/2))
then
outclk1<='0';
else
outclk1<='1';
end if;
end if;
end if;
end process;
process(clk)
begin
if(clk'event and clk='0')
then
if(count2=n-1)then --计数周期
count2<=0;
else count2<=count2+1;
if count<(integer(n/2))
then
outclk2<='1';
else
outclk<='0';
end if;
end if;
end if;
end process;
end u1; |
阿莫论坛20周年了!感谢大家的支持与爱护!!
知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
|