Verilog - creating a timer to count a second - EDA Playground
Warning! This exercise has been opened in another tab; autosave has been disabled. Close this tab or refresh to reactivate.

 Languages & Libraries

 Tools & Simulators

 Examples

208


24
 
1
// Code your testbench here
2
// or browse Examples
3
4
module digital_clock_tb;
5
  
6
  reg clk = 1'b0;
7
  
8
  always #10 clk = ~clk;
9
  
10
  digital_clock digital_clock0 (.clk(clk));
11
  
12
  initial #100000 $finish;
13
  
14
  always begin 
15
    #10000 $display("tick");
16
    #10000 $display("tock");
17
  end
18
  
19
  initial begin
20
    $dumpfile("dump.vcd"); $dumpvars;
21
  end
22
                           
23
endmodule
24
xxxxxxxxxx
1
22
 
1
// Code your design here
2
3
module digital_clock(input clk);
4
5
localparam N = 26;
6
reg [N-1:0] slow_clk = 0;
7
reg [7:0] countsec = 0;
8
  
9
wire enable;
10
11
always @ (posedge clk)
12
  if (slow_clk == 26'd49) slow_clk <= 8'b0;
13
    else  slow_clk <= slow_clk + 8'b1;
14
15
assign enable = (slow_clk == 26'd49);
16
17
always @ (posedge clk)
18
  if (enable == 1'b1)
19
    if (countsec == 8'b00111011) countsec <= 8'b0;
20
    else  countsec <= countsec + 8'b1;
21
22
endmodule
12164 views and 2 likes     
 
http://stackoverflow.com/questions/37514979/verilog-creating-a-timer-to-count-a-second/37520261#37520261
REFERENCED
2160:0