Хронометър

Задача 1

Да се разработи модел на хронометър с диапазон 00.0 – 99.9 секунди, с точност 100 милисекунди.

module chrono(
	input	clock,reset,
	output 	reg[3:0] d0, d1, d2
  );

// TODO
  
endmodule
`timescale 1ns / 1ps

module chrono_tb;

   reg clock;
   reg reset;
   wire [3:0] d0, d1, d2;

   chrono uut(
      .clock(clock), 
      .reset(reset), 
      .d0(d0),
      .d1(d1),
      .d2(d2)            
      );
   
   parameter period = 100;
   
   initial begin  
      clock = 0;
      forever #(period/2) clock = ~clock;
   end
	
   	initial begin
	#100;
	reset = 1;
	#period reset = 0;
	
	for( int i=0; i<10; i++)
		for( int j=0; j<10; j++)
			for( int k=0; k<10; k++)
				begin
				@(negedge clock);
				assert (d0 == k) else $error("d0: expected=%1d, actual=%1d",k,d0);
				assert (d1 == j) else $error("d1: expected=%1d, actual=%1d",j,d1);
				assert (d2 == i) else $error("d2: expected=%1d, actual=%1d",i,d2);									
				end				
	@(negedge clock);
	assert (d0 == 0) else $error("d0: expected=%1d, actual=%1d",1,d0);
	assert (d1 == 0) else $error("d1: expected=%1d, actual=%1d",1,d1);
	assert (d2 == 0) else $error("d2: expected=%1d, actual=%1d",1,d2);	
	$finish; 
   end
   
   initial begin
      $monitor("%1d%1d,%1d",d2,d1,d0);   
   end
 
endmodule
module top 
  (
   input 	clk,
   input 	reset,
   output [6:0] seg,
   output [3:0] an
   );

   wire clock_10Hz, clock_500Hz;
   wire [3:0] d0, d1, d2, d3;
   wire [3:0] one_digit;   
   
   assign d3 = 4'b1111;
   
   clk_div #(.SCALE(50000)) m1
     (
      .clock_in(clk),
      .clock_out(clock_500Hz),
      .reset(reset)
      );
   
   clk_div #(.SCALE(25)) m2
     (
      .clock_in(clock_500Hz),
      .clock_out(clock_10Hz),
      .reset(reset)
      );		
   
	chrono m3
		(
		.clock(clock_10Hz), 
		.reset(reset), 
		.d0(d0),
		.d1(d1),
		.d2(d2)            
		);	
   
   disp_ctrl m4
   		(
		.clock(clock_500Hz), 
		.reset(reset), 
		.d0(d0), 
		.d1(d1), 
		.d2(d2), 
		.d3(d3), 
		.an(an), 
		.dout(one_digit)
		);	
   
   decoder7s m5
     (
      .hex(one_digit),
      .seg(seg)
      );	
   
endmodule

Задача 2

Да се добави start/stop бутон.