数控分频器的功能就是当在输入端给定不同输入数据时,将对输入的时钟信号实现不同的分频比,即可实现设置数的分频计数器。
程序:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity dvf is
port(
clk:in std_logic;
d:in std_logic_vector(7 downto 0);
four:out std_logic
);
end;
architecture one of dvf is
signal full:std_logic;
begin
p_reg:process(clk)
variable cnt8:std_logic_vector(7 downto 0);
begin
if clk'event and clk='1' then
if cnt8="11111111" then
cnt8:=d;
full<='1';
else cnt8:=cnt8+1;
full<='0';
end if;
end if;
end process p_reg;
p_div:process(full)
variable cnt2:std_logic;
begin
if full'event and full='1' then
cnt2:=not cnt2;
if cnt2='1'then four<='1';
else four<='0';
end if;
end if;
end process p_div;
end;
RTL原图:
其仿真图: