![](https://csdnimg.cn/release/download_crawler_static/86516794/bg1.jpg)
div2=fin/(2N-1)
clk
div2 div2
fin
preset[3..0] fout
fout=fin/(N-0.5)
问题:利用 250KHz 时钟源产生 100KHz 的时钟信号,分频比 2.5。
解决:模 N 减法计数器可以设成带预置数的计数器,这样就可以分频系数为 N-0.5 的分频
器;如上图市。图中预置数 preset[3..0]的模 N 减法计数器,N 为 1-16,N=3 时就是 2.5 分
频器,程序如下:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity decount is
port(
fin:in std_logic;
preset:in std_logic_vector(3 downto 0);
fout:buffer std_logic);
end decount;
architecture fpq of decount is
signal clk,div2:std_logic;
signal count:std_logic_vector(3 downto 0);
begin
clk<=fin xor div2;
p1:process(clk)
begin
if(clk’event and clk=’1’)then
if(count=”0000”)then
count<=preset-1;
fout<=’1’;
else
count<=count-1;
fout<=’0’;
end if;
Fin
fout
Preset[3..0]
异或门
带预置数功能的模
N 减法计数器
2 分 频
计数器