Tutorial: a counter from scratch
In this tutorial you write a 4-bit counter yourself, prove that it works, and turn it into a chip layout. It takes about fifteen minutes. You type two short Verilog files, and Vulkos writes the configuration and runs the tools.
What you will build#
A counter is a small circuit that holds a number and adds one to it on every tick of a clock. Yours holds 4 bits, so it counts from 0 to 15 and then wraps back to 0. It has two controls:
rst(reset) puts the count back to 0.en(enable) decides whether it counts. Whileenis low the count holds still.
You will go through the same loop you use on every design:
- Write the design in Verilog.
- Test it in a simulator, with a second file called a testbench that drives the inputs and checks the outputs.
- Build it with LibreLane, the tool that turns Verilog into a physical layout.
- Read the result: is it fast enough, and does the layout match the design?
Rather not type?
The Quickstart does the same journey from a ready-made template, with no typing. This page starts from an empty project so you see where every file comes from.Part 1: a blank project#
- 1
Create a blank chip project
Go to My Work and choose Create project, then Chip project. Name itCounter, leave Start with on Blank, and press Create project.

The IDE opens with an empty file list on the left and an empty editor in the middle. The green button at the top right is the Run button. It runs whichever tool is chosen in the Tools menu, and its label changes to say what it will do.
Part 2: write the counter#
- 1
Add the design file
Press the New file button above the file list, typesrc/counter_en.vand press Enter. Typing the folder as part of the name creates thesrcfolder too. Paste this in, or use the Copy button on the block:
1module counter_en (
2 input wire clk,
3 input wire rst,
4 input wire en,
5 output reg [3:0] count
6);
7
8 always @(posedge clk) begin
9 if (rst)
10 count <= 4'd0;
11 else if (en)
12 count <= count + 4'd1;
13 end
14
15endmoduleHow to read it:
module counter_en ( ... );names the circuit and lists its pins. Three are inputs. One,count, is a 4-bit output:[3:0]means bits 3 down to 0.always @(posedge clk)means "do this on every rising edge of the clock". Everything inside happens once per tick, which is what makes this a register (a circuit that remembers).- The
ifgives reset the first say. Ifrstis high the count becomes 0. Otherwise, ifenis high, it goes up by one. If neither is true nothing is assigned, so the count keeps its value. 4'd1is the number 1 written as 4 bits. Adding 1 to 15 in 4 bits gives 0, which is the wrap.
Your work saves on its own. The file list tags the file top: Vulkos has worked out that counter_en is the top module, the outermost one that the tools start from.
Part 3: write the testbench#
A testbench is a second Verilog module that is never built into the chip. It creates your counter, wiggles its inputs, and checks what comes out. This one checks itself and prints a verdict, so you do not have to read a waveform to know whether the design works.
- 1
Add the testbench file
Press New file again, typetb/counter_en_tb.vand press Enter. Paste this in:
1`timescale 1ns/1ps
2
3module counter_en_tb;
4
5 reg clk = 0;
6 reg rst = 1;
7 reg en = 0;
8 wire [3:0] count;
9 integer errors = 0;
10
11 counter_en dut (.clk(clk), .rst(rst), .en(en), .count(count));
12
13 // A clock with a 10 ns period.
14 always #5 clk = ~clk;
15
16 // Record every signal in a waveform file.
17 initial begin
18 $dumpfile("counter_en_tb.vcd");
19 $dumpvars(0, counter_en_tb);
20 end
21
22 // Compare count with what we expect and say which check it was.
23 task check(input [3:0] expected, input [127:0] label);
24 begin
25 if (count !== expected) begin
26 $display("ERROR %0s: expected %0d, got %0d at %0t", label, expected, count, $time);
27 errors = errors + 1;
28 end else begin
29 $display("ok %0s: count = %0d", label, count);
30 end
31 end
32 endtask
33
34 initial begin
35 // Hold reset across two rising edges, then release it on a falling edge.
36 repeat (2) @(posedge clk);
37 @(negedge clk) rst = 0;
38
39 @(posedge clk); #1 check(4'd0, "idle, en=0");
40
41 en = 1;
42 repeat (3) @(posedge clk);
43 #1 check(4'd3, "after 3 clocks");
44
45 en = 0;
46 repeat (2) @(posedge clk);
47 #1 check(4'd3, "held, en=0");
48
49 en = 1;
50 repeat (13) @(posedge clk);
51 #1 check(4'd0, "wrapped past 15");
52
53 rst = 1;
54 @(posedge clk);
55 #1 check(4'd0, "reset to 0");
56
57 if (errors == 0) $display("VULKOS_RESULT: PASS");
58 else $display("VULKOS_RESULT: FAIL (%0d checks failed)", errors);
59 $finish;
60 end
61
62endmoduleThe parts that matter:
counter_en dut (...)creates one counter and wires it to the testbench's own signals. DUT stands for design under test.always #5 clk = ~clk;flips the clock every 5 ns, which makes a 10 ns clock.$dumpfileand$dumpvarsrecord every signal to a waveform file, which you open in Part 5.- The
checktask comparescountwith the value you expect and printsokorERROR. - The last lines print
VULKOS_RESULT: PASSorVULKOS_RESULT: FAIL. Vulkos looks for that line to decide what the run badge says.
The file list tags this one testbench, and the Run button now reads Simulate. With no testbench in the project it read Lint, because there was nothing to simulate with.
Part 4: simulate it#
- 1
Press Simulate
The Terminal tab opens at the bottom. After a few seconds the output appears under the headingVERILATOR OUTPUT. Verilator is the simulator a new project uses.
ok idle, en=0: count = 0
ok after 3 clocks: count = 3
ok held, en=0: count = 3
ok wrapped past 15: count = 0
ok reset to 0: count = 0
VULKOS_RESULT: PASS
- tb/counter_en_tb.v:59: Verilog $finishFive checks, five ok lines, and a pass. The badge beside the Inspect menu reads Passed.

Part 5: look at the waveform#
The verdict tells you it works. The waveform shows you how: every signal drawn against time.
- 1
Open the waves
OpenInspectand choose Open waves in panel. A Waves tab opens beside the Terminal. - 2
Add the signals
Under Scopes, click the arrow besideTOP, then clickcounter_en_tb. Press the + beside the Filter box to add every signal in it.

Follow count along the row. It sits at 0 while rst is high. It goes 1, 2, 3 once en rises, holds at 3 for the two clocks where en drops, then runs up through f (15 in hexadecimal) and wraps to 0. That is the behaviour you wrote.
Part 6: break it on purpose#
A testbench earns its keep when something is wrong. Make a mistake and watch it get caught.
- 1
Add a bug
Insrc/counter_en.v, changecount + 4'd1tocount + 4'd2, so the counter goes up in twos. - 2
Press Simulate again
The Terminal now shows:
ok idle, en=0: count = 0
ERROR after 3 clocks: expected 3, got 6 at 56000
ERROR held, en=0: expected 3, got 6 at 76000
ok wrapped past 15: count = 0
ok reset to 0: count = 0
VULKOS_RESULT: FAIL (2 checks failed)
Each error names the check, the value it wanted, the value it got and the time. After three clocks the count is 6, not 3, which points straight at the adding.
A check can pass by luck
Look atwrapped past 15. It still says ok, because counting in twos from 6 for 13 clocks also lands on 0. One passing check does not prove a design. Several checks that look at it from different sides do.- 3
Put it right
Change4'd2back to4'd1and press Simulate once more. The badge returns to Passed.
Part 7: build the chip#
Now turn the working Verilog into a layout. LibreLane does this in stages: it maps your code to real logic gates (synthesis), places those gates on the silicon, builds the clock wiring, routes every wire, and then checks the result.
- 1
Choose LibreLane
OpenToolsand choose LibreLane. The Run button now reads Run LibreLane. - 2
Press Run LibreLane, then Generate config.json
LibreLane needs a settings file calledconfig.json, and the project does not have one yet. A dialog says so. Press Generate config.json.

Vulkos reads your design and writes the file. These are the lines that describe your counter. The rest are defaults you can leave alone:
1"DESIGN_NAME": "counter_en",
2"VERILOG_FILES": [
3 "dir::src/counter_en.v"
4],
5"CLOCK_PORT": "clk",
6"CLOCK_PERIOD": 20,
7"DIE_AREA": "0 0 161.00 111.52",DESIGN_NAMEis your top module, andVERILOG_FILESlists the design files. The testbench is left out, because it is not part of the chip.CLOCK_PORTis the clock pin.CLOCK_PERIODis the time between ticks you are asking for, in nanoseconds: 20 ns is 50 MHz.DIE_AREAis the size of the silicon in microns: 161 by 111.52, the smallest Tiny Tapeout tile.
- 3
Press Run LibreLane again
The Terminal lists each stage as it finishes: Lint, Synthesis, Floorplanning, Placement, Cts, Routing, Antenna, Timing and the final checks. The badge counts the steps. This run took about a minute and a half. You can keep reading or editing while it goes.
Part 8: read the result#
When the badge reads Completed, new tabs appear beside the Terminal: Problems, Schematic, Layout, Timing, Power and Signoff. Three of them answer the questions that matter.
Is it fast enough? Open Timing.

- Meets timing is the verdict, given for the slowest conditions the chip must work in.
- Setup asks whether a signal gets from one register to the next before the next tick. Slack is the time to spare. A worst slack of 14.17 ns out of a 20 ns period means the slowest path needs under 6 ns, so this counter could run much faster than you asked.
- Hold asks the opposite: that a signal does not change too soon after a tick. It also has time to spare.
Is the layout the circuit you wrote? Open Signoff. It reads Circuits match. That check, layout versus schematic, extracts a circuit back out of the finished layout and compares it with the gates from synthesis.
What does it look like? Open Layout, then press Full screen.

The big rectangle is the die. The cluster at the bottom is your counter: 19 cells joined by 22 nets (a net is one electrical connection). Four of those cells are the registers that hold count, and the panel tells you three more are buffers that carry the clock to them. The logic fills about 2% of the space, which is why most of the die looks empty. Click a wire to light up its whole net, or a cell to see what it does.
That is a chip design
You wrote a circuit, proved it with a testbench, caught a bug with it, and produced a layout that meets timing and matches the design. Every bigger project is the same loop with more Verilog in it.Where to go next#
Try one change and run the loop again:
- Make the counter 8 bits wide: change
[3:0]to[7:0]in both files and4'dto8'd. The testbench will tell you which of its checks no longer hold, and why. - Lower
CLOCK_PERIODinconfig.jsonand see how far the slack shrinks.