Problems

6. Rising and falling edge detector

EasyWrite the moduleAbout 10 minFree
sequentialedge detectionregisters

din is a signal that is already synchronous to clk. Report when it changes.

Keep a copy of din as it was at the last rising clock edge (call it the previous value). rise is 1 while din is 1 and the previous value is 0. fall is 1 while din is 0 and the previous value is 1. Both are combinational outputs of din and the stored previous value, so each one stays high for one clock cycle when din changes cleanly.

rst is synchronous and active high: on a clock edge with rst = 1, the previous value becomes 0. So if din is 1 right after reset, rise is 1 until the next edge.

Ports

Module edge_detect

PortDirBitsWhat it is
clkin1Clock.
rstin1Synchronous reset, active high.
dinin1Signal to watch.
riseout1din went from 0 to 1.
fallout1din went from 1 to 0.

Example

With din = 0 at the last edge, setting din to 1 makes rise = 1 at once. After the next clock edge the previous value is 1, so rise drops to 0 and stays 0 while din stays 1.

Stuck? . Sign in to save your progress. You can solve the free problems without an account.

Verilogedge_detect.v
14px
Loading the editor…

Submit your answer to have it graded. The hidden test runs on the server; you see whether it passes and, if not, the first case it gets wrong.

Rising and falling edge detector: Verilog interview question | breadboardhub