You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.1 KiB
Coq

7 months ago
module timer(
input wire sys_clk ,
input wire sys_rst_n ,
output wire [4: 0] hour ,
output wire [5: 0] min ,
output wire [5: 0] sec
);
parameter MAX = 28'd50_000_000;
parameter DAY = 17'd86400;
reg [27: 0] cnt_s;//
reg [16: 0] cnt_day;//
//
always @(posedge sys_clk or negedge sys_rst_n) begin
if(!sys_rst_n)begin
cnt_s <= 28'd0;
end
else if(cnt_s == MAX - 1'd1)begin
cnt_s <= 28'd0;
end
else begin
cnt_s <= cnt_s + 1'd1;
end
end
//
always @(posedge sys_clk or negedge sys_rst_n)begin
if(!sys_rst_n)begin
cnt_day <= 17'd0;
end
else if((cnt_day == DAY - 1'd1) && (cnt_s == MAX - 1'd1))begin
cnt_day <= 17'd0;
end
else if(cnt_s == MAX - 1'd1)begin
cnt_day <= cnt_day + 1'd1;
end
else begin
cnt_day <= cnt_day;
end
end
assign hour = cnt_day / 3600;//
assign min = cnt_day % 3600 / 60;//
assign sec = cnt_day % 60;//
endmodule