Electronics · Integrated circuits and programmable hardware
Describe and synthesise a small FPGA circuit
A hardware description language describes connected state and logic. The source can look like a program, but its registers, clocks and concurrent processes do not share one program counter. A tiny enabled counter makes that distinction visible without requiring an FPGA board.
Lesson preparation and course links
Use the retained digital/CMOS introductions and earlier event-sequence design as preparation. Shared Computing architecture/testing map links are optional orientation locations with planned topics. The local language explanation and full supplied-evidence route require no FPGA purchase, tool installation or simulator.
Back to the Electronics chapterAfter reading, you can
Read a complete small SystemVerilog state circuit and testbench, derive its intended trace and relate it to registers/logic. Distinguish concurrent hardware description, language simulation, synthesis, physical timing and programming; provide a complete supplied-evidence route without claiming any tool run.
Define the hardware and the language subset locally
A field-programmable gate array (FPGA) is configurable digital hardware. A hardware description language (HDL) expresses a circuit for analysis and possible synthesis. Here SystemVerilog module enabled_counter has clock clk, synchronous reset rst, enable en, two-bit count and one-bit pulse outputs.
A module names a connected circuit and its ports. logic [1:0] is an unsigned packed two-bit vector here. SystemVerilog logic has four-state values 0,1,X,Z; X represents an unknown simulation value and Z a high-impedance value. This exercise supplies only known 0/1 inputs and does not claim exhaustive X/Z behaviour.
always_ff @(posedge clk) describes the one positive-edge state process. rst is active-high and synchronous, with priority over en. Enable controls whether count changes; it is not a second clock. No initial register value is supplied in the design, so do not claim known count/pulse before a valid reset edge.
Shared Computing architecture and verification map locations are linked in the references. Their observed topic entries are planned; they are optional orientation links rather than a requirement to read unavailable articles. This lesson develops the needed state, language and checking concepts locally.
Read the complete circuit description
The complete supplied module is below as enabled_counter.sv. Nonblocking assignment uses <=. For this clocked process, right-hand expressions read pre-update values and register updates occur later in that simulation time, as explained by the cited language-methodology source.
Processes and connected modules run concurrently in HDL simulation; statements within this particular triggered process still have their language-defined evaluation/scheduling. Textually updating count later does not turn pulse’s expression into a test of the new count.
With rst=0 and en=1, two-bit count+2'd1 wraps modulo four. pulse is computed from en and old count==3. On a disabled non-reset edge, count retains its value because its assignment is conditional, while pulse is assigned zero. This is intentional edge-triggered register hold, not a combinational latch.
Complete original enabled_counter.sv — SystemVerilog-2012 assumption; no compilation or synthesis run
// Original optional research fixture. SystemVerilog-2012 semantics assumed.
// Not compiled, simulated, synthesized, placed/routed or programmed here.
module enabled_counter (
input logic clk,
input logic rst,
input logic en,
output logic [1:0] count,
output logic pulse
);
always_ff @(posedge clk) begin
if (rst) begin
count <= 2'd0;
pulse <= 1'b0;
end else begin
pulse <= en && (count == 2'd3);
if (en)
count <= count + 2'd1;
end
end
endmodule
Check the known-input state rule independently of tool output
At each rising edge, if rst=1 then next count=0 and next pulse=0. Otherwise next count=(old count+1) mod 4 when en=1, or old count when en=0; next pulse=en AND (old count==3). Previous pulse need not enter that next-pulse rule.
The compact table covers all sixteen combinations of the four known old-count values and the four known rst/en combinations. Each cell is next count / next pulse. It is supplied mathematical state reasoning, not a simulator log or a proof of all four-state language behaviour.
For old count 3 with rst=0,en=1, the next state is 0/1. At the following disabled edge it becomes 0/0. The pulse lasts one ideal clock interval even if counting then remains paused. Reset and enable both high instead select 0/0 by reset priority.
| Old count | rst=0, en=0 | rst=0, en=1 | rst=1, en=0 | rst=1, en=1 |
|---|---|---|---|---|
| 0 | 0 /0 | 1 /0 | 0 /0 | 0 /0 |
| 1 | 1 /0 | 2 /0 | 0 /0 | 0 /0 |
| 2 | 2 /0 | 3 /0 | 0 /0 | 0 /0 |
| 3 | 3 /0 | 0 /1 | 0 /0 | 0 /0 |
Keep the complete testbench separate from the circuit
The second complete file is tb_enabled_counter.sv, with simulation top tb_enabled_counter and the design under test (DUT) instantiated as dut. Its 1 ns/1 ps timescale and clock transition every 5 ns create an ideal 10 ns period, not a measured FPGA speed.
Inputs change at falling edges. Each check waits for the next rising edge and then 1 ns so the scheduled nonblocking updates have occurred. This observation delay avoids an event-scheduling race; it does not insert a physical delay into the circuit or prove setup/hold margin.
Case inequality !== treats an X/Z output versus a known expected value as a mismatch. $fatal is the mismatch path. The literal PASS display is code that would execute after successful checks if a suitable simulator is later run; it is not a result obtained here.
Complete original tb_enabled_counter.sv — supplied positive and negative checking route, unexecuted
`timescale 1ns/1ps
// Original optional research fixture; no simulator was invoked here.
module tb_enabled_counter;
logic clk = 1'b0;
logic rst = 1'b1;
logic en = 1'b0;
logic [1:0] count;
logic pulse;
enabled_counter dut (
.clk(clk), .rst(rst), .en(en), .count(count), .pulse(pulse)
);
always #5 clk = ~clk;
task automatic step (
input logic next_rst,
input logic next_en,
input logic [1:0] expected_count,
input logic expected_pulse
);
@(negedge clk);
rst = next_rst;
en = next_en;
@(posedge clk);
#1; // Observe after the DUT nonblocking updates, not a physical fix.
if ((count !== expected_count) || (pulse !== expected_pulse))
$fatal(1, "Mismatch t=%0t rst=%b en=%b count=%b pulse=%b expected=%b/%b",
$time, rst, en, count, pulse, expected_count, expected_pulse);
endtask
initial begin
repeat (2) @(posedge clk);
#1;
step(1'b1, 1'b0, 2'd0, 1'b0);
step(1'b0, 1'b1, 2'd1, 1'b0);
step(1'b0, 1'b1, 2'd2, 1'b0);
step(1'b0, 1'b0, 2'd2, 1'b0);
step(1'b0, 1'b1, 2'd3, 1'b0);
step(1'b0, 1'b1, 2'd0, 1'b1);
step(1'b0, 1'b0, 2'd0, 1'b0);
step(1'b0, 1'b1, 2'd1, 1'b0);
step(1'b1, 1'b1, 2'd0, 1'b0);
$display("PASS: supplied nine-step trace");
$finish;
end
endmodule
Reproduce the declared nine-step schedule
The testbench starts rst=1,en=0 and waits for rising edges at 5 and 15 ns, then 1 ns. The first task waits until falling edge 20 ns and samples after rising edge 25 ns, at 26 ns. The next rows follow at 10 ns intervals.
Step 4 pauses at count 2. Step 6 wraps old count 3 to 0 and asserts pulse. Step 7 disables counting and clears pulse. Step 9 presents rst=1,en=1 and demonstrates reset priority. Every row is an expected result derived from the supplied recurrence.
The independent mathematical transition check and hand trace support the intended specification. No HDL parser/compiler, simulator, formal-equivalence engine or mapped FPGA has executed these files in this lesson.
| Step | Drive / sample | Old count | rst / en | Expected count | Expected pulse |
|---|---|---|---|---|---|
| 1 | 20 /26 | 0 | 1 /0 | 0 | 0 |
| 2 | 30 /36 | 0 | 0 /1 | 1 | 0 |
| 3 | 40 /46 | 1 | 0 /1 | 2 | 0 |
| 4 | 50 /56 | 2 | 0 /0 | 2 | 0 |
| 5 | 60 /66 | 2 | 0 /1 | 3 | 0 |
| 6 | 70 /76 | 3 | 0 /1 | 0 | 1 |
| 7 | 80 /86 | 0 | 0 /0 | 0 | 0 |
| 8 | 90 /96 | 0 | 0 /1 | 1 | 0 |
| 9 | 100 /106 | 1 | 1 /1 | 0 | 0 |
Relate the state rule to intended hardware
The intended architecture has three logical state bits: two count bits and one pulse bit. Count feeds increment/enable/reset selection and the terminal-count comparison. The next values enter registers on the same clock edge; pulse does not need its previous value as feedback.
Synthesis translates the described state/logic into a selected target’s resources and may optimise or transform the implementation. Three logical state bits are not an actual lookup table (LUT) or flip-flop utilisation report. Power-up behaviour, electrical pins, clock routing and physical delays require additional target information.
The drawing is a conceptual register-transfer architecture. It is neither a generated netlist nor proof of timing. The following timing lesson uses this same actual supplied module/testbench while keeping hypothetical delay bounds separate from a physical implementation.
If tools are already available, collect the evidence in stages
The documented example language profile is SystemVerilog-2012 with the cited AMD 2023.1 support pages. It is an illustration, not an instruction to install that version or purchase hardware. In an already configured suitable simulator, save both files, compile them in SystemVerilog mode in one work/library, select tb_enabled_counter as top, elaborate (resolve and connect the simulation hierarchy) and run until $finish.
Retain the actual tool/version, source hashes, compile/elaboration diagnostics and checker transcript. Then in a separate negative-test copy, change only the sixth step expected_count from 2'd0 to 2'd1, leaving the design/stimulus unchanged. Its intended result is $fatal at the 76 ns check; verify that actual failure if running the tool.
For optional synthesis in an existing selected FPGA flow, use enabled_counter as design top and keep tb_enabled_counter in the simulation set. Record the exact target/tool and actual mapped reports. Clock and external interface constraints must be declared and validated; the testbench’s # delays are not board constraints. Programming a bitstream (the FPGA’s configuration data) and testing pins would be additional stages, not implied by synthesis.
| Stage | What it can add | What it does not establish alone |
|---|---|---|
| Supplied recurrence/trace | Intended known-input state rule | HDL tool acceptance |
| Compile / elaborate | Language/source acceptance and connected simulation model | Passing behaviour or physical timing |
| Simulate with positive/negative checks | Observed responses for actual stimuli/checks | Exhaustive proof or routed timing |
| Synthesis | Mapped logic for the exact chosen target/flow | Complete constraints or physical timing closure |
| Physical implementation / timing analysis | Modelled path bounds under validated constraints/corners | Actual board electrical/functional operation |
| Programming / board test | Observed configured hardware under stated conditions | Untested environments, coverage or lifetime |
Complete the paper route without inventing a pass
Without tools, reproduce the complete sixteen-transition table, nine expected rows and the intentional wrong sixth expectation. Explain why the wrong count 1 conflicts with the design’s required count 0/pulse 1 at that check. This supplied-evidence route is complete on its own.
With tools, a real positive run and a real deliberately failing check test the checker path. They still do not establish every stimulus, X/Z case, formal equivalence, metastability behaviour, post-route timing, I/O compatibility or hardware operation.
Preserve compilation, simulation, synthesis, physical implementation and board results as separate fields. A source file that contains a PASS string, or a correct mathematical trace, cannot fill those fields.
Read old count at the wrap edge
Before step 6, old count=3, rst=0 and en=1. The pulse expression reads that old 3 and schedules 1. The count expression schedules two-bit 3+1=0. Both are next registered values after that edge’s nonblocking updates.
At step 7, en=0 with old count 0. Count has no new assignment and holds 0; pulse is assigned 0. The wrap indication therefore clears after one clock interval instead of sticking until the next enabled count.
Changing only the sixth expected count to 1 creates a deliberately wrong expectation. It should reach the mismatch handler in an actual suitable simulation, while the supplied logical result remains 0/1. No simulator or FPGA was run to produce a transcript here.
Try the reasoning
What are next count/pulse for old count=3, rst=0, en=1?
Show the answer and reasoning
Next count 0 by two-bit modulo-four arithmetic, and pulse 1. Both right-hand expressions read pre-update count 3 in this process; the count assignment does not change the value seen by the pulse expression first.
What happens on the disabled edge immediately after the wrap?
Show the answer and reasoning
Count holds 0 because its assignment is conditional on en. Pulse becomes 0 because its non-reset assignment executes with en=0. This is register hold and pulse clearing, not a combinational latch or a new clock.
Is rst asynchronous, and what if rst/en are both 1?
Show the answer and reasoning
rst is synchronous: only posedge clk triggers the state process. At a rising edge with rst=1, its branch takes priority and sets count/pulse 0/0. Changing rst between rising edges does not asynchronously reset this design.
Why are inputs driven at falling edges and sampled 1 ns after rising edges?
Show the answer and reasoning
The stimulus avoids racing the DUT’s sampling edge, and the later check observes scheduled nonblocking updates. The 1 ns is simulation observation scheduling, not a manufactured data delay or setup/hold qualification.
Does an HDL description mean no statement is evaluated in order?
Show the answer and reasoning
No. Connected modules/processes operate concurrently, but statements in this triggered process have defined evaluation/scheduling. Nonblocking right-hand values use the pre-update state here; do not replace the actual language semantics with a one-program-counter or an unordered-text story.
How does the intentional negative test differ from changing the circuit?
Show the answer and reasoning
Change only step 6’s expected count from 0 to 1 in a separate testbench copy. Keep source design/stimulus fixed. The intended count 0/pulse 1 then conflicts with that expectation and should call $fatal if actually simulated; no negative run occurred here.
Do sixteen known-input transitions cover all SystemVerilog states?
Show the answer and reasoning
No. They cover four known count values and four known rst/en combinations. X/Z language behaviour, other event schedules and properties need additional analysis/tests. The table is mathematical specification evidence, not an HDL execution log.
May three logical state bits be reported as actual FPGA utilisation?
Show the answer and reasoning
No. They describe intended state. Synthesis/optimisation/mapping and the exact target can affect resources. An actual tool report, implementation constraints/timing and board results are separate evidence stages.
What is complete without tools, and what remains unperformed?
Show the answer and reasoning
The complete module/testbench, sixteen-transition table, nine expected rows and intentional-failure reasoning support the supplied-evidence route. Compilation/simulation, synthesis, formal proof, routed timing, programming and board operation remain unperformed. Shared Computing references are planned map locations, not a new unavailable prerequisite.
What to carry forward
Describe state and its concurrent hardware context precisely, then name which evidence stage you actually have. A correct intended recurrence and a complete testbench prepare simulation/synthesis; they do not become executed tool or FPGA results.
References
Sources supporting this lesson’s explanations and examples.