程序给你做出来了,完全符合你的要求。仿真的话时间用的太长,就仿了一个set1set2=00的50M的2500分频20k的,图也给你贴出来,不过频率太高,图片已经看不出clk的波形了。
程序:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity fen is
port(
clk,set1,set2:in std_logic;
out1:out std_logic);
end ;
architecture arch of fen is
signal a:std_logic;
begin
process(clk)
variable data:integer range 0 to 50000;
begin
if clk'event and clk='1' then
if set1='0' and set2='0' then
if data=2500 then
data:=0;
a<= not a;
else
data:=data+1;
end if;
out1<=a;
elsif set1='0' and set2='1' then
if data=10000 then
data:=0;
a<= not a;
else
data:=data+1;
end if;
out1<=a;
elsif set1='0' and set2='1' then
if data=50000 then
data:=0;
a<= not a;
else
data:=data+1;
end if;
out1<=a;
end if;
end if;
end process;
end arch;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity fen is
port(clk:in std_logic;
set:in std_logic_vector(1 downto 0);
clock:out std_logic);
end;
architecture art of fen is
signal count:integer range 0 to 500000;
signal clk_data:std_logic:='1';
signal con: integer range 0 to 500000;
begin
process(clk)
begin
case set is
when "00"=>con<=1;
when "01"=>con<=2;
when "10"=>con<=3;
when "11"=>con<=4;
end case;
if clk'event and clk='1' then
if count=con then -------频率多大,你可以改这个 计算公式为
count<=0; -- f1=2*count*f2,f1为分频前的频率
clk_data<=not clk_data; -- f2为分频后的频率
else
count<=count+1;
end if;
end if;
clock<=clk_data;
end process;
end art;
为了方便显示 计数自己改