我刚写了一个VHDL代码,但它无法正常工作。我想用D Flip-Flop写一个不规则的计数器,计算如下:0 –> 13 –> 5 –> 7 –> 12 –> 6 –> 3 –> 15 –> 10 -> 0
。
它应该具有以下属性:
我在下面写了我的代码,但我知道这不行。有人可以帮帮我吗?
library IEEE ;
use IEEE.std_logic_1164.all ;
-- and_gate
entity and_gate is
port(Input1, Input2:in bit;
Output:out bit);
end and_gate;
architecture behavioral of and_gate is
begin
Output <= (Input1 and Input2) ;
end behavioral;
-- or_gate
entity or_gate is
port(Input1, Input2:in bit;
Output:out bit);
end or_gate;
architecture behavioral of or_gate is
begin
Output <= (Input1 or Input2);
end behavioral;
-- not_gate
entity not_gate is
port(Input : in bit; Output : out bit);
end not_gate;
architecture behavioral of not_gate is
begin
Output <= not(Input);
end behavioral;
-- D-FF
entity DFF is
port(CLK,RESET,EN,DIN :in bit;
COUNT :out bit);
end DFF;
architecture behavioral of DFF is
begin
LSEQ :process(RESET,CLK)
begin
if(RESET ='0')then
COUNT <='0';
elsif(CLK'event and CLK ='1')then
if(EN ='1')then
COUNT <=DIN;
end if;
end if;
end process;
end behavioral;
-- counter
entity counter is
port (CLK,RESET,EN: in bit;
COUNT : out bit_vector(3 downto 0));
end counter;
architecture counter_structural of counter is
component and_gate
port(Input1,Input2 : in bit; Output: out bit);
end component;
component or_gate
port(Input1,Input2 : in bit; Output : out bit);
end component;
component not_gate
port(Input : in bit; Output : out bit);
end component;
component DFF
port(CLK,RESET,EN,DIN :in bit; COUNT :out bit);
end component;
signal A,B,C,D,ai,bi,ci,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15 : bit;
begin
Gate1: not_gate port map (A,ai);
Gate2: not_gate port map (B,bi);
Gate3: and_gate port map (ai,bi,a1);
Gate4: and_gate port map (C,D,a2);
Gate5: or_gate port map (a1,a2,a3);
Gate6: DFF port map (CLK,RESET,EN,a3,COUNT(0));
Gate7: and_gate port map (ai,B,a4);
Gate8: not_gate port map (c,ci);
Gate9: and_gate port map (ai,D,a5);
Gate10: or_gate port map (a4,ci,a6);
Gate11: or_gate port map (a5,a6,a7);
Gate12: DFF port map (CLK,RESET,EN,a7,COUNT(1));
Gate13: and_gate port map (A,B,a8);
Gate14: and_gate port map (C,D,a9);
Gate15: or_gate port map (a8,a9,a10);
Gate16: DFF port map (CLK,RESET,EN,a10,COUNT(2));
Gate17: and_gate port map (ai,B,a11);
Gate18: and_gate port map (ci,D,a12);
Gate19: and_gate port map (ai,D,a13);
Gate20: or_gate port map (a11,a12,a14);
Gate21: or_gate port map (a13,a14,a15);
Gate22: DFF port map (CLK,RESET,EN,a15,COUNT(3));
end counter_structural ;
答案 0 :(得分:0)
为此,您可以使用LFSR(线性反馈移位寄存器)。 如果选择正确的参数并更正第一个值,则会得到一个伪随机生成器。 好的一点是,网上提供了正确的参数和第一个值。 (谷歌应该足够快地提供给你)
答案 1 :(得分:0)
使用戒指计数器。环形计数器只是n个寄存器,其输入和输出链接在一个环中。最终寄存器的输出也可以用作计数器的输出。您要输出的值可用作寄存器的初始值和复位值。确保寄存器的初始值与您想要输出的值相反,因为环形计数器将在寄存器n上输出初始值,然后输出n-1,n-2等。
在这种情况下,您可以使用:
register value
0 0
1 10
2 15
3 3
4 6
5 12
6 7
7 5
8 13
9 0
编辑:使用环形计数器的另一个好处是重用组件。结构环计数器只需要一个组件,一个寄存器。这将阻止您的代码被现在的所有组件声明所臃肿。