• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Logic Design
  3. verilog . D-latch with memory.

Stats

  • Locked Locked
  • Replies 2
  • Subscribers 64
  • Views 15781
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

verilog . D-latch with memory.

dvdeepak
dvdeepak over 15 years ago
Hi
can any one help me for the module and testbench of D-latch with memory.in this file attatched the figure has rd/wrd and clk are inputs and data is an inout. if rd/wrb is low then flip-flop is in write mode ;data are an input line;data on data line are written into latch when clk is positive. when rd/wrb is high , flip-flop is in read mode, data stored in latch are made available on data line..I tried alot but couldn't get it done.Please help.

Thanx.
  • dlatch with memory.PNG
  • View
  • Hide
  • Cancel
Parents
  • tpylant
    tpylant over 15 years ago

    latch.v

    module latch (clk, rd, wr, d);
      input clk;
      input rd, wr;
      inout d;

      reg d_out;

      assign d = (rd && wr) ? d_out : 1'bz;

      always @(posedge clk) begin
        if (!rd && !wr)
          d_out = d;
      end
    endmodule

    test.v

    module test;
      reg clk = 0;
      reg rd, wr;
      reg d_in;
      wire d;

      latch i1 (clk, rd, wr, d);
      assign d = (!rd && !wr) ? d_in : 1'bz;

      always #5 clk = ~clk;

      initial begin
        @(negedge clk) rd = 0; wr = 0; d_in = 0;
        @(negedge clk) rd = 1; wr = 1; d_in = 0;
        @(negedge clk) rd = 0; wr = 0; d_in = 1;
        @(negedge clk) rd = 1; wr = 1; d_in = 1;
      end

      initial $monitor($time,,rd,,wr,,d);

    endmodule

    Tim

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • tpylant
    tpylant over 15 years ago

    latch.v

    module latch (clk, rd, wr, d);
      input clk;
      input rd, wr;
      inout d;

      reg d_out;

      assign d = (rd && wr) ? d_out : 1'bz;

      always @(posedge clk) begin
        if (!rd && !wr)
          d_out = d;
      end
    endmodule

    test.v

    module test;
      reg clk = 0;
      reg rd, wr;
      reg d_in;
      wire d;

      latch i1 (clk, rd, wr, d);
      assign d = (!rd && !wr) ? d_in : 1'bz;

      always #5 clk = ~clk;

      initial begin
        @(negedge clk) rd = 0; wr = 0; d_in = 0;
        @(negedge clk) rd = 1; wr = 1; d_in = 0;
        @(negedge clk) rd = 0; wr = 0; d_in = 1;
        @(negedge clk) rd = 1; wr = 1; d_in = 1;
      end

      initial $monitor($time,,rd,,wr,,d);

    endmodule

    Tim

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information