Skip to content

Commit 39c1b4c

Browse files
committed
Restored simplified Verilog version of edge_detect
1 parent 213e17c commit 39c1b4c

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed

delay.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222

2323
/* --- INSTANTIATION TEMPLATE BEGIN ---
2424
25-
delay S1 #(
25+
delay #(
2626
.LENGTH( 2 ),
2727
.WIDTH( 1 )
28-
)(
28+
) S1 (
2929
.clk( clk ),
3030
.nrst( 1'b1 ),
3131
.ena( 1'b1 ),

edge_detect.v

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy