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
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 | ? ?
To my understanding, with the available outputs as q2 = 1 and q1 same
as previous state , inputs d1 = 1 and d2 = 0.
--Jacky
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.
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...
> 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