Detecting Sampled Edges
Part of the RTL Design & Verification section of Coddy's Verilog journey. Lesson 19 of 38.
A level can remain high for many cycles, while an event pulse should last for one cycle. Store the previous sampled level and compare it with the current one. This edge detector assumes an input already synchronous to this clock; it is not a clock-domain crossing synchronizer.
Relevant excerpt; surrounding declarations and connections are supplied in the challenge.
previous <= sig;
rising <= sig & ~previous;The old stored level makes a single pulse at the sampled transition.
Compare current and previous sampled levels; use this detector only with a synchronous input.
Challenge
MediumFor a signal sig already synchronous to clk, produce a registered one-cycle pulse on each sampled 0-to-1 transition. Synchronous rst clears the stored previous level and pulse. A high sig on the first non-reset edge therefore produces a pulse. Output columns: pulse. All controls and data are stable before each rising clock edge; results are observed afterward.
Complete design.v and preserve its module names and ports. The locked testbench.v supplies input changes and prints the outputs after they settle. It chooses a scenario using a simulator argument such as +CASE=1; no standard input is required. Do not add printing, delays or simulation termination to the design. Expected output is one row of decimal values per observation, separated by one space and ending with a newline.
Try it yourself
module dut (input clk, input rst, input sig, output reg pulse);
// Replace this placeholder with your design.
initial pulse = 0;
endmoduleThis lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in RTL Design & Verification
1Reliable Combinational RTL
Defaults Prevent LatchesPriority EncodersOne-Hot ValidationSafe Case DecodingRecap - Request Router4Controlled Sequential RTL
Reset and Enable PrioritySaturating CountersPipelining Data and ValidDetecting Sampled EdgesRecap - Event CounterPractice on your own: Online Verilog compiler