Can you please help me on how to create a Verilog code for frequency divider circuit that can generate 50Hz clock signal out of 50MHz signal using 16 bit synchronous counter. I have tried to do it, but it didn't work!
module divier_16 (clk_in, clk_out);
input clk_in;
wire w;
wire [0:15]temp;
output clk_out;
count_16 c1 (clk_in, w);
count_16 c2 (w, temp);
assign clk_out= temp[6];
-
1\$\begingroup\$ Using 16 bits of what? \$\endgroup\$Eugene Sh.– Eugene Sh.2016年11月01日 20:32:19 +00:00Commented Nov 1, 2016 at 20:32
-
1\$\begingroup\$ And what have you tried? Could you post your code? \$\endgroup\$Florent– Florent2016年11月01日 20:32:54 +00:00Commented Nov 1, 2016 at 20:32
-
\$\begingroup\$ 16 bit synchronous counter \$\endgroup\$Fatima– Fatima2016年11月01日 20:38:18 +00:00Commented Nov 1, 2016 at 20:38
-
\$\begingroup\$ Can you use two of these? \$\endgroup\$Eugene Sh.– Eugene Sh.2016年11月01日 20:40:53 +00:00Commented Nov 1, 2016 at 20:40
-
1\$\begingroup\$ Good. Then first divide by 1000, then divide by another 1000.. \$\endgroup\$Eugene Sh.– Eugene Sh.2016年11月01日 20:45:57 +00:00Commented Nov 1, 2016 at 20:45
1 Answer 1
Unfortunately, 16 bits is not enough to convert a 50MHz signal into a 50Hz signal. This is because you need to divide the clock by 1 million. $2ドル^{16}= 65536$$ Therefore it is not nearly enough. A counter with at least 20 bits would be enough because: $2ドル^{20} = 1048576$$
To convert the signal you simply count to 1 million clock cycles, and then change the state of the output signal.
example:
always @(posedge clk_in) begin
count_20 <= count_20 + 1;
if(count_20 == 1000000)
begin
count<=0;
clk_out <= !clk_out;
end
end
Edit: It turns out that that ^^ would result in a 25Hz signal, so you only need to count to 500000 which needs 19 bits. The question then is where does that 20th bit come from seeing as you do need to divide by 1 million. Well, the clk_out bit serves as that 20th bit.
-
\$\begingroup\$ another solution is to use several of those 16 bits counters. you would need at least 16 of those (16*65536 = 2²0 = 1048576) \$\endgroup\$Florent– Florent2016年11月01日 21:03:39 +00:00Commented Nov 1, 2016 at 21:03
-
\$\begingroup\$ I may have made a mistake, i think my solution would result in 25Hz? \$\endgroup\$Makoto– Makoto2016年11月01日 21:05:12 +00:00Commented Nov 1, 2016 at 21:05
-
\$\begingroup\$ you would only need two, that would give you 32 bits \$\endgroup\$Makoto– Makoto2016年11月01日 21:05:58 +00:00Commented Nov 1, 2016 at 21:05
-
\$\begingroup\$ @Makoto yes, you need to count to 500_000, and second - most probably there will be warning about using different assignment type in always construct, I think you meant
clk_out <= !clk_out
; \$\endgroup\$Anonymous– Anonymous2016年11月01日 21:07:27 +00:00Commented Nov 1, 2016 at 21:07 -
\$\begingroup\$ yep will change it \$\endgroup\$Makoto– Makoto2016年11月01日 21:08:10 +00:00Commented Nov 1, 2016 at 21:08