weird Altera simulation result

I am trying to build a T flip-flop from a D flip-flop. The D flip-flop looks like this

and the simulated waveform shows that it works.(when there is a rising edge D will be passed to Q)

So I started building a T flip-flop by connecting Qnot to D (I am expecting every clock rising edge Q will be toggled because Qnot is passed to Q)

but the simulated waveform looks like this

Q will oscillate when CLK is low. One oscillation period is around couple ns. I played with different Clear and Preset signals but it still happens.

If anyone can point out my errors. Thanks.

• The first thing is not a FF, it's a latch. – avakar Jun 24 '13 at 20:06

The first schematic shows a latch rather than a D flip-flop -- it forwards D to Q when CLK is high. Q maintains its value for CLK low.

This would almost explain the behavior of your latter circuit. Q should remain constant when CLK is low. It will forward !Q when CLK is high and therefore oscillate.

Why the oscillation happens with CLK low I cannot explain (perhaps the two screenshots are inconsistent?).

• The first circuit is indeed a latch. Sorry I was confused. But I took the screen shots after I compiled two circuits with no errors. Still struggling with the oscillation. – Timtianyang Jun 24 '13 at 21:08
• So would Q oscillate when CLK is high because !Q is passed to Q continuously as long as CLK is high? It looks like I cannot build a T flip-flop from it then... – Timtianyang Jun 24 '13 at 21:12

When the clock is HIGH there seems to be a race hazard through the circuit which causes a rapid oscillation.

Lets assume the starting condition is Q = 0 (NOT Q = 1)

when the clock signal goes HIGH

                        a b c d e f g
1   1 0


g will go low causing d to go high causing c to go low causing g to go high and so on and so forth

when clock is low

                        a b c d e f g
0   1 0


f is low, b is high, c is high the system is stable

• Thanks for walking it through. Your analysis is right. My implementation to build a T flip-flop is incorrect because the toggle happens too much when CLK is high. – Timtianyang Jun 24 '13 at 21:21
• Timtianyang - your very welcome, good luck with you next implementation – JIm Dearden Jun 25 '13 at 7:27