Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Desiging a synchronous divide by 3 circuit in verilog

358 views
Skip to first unread message

jacky

unread,
Jun 2, 2007, 7:41:26 AM6/2/07
to
I have designed a syhnchronous divide by 3 sequential circuit with 2 D
flip flops

I have written this verilog code :

module sync_counter(
output reg q2;
input clk,rst_n);
reg d1,q,d2;

always @(q1) begin
d1 = q2;
d2 = ~(q1 | q2);
end

always @(posedge clk or negedge rst_n)
begin
if (rst_n)
q2 <= 0;
q1 <= 0;
end

else begin
q2<=d2;
q1 <= d1;
end
endmodule

I guess combinational block i have implemented is wrong. Can anyone
help

--Jacky

John_H

unread,
Jun 2, 2007, 11:32:53 AM6/2/07
to


So, tell me: what does your circuit do when q2 changes but q1 stays the
same?

q1 q2 | d1 d2
------+------
x x | x x
reset
0 0 | 0 1
0 1 | ? ?

jacky...@hotmail.com

unread,
Jun 2, 2007, 11:45:33 PM6/2/07
to
> 0 1 | ? ?- Hide quoted text -
>
> - Show quoted text -

To my understanding, with the available outputs as q2 = 1 and q1 same
as previous state , inputs d1 = 1 and d2 = 0.

--Jacky

John_H

unread,
Jun 3, 2007, 1:34:52 AM6/3/07
to

If your logic for the d values was actually combinatorial, you'd be
correct. Your always block doesn't provide a continuous assignment.

Ask yourself why
assign d1 = q2;
and
assign d2 = ~(q1 | q2);
give you the results that you want yet


always @(q1) begin
d1 = q2;
d2 = ~(q1 | q2);
end

doesn't.

Think of the problem in the way a simulator schedules events.

sris...@gmail.com

unread,
Jul 9, 2007, 7:40:12 AM7/9/07
to
Hi
This circuit will generate divide by 3 clk with 33.3 and 66.6 %duty
cycle taking q1, a2 as otputs
to get 50% duty cycle
u need to use a neg edge vlk to drive a third flop whose input is q2
and then or the final output of this gate with q2
u will get 50%duty cycle

John_H

unread,
Jul 9, 2007, 11:42:19 AM7/9/07
to
Since you're not the original poster and you're trying to help: did you
simulate this design that was submitted over a month ago? The specific
issue from the original poster was a problem with the combinatorial block
where d1 and d2 get assigned. By inspection, one can see that d1 and d2
only change when q1 changes though the intent of the combinatorial block
would be to change the values for changes to q1 OR q2 for the divide-by-3.

The circuit does not provide a divide-by-3 as coded. There's no 33% or 66%
duty cycle because the circuit stalls.


<sris...@gmail.com> wrote in message
news:1183981212....@e16g2000pri.googlegroups.com...

glen herrmannsfeldt

unread,
Jul 9, 2007, 2:29:08 PM7/9/07
to
sris...@gmail.com wrote:

> This circuit will generate divide by 3 clk with 33.3 and 66.6 %duty
> cycle taking q1, a2 as otputs to get 50% duty cycle
> u need to use a neg edge vlk to drive a third flop whose input is q2
> and then or the final output of this gate with q2
> u will get 50%duty cycle

With the assumption of 50% on the input clock.

-- glen

0 new messages