Learn Verilog
Verilog basics
Learn Verilog
Build a practical foundation in digital design, simulation, and self-checking testbenches.
What you will learn
Work through the lessons in order. Each lesson introduces one idea, shows a focused example, explains the important lines, and gives you a practical exercise.
Start with the learning path
Verilog describes hardware behavior. You will learn how modules, signals, combinational logic, sequential logic, and testbenches work together before moving into SystemVerilog and UVM.
Lesson 5 of 7: Sequential Logic
Model state that changes at a clock edge, including reset behavior.
module counter (
input wire clk, reset,
output reg [3:0] count
);
always @(posedge clk) begin
if (reset)
count <= 4'b0000;
else
count <= count + 1'b1;
end
endmodule
What to notice
- posedge clk runs the block at each rising clock edge.
- When reset is high, the counter returns to zero.
- Otherwise the counter increments by one.
Practice: Add an enable input so count holds its value while enable is low.
How to study each lesson
- Read the concept before copying the example.
- Predict the output or waveform before running the simulator.
- Change one input, parameter, or statement and observe the result.
- Use a self-checking assertion or comparison whenever possible.
- Keep the smallest working example as evidence for the next lesson.