Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

SR latch- VHDL code. Please help.

Status
Not open for further replies.

delon

Junior Member level 2
Joined
Sep 11, 2011
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,449
Hello, I am a beginner in VHDL. I wrote a code for gated SR latch which is mentioned bellow:

LIBRARY ieee;
USE ieee.std_logic_1164.all;

ENTITY hw IS
PORT ( ck, s, r : IN std_logic;
q, qnot : BUFFER std_logic);
END hw;

ARCHITECTURE sr OF hw IS

BEGIN
PROCESS (ck,s,r) BEGIN
IF ( ck ='1' AND r='1' AND s='0') THEN
q <='0';
qnot<= NOT q;
ELSIF ( ck ='1' AND r='0' and s='1') THEN
q <='1';
qnot<= NOT q;
ELSIF ( ck ='1' AND r='1' and s='1') THEN
q <='X';
qnot<= 'X';
END IF;
END PROCESS;

END sr;

I run this code as a functional simulation in Altera Quartus II. In the simulation result, I am not getting 'X' for s=r=1 input combination. Here is a screenshot: SR.JPG

For s=1, r=1, I am getting '0' in q. Does it mean that, the PROCESS is not evaluating the condition when s or r changes it's value? What might be the reason for that. Please help.
 

the quartus simulator does a post place and route simulation, so 'X' is not a valid output. for 'X' you need to use modelsim. quartus converts your code to actual logic.

just a note, this is not a valid Sr latch description. I suggest you have a look at the quartus coding guidelines.
 

Thanks for your response. It make sense. But what do mean "this is not a valid Sr latch description"? Would you please give me a little more hint ?
 

you have not used the correct synchronous template, so it is not synchronous. it is just a load of logic, and the output can change whenever the click is high rather than on the rising edge of the clock.

this is the standard template.

Code:
process(clk, async_reset)
begin
  if async_reset = '1' then 
    --do asynchronous reset

  elsif rising_edge(clk) then
    -- put sync stuff here

  end if;
end process;
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top