Question

In: Electrical Engineering

I am trying to create an 8-bit random number generator in verilog code using a mux,...

I am trying to create an 8-bit random number generator in verilog code using a mux, a d flip flop and a LFSR not sure what I am doing wrong but need some help with getting it working properly any help would be greatly appreciated.

here is what I have so far:

module RNG #(parameter size=8)(output [7:0]SO,output [7:0] RN,input clk,rst,input[size-1:0]seed,input L);
   wire [7:0] Sin=SO[7]^SO[5]^SO[4]^SO[3];
   ffw F1 (SO,clk,rst,Sin);
   MUX M1 (Sin,seed,{SO[size-2:0],next},L);
   xor X1 (next,SO[6],SO[7]);
   assign RN=next;
endmodule
module ffw #(parameter size=8)(output reg [size-1:0]SO,input clk,rst,input [size-1:0] Sin);
   always @(posedge clk or posedge rst)
       begin
       if(rst==1)
           SO=0;
       else
           SO=Sin;
       end
endmodule
// input A1 = Seed, input B0 =Sin ,L=SEL,
module MUX #(parameter size=8)(output[size-1:0]SO,input[size-1:0]Sin,seed,input L);
   assign SO = (L) ? Sin:seed;
endmodule
module RNG_TB();
   reg clk;
   reg rst,L;
   wire [7:0] SO;
   reg [7:0] seed;
   wire [7:0] RN;
   integer x;
   RNG RN1 (SO,RN,clk,rst,seed,L);
   initial begin
       x=0; clk=0; rst=1; L=0; #5;
       rst=0; L=0; seed=255; #5;
       rst=0; L=1; seed=255; clk=1; #5
       L=0;
       repeat (10) begin
           clk = ~clk; #10;
           x=x+1;
           $display("x=%d,clk=%d,SO=%b",x,clk,SO);
           clk = ~clk; #10;
       end
   end
endmodule

Solutions

Expert Solution

//You are assigning Sin at two places.

//Sin=SO[7]^SO[5]^SO[4]^SO[3];

// And at mux instance. I removed one. If you need some other Design let me know. Now it's working. And at mux I changed look at mux assign statement.


module RNG #(parameter size=8)(output [7:0]SO,output [size-1:0]RN,input clk,rst,input[size-1:0]seed,input L);
wire [7:0] Sin;//=SO[7]^SO[5]^SO[4]^SO[3];
ffw F1 (SO,clk,rst,Sin);
MUX M1 (Sin,{SO[size-2:0],next},seed,L);
xor X1 (next,SO[6],SO[7]);
assign RN=next;
endmodule
module ffw #(parameter size=8)(output reg [size-1:0]SO,input clk,rst,input [size-1:0] Sin);
always @(posedge clk or posedge rst)
begin
if(rst==1)
SO <= 0;
else
SO <= Sin;
end
endmodule
// input A1 = Seed, input B0 =Sin ,L=SEL,
module MUX #(parameter size=8)(output[size-1:0]SO,input[size-1:0]Sin,seed,input L);
assign SO = (L) ? seed:Sin; // changed here to get output correct
endmodule

module RNG_TB();
reg clk;
reg rst,L;
wire [7:0] SO;
reg [7:0] seed;
wire [7:0] RN;
integer x;
RNG RN1 (SO,RN,clk,rst,seed,L);
initial begin
$dumpfile("dump.vcd"); $dumpvars;
x=0; clk=0; rst=1; L=0; #5;
rst=0; L=0; seed=255; #5;
rst=0; L=1; seed=255; clk=1; #5
L=0;
repeat (10) begin
clk = ~clk; #10;
x=x+1;
$display("x=%d,clk=%d,SO=%b",x,clk,SO);
clk = ~clk; #10;
end
end
endmodule


Related Solutions

code an 8 bit LFSR random number generator in system verilog. Write a test bench, load...
code an 8 bit LFSR random number generator in system verilog. Write a test bench, load the seed 11111111, and generate the first 10 random numbers.
I am trying to write the code for an 8 bit adder in VHDL so that...
I am trying to write the code for an 8 bit adder in VHDL so that I can program it onto my Elbert V2 Spartan 3A FPGA Development Board, but I keep getting errors. Any ideas what I am doing wrong? library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity adder8bit is Port ( a : in STD_LOGIC_VECTOR(7 downto 0); b : in STD_LOGIC_VECTOR(7 downto 0); cin : in STD_LOGIC; o : out STD_LOGIC_VECTOR(7 downto 0); cout : out STD_LOGIC); end adder8bit; architecture Behavioral...
1.Write verilog code for a 8:1 Mux using the blocks of 2:1 Mux; Draw the block...
1.Write verilog code for a 8:1 Mux using the blocks of 2:1 Mux; Draw the block diagram for this design and write the truth table to prove that the design works as intended. 2. Write verilog code for a 16:1 Mux using the blocks of 4:1 Mux; Draw the block diagram for this design and write the truth table to prove that the design works as intended.
Design an 8-bit adder. Show Verilog code and testbench.
Design an 8-bit adder. Show Verilog code and testbench.
Design a 32 bit after using a single 4 bit using verilog code
Design a 32 bit after using a single 4 bit using verilog code
Design a 32 bit adder using a single 4 bit adder using verilog code
Design a 32 bit adder using a single 4 bit adder using verilog code
Please Create the Verilog/Vivado Code For: An LFSR Pseudonumber generator, and the testbench for test it,...
Please Create the Verilog/Vivado Code For: An LFSR Pseudonumber generator, and the testbench for test it, please comment and explain the answer as much as possible if possible, post Pic of the waveform simulation!
Please Create the Verilog/Vivado Code For: An LFSR Pseudonumber generator, and the testbench for test it,...
Please Create the Verilog/Vivado Code For: An LFSR Pseudonumber generator, and the testbench for test it, please comment and explain the answer as much as possible waveform simulation answer would be nice too!
Please Create the Verilog/Vivado Code For: An LFSR Pseudonumber generator, and the testbench for test it,...
Please Create the Verilog/Vivado Code For: An LFSR Pseudonumber generator, and the testbench for test it, please comment and explain the answer as much as possible!
Please Create the Verilog/Vivado Code For: An LFSR Pseudonumber generator, and the testbench for test it,...
Please Create the Verilog/Vivado Code For: An LFSR Pseudonumber generator, and the testbench for test it, please comment and explain the answer as much as possible,(Make your own code, even it is more simple, but do not copy from others sources on the internet) if possible, post Pic of the waveform simulation!
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT