6. Rising and falling edge detector
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
| Port | Dir | Bits | What it is |
|---|---|---|---|
clk | in | 1 | Clock. |
rst | in | 1 | Synchronous reset, active high. |
din | in | 1 | Signal to watch. |
rise | out | 1 | din went from 0 to 1. |
fall | out | 1 | din 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.
Written hints
AI hint
Submissions
No submissions yet. Submit your answer and it shows here. Sign in to keep them.
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.
Press Build to check your code with Yosys. Errors and warnings show here, and a clean build draws the logic diagram.
Build your design to drive it by hand and see its signals here.