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

80.2K

Verified Solution

Question

Electrical Engineering

I am trying to create an 8-bit random number generator inverilog code using a mux, a d flip flop and a LFSR not sure what Iam doing wrong but need some help with getting it working properlyany 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,inputclk,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 #(parametersize=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

Answer & Explanation Solved by verified expert
4.1 Ratings (606 Votes)
You are assigning Sin at two placesSinSO7SO5SO4SO3 And at mux instance I removed one If you need    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students