2 Star 1 Fork 0

史峰/basic_verilog

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
edge_detect.v 1.55 KB
Copy Edit Raw Blame History
//------------------------------------------------------------------------------
// edge_detect.v
// published as part of https://github.com/pConst/basic_verilog
// Konstantin Pavlov, pavlovconst@gmail.com
//------------------------------------------------------------------------------
// INFO ------------------------------------------------------------------------
// Edge detector, ver.4
// (simplified Verilog version, see ./edge_detect.sv for advanced features)
//
// In case when "in" port has toggle rate 100% (changes every clock period)
// "rising" and "falling" outputs will completely replicate input
// "both" output will be always active in this case
//
/* --- INSTANTIATION TEMPLATE BEGIN ---
edge_detect #(
.WIDTH( 32 )
) ED1 (
.clk( clk ),
.anrst( 1'b1 ),
.in( in[31:0] ),
.rising( in_rise[31:0] ),
.falling( ),
.both( )
);
--- INSTANTIATION TEMPLATE END ---*/
module edge_detect #( parameter
bit [7:0] WIDTH = 1
)(
input clk,
input anrst,
input [WIDTH-1:0] in,
output [WIDTH-1:0] rising,
output [WIDTH-1:0] falling,
output [WIDTH-1:0] both
);
// data delay line
reg [WIDTH-1:0] in_d = '0;
always_ff @(posedge clk or negedge anrst) begin
if ( ~anrst ) begin
in_d[WIDTH-1:0] <= '0;
end else begin
in_d[WIDTH-1:0] <= in[WIDTH-1:0];
end
end
always @(*) begin
rising[WIDTH-1:0] = {WIDTH{anrst}} & (in[WIDTH-1:0] & ~in_d[WIDTH-1:0]);
falling[WIDTH-1:0] = {WIDTH{anrst}} & (~in[WIDTH-1:0] & in_d[WIDTH-1:0]);
both[WIDTH-1:0] = rising[WIDTH-1:0] | falling[WIDTH-1:0];
end
endmodule
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Verilog
1
https://gitee.com/shi-feng-logic/basic_verilog.git
git@gitee.com:shi-feng-logic/basic_verilog.git
shi-feng-logic
basic_verilog
basic_verilog
master

Search

23e8dbc6 1850385 7e0993f3 1850385