[systemverilog] first attempt

Viewer

copydownloadembedprintName: first attempt
  1. `timescale 1ns / 1ps
  2. // D-flip-flop using JK flip-flop
  3. module FlipFlopD(input logic D, clock, clear
  4.                  output logic q);
  5.   always_ff @(negedge clock, posedge clear)
  6.     if (clear)
  7.         q <= 0;
  8.     else
  9.         case ({d, ~d})
  10.             2'b01: q <= 0;
  11.             2'b10: q <= 1;
  12.         endcase
  13. endmodule
  14.  
  15.  
  16. c)  (3 pt.) Write a test-bench for the D flip-flop that illustrates
  17. its behavior when input D takes values of 0 and 1, and for different
  18. current states of the flip-flop. The test-bench should use an initial
  19. pulse for the clear signal of the flip-flop to bring it into a
  20. well-defined state, as seen in class.
  21.  
  22. module FlipFlopTest;
  23.  
  24.     logic d, clock, clear;
  25.     logic q;
  26.     
  27.     FlipFlipD flip_flop(d, clock, clear, q);
  28.     
  29.     // 1) Initial pulse for 'clear'
  30.     initial begin
  31.         clear = 1;
  32.         #5 clear = 0;
  33.     end
  34.     
  35.     // 2) Clock signal
  36.     initial begin
  37.         clock = 1;
  38.         forever #5 clock = ~clock;
  39.     end
  40.     
  41.     // 3) Values for 'd'
  42.     initial begin
  43.         d = 0; // reset
  44.         #10 d = 1; // set
  45.         #10 $finish;
  46.     end
  47. endmodule
  48.         
  49.     
  50.  
  51.  

Editor

You can edit this paste and save as new:


File Description
  • first attempt
  • Paste Code
  • 05 Oct-2023
  • 1.13 Kb
You can Share it: