ruthvik_BRN49_Verilog-coding-test
ruthvik_BRN49_Verilog-coding-test
Write an RTL code and a task-based test for an 8-bit BCD counter RUTHVIK BJ, BRN 49
RTL:
module bcd_counter (
input wire clk,
input wire reset,
output reg [7:0] bcd
);
always @* begin
bcd = {tens, units};
end
endmodule
test bench:
module tb_task_bcd_counter;
reg clk;
reg reset;
wire [7:0] bcd;
bcd_counter uut (
.clk(clk),
.reset(reset),
.bcd(bcd)
);
initial begin
clk = 0;
reset = 0;
apply_reset();
#100; check_bcd_counter();
#200;
$stop;
end
task apply_reset;
begin
$display("Time %0t: Applying reset...", $time);
reset = 1;
#10;
reset = 0;
$display("Time %0t: Reset deasserted. Counter should be at 0.", $time);
end
endtask
task check_bcd_counter;
integer i;
begin
$display("Time %0t: Starting BCD counter check...", $time);
endmodule
output: