As it says on the tin, I have a 100MHz clock (drawn from Nexys 3 Spartan 6 board) that I want divided a into 16MHz clock. I made 1Mhz and 60Hz clocks without issue, but I'm having some issues getting clean 16MHz signal.
Here's what I'm currently testing out:
module clk_gen(
input clk_100MHz,
output reg clk_16MHz,
output reg clk_1MHz,
output reg clk_1s );
integer count_16MHz;
integer count_1MHz;
integer count_1s;
integer skip_cnt;
initial begin
count_16MHz = 1;
count_1MHz = 1;
count_1s = 1;
skip_cnt = 1;
clk_1s = 1'b0;
clk_1MHz = 1'b0;
clk_16MHz = 1'b0;
end
//16MHz
always@(posedge clk_100MHz) begin
//8*(100Mhz/6.25) == 7*(100MHz/6)+((100MHz/8))
if((skip_cnt == 8) & (count_16MHz == 4)) begin
clk_16MHz = ~clk_16MHz;
skip_cnt = 1;
count_16MHz = 1;
end
else if((skip_cnt < 8) & (count_16MHz == 3)) begin
clk_16MHz = ~clk_16MHz;
skip_cnt = skip_cnt + 1;
count_16MHz = 1;
end
count_16MHz = count_16MHz + 1;
end
//1MHz
always@(posedge clk_100MHz) begin
if(count_1MHz == 50) begin
clk_1MHz = ~clk_1MHz;
count_1MHz = 1;
end
count_1MHz = count_1MHz + 1;
end
I have my 1Mhz and 60Hz (1sec) divides, but the 16MHz is being a pain. Is there a better way (while staying in Verilog)?
Unfortunately I do want a very strict 16MHz due to a shifting operation occurring 16 times between the 1MHz clock's cycle. My only other method of attack is perhaps lowering the 1MHz to something slower and more easily divided by 16.