BitFlow

Edge Detector

intermediate · sequential · 130 XP

Sign in to write your solution, run it in the simulator and submit it for grading.

Sign in or create a free account →

Problem

Edge Detector Detect the rising edge, falling edge, and either edge of an input signal, producing a **single-cycle pulse** for each event. The technique: store the previous value of the signal in a 1-bit register, then compare against the current value. **Interface** | Port | Direction | Description | |-----------|-----------|------------------------------------------| | `clk` | input | Clock | | `rst` | input | Async reset (active-high) | | `sig` | input | Input signal (may be async to clk) | | `rising` | output | 1-cycle pulse on 0→1 transition | | `falling` | output | 1-cycle pulse on 1→0 transition | | `either` | output | 1-cycle pulse on any transition | **Logic:** ``` sig_q = sig sampled on each clock edge (this also tames an async input) sig_qq = sig_q delayed one more cycle (the previous sample) rising = sig_q & ~sig_qq // was 0, now 1 falling = ~sig_q & sig_qq // was 1, now 0 either = sig_q ^ sig_qq // changed in either direction ``` Because the outputs are computed from registered samples, each pulse starts right after the clock edge that sees the change, and lasts exactly one cycle. The output pulse is exactly **one clock cycle wide** regardless of how long the input stays high or low. This circuit appears in every interrupt controller, debouncer, handshake detector, and edge-sensitive protocol trigger.

Constraints

  • Store previous value of sig in a register sig_d.
  • rising/falling/either are purely combinational from sig and sig_d.
  • rst clears sig_d to prevent spurious pulse on first cycle.

Examples

Input: sig 0→1

Output: rising=1 for exactly 1 cycle

Rising edge detected

Input: sig 1→0

Output: falling=1 for exactly 1 cycle

Falling edge detected

Input: sig held high for 10 cycles

Output: rising=1 once, then 0 for 9 cycles

Pulse width is exactly 1 cycle

Common questions

What does the Edge Detector problem ask you to build?
Edge Detector Detect the rising edge, falling edge, and either edge of an input signal, producing a **single-cycle pulse** for each event. The technique: store the previous value of the signal in a 1-bit register, then compare against the current value.
What constraints does Edge Detector have?
Store previous value of sig in a register sig_d.; rising/falling/either are purely combinational from sig and sig_d.; rst clears sig_d to prevent spurious pulse on first cycle.
What is an example input and output for Edge Detector?
Input sig 0→1 gives output rising=1 for exactly 1 cycle. Rising edge detected
Which Verilog concepts does Edge Detector practise?
sequential, edge-detect, interview, pulse.