Quartus II 13.1中,使用 VHDL编程,设计任意分频器。当设计计数器达到具体值的时候,设计一个脉冲,这时利用脉冲的上升沿反转输出值,达到分频效果。
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;
entity DIV_N is
generic(n:integer:=7);
port(signal clk:in std_logic;signal LED:out std_logic);
end DIV_N;
architecture behave of DIV_N is
signal CNT2,CNT1,temp:std_logic_vector(7 downto 0);
signal clear,clearA,mark,clearB,CNT3:std_logic:='0';
begin
process(clk)
begin
if clk'event and clk='1' then
if clear='1' then
CNT1<=(0=>'1',others=>'0');
else
if CNT1>CNT2 and CNT1-CNT2>1 then
CNT1<=(0=>'1',others=>'0');
else
CNT1<=CNT1+1;
end if;
end if;
end if;
end process;
process(clk)
begin
if clk'event and clk='0' then
if clear='1' then
CNT2<=(0=>'1',others=>'0');
else
if CNT1<CNT2 and CNT2-CNT1>1 then
CNT2<=(0=>'1',others=>'0');
else
CNT2<=CNT2+1;
end if;
end if;
end if;
end process;
process(CNT1,CNT2,temp)
begin
temp<=CNT1+CNT2;
if temp=n then
mark<='1';
clear<='1';
else
mark<='0';
clear<='0';
end if;
end process;
process(mark)
begin
if mark'event and mark='0' then
CNT3<=not CNT3;
end if;
end process;
LED<=CNT3;
end behave;
无报错
两个进程分别为上升沿和下降沿,达到5次后刷新。达到五次之后给一个脉冲信号,这个脉冲信号的上升沿作为反转输出
当n为大于2的任意值时可以实现任意分频。
代码看了,也仿真过,有些小毛病
但是能实现,当n为大于2的任意值时可以实现任意分频
主要的错误是 CNT1,CNT2 没初值
将第 10 行代码改下就行
signal CNT2,CNT1,temp:std_logic_vector(7 downto 0):="00000000";