Question

How do I create a testbench with the verilog code below? module ganada(Clk, U1, D2, U2,...

How do I create a testbench with the verilog code below?

module ganada(Clk, U1, D2, U2, D3, U3, D4, F1, F2, F3, F4, CF, S);

input Clk, U1, D2, U2, D3, U3, D4, F1, F2, F3, F4;
output [6:0] CF, S;
reg [6:0] CF, S;
reg [1:0] SS, B, NS;

initial begin
NS=2'b00; SS=2'b00;
end
always@(posedge Clk) begin   
case(NS)   
2'b00: CF=7'b1111001;
2'b01: CF=7'b0100100;
2'b10: CF=7'b0110000;
2'b11: CF=7'b0011001;
endcase

case(SUD)
2'b00: S=7'b1000000;   
2'b01: S=7'b1111001;
2'b10: S=7'b0100100;
default: S=7'b0000000;
endcase

if(U1==1 || F1==1) begin
B=2'b00;
end

if(D2==1 || U2==1 || F2==1) begin
B=2'b01;
end

if(D3==1 || U3==1 || F3==1) begin
B=2'b10;
end

if(D4==1 || F4==1) begin
B=2'b11;
end

if(NS==B) begin
SS=2'b00;
end

else if(NS<B) begin
SS=2'b01;
end

else if(NS>B) begin
SS=2'b10;
end

if(SS==2'b01) begin

if(NS<B) begin
SS=2'b01;
end

else if(NS==B) begin
SS=2'b00;
end
end

if(SS==2'b10) begin

if(NS>B) begin
SS=2'b10;
end

else if(NS==B) begin
SS=2'b00;
end
end


if(SS==2'b00) begin
NS=NS;
end

else if(SS==2'b01) begin
NS=NS+1;
end

else if(SS==2'b10) begin
NS=NS-1;
end

end
endmodule

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Given code has a syntax mistake so code modified as below;

module ganada(Clk, U1, D2, U2, D3, U3, D4, F1, F2, F3, F4, CF, S);

input Clk, U1, D2, U2, D3, U3, D4, F1, F2, F3, F4;

output [6:0] CF, S;

reg [6:0] CF, S;

reg [1:0] SS, B, NS;

initial begin

NS=2'b00; SS=2'b00;

end

always@(posedge Clk) begin

case(NS)

2'b00: CF=7'b1111001;

2'b01: CF=7'b0100100;

2'b10: CF=7'b0110000;

2'b11: CF=7'b0011001;

endcase

// in sensitivity list of given code u mentioned SUD which is not at all defined,and as per logic i understand here internal register SS is defined in case statement sensitivity list.

case(SS)

2'b00: S=7'b1000000;

2'b01: S=7'b1111001;

2'b10: S=7'b0100100;

default: S=7'b0000000;

endcase

if(U1==1 || F1==1) begin

B=2'b00;

end

if(D2==1 || U2==1 || F2==1) begin

B=2'b01;

end

if(D3==1 || U3==1 || F3==1) begin

B=2'b10;

end

if(D4==1 || F4==1) begin

B=2'b11;

end

if(NS==B) begin

SS=2'b00;

end

else if(NS<B) begin

SS=2'b01;

end

else if(NS>B) begin

SS=2'b10;

end

if(SS==2'b01) begin

if(NS<B) begin

SS=2'b01;

end

else if(NS==B) begin

SS=2'b00;

end

end

if(SS==2'b10) begin

if(NS>B) begin

SS=2'b10;

end

else if(NS==B) begin

SS=2'b00;

end

end

if(SS==2'b00) begin

NS=NS;

end

else if(SS==2'b01) begin

NS=NS+1;

end

else if(SS==2'b10) begin

NS=NS-1;

end

end

endmodule

//verilog testbench code for given module

module testbench;

// input and output declarations

reg Clk, U1, D2, U2, D3, U3, D4, F1, F2, F3, F4;

wire [6:0] CF, S;

  

// instantiate device under test (DUT)

ganada DUT (Clk, U1, D2, U2, D3, U3, D4, F1, F2, F3, F4, CF, S);

  

// clock defined with 10 ns period

initial begin

Clk =0;

forever #5 Clk=~Clk;

end

  

// random input stimuli given in below block( all inputs are applied in some of different cases with different values)

initial begin

$dumpfile ("dump.vcd");

$dumpvars;

U1 = 0; D2=0; U2=0;D3=0;U3=0;

D4=0; F1=0; F2=0;F3=0; F4=0;#5;

U1 = 0; D2=1; U2=0;D3=1;U3=0;

D4=0; F1=0; F2=0;F3=0; F4=0;#5;

U1 = 0; D2=0; U2=1;D3=0;U3=1;

D4=0; F1=1; F2=0;F3=0; F4=0;#5;

U1 = 0; D2=0; U2=1;D3=1;U3=0;

D4=1; F1=1; F2=1;F3=1; F4=1;#5;

U1 = 1; D2=1; U2=1;D3=1;U3=1;

D4=0; F1=1; F2=0;F3=0; F4=1;#5;

U1 = 1; D2=1; U2=0;D3=1;U3=0;

D4=1; F1=0; F2=1;F3=0; F4=1;#5;

U1 = 1; D2=0; U2=1;D3=0;U3=1;

D4=0; F1=1; F2=0;F3=1; F4=1;#5;

U1 = 0; D2=1; U2=0;D3=1;U3=0;

D4=1; F1=0; F2=0;F3=0; F4=0;#5;

U1 = 1; D2=1; U2=1;D3=1;U3=1;

D4=1; F1=0; F2=1;F3=0; F4=0;#5;

U1 = 0; D2=0; U2=0;D3=0;U3=0;

D4=1; F1=1; F2=1;F3=1; F4=1;

  

#5 $finish;

end

endmodule

// Simulation waveforms

From: Ons To: 50ns Get Signals Radix 100% 2ns 30 20 110000 CF6:0 xxx xxxxxx 1111001 h00100 11001 Cik D2 D3 D4 0 F1 0 F2 F3 F4

Add a comment
Know the answer?
Add Answer to:
How do I create a testbench with the verilog code below? module ganada(Clk, U1, D2, U2,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Given the following verilog code, draw the corresponding state diagram for it. module mysterious (input reset,...

    Given the following verilog code, draw the corresponding state diagram for it. module mysterious (input reset, clk, TB, TA, output reg [1:0] LB, LA); reg [1:0] cstate, nstate; parameter S0 = 2'b00; parameter S1 = 2'b01; parameter S2 = 2'b10; parameter S3 = 2'b11; parameter grn = 2'b00; parameter ylw = 2'b01; parameter rd = 2'b10; // state register always @ (posedge clk, posedge reset) begin if (reset) cstate <= S0; else cstate <= nstate; end // next state logic...

  • 3. Answer the question below for the following code. module Shift_Register8 (Q, Data_in, Clk, Load, Shift_left,...

    3. Answer the question below for the following code. module Shift_Register8 (Q, Data_in, Clk, Load, Shift_left, Shift_right); output [ 7:0] Q; reg [7:0] Q; input [7:0] Data_in; input Clk, Load, Shift_left, Shift_right; always @ (posedge Clk) if (Load) Q<= Data_in; else case ( { Shift_left, Shift_right }) 2'600: if (Clk == 1) Q<=Q; 2'b01: if (Clk == 1) Q<= >> 1; 2'b10: if (Clk == 1) Q<=Q<< 1; default: Q<=Q; endcase endmodule a) What does reg (7:0] Q do? b)...

  • Answer the question below for the following code, What does reg (7:0) do? What does always...

    Answer the question below for the following code, What does reg (7:0) do? What does always @ (posedge Cik) do? C What causes 2"b01: if (Clk 1) Q<= >> 1 to execute? When it executes, what does it do module Shift_Register (Q, Data_in, Clk, Load, Shift_left, Shift_right); output [ 7:0] Q; reg [7:0] Q, input (7:0) Data_in; input Clk, Load, Shift_left, Shift_right; always @ (posedge Clk) if (Load) Q<Data_in; else case ( { Shift_left, Shift_right)) 2'600: if (Clk - 1)...

  • I need help writing a test bench for the following Verilog code module CU(IE, WE, WA,...

    I need help writing a test bench for the following Verilog code module CU(IE, WE, WA, RAE, RAA, RBE, RBA, ALU,                SH, OE, start, clk, reset, Ng5); //nG5 denotes (N>5);    input start, clk, reset;    output IE, WE, RAE, RBE, OE;    output [1:0] WA, RAA, RBA, SH;    output [2:0] ALU;       input wire Ng5;    reg [1:0] state;    reg [1:0] nextstate;    parameter S0 = 3'b000;    parameter S1 = 3'b001;...

  • Modify the Moore FSM below to detect the sequence "110" , simulate using the same test...

    Modify the Moore FSM below to detect the sequence "110" , simulate using the same test bench and create a Moore Transition Diagram for the new sequence 110. module moore_seq (    input clock, reset, x,    output reg z ); //assign binary encoded codes to the states A through D parameter    A = 2'b00,    B = 2'b01,    C = 2'b10,    D = 2'b11; reg [1 : 0] current_state, next_state; //Section 1: Next state generator (NSG)...

  • I am making a 4-bit universal shift register that can perform right shift, left shift, and...

    I am making a 4-bit universal shift register that can perform right shift, left shift, and parallel loading using 4-to-1 multiplexers in VHDL. I keep getting red lines for u3, u2, u1, u0. The error says the following below. What is wrong with my code? How can I fix it? librarviees, use ieee.std_logic_1164.all; entity uni shift.reg.is porti 1 : in std. Jogis vector (3 downto.0); I, w, clock : in std logici 9: buffer std. Jogis vector (3 downto 0));...

  • on calculations can i see how did the expect come to the solution ,all the workout...

    on calculations can i see how did the expect come to the solution ,all the workout should be included QUESTION 1 A file of size F = 8 Gbits needs to be distributed to10 peers. Suppose the server has an upload rate of u = 68 Mbps, and that the 10 peers have upload rates of: u1 = 20 Mbps, u2 = 22 Mbps, u3 = 12 Mbps, u4 = 19 Mbps, u5 = 25 Mbps, u6 = 24 Mbps,...

  • Below is my code please help me edit it so in the beginning it ask for Press any key to start Tas...

    below is my code please help me edit it so in the beginning it ask for Press any key to start Task n, where n is the task number (1, 2, or 3,4). I already wrote the code for the 4 task. Also please write it so when 1 code is finish running it return to the prompt where it ask to run another task #task 1 list1 = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','.',',','?'] morse = ['.-','-...','-.-.','-..','.','..-.','--.','....','..','.---','-.-','.-..','--','-.','---','.--.','--.-','.-.','...','-','..-','...-','.--','-..-','-.--','--..','-----','.----','..---','...--','....-','.....','-....','--...','---..','----.','.-.-.-','--..--','..--..'] inp = input("Enter original text : ")...

  • This is for a Unix class. Please help me out. I am attaching a skeletal code of the program below, it just needs ti be filled in. Below is a skeletal code of the program. Fork a child process...

    This is for a Unix class. Please help me out. I am attaching a skeletal code of the program below, it just needs ti be filled in. Below is a skeletal code of the program. Fork a child process and then use the parent for reading and the child for writing.  This is just a way of sending and receiving messages asynchronously. /* ************************************************************* * Utility functions * ************************************************************** */ static void usageError(const char * progName, const char *msg) {...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT