What is wrong with my D flip-flop toggle switch?

I duplicated your circuit in Logisim (as an opportunity to do something in Logisim). There's nothing wrong with your circuit. There is something about Logisim I don't understand.

First off, the red lines are not lines in a high state; they are errors. One would expect this sort of error if two outputs were tied together. I did a bunch of breaking the circuit and tying lines high or low, and eventually, all the errors were "flushed out" and reconnecting the circuit normally produced the toggling it was designed to do.

Specifically, break the upper leftmost wire, the one that connects Q' to D, then connect D to a high or low source ("pull resistor" works well here), and toggle it until it's all green. Then, reconnect the feedback, and it will all work. Note that high and low are represented by green and dark green (?).

Pressing "Reset Simulation" will bring all the errors back. My guess is, that somewhere in the logic of the program, it has an "undefined state". These undefined states propagate through the gates to the extent that they don't "sort themselves out" the way real electronics do. Undef AND 0 should result in 0, not Undef. Same goes for 1 OR Undef.

Just in case this has been addressed in a later version, I'll note this Logisim is 2.7.1


Update: I "fixed" the problem (within the scope of this simulator, anyway) by inserting a NOR gate in the feedback path. Then connect a pushbutton to the other input. I replaced the original button with a clock signal (found under "wiring"). Now, pressing the button clears the error. (Resetting the logic brings the error back).


Based on gbarry's response, it sounds as though LogicSim is using pessimistic "don't know" logic evaluation, meaning that wires are only low if the simulator can tell that, given the stimuli received to date, they should definitely be low; likewise, they're only high if the simulator can tell that they should definitely be high. Such pessimistic logic evaluation often precludes simulation of devices which would probably happen to work satisfactorily in the real world, but it tends to ensure that devices will only behave as desired in simulation if they would in fact work in the real world.

If the circuitry were implemented with real-world logic, the circuit would likely stabilize so the top red wire was either high or low, but its actual level would be arbitrary. Pushing the button should cause the top wire to assume the state opposite the one before the push, but since that initial state cannot be predictably defined as high or low, nor can the state after the push.

In some cases it may be more useful to have a simulator arbitrarily power up in some particular state, than to have it simply indicate an unresolved indeterminate state. A major danger with simulators that do so, however, is that they may lead one to believe that a circuit will work in real life when in fact it will not. By contrast, if a pessimistic simulation indicates that indeterminate states get resolved, they will almost certainly do so in the real world; if it doesn't, such states may or may not get resolved in the real world, but one shouldn't rely upon such behavior unless one has examined timing constraints very carefully.