📄 foudiv.vhd
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity foudiv is
port(
clk,pclk :in std_logic; --clk:待分频时钟 pclk:按键
clkmd:in std_logic;--按键加减模式
rst:in std_logic;--复位,
fout:out std_logic--频率输出
);
end;
architecture lammy of foudiv is
signal up:std_logic;--上升沿计数结束标志位
signal do:std_logic;--下降沿计数结束标志位
signal full:std_logic;--分频频率输出状态位
signal fullup:std_logic;--分频频率翻转标志位
signal fulldo:std_logic;--分频频率翻转标志位
signal db:std_logic_vector(7 downto 0);--分频数
signal du:std_logic_vector(7 downto 0);--上升沿计数器
signal dd:std_logic_vector(7 downto 0);--下降沿计数器
begin
lammy01:process(pclk,rst,clkmd)
begin
if rst='1' then db<=(others=>'0');
elsif pclk'event and pclk='1' then
if clkmd='1' then db<=db+1;
elsif clkmd='0' then db<=db-1;
end if;
end if;
end process;
lammy02:process(clk)
variable updata:std_logic_vector(7 downto 0);
begin
if rst='1' then fullup<='0';
elsif clk'event and clk='1' then
-- if updata=db-1 then updata:=(others=>'0');
if do='1' then updata:=(others=>'0');
end if;
updata:=updata+1;
if dd+updata=db then updata:=(others=>'0');fullup<='1';up<='1';
else fullup<='0';up<='0';
end if;
end if;
du<=updata;
end process;
lammy03:process(clk)
variable dodata:std_logic_vector(7 downto 0);
begin
if rst='1' then fulldo<='0';
elsif clk'event and clk='0' then
-- if dodata=db-1 then dodata:=(others=>'0');
if up='1' then dodata:=(others=>'0');
end if;
dodata:=dodata+1;
if du+dodata=db then dodata:=(others=>'0');fulldo<='1';do<='1';
else fulldo<='0';do<='0';
end if;
end if;
dd<=dodata;
end process;
lammy04:process(fulldo,fullup)
begin
full<=fulldo or fullup;
end process;
lammy05:process(full)
variable cnt2:std_logic;
begin
if full'event and full='1' then cnt2:=not cnt2;
if cnt2='1' then fout<='1';
else fout<='0';
end if;
end if;
end process;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -