Codiode

Registered vs Combinational Output

EasyVerilog / SystemVerilogBuild

A Mealy output reacts to the input within the same cycle, glitches included. Registering it gives a clean signal one cycle later. This problem asks for both, so you can compare them.

This module implements an overlapping sequence detector that searches for the pattern consisting of two consecutive ones on a serial input line. It provides two distinct detection flags to illustrate output timing differences. The combinational flag asserts immediately as soon as the second one is present at the input while the machine is in the correct state. The registered flag asserts one clock cycle later, capturing the combinational flag's state into a dedicated flip flop.

Timing and Reset Rules

  • Clock edge: posedge clk
  • Reset type: asynchronous active low rst_n
  • Output values on reset: detect_reg must be 0; the internal state machine must return to the IDLE state, meaning detect_comb must also evaluate to 0
  • Priority rules: Reset has the highest priority and takes effect immediately, regardless of the clock
  • State encoding: Use 0 for IDLE (waiting for the first 1) and 1 for SEEN_1 (waiting for the second 1)
  • Overlapping behaviour: The sequence of three consecutive ones must trigger the detection flags twice

Worked Trace

Combinational Mealy outputs evaluate at the end of the clock cycle, just before the next positive edge.

Cycle 1: rst_n=0, din=0 → state=IDLE, detect_comb=0, detect_reg=0
Cycle 2: rst_n=1, din=1 → state=IDLE, detect_comb=0, detect_reg=0
Cycle 3: rst_n=1, din=1 → state=SEEN_1, detect_comb=1, detect_reg=0
Cycle 4: rst_n=1, din=1 → state=SEEN_1, detect_comb=1, detect_reg=1
Cycle 5: rst_n=1, din=0 → state=SEEN_1, detect_comb=0, detect_reg=1
Cycle 6: rst_n=1, din=0 → state=IDLE, detect_comb=0, detect_reg=0

State Diagram

Timing Diagram

Port Table

Signal Direction Width Description
clk input 1 Positive edge triggered clock
rst_n input 1 Asynchronous active low reset; all registers go to 0 when asserted
din input 1 Serial data input
detect_comb output 1 Combinational Mealy output; goes high immediately when state is SEEN_1 and din is 1
detect_reg output 1 Registered output; captures the value of detect_comb on the posedge of clk

Constraints

  • The design must trigger on posedge clk and reset on negedge rst_n
  • detect_reg must be strictly 0 upon reset
  • The FSM must support overlapping sequences without returning to IDLE
  • detect_comb must be purely combinational and respond to din changes in the exact same clock cycle
  • detect_reg must be a registered version of detect_comb, introducing exactly one clock cycle of latency

Topics

FSMMealySequential LogicTiming

Solve this problem

Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against the problem's testbench. You get the waveform back, not a stored answer.

This problem is part of Codiode Pro. The statement above is free to read.

The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.

Part of Synthesis Intuition

Problem 16 of 25 in the Synthesis Intuition track.

Related problems

Browse all problems · Verilog practice problems · Learning tracks

Solve this on a laptopSend yourself the link and continue there.