R
Robert Willy
Guest
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
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