EDAboard.com | EDAboard.de | EDAboard.co.uk | WTWH Media

What is tut1 for here?

Ask a question - edaboard.com

elektroda.net NewsGroups Forum Index - Verilog Language - What is tut1 for here?

Robert Willy
Guest

Fri May 05, 2017 9:48 pm   



Hi,
I am new to verilog. I don't find an answer for 'tut1' in the testbench.

tutorial tut1(.led(leds),.swt(switches));


Could you help me out?


thanks,


,,,,,,,,,,,,,,,,,,,,,,,,

module tutorial_tb(

);

reg [7:0] switches;
wire [7:0] leds;
reg [7:0] e_led;

integer i;

tutorial tut1(.led(leds),.swt(switches));

function [7:0] expected_led;
input [7:0] swt;
begin
expected_led[0] = ~swt[0];
expected_led[1] = swt[1] & ~swt[2];
expected_led[3] = swt[2] & swt[3];
expected_led[2] = expected_led[1] | expected_led[3];
expected_led[7:4] = swt[7:4];
end
endfunction

initial
begin
for (i=0; i < 255; i=i+2)
begin
#50 switches=i;
#10 e_led = expected_led(switches);
if(leds == e_led)
$display("LED output matched at", $time);
else
$display("LED output mis-matched at ",$time,": expected: %b, actual: %b", e_led, leds);
end
end

endmodule
............

`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Module Name: tutorial
//////////////////////////////////////////////////////////////////////////////////


module tutorial(
input [7:0] swt,
output [7:0] led
);

assign led[0] = ~swt[0];
assign led[1] = swt[1] & ~swt[2];
assign led[3] = swt[2] & swt[3];
assign led[2] = led[1] | led[3];

assign led[7:4] = swt[7:4];

endmodule

Gabor
Guest

Sat May 06, 2017 12:09 am   



On Friday, 5/5/2017 3:48 PM, Robert Willy wrote:
Quote:
Hi,
I am new to verilog. I don't find an answer for 'tut1' in the testbench.

tutorial tut1(.led(leds),.swt(switches));


Could you help me out?


thanks,


,,,,,,,,,,,,,,,,,,,,,,,,

module tutorial_tb(

);

reg [7:0] switches;
wire [7:0] leds;
reg [7:0] e_led;

integer i;

tutorial tut1(.led(leds),.swt(switches));

function [7:0] expected_led;
input [7:0] swt;
begin
expected_led[0] = ~swt[0];
expected_led[1] = swt[1] & ~swt[2];
expected_led[3] = swt[2] & swt[3];
expected_led[2] = expected_led[1] | expected_led[3];
expected_led[7:4] = swt[7:4];
end
endfunction

initial
begin
for (i=0; i < 255; i=i+2)
begin
#50 switches=i;
#10 e_led = expected_led(switches);
if(leds == e_led)
$display("LED output matched at", $time);
else
$display("LED output mis-matched at ",$time,": expected: %b, actual: %b", e_led, leds);
end
end

endmodule
...........

`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Module Name: tutorial
//////////////////////////////////////////////////////////////////////////////////


module tutorial(
input [7:0] swt,
output [7:0] led
);

assign led[0] = ~swt[0];
assign led[1] = swt[1] & ~swt[2];
assign led[3] = swt[2] & swt[3];
assign led[2] = led[1] | led[3];

assign led[7:4] = swt[7:4];

endmodule


tut1 is just the instance name. In Verilog, when you instantiate a
module you are required to assign it a unique instance name. This
is used for hierarchical names so your test bench can access code
outside its own context. In your case, the "tutorial" module has
no internal signals defined, so hierarchical names are not very
useful. However imagine that it had some internal signal like:

reg [3:0] foo; // this would be inside tutorial module

Then your testbench could access that register like:

$display ("foo equals %d", tut1.foo); // this would be in tutorial_tb

It's common in testbench code to use a name like UUT
(unit under test) as the instance name for the module
being tested. However the instance name has no special
meaning. It just needs to be unique and not a reserved
word.

--
Gabor

Robert Willy
Guest

Sat May 06, 2017 2:42 am   



On Friday, May 5, 2017 at 6:09:17 PM UTC-4, Gabor wrote:
Quote:
On Friday, 5/5/2017 3:48 PM, Robert Willy wrote:
Hi,
I am new to verilog. I don't find an answer for 'tut1' in the testbench.

tutorial tut1(.led(leds),.swt(switches));


Could you help me out?


thanks,


,,,,,,,,,,,,,,,,,,,,,,,,

module tutorial_tb(

);

reg [7:0] switches;
wire [7:0] leds;
reg [7:0] e_led;

integer i;

tutorial tut1(.led(leds),.swt(switches));

function [7:0] expected_led;
input [7:0] swt;
begin
expected_led[0] = ~swt[0];
expected_led[1] = swt[1] & ~swt[2];
expected_led[3] = swt[2] & swt[3];
expected_led[2] = expected_led[1] | expected_led[3];
expected_led[7:4] = swt[7:4];
end
endfunction

initial
begin
for (i=0; i < 255; i=i+2)
begin
#50 switches=i;
#10 e_led = expected_led(switches);
if(leds == e_led)
$display("LED output matched at", $time);
else
$display("LED output mis-matched at ",$time,": expected: %b, actual: %b", e_led, leds);
end
end

endmodule
...........

`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Module Name: tutorial
//////////////////////////////////////////////////////////////////////////////////


module tutorial(
input [7:0] swt,
output [7:0] led
);

assign led[0] = ~swt[0];
assign led[1] = swt[1] & ~swt[2];
assign led[3] = swt[2] & swt[3];
assign led[2] = led[1] | led[3];

assign led[7:4] = swt[7:4];

endmodule


tut1 is just the instance name. In Verilog, when you instantiate a
module you are required to assign it a unique instance name. This
is used for hierarchical names so your test bench can access code
outside its own context. In your case, the "tutorial" module has
no internal signals defined, so hierarchical names are not very
useful. However imagine that it had some internal signal like:

reg [3:0] foo; // this would be inside tutorial module

Then your testbench could access that register like:

$display ("foo equals %d", tut1.foo); // this would be in tutorial_tb

It's common in testbench code to use a name like UUT
(unit under test) as the instance name for the module
being tested. However the instance name has no special
meaning. It just needs to be unique and not a reserved
word.

--
Gabor


Thank you so much. My previous question was too simple to post. Sorry about
it.
Now this one looks very strange to me. I find that '@' means waiting for
something. What is '*' here? It is the same wild character in a command
console?

..................
always @(*) begin
ctr_d = ctr_q + 1'b1;

if (compare > ctr_q)
pwm_d = 1'b1;
else
pwm_d = 1'b0;
end

rickman
Guest

Sat May 06, 2017 3:29 am   



On 5/5/2017 8:42 PM, Robert Willy wrote:
Quote:
On Friday, May 5, 2017 at 6:09:17 PM UTC-4, Gabor wrote:
On Friday, 5/5/2017 3:48 PM, Robert Willy wrote:
Hi,
I am new to verilog. I don't find an answer for 'tut1' in the testbench.

tutorial tut1(.led(leds),.swt(switches));


Could you help me out?


thanks,


,,,,,,,,,,,,,,,,,,,,,,,,

module tutorial_tb(

);

reg [7:0] switches;
wire [7:0] leds;
reg [7:0] e_led;

integer i;

tutorial tut1(.led(leds),.swt(switches));

function [7:0] expected_led;
input [7:0] swt;
begin
expected_led[0] = ~swt[0];
expected_led[1] = swt[1] & ~swt[2];
expected_led[3] = swt[2] & swt[3];
expected_led[2] = expected_led[1] | expected_led[3];
expected_led[7:4] = swt[7:4];
end
endfunction

initial
begin
for (i=0; i < 255; i=i+2)
begin
#50 switches=i;
#10 e_led = expected_led(switches);
if(leds == e_led)
$display("LED output matched at", $time);
else
$display("LED output mis-matched at ",$time,": expected: %b, actual: %b", e_led, leds);
end
end

endmodule
...........

`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Module Name: tutorial
//////////////////////////////////////////////////////////////////////////////////


module tutorial(
input [7:0] swt,
output [7:0] led
);

assign led[0] = ~swt[0];
assign led[1] = swt[1] & ~swt[2];
assign led[3] = swt[2] & swt[3];
assign led[2] = led[1] | led[3];

assign led[7:4] = swt[7:4];

endmodule


tut1 is just the instance name. In Verilog, when you instantiate a
module you are required to assign it a unique instance name. This
is used for hierarchical names so your test bench can access code
outside its own context. In your case, the "tutorial" module has
no internal signals defined, so hierarchical names are not very
useful. However imagine that it had some internal signal like:

reg [3:0] foo; // this would be inside tutorial module

Then your testbench could access that register like:

$display ("foo equals %d", tut1.foo); // this would be in tutorial_tb

It's common in testbench code to use a name like UUT
(unit under test) as the instance name for the module
being tested. However the instance name has no special
meaning. It just needs to be unique and not a reserved
word.

--
Gabor

Thank you so much. My previous question was too simple to post. Sorry about
it.
Now this one looks very strange to me. I find that '@' means waiting for
something. What is '*' here? It is the same wild character in a command
console?

..................
always @(*) begin
ctr_d = ctr_q + 1'b1;

if (compare > ctr_q)
pwm_d = 1'b1;
else
pwm_d = 1'b0;
end


Don't you have a text book for this? How about trying a google search?
These are easy questions that you should be able to answer by reading
any of the many materials available.

http://stackoverflow.com/questions/8865877/verilog-always-begin-and-end-evaluation

--

Rick C

elektroda.net NewsGroups Forum Index - Verilog Language - What is tut1 for here?

Ask a question - edaboard.com

Arabic version Bulgarian version Catalan version Czech version Danish version German version Greek version English version Spanish version Finnish version French version Hindi version Croatian version Indonesian version Italian version Hebrew version Japanese version Korean version Lithuanian version Latvian version Dutch version Norwegian version Polish version Portuguese version Romanian version Russian version Slovak version Slovenian version Serbian version Swedish version Tagalog version Ukrainian version Vietnamese version Chinese version Turkish version
EDAboard.com map