下面是n分频器的VHDL描述,你只要将两个分频器串联起来就行了。第一个的分频系数为20MHz/10KHz=2000,第二个的分频系数为10KHz/1KHz=10,再将第一个分频器的输出通过一个D触发器构成的2分频器(将q_n输出端反馈至d输入端,输出端q即为输入端clk的2分频)即可。
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity div is
generic(n:integer :=2000);
port (clk:in std_logic;
q:out std_logic);
end div;
architecture behave of div is
signal count :integer range n-1 downto 0:=n-1;
begin
process(clk)
begin
if (clk'event and clk='1' and clk'last_value ='0') then
count<=count-1;
if count>=n/2 then
q<='0';
else
q<='1';
end if;
if count<=0 then
count<=n-1;
end if;
end if;
end process;
end behave;
追问问题已经解决,首先将20Mhz的频率波分成占空比为50%5KHZ的方波,很容易,然后将5KHZ的方波分成1KHZ占空比为50%的方波,采用上升沿和下降沿相或便可组成1KHZ占空比为50%的方波.。