Verilog Programming: Simulation vs Synthesis
1. What is Simulation in Verilog?
Simulation is the process of verifying the functionality of your Verilog code before implementing it in
hardware.
- Purpose: Check logic correctness, visualize waveforms, debug early design errors.
- Tools: ModelSim, Icarus Verilog, Vivado Simulator.
- Example: Simulating a 4-bit counter to verify count sequence using a testbench.
2. What is Synthesis in Verilog?
Synthesis converts Verilog code into a gate-level netlist for real hardware (FPGA or ASIC).
- Purpose: Convert RTL to gates, optimize area/power/speed, generate bitstream.
- Tools: Xilinx Vivado, Intel Quartus, Synopsys Design Compiler.
3. Real-Time Example: 4-bit Up Counter
Verilog Code:
module up_counter(input clk, input reset, output reg [3:0] count);
always @(posedge clk or posedge reset)
if (reset) count <= 0;
else count <= count + 1;
endmodule
Page 1
Verilog Programming: Simulation vs Synthesis
Testbench:
module tb_up_counter;
reg clk; reg reset; wire [3:0] count;
up_counter uut (.clk(clk), .reset(reset), .count(count));
always #5 clk = ~clk;
initial begin
$dumpfile("counter.vcd");
$dumpvars(0, tb_up_counter);
clk = 0; reset = 1; #10 reset = 0; #100 $finish;
end
endmodule
4. Simulation Flow
1. Write design and testbench code.
2. Compile with Icarus Verilog: iverilog -o sim.vvp design.v testbench.v
3. Run: vvp sim.vvp
4. View waveforms: gtkwave counter.vcd
5. Synthesis Flow in Vivado
1. Create Vivado Project.
Page 2
Verilog Programming: Simulation vs Synthesis
2. Add RTL sources and constraints (.xdc).
3. Run Synthesis and Implementation.
4. Generate Bitstream and Program FPGA.
6. Testbench Flow
- Instantiate the DUT (Design Under Test).
- Generate clock using always block.
- Stimulate inputs in initial block.
- Use $dumpfile and $dumpvars for waveform.
- Use $finish to end simulation.
7. Synthesizable vs Non-Synthesizable Constructs
Synthesizable: assign, always @(posedge clk), for (fixed), reg, wire.
Non-Synthesizable: $display, #delays, initial blocks, infinite loops.
8. Summary Flow
1. Write RTL Design
2. Write Testbench
3. Run Simulation and Debug
Page 3
Verilog Programming: Simulation vs Synthesis
4. Synthesize and Implement
5. Generate Bitstream
6. Program FPGA Device
Page 4