25 Advanced Verilog Projects
25 Advanced Verilog Projects
25 ADVANCED
VERILOG
PROJECTS
COMPLETE CODE | REAL WORLD PROBLEMS | REUSABLE
SNIPPETS | OPTIMIZED FOR FPGA & ASIC
Prasanthi Chanda
Q1. 5-Stage Pipeline Instruction Fetch Stage (IF Stage)
module IF_stage (
input clk,
input reset,
input [31:0] pc_in,
output reg [31:0] pc_out,
output reg [31:0] instruction
);
initial begin
instr_mem[0] = 32'h00000013; // NOP (addi
x0,x0,0)
instr_mem[1] = 32'h00100093; // addi x1,x0,1
instr_mem[2] = 32'h00200113; // addi x2,x0,2
instr_mem[3] = 32'h00308193; // addi x3,x1,3
instr_mem[4] = 32'h00410213; // addi x4,x2,4
// ... fill rest with NOP
instr_mem[5] = 32'h00000013;
instr_mem[6] = 32'h00000013;
instr_mem[7] = 32'h00000013;
instr_mem[8] = 32'h00000013;
instr_mem[9] = 32'h00000013;
instr_mem[10] = 32'h00000013;
instr_mem[11] = 32'h00000013;
instr_mem[12] = 32'h00000013;
instr_mem[13] = 32'h00000013;
instr_mem[14] = 32'h00000013;
instr_mem[15] = 32'h00000013;
end
// Address handshake
if(!awready && awvalid)
awready <= 1;
else
awready <= 0;
// UART TX FSM
reg [3:0] bit_idx = 0;
reg [9:0] shift_reg = 10'b1111111111; // start(0),
data(8), stop(1)
always @(posedge clk) begin
if(reset) begin
tx <= 1;
tx_busy <= 0;
bit_idx <= 0;
shift_reg <= 10'b1111111111;
end else if(baud_tick) begin
if(tx_busy) begin
tx <= shift_reg[0];
shift_reg <= {1'b1, shift_reg[9:1]};
if(bit_idx == 9) begin
tx_busy <= 0;
bit_idx <= 0;
end else
bit_idx <= bit_idx + 1;
end else if(tx_start) begin
shift_reg <= {1'b1, tx_data, 1'b0}; // stop bit =1,
data bits, start bit=0
tx_busy <= 1;
end else
tx <= 1; // idle high
end
end
endmodule
Q5. Power-Efficient Clock Gating Module (Simple
Enable-Based)
module clock_gating (
input clk,
input enable,
output gated_clk
);
reg gated_clk_reg;
always @(posedge clk) begin
gated_clk_reg <= enable;
end
assign gated_clk = clk & gated_clk_reg;
endmodule
endmodule
endmodule
Q15. Problem Statement: 8-bit Arithmetic Logic Unit
(ALU)
module alu (
input [7:0] a, b,
input [2:0] sel,
output reg [7:0] y
);
always @(*) begin
case(sel)
3'b000: y = a + b;
3'b001: y = a - b;
3'b010: y = a & b;
3'b011: y = a | b;
3'b100: y = a ^ b;
3'b101: y = ~a;
3'b110: y = a << 1;
3'b111: y = a >> 1;
endcase
end
endmodule
Q16. Problem Statement: N-bit Barrel Shifter
module barrel_shifter #(
parameter N = 8
)(
input [N-1:0] data_in,
input [$clog2(N)-1:0] shift_amt,
input dir, // 0 = left, 1 = right
output reg [N-1:0] data_out
);
always @(*) begin
if (dir == 0)
data_out = data_in << shift_amt;
else
data_out = data_in >> shift_amt;
end
endmodule
Q17. Problem Statement: Parity Generator and Checker
module parity_gen_check (
input [7:0] data_in,
input parity_bit, // received parity
output reg parity_gen,
output reg error
);
always @(*) begin
parity_gen = ^data_in; // Even parity
error = (parity_gen != parity_bit);
end
endmodule
endmodule
module priority_encoder (
input [7:0] in,
output reg [2:0] out,
output reg valid
);
always @(*) begin
valid = 1;
casex(in)
8'b1xxxxxxx: out = 3'b111;
8'b01xxxxxx: out = 3'b110;
8'b001xxxxx: out = 3'b101;
8'b0001xxxx: out = 3'b100;
8'b00001xxx: out = 3'b011;
8'b000001xx: out = 3'b010;
8'b0000001x: out = 3'b001;
8'b00000001: out = 3'b000;
default: begin out = 3'b000; valid = 0; end
endcase
end
endmodule
always @(*)
if (wr_en)
mem[wr_addr] = wr_data;
endmodule
Q24. Problem Statement: N-bit Carry-Save Adder (CSA)
module carry_save_adder #(
parameter N = 8
)(
input [N-1:0] a, b, c,
output [N-1:0] sum,
output [N-1:0] carry
);
assign sum = a ^ b ^ c;
assign carry = (a & b) | (b & c) | (c & a);
endmodule
Q25. Problem Statement: Signed Multiplier (4-bit
Booth’s Algorithm)
module booth_multiplier (
input clk,
input start,
input signed [3:0] multiplicand,
input signed [3:0] multiplier,
output reg signed [7:0] product,
output reg done
);
reg signed [7:0] A, S, P;
reg [2:0] count;
always @(posedge clk) begin
if (start) begin
A = {multiplicand, 4'b0000};
S = {-multiplicand, 4'b0000};
P = {4'b0000, multiplier, 1'b0};
count = 4;
done = 0;
end else if (count > 0) begin
case (P[1:0])
2'b01: P = P + A;
2'b10: P = P + S;
endcase
P = P >>> 1;
count = count - 1;
end else begin
product = P[7:0];
done = 1;
end
end
endmodule
Excellence in World class
VLSI Training & Placements
+91- 9182280927