I was wondering how can i write a verilog program for a tick counter. When the fast input is low, the output tick is high for one cycle every 150 ms (every 7500000 cycles) The clk period is 20ns. If the fast input is high, tick should go high for one cycle every other clock cycle.
I'm thinking that I should count the clk cycles and use the count to output tick as high when the number of cycles are met but I can't seem to get it to work.
heres my code:
module tick_counter(
input clk,
input reset,
input fast,
output reg tick
);
reg count;
always @(posedge clk) begin
count <= count + 1;
if((fast == 1)&&(count == 2)) begin
tick <= 1;
end
else if(fast == 0)&&(count == 7500000)) begin
tick <= 1;
end
end
endmodule