Actually you almost got it. See below with minor changes.
Code Verilog - [expand] |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| module Seconds_Clock(clk, count, q_out);
input clk;
output reg q_out = 1'b0; // this makes sure the register gets a known state BOTH for simulation and actual hardware
output reg [24:0] count = 0; // same story as for q_out
always@(posedge clk)
begin
if (count == 25000000)
begin
q_out <= ~q_out; // this toggles the q_out register every second. So you get 1 sec on, 1 sec off, etc.
count <= 1'b0;
end
else
begin
count <= count + 1'd1; // note the 1'd1 .. this takes care of silly warnings about non-matching widths
end
end
endmodule |
Incidentally, you are better of writing the module declaration something like this:
Code Verilog - [expand] |
1
2
3
4
5
| module Seconds_Clock(
input clk,
output reg [24:0] count,
output reg q_out
); |
That way you don't have to repeat yourself. ;-)
PS: I take it the counter as output of the module is for debugging purposes? If all you want is the 1 PPS, then you can keep counter internal to the module...