File tree Expand file tree Collapse file tree 2 files changed +64
-2
lines changed Expand file tree Collapse file tree 2 files changed +64
-2
lines changed Original file line number Diff line number Diff line change 22
22
23
23
/* --- INSTANTIATION TEMPLATE BEGIN ---
24
24
25
- delay S1 #(
25
+ delay #(
26
26
.LENGTH( 2 ),
27
27
.WIDTH( 1 )
28
- )(
28
+ ) S1 (
29
29
.clk( clk ),
30
30
.nrst( 1'b1 ),
31
31
.ena( 1'b1 ),
Original file line number Diff line number Diff line change
1
+ // ------------------------------------------------------------------------------
2
+ // edge_detect.v
3
+ // published as part of https://github.com/pConst/basic_verilog
4
+ // Konstantin Pavlov, pavlovconst@gmail.com
5
+ // ------------------------------------------------------------------------------
6
+
7
+ // INFO ------------------------------------------------------------------------
8
+ // Edge detector, ver.4
9
+ // (simplified Verilog version, see ./edge_detect.sv for advanced features)
10
+ //
11
+ // In case when "in" port has toggle rate 100% (changes every clock period)
12
+ // "rising" and "falling" outputs will completely replicate input
13
+ // "both" output will be always active in this case
14
+ //
15
+
16
+ /* --- INSTANTIATION TEMPLATE BEGIN ---
17
+
18
+ edge_detect #(
19
+ .WIDTH( 32 )
20
+ ) ED1 (
21
+ .clk( clk ),
22
+ .anrst( 1'b1 ),
23
+ .in( in[31:0] ),
24
+ .rising( in_rise[31:0] ),
25
+ .falling( ),
26
+ .both( )
27
+ );
28
+
29
+ --- INSTANTIATION TEMPLATE END ---*/
30
+
31
+
32
+ module edge_detect #( parameter
33
+ bit [7 :0 ] WIDTH = 1
34
+ )(
35
+ input clk,
36
+ input anrst,
37
+
38
+ input [WIDTH- 1 :0 ] in,
39
+
40
+ output [WIDTH- 1 :0 ] rising,
41
+ output [WIDTH- 1 :0 ] falling,
42
+ output [WIDTH- 1 :0 ] both
43
+ );
44
+
45
+ // data delay line
46
+ reg [WIDTH- 1 :0 ] in_d = '0 ;
47
+ always_ff @(posedge clk or negedge anrst) begin
48
+ if ( ~ anrst ) begin
49
+ in_d[WIDTH- 1 :0 ] <= '0 ;
50
+ end else begin
51
+ in_d[WIDTH- 1 :0 ] <= in[WIDTH- 1 :0 ];
52
+ end
53
+ end
54
+
55
+ always @(* ) begin
56
+ rising[WIDTH- 1 :0 ] = {WIDTH{anrst}} & (in[WIDTH- 1 :0 ] & ~ in_d[WIDTH- 1 :0 ]);
57
+ falling[WIDTH- 1 :0 ] = {WIDTH{anrst}} & (~ in[WIDTH- 1 :0 ] & in_d[WIDTH- 1 :0 ]);
58
+
59
+ both[WIDTH- 1 :0 ] = rising[WIDTH- 1 :0 ] | falling[WIDTH- 1 :0 ];
60
+ end
61
+
62
+ endmodule
You can’t perform that action at this time.
0 commit comments