I am currently learning Verilog and trying to make a PRBS generator in Verilog. While doing that, I have tried different combinations as shown in the code and pictures below. Later on, I have to put it on an Artix A7 FPGA. I'll add a clock frequency divider circuit later on for the PRBS to show on a speed perceivable to human eye.
Which one is better for real life implementation? I am sure that due to reasons like space, time, energy or some other reason, one will be preferable over other.
Configurations are like
- Output is register and has non-blocking assignment to it
module prbs_gen(clk, prbs);
input clk;
output reg prbs;
reg[31:0] temp = 32'b11010101110101011101010111010101;
reg x;
always @(posedge clk)
begin
prbs <= temp[0];
x = temp[1]^temp[0];
temp = temp >> 1;
temp[31] = x;
end
endmodule
- Output is reg but has blocking assignment to it, inside always block
module prbs_gen(clk, prbs);
input clk;
output reg prbs;
reg[31:0] temp = 32'b11010101110101011101010111010101;
reg x;
always @(posedge clk)
begin
prbs = temp[0];
x = temp[1]^temp[0];
temp = temp >> 1;
temp[31] = x;
end
endmodule
- Output is reg and blocking assignment with "assign" keyword inside "always" block
module prbs_gen(clk, prbs);
input clk;
output reg prbs;
reg[31:0] temp = 32'b11010101110101011101010111010101;
reg x;
always @(posedge clk)
begin
assign prbs = temp[0];
x = temp[1]^temp[0];
temp = temp >> 1;
temp[31] = x;
end
endmodule
- Output type isn't specified, but the blocking assignment is out of the "always" block
module prbs_gen(clk, prbs);
input clk;
output prbs;
reg[31:0] temp = 32'b11010101110101011101010111010101;
reg x;
assign prbs = temp[0];
always @(posedge clk)
begin
x = temp[1]^temp[0];
temp = temp >> 1;
temp[31] = x;
end
endmodule
- Output is reg and non-blocking assignment to it in "always" block
module prbs_gen(clk, prbs);
input clk;
output reg prbs;
reg[31:0] temp = 32'b11010101110101011101010111010101;
reg x;
always @(posedge clk)
begin
prbs <= temp[0];
x = temp[1]^temp[0];
temp = temp >> 1;
temp[31] = x;
end
endmodule
Common testbench code
module tb();
reg clk;
wire prbs;
prbs_gen uut(clk, prbs);
initial clk = 0;
always #5 clk = ~clk;
endmodule
Codes with waveforms below.
assign
inalways
? \$\endgroup\$