📖 Scenario: You are designing a simple digital circuit using Verilog. You want to understand how your code behaves during simulation and how it will be interpreted during synthesis to hardware.This project will help you see the difference between simulation-only constructs and synthesis-friendly code.
🎯 Goal: Build a Verilog module that uses a simulation-only construct and a synthesis-compatible construct. Then observe the output during simulation and understand what will be synthesized.
📋 What You'll Learn
Create a Verilog module with a register and a wire
Add a simulation-only initial block to set the register
Add a synthesis-compatible always block to update the register
Print the register value during simulation
💡 Why This Matters
🌍 Real World
Understanding the difference between simulation-only code and synthesisable code is crucial when designing digital circuits to ensure your design works correctly in simulation and can be implemented in hardware.
💼 Career
Digital design engineers and FPGA developers must write Verilog code that simulates correctly and synthesizes to hardware. Knowing which constructs are simulation-only helps avoid bugs and synthesis errors.
Progress0 / 4 steps
1
Create the basic Verilog module with a register and a wire
Write a Verilog module named sim_vs_syn with an input clock clk, a register reg_val of 8 bits, and a wire wire_val of 8 bits.
Verilog
Hint
Define a module with input clk, an 8-bit register reg_val, and an 8-bit wire wire_val.
2
Add a simulation-only initial block to set the register
Add an initial block that sets reg_val to 8'hAA at the start of simulation.
Verilog
Hint
Use an initial block to assign reg_val the value 8'hAA at simulation start.
3
Add a synthesis-compatible always block to update the register
Add an always @(posedge clk) block that increments reg_val by 1 on each clock rising edge.
Verilog
Hint
Use an always @(posedge clk) block to increment reg_val by 1 on each clock.
4
Print the register value during simulation
Add an always @(posedge clk) block that uses $display to print the current value of reg_val during simulation.
Verilog
Hint
Use $display inside an always @(posedge clk) block to print reg_val in hexadecimal.
Practice
(1/5)
1. What is the main purpose of simulation in Verilog?
easy
A. To convert the design into physical hardware
B. To check how the design behaves over time step-by-step
C. To write the final hardware layout
D. To optimize the hardware speed automatically
Solution
Step 1: Understand simulation role
Simulation runs the design in a virtual environment to see how it behaves over time.
Step 2: Compare with synthesis role
Synthesis is about creating hardware, not checking behavior step-by-step.
Final Answer:
To check how the design behaves over time step-by-step -> Option B
Quick Check:
Simulation = behavior check [OK]
Hint: Simulation means testing behavior over time, not hardware creation [OK]
Common Mistakes:
Confusing synthesis with simulation
Thinking simulation creates hardware
Believing simulation optimizes hardware
2. Which of the following is a correct Verilog syntax for a simple always block used in simulation?
easy
A. always @(posedge clk) begin count = count + 1; end
B. always posedge clk { count = count + 1; }
C. always @(clk) count <= count + 1;
D. always #10 count = count + 1
Solution
Step 1: Check correct always block syntax
The correct syntax uses 'always @(posedge clk) begin ... end' with proper parentheses and keywords.
Step 2: Identify syntax errors in other options
always posedge clk { count = count + 1; } uses braces and wrong syntax; C uses wrong sensitivity list; D uses delay but lacks begin-end block.
Final Answer:
always @(posedge clk) begin count = count + 1; end -> Option A
Quick Check:
Correct always block syntax = always @(posedge clk) begin count = count + 1; end [OK]
Hint: Always blocks use @(event) with begin-end for multiple statements [OK]
Common Mistakes:
Using braces {} instead of begin-end
Wrong sensitivity list syntax
Missing begin-end for multiple statements
3. Given this Verilog code snippet used in simulation: