14
\$\begingroup\$

How does a latch get its initial state? I'm guessing that it depends on race conditions and which ever condition comes first then that is the state that the latch starts off with.

\$\endgroup\$
6
  • 3
    \$\begingroup\$ Headline question is too broad to generate a single answer, so its probably not a good fit for this site. Your (valid) technical question is pretty much a duplicate of another question from earlier today: electronics.stackexchange.com/questions/25581/… \$\endgroup\$
    – The Photon
    Commented Jan 25, 2012 at 2:48
  • \$\begingroup\$ Yeah, but the answers to that question weren't really as informative as the ones below and I'm not sure too many questions have a single answer which is evidenced partially by having a site like this in the first place. I agree though that this might be a bit too broad but with all the other helpful broad questions on these sites I thought it might be best to post this question for both others and I. \$\endgroup\$ Commented Jan 25, 2012 at 3:02
  • 1
    \$\begingroup\$ If you edit the question to just include the technical part (2nd paragraph), I'll remove my downvote. \$\endgroup\$
    – The Photon
    Commented Jan 25, 2012 at 3:05
  • 3
    \$\begingroup\$ Enough to re-teach themselves a forgotten concept quickly. Or to teach themselves a new concept in the same way. Unless a paradigm shift occurs, fundamentals are relevant, and most (practical) shifts in technology are marginal enough to keep up with. \$\endgroup\$
    – Jon L
    Commented Jan 25, 2012 at 7:29
  • \$\begingroup\$ There is no right answer to this question. If the community really wants this question left open, then it should at least be community wiki. \$\endgroup\$
    – Kellenjb
    Commented Jan 25, 2012 at 12:33

5 Answers 5

23
\$\begingroup\$

There is certainly a lot of stuff taught in school that is not required in the job market. And, of course, there is a lot that is not taught that should be. This could probably be said about any job market, since it depends on what specialty the person ends up being employed in. Unfortunately for you, neither your professors or I can tell you what you will and will not use once you get a real job in your field.

For example, I don't use calculus in my job as an E.E.. But a coworker, who is also technically an E.E., uses calculus almost daily. I design PCB's and FPGA's, while he writes DSP algorithms. There was no way our teachers could have ever known what we needed to get the job done.

That being said... Your question to your teacher, about the initial value of the latch or Flip Flop (FF), was a great question and the way your professor responded shows her ignorance of the requirements for designing practical digital logic circuits.

Simply put, the initial value of a Latch or FF is indeterminate. Meaning, it will have an initial value but you won't know what it is in advance. A given latch/FF might even have different initial values from one power-up to the next. Sometimes it'll be a '0', other times a '1'. Things like temperature and how fast the power rails ramp up will effect the initial value.

If your circuit requires a known initial value then you must force the value. Normally this is done using some sort of set/reset/clear input that is driven by a reset signal. This is also why almost any digital circuit of reasonable complexity has a reset signal. Reset signals are not just for CPU's.

\$\endgroup\$
3
  • 4
    \$\begingroup\$ In my studies I learned a lot of stuff that did not stricly need lateron in my professional life, but was still very usefull for me. An important part of an education is 'learning to learn'. \$\endgroup\$ Commented Jan 25, 2012 at 8:21
  • 2
    \$\begingroup\$ You never know what you're going to need to know. I got my EE degree way back in the 1960's. I remember taking courses like microwave radio, and at the time thinking I'm going to be working with digital systems and never going to use any of this stuff (at the time, microwave was mostly used by the telephone company for long distance radio relays). Now, 40+ years later, I'm working on embedded systems, everything's wireless, and I'm laying out microstrip antennas on a PCB. \$\endgroup\$
    – tcrosley
    Commented Jan 25, 2012 at 9:49
  • 1
    \$\begingroup\$ @davidKessner, I thought in some of the race condition latches it really mattered how your power rail charged. A very fast charge could lead to one thing, while a slow charge another, but you needed a very good quality characterization of your gates. This alone would make the process a bit worthless for any real device where a reset pin works easily, with little design and low complexity. \$\endgroup\$
    – Kortuk
    Commented Jan 25, 2012 at 18:41
5
\$\begingroup\$

If you mean at turn on (before reset), then it's pretty much as you say - the gates in the FF will not be perfectly symmetrical so one will "win" the race and the latch will head towards that state. Which state it will be is unpredictable.

It's a bit like if you balance a ball at the top of a pointy house roof - in theory if everything was perfectly still, it should stay there. In practice it will always roll off to one side or the other.

So this is why on turn on, most digital circuits need to be reset to a known state (where it's necessary for the state to be known initially, you mat leave some registers undefined/unused until thy are written to the first time)

\$\endgroup\$
1
\$\begingroup\$

I guess it depends on what latch you are talking about.

http://en.wikipedia.org/wiki/Latch_%28electronics%29

Some of the latches can be reset, so you know where you begin with. I also think she was just trying to demonstrate the concept of "unchanged"/"keep" state, it does not really matter what the previous state is.

\$\endgroup\$
1
\$\begingroup\$

Two brief things: for the first question, I'm still a student, I'm doing an internship in a company and I found that many concepts, even some that I considered less important, are useful, and you will complain when you won't know well these notions because you had a bad teacher. (I know that it may seem trivial, but it's the first impression I had when I got to the real world)

For the second question, I would just add my point of view: latches and FFs are meant to hold values, and they have sense if you give that value first (unless you want to create a somehow random generator). So, with reset or putting a value, the first step is always the input.

\$\endgroup\$
0
\$\begingroup\$

(German translation further below)
(Deutsche Übersetzung weiter unten)

The accepted answer from user "user3624" and the other answers already give lots of good and sufficient information.
But all of them either refer to the theoretical behaviour of the circuit. Or they refer to real ICs, which means electronic circuits that are built under industrial conditions: the circuits are highly accurate and almost symmetric.
In theory, a latch or flipflop will never work because the theory (which uses perfect electronic parts) cannot explain the switch-on behavior of the circuit. For the same reason a lot of simulators cannot simulate a (perfect) flipflop.

If you don't use a latch or flipflop in an IC (like ICs from the 7400 series, e.g. 7474 or 74279), but create a simple by yourself, you can modify it easily to get a perfectly determined initial state. Building a latch is very easy and requires just a couple of parts: 2 transistors and 4 resistors; and 2 push-button switches for controlling the states.
Here's a circuit diagram of a simple latch. I used the same transistors that are shown in the diagram:
enter image description here When building this circuit on a breadboard (with an additional LED before the 1k resistor), I found that always the same LED was lit when switching it on. This is due to the tolerances in the electronic parts: one transistors is never like the other. It switches a little bit faster or slower, so the whole circuit has a favorite initial state, that it falls into at power-up.
Now I wanted to force this circuit to the opposite initial state, where the other LED was always lit on power-up. I found some advices on the internet, which included:

  • use different resistors on the transistor bases
  • add a diode before one transistor base

I tried both, separately and together, but the result was not satisfying. Instead of having always the same initial state, it became random when applying one or both of the mentioned changes. So it went into the right direction, but it was not enough. I could have altered the resistor values more, or use 2 diodes instead of one, but I think that this still wouldn't give a save solution. So I had another idea:

  • put a small capacitor to one transistor base, one side connected to the transistor base and the other side connected to ground.

I tried 1uF first, and it worked perfectly. Then I went down to 10nF and further down to 100pF and 10pF, and it still worked. It even worked 90% of the time with 1pF.
enter image description here It works because the capacitor short-circuits the connected transistor base (Q1) to ground for a very short time until the capacitor is charged... would be charged. "would be", because this short moment is enough for the other transistor Q2 to switch on, and once Q2 is on, the base of Q1 is connected to ground, so Q1 will remain off until someone pushes SW2. When SW2 is pushed, the capacitor gets charged and when finished Q1 is switched on.

For a safe long-term usage you may want to add a small resistor (like 10R) in row with the capacitor to avoid high currents when it is discharged.

(circuit diagrams created online with "CircuitLab")


Finally, because I am German and because I want my fellow countrymen to find answers also in our language, I am writing the whole text again in German:

Die akzeptierte Antwort von Benutzer "user3624" und die anderen Antworten liefern bereits viele gute und ausreichende Informationen.
Aber alle beziehen sich entweder auf das theoretische Verhalten der Schaltung, oder sie beziehen sich auf einen realen IC, also eine elektronische Schaltung, die unter industriellen Bedingungen hergestellt wurde: extrem genau und fast symmetrisch.
In der Theorie wird eine bistabile Kippstufe oder ein Flipflop nie funktionieren, da die Theorie mittels perfekter elektronischer Bauteile den Einschaltvorgang nicht erklären kann. Aus diesem Grund können Flipflops von vielen Simulatoren auch nicht simuliert werden.

Falls man keine Kippstufe oder Flipflop in einem IC verwendet (wie in der 7400er Serie, z.B. 7474 oder 74279), sondern sich selbst eine baut, kann man diese sehr einfach modifizieren, um einen sicher festgelegten Einschaltzustand zu bekommen. Eine Kippstufe aufzubauen ist sehr einfach und man benötigt dafür bloß eine Handvoll Bauteile: 2 Transistoren und 4 Widerstände, und 2 Taster zum Umschalten des Zustandes.
Oben ist ein Schaltplan einer einfachen Kippstufe abgebildet. Ich habe in meiner Schaltung dieselben Transistoren wie im Schaltplan verwendet.
[ BILD 1 ]
Als ich diese Schaltung auf einer Steckplatine aufgebaut habe (mit zusätzlicher LED vor dem 1k-Widerstand), habe ich festgestellt, dass stets dieselbe LED beim Einschalten geleuchtet hat. Das liegt an den Toleranzen in den elektronischen Bauteilen: Kein Transistor ist wieder der andere. Einer schaltet schneller oder langsamer, wodurch die gesamte Schaltung einen bevorzugten Zustand hat, den sie nach dem Einschalten einnimmt.
Nun wollte ich die Schaltung zwingen, beim Einschalten den gegenteiligen Zustand einzunehmen, bei dem stets die andere LED leuchtet. Im Internet hab ich verschiedene Ratschläge gefunden, darunter:

  • unterschiedliche Widerstände vor den Transistorbasen verwenden
  • eine Diode vor einer Transistorbasis hinzufügen

Ich hab beides ausprobiert, einzeln und auch zusammen, aber das Ergebnis war nicht zufriedenstellend. Anstatt immer denselben Einschaltzustand zu bekommen, war es nun Zufall, welche LED nach dem Einschalten leuchtete. Es ging in die richtige Richtung, aber es war nicht ausreichend. Ich hätte die Widerstandswerte noch stärker verändern oder vielleicht auch 2 Dioden in Reihe vor die Transistorbasis schalten können, aber ich denke, dass dies immer noch keine sichere Lösung brächte. Daher hatte ich eine andere Idee:

  • einen kleinen Kondensator vor einer Transistorbasis hinzufügen, eine Seite verbunden mit der Transistorbasis und die andere mit Masse.

Ich hab zuerst 1uF ausprobiert und es hat perfekt funktioniert. Dann hab ich kleinere Werte verwendet, erst 10nF, dann 100pF und 10pF, und es funktionierte immer noch. Es funktionierte sogar in 90% der Fälle noch mit 1pF.
[BILD 2]
Es funktioniert, weil der Kondensator kurzzeitig die Basis von Transistor Q1 mit Masse kurzschließt, bis der Kondensator aufgeladen ist... aufgeladen wäre. "Wäre", weil dieser kurze Moment ausreicht, damit der Transistor Q2 durchschaltet, und sobald dieser durchgeschaltet hat, ist die Basis von Q1 mit Masse verbunden und Q1 bleibt aus, bis jemand SW2 betätigt. Wenn SW2 gedrückt wird, wird der Kondensator geladen und sofort danach Q1 durchgeschaltet.

Für eine sichere Langzeitanwendung ist es empfehlenswert, einen kleinen Widerstand (z.B. 10R) in Reihe mit dem Kondensator zu schalten, um hohe Entladeströme zu vermeiden.

\$\endgroup\$
1
  • \$\begingroup\$ Welcome to EE.SE. Note that when you use the CircuitLab button on the editor toolbar an editable schematic is saved in your post. That makes it easy for us to copy and edit in our answers. You don't need a CircuitLab account, no screengrabs, no image uploads, no background grid. \$\endgroup\$
    – Transistor
    Commented Jul 1, 2019 at 22:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.