Problems

22. Level and pulse synchronizers

MediumWrite the moduleAbout 25 min
cdcsynchronizertoggleedge detection

Build the logic of two classic clock-domain-crossing circuits. Here everything runs on one clock, clk, so the test can check the logic and the latency; in a real design the inputs would come from another clock domain.

Level synchronizer: async_in passes through two flip-flops in a row. sync_out is the second flip-flop, so it follows async_in two clock edges later.

Pulse synchronizer: pulse_in is a one-cycle pulse from the "source" side. A toggle flip-flop flips on every edge where pulse_in is 1. The toggle passes through a 2-flop synchronizer and one more flip-flop; pulse_out is the XOR of the last two of those three flip-flops. So each input pulse produces exactly one one-cycle output pulse, which appears two edges after the edge that saw pulse_in (it is high after the third edge counting that one, for one cycle).

rst (synchronous, active high) clears every flip-flop.

Ports

Module sync_pair

PortDirBitsWhat it is
clkin1Clock.
rstin1Synchronous reset, active high.
async_inin1Level to synchronize.
pulse_inin1One-cycle pulse to carry across.
sync_outout1async_in after two flip-flops.
pulse_outout1One cycle per input pulse.

Example

pulse_in is 1 at edge 1 only: the toggle flips at edge 1, the synchronizer flops copy it at edges 2 and 3, the last flop at edge 4, so pulse_out is 1 between edges 3 and 4.

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

Verilogsync_pair.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.

Level and pulse synchronizers: Verilog interview question | breadboardhub