Codiode

Convert to always_ff

EasyVerilog / SystemVerilogBuild

Plain always blocks describe flip-flops and combinational logic with the same keyword. SystemVerilog's always_ff states the intent, so tools can warn when the code doesn't match it.

The provided module is an 8-bit counter written using legacy Verilog syntax. It features a synchronous active-high reset, a data load function, and an increment enable. The logic works correctly, but the codebase is migrating to SystemVerilog standards. The task is to update the sequential block to use always_ff and verify that the module retains its exact functionality.

The counter operates on the positive edge of the clock. When the synchronous reset is asserted, the output clears to zero. If reset is de-asserted, the load signal takes priority over the enable signal. When load is high, the counter takes the value of the input data. When enable is high and load is low, the counter increments by one.

Signal Direction Width Description
clk input 1 Positive-edge triggered clock
rst input 1 Synchronous active-high reset; clears count to 0 when asserted
load input 1 Load enable; loads data_in into count when high
en input 1 Count enable; increments count by 1 when high
data_in input 8 Data to load into the counter
count output 8 Current counter value; resets to 8'h00

Constraints

  • The module must use always_ff for all sequential logic
  • The always keyword must not be used without the _ff suffix
  • The clock edge must be posedge clk
  • The reset must be synchronous and active-high
  • Priority must be strictly maintained: rst overrides load, which overrides en
  • The counter must wrap around to 8'h00 naturally upon reaching 8'hFF

Topics

SequentialSystemVerilogRefactoringAlways_ff

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 Sequential RTL

Problem 21 of 26 in the Sequential RTL track.

Related problems

Browse all problems · Verilog practice problems · Learning tracks

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