Stop Watch DSD
Stop Watch DSD
Stop Watch DSD
module stop_watch_if
);
// declaration
wire ms_tick;
// body
// register
begin
end
// next-state logic
always@(*)
begin
d0_next = d0_reg;
d1_next = d1_reg;
d2_next = d2_reg;
if (clr)
begin
d0_next = 4'b0;
d1_next = 4'b0;
d2_next = 4'b0;
end
else if (ms_tick)
if (d0_reg != 9)
d0_next = d0_reg + 1;
begin
d0_next = 4'b0;
if (d1_reg != 9)
d1_next = d1_reg + 1;
begin
d1_next = 4'b0;
if (d2_reg != 9)
d2_next = d2_reg + 1;
d2_next = 4'b0;
end
end
end
// output logic
assign d0 = d0_reg;
assign d1 = d1_reg;
assign d2 = d2_reg;
endmodule
module disp_hex_mux
);
// constant declaration
localparam N = 18;
reg dp;
// N-bit counter
// register
if (reset)
q_reg <= 0;
else
// next-state logic
always@*
2'b00:
begin
an = 4'b1110;
hex_in = hex0;
dp = dp_in[0] ;
end
2'b01:
begin
an = 4'b1101;
hex_in = hex1;
dp = dp_in [1] ;
end
2'b10:
begin
an = 4'b1011;
hex_in = hex2;
dp = dp_in [2] ;
end
default:
begin
an = 4'b0111;
hex_in = hex3;
dp = dp_in[3];
end
endcase
always@(*)
begin
case (hex_in)
endcase
sseg[7]= dp;
end
endmodule
);
disp_hex_mux unit_DISP
(.clk(clk), .reset(1'b0), .hex3(1'b0), .hex2(d2), .hex1(d1), .hex0(d0), .dp_in(4'b0010), .an(an),
.sseg(sseg))
endmodule