PRBS Generator Verilog Code and Test Bench
Advertisement
This page provides the Verilog code for a PRBS (Pseudo-Random Binary Sequence) generator and a corresponding test bench script.
PRBS Generator Verilog Code
The following is the Verilog code for a PRBS generator:
module prbs (rand, clk, reset);
input clk, reset;
output rand;
wire rand;
reg [3:0] temp;
always @ (posedge reset) begin
temp <= 4'hf;
end
always @ (posedge clk) begin
if (~reset) begin
temp <= {temp[0]^temp[1],temp[3],temp[2],temp[1]};
end
end
assign rand = temp[0];
endmodule
Explanation:
- The module
prbshas inputsclk(clock) andreset, and an outputrand(random bit). tempis a 4-bit register that holds the state of the PRBS generator.- The
always @ (posedge reset)block initializes thetempregister to4'hf(1111 in binary) when theresetsignal is asserted (positive edge). - The
always @ (posedge clk)block updates thetempregister on each rising edge of the clock. - The core logic of the PRBS generator is within the
if (~reset)statement. It implements a linear feedback shift register (LFSR) with a specific feedback tap. The next state oftempis derived by XORingtemp[0]andtemp[1]and shifting the bits. - The
assign rand = temp[0]statement assigns the value of the least significant bit oftempto the outputrand. This provides the pseudo-random bit.
PRBS Generator Test Script Code
Here’s the test script code for the PRBS generator:
module main;
reg clk, reset;
wire rand;
prbs pr (rand, clk, reset);
initial begin
forever begin
clk <= 0;
#5 clk <= 1;
#5 clk <= 0;
end
end
initial begin
reset = 1;
#12 reset = 0;
#90 reset = 1;
#12 reset = 0;
end
endmodule
Explanation:
- The
mainmodule instantiates theprbsmodule. clkandresetare declared asregbecause their values are driven by the test bench.randis awirebecause it’s an output from theprbsmodule.- The first
initialblock generates a clock signal with a period of 10 time units (5 for the low phase and 5 for the high phase). - The second
initialblock generates a reset signal. It asserts the reset for 12 time units, de-asserts it for 90 time units, asserts it again for 12 time units, and then de-asserts it again. This provides a couple of reset cycles for testing the PRBS generator.
Explore Verilog Logic Gates, Mux & Encoders
- Verilog HDL Code for All Logic Gates
- 2-to-4 Decoder (Verilog HDL Code)
- 4-to-1 Multiplexer and 1-to-4 Demultiplexer (Verilog Code)
- Verilog Code: 1-to-4 Demultiplexer
- 8-to-1 Multiplexer (Verilog HDL Code)
- 8-to-3 Encoder Without Priority (Verilog)
- 8-to-3 Priority Encoder (Verilog)
- 8-to-3 Priority Encoder (Verilog Code)
- 1-Bit and 4-Bit Comparator Design (Verilog)
Explore Verilog Flip-Flops, Counters & Registers
- T, D, SR, JK Flip Flop (Verilog HDL Code)
- D Flip Flop Synchronous Reset (Verilog)
- D Flip Flop Without Reset (Verilog)
- Verilog Code for Binary Up-Down Counter
- Verilog HDL: BCD & Gray Counters
- 4-bit Down Counter (Verilog Code Test Bench)
- 4-bit Binary Asynchronous Reset Counter (Verilog)
- 4-bit Binary Synchronous Reset Counter (Verilog)
- 4-bit BCD Asynchronous Reset Counter (Verilog)
- 4-bit BCD Synchronous Reset Counter (Verilog Code)
- 4-bit Mod-13 Counter (Verilog Code Test Bench)
- Shift Left / Shift Right Register (Verilog)
- Parallel Load Shift Left Register (Verilog Code)
- PRBS Generator (Verilog Code Test Bench)
Explore Verilog Math, Processing & Memory
- Full Adder (Verilog HDL Code)
- Verilog Code: Half Adder, Half Subtractor, Full Subtractor
- 32-Bit ALU (Verilog Code)
- RAM / ROM (Verilog Code)
- Asynchronous FIFO (Verilog Code Test Bench)
- Asynchronous FIFO Design (Verilog Code and Explanation)
- Mealy / Moore Machine (Verilog)
- Low Pass FIR Filter (Verilog Code)
- 4-bit Binary to Gray Counter Converter in Verilog
