File: dffn.v

package info (click to toggle)
gplcver 2.12a-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 7,604 kB
  • ctags: 9,129
  • sloc: ansic: 126,201; sh: 1,539; makefile: 86; perl: 22
file content (72 lines) | stat: -rw-r--r-- 1,205 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// pipeline model from LRM section 7.1.6 
module DFF(q, d, clk);
 output q;
 input d, clk;
 reg q;
 
 always @(posedge clk)
  begin
   $display($stime,, "-- %m: positive clock edge old q=%b d=%b", q, d);
   q = d;
  end
endmodule

module dffn(q, d, clk); 
 parameter bits = 1;

 input [bits-1:0] d;
 output [bits-1:0] q;
 input clk;

 DFF dff[bits-1:0] (q, d, clk);
endmodule

module MxN_pipeline(in, out, clk);
 parameter M = 3, N = 4;

 input [M-1:0] in;
 output [M-1:0] out;
 input clk;

 wire [M*(N-1):1] t;

 dffn #(M) p[1:N] ({out, t}, {t, in}, clk);
endmodule

module top;
 reg [M-1:0] in;
 reg clk;
 wire [M-1:0] out;
 parameter M = 3, N = 4;

 MxN_pipeline #(M, N) pipe1(in, out, clk);

 initial
  begin
   $monitor($stime,, "in=%b, out=%b, clk=%b", in, out, clk);
   #10 in = 3'b0;
   #10 clk = 0;
   #10 clk = 1;
   #10 clk = 1'bx;
   #10 clk = 0;

   #10 in = 3'b111;
   #10 clk = 0;
   #10 clk = 1;
   #10 clk = 1'bx;
   #10 clk = 0;

   #10 in = 3'b0;
   #10 clk = 0;
   #10 clk = 111;
   #10 clk = 1'bx;
   #10 clk = 0;

   // notice values do not propagate through pipeline until here 
   #10 in = 3'b111;
   #10 clk = 0;
   #10 clk = 1;
   #10 clk = 1'bx;
   #10 clk = 0;
  end
endmodule