Altera_Forum
Honored Contributor
16 years agoProblem with behavioral code for SR latch
Two behavioral codes for a gated SR latch that to me seem like they should give identical results instead give radically different results, one of which has a glitch that gives wrong behavior (that Quartus warns about). Here is the VHDL for the two cases:
--file mysrlatch1.vhd with incorrect results library ieee; use ieee.std_logic_1164.all; entity mysrlatch1 is port( r,clk,s,clr:in std_logic; q: out std_logic); end mysrlatch1; architecture arch of mysrlatch1 is begin process(r,s,clk,clr) begin if clr='1' then q<='0'; elsif clk='1' then if r='1' then q<='0'; elsif s='1' then q<='1'; end if; end if; end process; end arch; --file mysrlatch2.vhd with correct results library ieee; use ieee.std_logic_1164.all; entity mysrlatch2 is port( r,clk,s,clr:in std_logic; q: out std_logic); end mysrlatch2; architecture arch of mysrlatch2 is begin process(r,s,clk,clr) begin if clr='1' then q<='0'; elsif clk='1' and r='1' then q<='0'; elsif clk='1' and s='1' then q<='1'; end if; end process; end arch; I see in looking at the code generated for the two cases that case 1 does indeed have a glitch generator with the way it handles the R input. But the two cases seem like they should generate the same results -- the results of running through the process seem like they should be identical. What am I missing? Thanks. Using Quartus-II version 9.1 build 222, web version. Windows XP home, up-to-date.