分频电路
1.利用计数器实现分频电路,例如,4位计数器计数值输出的最高位信号就是输入时钟信号的16分频,而最低位则为输入时钟信号的2分频。此为2^n分频。
整数分频电路
1.对于一些非2的整数次幂的分频,还需要加上复位控制电路
2.实战代码:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity fenping is
port(
clk:in std_logic;
cout: out std_logic);
end entity;
architecture behav of fenping is
signal rst:std_logic;
signal cnt:std_logic_vector(2 downto 0);
begin
process(clk,rst)
begin
if rst='1' then
cnt<="000";
elsif (clk 'event and clk='1') then
cnt<=cnt+1;
end if;---记住是一个end if;啊啊啊啊啊啊,时间废在上面
if cnt="110" then
rst<='1';
else rst<='0';
end if;
end process;
cout<=cnt(2);
end behav;
仿真波形:
2.5分频电路
对于小数分频的实现,需要在计数器的基础上增加一定的逻辑控制电路来完成。其基本原理是运用脉冲吞吐计数器和PLL技术,先设计两个不同分频比的整数计数器,然后通过控制单位时间内两种分频比出现的不同次数来改变小数分频值。
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity fenpin is
port(
clk: in std_logic;
cout: out std_logic);
end entity;
architecture rtl of fenpin is
constant md: std_logic_vector(3 downto 0):="0011";---设置模N的值
signal count: std_logic_vector(3 downto 0);
signal clk_tmp1: std_logic;
signal clk_tmp2: std_logic;
signal clk_out_tmp: std_logic; ----设定常量的整数分频
begin
clk_tmp1<=clk xor clk_tmp2; ---升降沿微分电路
process(clk_tmp1)
begin
if (clk_tmp1 'event and clk_tmp1='1') then
if (count="0000") then
count<=md-1;
cout<='1';
clk_out_tmp<='1';
else
count<=count-1;
cout<='0';
clk_out_tmp<='0';
end if;
end if;
end process;
process(clk_out_tmp)
begin
if(clk_out_tmp 'event and clk_out_tmp='1') then
clk_tmp2<=not clk_tmp2; --clk_tmp2为clk_out_tmp二分频
end if;
end process;
end rtl;
仿真波形:
注:此代码可以实现当分频系数为N-0.5,可以修改md的值来改变。