Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

module TestBench ( ) ; reg clk _ enable, reset, CLK; wire [ 1 5 : 0 ] Rand _ out, preset _ 0 2

module TestBench();
reg clk_enable, reset, CLK;
wire [15:0] Rand_out, preset_023;
// Instantiate Main module
Main DUT0(Rand_out, CLK, clk_enable, reset, preset_023);
// Instantiate Lsfr module
Lsfr DUT1(
.clk(CLK),
.reset(reset),
.enable(clk_enable),
.lfsr_out(preset_023)
);
// Clock generation
always begin
#10
CLK =0;
#10
CLK =1;
end
// Initialize inputs
initial begin
clk_enable =0;
reset =0;
#100; // Wait for 100 time units for initialization
// Print Rand_out
$display("Rand_out =%b", Rand_out);
// Finish simulation
$finish;
end
endmodule this the testbench file module Main(
output [15:0] Rand_out,
input clk_enable, reset, preset_023, CLK
);
wire [15:0] Splitter_0_cmb;
wire and_0_out, q_0, q_1, q_2, q_3, q_4, q_5, q_6, q_7, q_8, q_9, q_10, q_11, q_12, q_13, q_14, q_15;
wire xor_0_out, xor_1_out, xor_2_out;
assign and_0_out = clk_enable & CLK;
DflipFlop #(.WIDTH(1)) flip_flop_1(.q(q_1),.q_inv(),.clk(and_0_out),.d(),.a_rst(reset),.pre(),.en(preset_023));
DflipFlop #(.WIDTH(1)) flip_flop_2(.q(q_2),.q_inv(),.clk(and_0_out),.d(q_1),.a_rst(reset),.pre(preset_023),.en());
// Instantiate other D flip-flops similarly
assign Splitter_0_cmb ={q_15, q_14, q_13, q_12, q_11, q_10, q_9, q_8, q_7, q_6, q_5, q_4, q_3, q_2, q_1, q_0};
assign Rand_out = Splitter_0_cmb;
assign xor_0_out = q_13^ q_15;
assign xor_1_out = q_12^ xor_0_out;
assign xor_2_out = q_10^ xor_1_out;
DflipFlop #(.WIDTH(1)) flip_flop_0(.q(q_0),.q_inv(),.clk(and_0_out),.d(xor_2_out),.a_rst(reset),.pre(preset_023),.en());
endmodule this the design.sv module Lsfr(
input clk,
input reset,
input enable,
output reg [15:0] lfsr_out
);
// Internal registers
reg [15:0] lfsr_reg;
always @(posedge clk or posedge reset) begin
if (reset)
lfsr_reg <=16'hFFFF; // Initialize LFSR to all ones when reset is active
else if (enable) begin
// Feedback logic
lfsr_reg[0]<= lfsr_reg[15]^ lfsr_reg[14]^1'b1; // Feedback polynomial: x^16+ x^15+1
// Shift right
lfsr_reg <={lfsr_reg[14:0], lfsr_reg[15]}; // Shift right by 1 bit
end
end
// Output
assign lfsr_out = lfsr_reg;
endmodule lsfr.v module DflipFlop(
output reg q,
input clk,
input a_rst,
input pre,
input en,
input [15:0] d
);
always @ (posedge clk or posedge a_rst)
if (a_rst)
q <=1'b0;
else if (en ==1'b1)
q <= d;
endmodule dflipflop.v can you fix it in verilog using the edaplayground

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions