简体   繁体   中英

Simple SR Latch Simulation in VHDL(with Xilinx) doesn't oscillate

I've learned that SR-Latch does oscillate when S and R are both '0' after they were just '1' in following circuit VHDL Code.

here is VHDL of SRLATCH

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity SRLATCH_VHDL is
port(
        S : in STD_LOGIC;
        R : in STD_LOGIC;
        Q : inout STD_LOGIC;
        NOTQ: inout STD_LOGIC);
end SRLATCH_VHDL;

architecture Behavioral of SRLATCH_VHDL is
begin

process(S,R,Q,NOTQ)
    begin
        Q <= R NOR NOTQ;
        NOTQ<= S NOR Q;
end process;

end Behavioral;

and followings are process in Testbench code and its simulation results

   -- Stimulus process
   stim_proc: process
   begin        
    S <= '1'; R <= '0'; WAIT FOR 100NS;
    S <= '0'; R <= '0'; WAIT FOR 100NS;
    S <= '0'; R <= '1'; WAIT FOR 100NS;
    S <= '0'; R <= '0'; WAIT FOR 100NS;
    S <= '1'; R <= '1'; WAIT FOR 500NS;
   end process;

and totally I don't have any idea why simulation doesn't reflect...

Xilinx Simul的SR LATCH
(click to enlarge)

Nice question, and your instructor is right - this circuit will oscillate if both S and R are released at the "same" time. Your issue is that your TB isn't doing this, but this one does:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity TOP is
end entity TOP;

architecture A of TOP is
  signal S,R,Q,NOTQ: std_logic;

  component SRLATCH_VHDL is
    port(
      S    : in    std_logic;
      R    : in    std_logic;
      Q    : inout std_logic;
      NOTQ : inout std_logic);
  end component SRLATCH_VHDL;

begin
  U1 : SRLATCH_VHDL port map(S, R, Q, NOTQ);

  process is
  begin
    S <= '1';
    R <= '1';
    wait for 10 ns;
    S <= '0';
    R <= '0';
    wait;
  end process;
end architecture A;

This will produce infinite delta-delay oscillation:

在此处输入图片说明

This isn't a great way to demonstrate asynchronous behaviour, because you are effectively simplifying the physical nature of the circuit, and using the VHDL scheduler to show that there's a problem (with the use of 'delta delays'). A better way to do this is to model real circuit behaviour by adding signal delays (this is exactly what your tools are doing when they back-annotate for timing simulations). Look up signal assignments with after , and the difference between transport and inertial delays. If you draw a circuit diagram, you'll see that the issue arises if both S and R are released in a 'small' time window that doesn't allow the signal propagation around your circuit to complete before the second control signal changes. You now need to write a testbench that changes S and R inside this time window.

Pretty much everything you ever design will be asynchronous, in exactly the same way as your SR circuit. We make circuits 'synchronous' only by ensuring that input signals don't change at the same time. The job of the timing tools is to tell us what 'same' actually means: when you get a report or a datasheet value giving you a setup or a hold time, then that number is simply the numerical version of 'not the same'.

Someone is teaching you wrong knowledge!

SR and RS basic flip-flops (also called latches) don't oscillate. The problem on S = R = 1 (forbidden) is that you don't know the state after you leave S = R = 1 because you can never go to S = R = 0 (save) simultaneously. You will transition for S = R = 1 to S = R = 0 through S = 1; R = 0 S = 1; R = 0 (set) or S = 0; R = 1 S = 0; R = 1 (reset). This will trigger either a set or reset operation before you arrive in state save .

Be aware that VHDL simulates with discrete time and is reproducing the same simulation results on every run. You can not (easily) simulate physical effects that cause different signal delays per simulation run.

Btw. you VHDL description is also wrong. Q and NOTQ are of mode out , not inout . Use either a proper simulator supporting VHDL-2008 (that allows read back of out-ports) or use an intermediate signal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM