100001-Verilog MASS Question January 2023
100001-Verilog MASS Question January 2023
www.maven-silicon.com
VLSI Training Services
Setting standards in VLSI Design
1. Write RTL code for a BCD counter that displays time in a 24hr format
as shown here HH:MM:SS with the following specification details:
I. Input Clock Frequency is 1Hz
II. Inputs: clock (posedge ), reset(Active high synchronous)
III. Outputs: ms_hr<3:0>, ls_hr<3:0>, ms_min<3:0>, ls_min<3:0>,
ms_sec<3:0>, ls_sec<3:0>
Solution:
RTL code
module timecount(input clk,rst, output reg [3:0]ms_hr, ls_hr, ms_min,
ls_min, ms_sec, ls_sec);
begin
if(ls_hr>=4'd3)
begin
{ms_hr,ls_hr,ms_min,ls_min,ms_sec,ls_sec}<=0;
end
end
end
end
end
end
end
end
end
end
endmodule
Testbench:
`timescale 1s/100ms;
module timecount_tb;
reg clk,rst;
wire [3:0]ms_hr,ls_hr,ms_min,ls_min,ms_sec,ls_sec;
//integer hand;
timecount DUT(clk,rst,ms_hr,ls_hr,ms_min,ls_min,ms_sec,ls_sec);
task rst_dut;
begin
@(negedge clk);
rst=1;
@(negedge clk);
rst=0;
end
endtask
initial
begin
clk=0;
forever
#0.5 clk=~clk;
end
initial
begin
rst_dut;
#(25*60*60);
$finish;
end
initial
begin
$monitor("Clock Counter Value Time = %d%d :%d%d :%d%d
",ms_hr,ls_hr,ms_min,ls_min,ms_sec,ls_sec);
end
endmodule