Electronic – Initial or undefined value of flip flop

counterdesignflipflop

I am modeling Digital Circuits using ICs in a software. I have worked with flip flops and counters, but I don't remember it well.
How do I model undefined or initial value of flip flop (SR or JK etc.)?
I have three options

  1. '0' state for all uninitialized nodes
  2. assign random value '0' or '1' to the new node
  3. generate error message, & ask user to clear or preset the flip flop

Also consider a JK flip flop, if the user input is '0' & '0', the output is 'Q' & 'Q bar'. What value do I assign in this case? '0' & '1'? This is the initial case, i.e the circuit has been made & the console just powered up.

Please share your experience.

Best Answer

In some types of simulation, the more states the merrier. If you are doing only single-clock synchronous logic, I would suggest three states (high/low/undefined), but expand out the JK flip flop's logic so as to include the full computation of the next value. For example, if one has a circuit in which both J and K inputs are tied to the AND of the output and a RESET signal, one should apply output := (J & !output) | (!K & output), so that the former term will cancel out, leaving output := !RESET & output, whose value would be well-defined if reset is high, even if output is undefined.

If you are trying to do a continuous-time simulation, many more states become necessary, including 'rising', 'falling', 'stable unknown', 'unstable unknown', etc. with some complicated truth tables which depend upon the previous states of inputs as well as the current states (e.g. 'rising:high & rising:high == rising', but 'rising:high & high:falling' == 'unstable unknown'), since the first signal might or might not have gotten high soon enough to generate a high pulse on the output.