如何在VHDL中用D触发器构建计数器时延迟复位信号?

时间:2016-12-14 20:24:03

标签: vhdl counter reset

我正在尝试使用sn7493计数器构建模数25计数器。我已经建模了我自己的D触发器并用它们来重建计数器的内部结构。它可以工作,直到需要重置。在 24'之后我得到了' 2'而不是' 0'。我想复位信号要短路才能正确复位,但我不知道如何让它更长。 The simulation This is how the counter I'm building looks like in schematic

--DFF model
LIBRARY ieee;
USE ieee.std_logic_1164.all;

ENTITY D IS
PORT(
    Din, CLK, RES :IN std_logic;
    Q :OUT std_logic
);
END D;

ARCHITECTURE behavior of D IS
begin 
PROCESS(CLK)
    begin
        if rising_edge(CLK) then
            Q <= Din;
        end if;
        if (RES='0') then
            Q <= '0';
        end if;
    end PROCESS;
END behavior;


--SN7493 counter model
LIBRARY ieee;
USE ieee.std_logic_1164.all;

ENTITY c7493 IS
PORT (
    CLKA,CLKB,R1,R2: IN std_logic;
    Q: INOUT std_logic_vector(0 to 3)
);
END c7493;

ARCHITECTURE behavior of c7493 IS

    COMPONENT D IS
    PORT(
        Din, CLK, RES :IN std_logic;
        Q :OUT std_logic
    );
END COMPONENT D;

signal A_out,B_out,C_out,D_out: std_logic;
BEGIN
    DA: D PORT MAP(
        Din => not A_out,
        CLK => not CLKA,
        RES =>R1 nand R2,
        Q => A_out
    );
    DB: D PORT MAP(
        Din => not B_out,
        CLK => not CLKB,
        RES => R1 nand R2,
        Q => B_out
    );
    DC: D PORT MAP(
        Din => B_out xor C_out,
        CLK => not CLKB,
        RES =>R1 nand R2,
        Q => C_out
    );
    DD: D PORT MAP(
        Din => (B_out and C_out) xor D_out,
        CLK => not CLKB,
        RES =>R1 nand R2,
        Q => D_out
    );
    Q(0) <=A_out;
    Q(1) <=B_out;
    Q(2) <=C_out;
    Q(3) <=D_out;

END behavior;


--main program
LIBRARY ieee;
USE ieee.std_logic_1164.all;

ENTITY plytka IS
PORT(
    SW: IN std_logic_vector(0 to 0);
    LEDR: OUT std_logic_vector (4 downto 0)
    );
END plytka;

ARCHITECTURE projekt OF plytka IS
COMPONENT c7493 IS
PORT(
    CLKA,CLKB,R1,R2: IN std_logic;
    Q: INOUT std_logic_vector(0 to 3)
);
END COMPONENT c7493;

signal A_out,B_out,C_out,D_out,E_out: std_logic;
BEGIN
    c7493A: c7493 PORT MAP(
        CLKA => SW(0),
        CLKB => A_out,
        R1 => (A_out and D_out and E_out),
        R2 => (A_out and D_out and E_out),
        Q(0) => A_out,
        Q(1) => B_out,
        Q(2) => C_out,
        Q(3) => D_out
    );
    c7493B: c7493 PORT MAP(
        CLKA => A_out and B_out and C_out and D_out,
          CLKB => '0',
        R1 => (A_out and D_out and E_out),
        R2 => (A_out and D_out and E_out),
        Q(0) => E_out
    );

    LEDR <= (E_out,D_out,C_out,B_out,A_out);
END projekt;

1 个答案:

答案 0 :(得分:1)

一种简单的方法是在复位信号中创建一个小矢量和时钟(假设同步复位!),然后检查它是否为零...

std_logic_vector reset_vec : std_logic_vector(3 downto 0) := (others => '0');

-- Then in architecture body
reset_vec   <= reset_vec(2 downto 0) & reset when rising_edge(clk);
elong_reset <= '1' when reset_vec /= "0000" OR reset = '1' else '0';
祝你好运!