SlideShare a Scribd company logo
Latches
• The second part of CS231 focuses on sequential circuits, where we add
    memory to the hardware that we’ve already seen.
•   Our schedule will be very similar to before:
     – We first show how primitive memory units are built.
     – Then we talk about analysis and design of sequential circuits.
     – We also see common sequential devices like registers and counters.
•   In the final third of the semester, we add memory to our ALU to make
    a complete processor!
•   But remember that sequential circuits are used for things other than
    processors




                     Latches                              1
Combinational circuits

                               Combinational
                Inputs            circuit          Outputs




• So far we’ve just worked with combinational circuits, where applying
    the same inputs always produces the same outputs.
•   This corresponds to a mathematical function, where every input has a
    single, unique output.
•   In programming terminology, combinational circuits are similar to
    “functional programs” that do not contain variables and assignments.




                     Latches                              2
Sequential circuits

                Inputs         Combinational        Outputs
                                  circuit


                                 Memory




• In contrast, the outputs of a sequential circuit depend on not only the
    inputs, but also the state, or the current contents of some memory.
•   This makes things more difficult to understand, since the same inputs
    can yield different outputs, depending on what’s stored in memory.
•   The memory contents can also change as the circuit runs.


• We’ll some need new techniques for analyzing and designing sequential
    circuits.

                     Latches                               3
Examples of sequential devices
• Many real-life devices are sequential in nature:
   – Combination locks open if you enter numbers in the right order.
   – Elevators move up or down and open or close depending on the
       buttons that are pressed on different floors and in the elevator
       itself.
     – Traffic lights may switch from red to green depending on whether
       or not a car is waiting at the intersection.
•   Most importantly for us, computers are sequential! For example, key
    presses and mouse clicks mean different things depending on which
    program is running and the state of that program.




                     Latches                             4
What exactly is memory?
• A memory should have at least three properties.
    1. It should be able to hold a value.
    2. You should be able to read the value that was saved.
    3. You should be able to change the value that’s saved.

• We’ll start with the simplest case, a one-bit memory.
    1. It should be able to hold a single bit, 0 or 1.
    2. You should be able to read the bit that was saved.
    3. You should be able to change the value. Since there’s only a single
       bit, there are only two choices:
        – Set the bit to 1
        – Reset, or clear, the bit to 0.




                     Latches                                  5
The basic idea of storage
• How can a circuit “remember” anything, when it’s just a bunch of gates
    that produce outputs according to the inputs?
•   The basic idea is to make a loop, so the circuit outputs are also inputs.
•   Here is one initial attempt, shown with two equivalent layouts:




• Does this satisfy the properties of memory?
   – These circuits “remember” Q, because its value never changes.
         (Similarly, Q’ never changes either.)
     –   We can also “read” Q, by attaching a probe or another circuit.
     –   But we can’t change Q! There are no external inputs here, so we
         can’t control whether Q=1 or Q=0.
                       Latches                                6
A really confusing circuit
• Let’s use NOR gates instead of inverters. The SR latch below has two
    inputs S and R, which will let us control the outputs Q and Q’.




• Here Q and Q’ feed back into the circuit. They’re not only outputs,
    they’re also inputs!
•   To figure out how Q and Q’ change, we have to look at not only the
    inputs S and R, but also the current values of Q and Q’:

                               Qnext = (R + Q’current)’
                               Q’next = (S + Qcurrent)’

• Let’s see how different input values for S and R affect this thing.
                      Latches                                7
Storing a value: SR = 00
• What if S = 0 and R = 0?
• The equations on the right reduce to:
              Qnext = (0 + Q’current)’ = Qcurrent
              Q’next = (0 + Qcurrent)’ = Q’current

• So when SR = 00, then Qnext = Qcurrent. Whatever
    value Q has, it keeps.                            Qnext = (R + Q’current)’
•   This is exactly what we need to store values in   Q’next = (S + Qcurrent)’
    the latch.




                          Latches                          8
Setting the latch: SR = 10
• What if S = 1 and R = 0?
• Since S = 1, Q’next is 0, regardless of Qcurrent:
                  Q’next = (1 + Qcurrent)’ = 0

• Then, this new value of Q’ goes into the top
    NOR gate, along with R = 0.
                                                      Qnext = (R + Q’current)’
                    Qnext = (0 + 0)’ = 1
                                                      Q’next = (S + Qcurrent)’

• So when SR = 10, then Q’next = 0 and Qnext = 1.
• This is how you set the latch to 1. The S input
    stands for “set.”
•   Notice that it can take up to two steps (two
    gate delays) from the time S becomes 1 to the
    time Qnext becomes 1.
• But once Qnext becomes 1, the outputs will stop
    changing. This is a stable state.

                          Latches                          9
Latch delays
• Timing diagrams are especially useful in
    understanding how sequential circuits work.
•   Here is a diagram which shows an example of
    how our latch outputs change with inputs SR=10.


     0.   Suppose that initially, Q = 0 and Q’ = 1.
                                                        Qnext = (R + Q’current)’
     1.   Since S=1, Q’ will change from 1 to 0         Q’next = (S + Qcurrent)’
          after one NOR-gate delay (marked by
          vertical lines in the diagram for clarity).
                                                             0    1   2   3   4
     2.   This change in Q’, along with R=0, causes
          Q to become 1 after another gate delay.       S
     3.   The latch then stabilizes until S or R        R
          change again.
                                                        Q

                                                        Q’


                       Latches                                   10
Resetting the latch: SR = 01
• What if S = 0 and R = 1?
• Since R = 1, Qnext is 0, regardless of Qcurrent:
                  Qnext = (1 + Q’current)’ = 0

• Then, this new value of Q goes into the bottom
    NOR gate, where S = 0.
                                                     Qnext = (R + Q’current)’
                    Q’next = (0 + 0)’ = 1
                                                     Q’next = (S + Qcurrent)’

• So when SR = 01, then Qnext = 0 and Q’next = 1.
• This is how you reset, or clear, the latch to 0.
    The R input stands for “reset.”
•   Again, it can take two gate delays before a
    change in R propagates to the output Q’next.




                          Latches                         11
SR latches are memories!
• This little table shows that our latch          S    R          Q
   provides everything we need in a               0    0       No change
   memory: we can set it, reset it, and           0    1       0 (reset)
   remember the current value.                    1    0        1 (set)


• The output Q represents the data
   stored in the latch. It is sometimes
   called the state of the latch.

                                              Inputs       Current    Next
• We can expand the table above into a        S    R       Q    Q’    Q Q’
   state table, which explicitly shows that   0   0        0      1   0    1
   the next values of Q and Q’ depend on      0   0        1      0   1    0
   their current values, as well as on the
                                              0   1        0      1   0    1
   inputs S and R.
                                              0   1        1      0   0    1
                                              1   0        0      1   1    0
                                              1   0        1      0   1    0


                     Latches                                12
SR latches are sequential!
• Notice that for inputs SR = 00, the             S    R          Q
    next value of Q could be either 0 or 1,       0    0       No change
    depending on the current value of Q.          0    1       0 (reset)
•   So the same inputs can yield different        1    0        1 (set)
    outputs, depending on whether the
    latch was previously set or reset.
•   This is very different from the
    combinational circuits that we’ve seen
    so far, where the same inputs always
    yield the same outputs.
                                              Inputs       Current    Next
                                              S    R       Q    Q’    Q Q’
                                              0   0        0      1   0    1
                                              0   0        1      0   1    0
                                              0   1        0      1   0    1
                                              0   1        1      0   0    1
                                              1   0        0      1   1    0
                                              1   0        1      0   1    0


                      Latches                               13
What about SR = 11?
• Both Qnext and Q’next will become 0.
                                                     Qnext = (R + Q’current)’
• This contradicts the assumption that Q and
    Q’ are always complements.                       Q’next = (S + Qcurrent)’

•   Another problem is what happens if we then
    make S = 0 and R = 0 together.               0                              0
                Qnext = (0 + 0)’ = 1
                Q’next = (0 + 0)’ = 1
                                                 0                              0

• But these new values go back into the NOR
    gates, and in the next step we get:

                Qnext = (0 + 1)’ = 0
                Q’next = (0 + 1)’ = 0            0                              1
• The circuit enters an infinite loop, where Q
    and Q’ cycle between 0 and 1 forever.
                                                                                1
•   This is actually the worst case, but the     0
    moral is don’t ever set SR=11!
                       Latches                               14
S’R’ latch
• There are several varieties of latches.
• You can use NAND instead of NOR gates to get a S’R’ latch.
                                           S’   R’      Q
                                           1    1    No change
                                           1    0    0 (reset)
                                           0    1     1 (set)
                                           0    0     Avoid!




• This is just like an SR latch, but with inverted inputs, as you can see
    from the table.
•   You can derive this table by writing equations for the outputs in terms
    of the inputs and the current state, just as we did for the SR latch.




                      Latches                                15
An SR latch with a control input
• Here is an SR latch with a control input C.

                                                  C   S   R   S’   R’      Q
                                                  0   x   x   1    1    No change
                                                  1   0   0   1    1    No change
                                                  1   0   1   1    0    0 (reset)
                                                  1   1   0   0    1     1 (set)
                                                  1   1   1   0    0     Avoid!




• Notice the hierarchical design!
   – The dotted blue box is the S’R’ latch from the previous slide.
   – The additional NAND gates are simply used to generate the correct
       inputs for the S’R’ latch.
•   The control input acts just like an enable.


                      Latches                                 16
D latch
• Finally, a D latch is based on an S’R’ latch. The additional gates
    generate the S’ and R’ signals, based on inputs D (“data”) and C
    (“control”).
     – When C = 0, S’ and R’ are both 1, so the state Q does not change.
     – When C = 1, the latch output Q will equal the input D.
•   No more messing with one input for set and another input for reset!


                                                        C   D          Q
                                                        0   x   No change
                                                        1   0       0
                                                        1   1       1




• Also, this latch has no “bad” input combinations to avoid.17 of the
                     Latches                                 Any
D latch
• Finally, a D latch is based on an S’R’ latch. The additional gates
    generate the S’ and R’ signals, based on inputs D (“data”) and C
    (“control”).
     – When C = 0, S’ and R’ are both 1, so the state Q does not change.
     – When C = 1, the latch output Q will equal the input D.
•   No more messing with one input for set and another input for reset!


                                                        C   D          Q
                                                        0   x   No change
                                                        1   0       0
                                                        1   1       1




• Also, this latch has no “bad” input combinations to avoid.18 of the
                     Latches                                 Any
Sequential circuits and state diagrams
• To describe combinational circuits, we used Boolean expressions and
    truth tables. With sequential circuits, we can still use expression and
    tables, but we can also use another form called a state diagram.
•   We draw one node for each state that the circuit can be in. Latches
    have only two states: Q=0 and Q=1.
•   Arrows between nodes are labeled with “input/output” and indicate how
    the circuit changes states and what its outputs are. In this case the
    state and the output are the same.
•   If you’ve taken CS273, this is basically the same as the finite state
    automata you saw there.
•   Here’s a state diagram for a D latch with inputs D and C.

                                0x/0             0x/1

                                        11/1
                                Q=0              Q=1
                                        10/0


                      Latches                              19
Using latches in real life
• We can connect some latches, acting as memory, to an ALU.
                       +1     S
                                      ALU       G
                              X

                                                D
                              Q      Latches
                                                C




• Let’s say these latches contain some value that we want to increment.
   – The ALU should read the current latch value.
   – It applies the “G = X + 1” operation.
   – The incremented value is stored back into the latches.
• At this point, we have to stop the cycle, so the latch value doesn’t get
    incremented again by accident.
•   One convenient way to break the loop is to disable the latches.

                      Latches                               20
The problem with latches

                       +1      S
                                       ALU       G
                               X

                                                 D
                               Q     Latches
                                                 C




• The problem is exactly when to disable the latches. You have to wait
    long enough for the ALU to produce its output, but no longer.
     – But different ALU operations have different delays. For instance,
        arithmetic operations might go through an adder, whereas logical
        operations don’t.
     – Changing the ALU implementation, such as using a carry-lookahead
        adder instead of a ripple-carry adder, also affects the delay.
•   In general, it’s very difficult to know how long operations take, and how
    long latches should be enabled for.
                      Latches                                21
Summary
• A sequential circuit has memory. It may respond differently to the
    same inputs, depending on its current state.
•   Memories can be created by making circuits with feedback.
     – Latches are the simplest memory units, storing individual bits.
     – It’s difficult to control the timing of latches in a larger circuit.
•   Next, we’ll improve upon latches with flip-flops, which change state only
    at well-defined times. We will then use flip-flops to build all of our
    sequential circuits.




                      Latches                               22

More Related Content

PPTX
Presentation on Flip Flop
PPTX
Flipflop
PPTX
latches
PPT
Multiplexers & Demultiplexers
PDF
Flip flop
PPT
Flip-Flop || Digital Electronics
PPT
Digital Logic Design
PPTX
Direct memory access (dma)
Presentation on Flip Flop
Flipflop
latches
Multiplexers & Demultiplexers
Flip flop
Flip-Flop || Digital Electronics
Digital Logic Design
Direct memory access (dma)

What's hot (20)

PPTX
flip flops
PPT
Sequential Logic Circuit
PPTX
Flip flop
PPT
8085 microproceesor ppt
PPTX
Flip Flop | Counters & Registers | Computer Fundamental and Organization
PPTX
Universal logic gate
PPT
Digital Logic circuit
PDF
Computer Organization And Architecture lab manual
PPTX
Presentation on Breadth First Search (BFS)
PPTX
Polish Notation In Data Structure
PPTX
D and T Flip Flop
PDF
Sequential circuits in Digital Electronics
PPTX
Sequential logic circuits flip-flop pt 1
PPTX
Latches and flip flops
PDF
Error detection & correction codes
PPTX
PPTX
Arithmetic and logical instructions
PPTX
Nand and nor as a universal gates
PDF
Boolean algebra & logic gates
PDF
Registers and counters
flip flops
Sequential Logic Circuit
Flip flop
8085 microproceesor ppt
Flip Flop | Counters & Registers | Computer Fundamental and Organization
Universal logic gate
Digital Logic circuit
Computer Organization And Architecture lab manual
Presentation on Breadth First Search (BFS)
Polish Notation In Data Structure
D and T Flip Flop
Sequential circuits in Digital Electronics
Sequential logic circuits flip-flop pt 1
Latches and flip flops
Error detection & correction codes
Arithmetic and logical instructions
Nand and nor as a universal gates
Boolean algebra & logic gates
Registers and counters
Ad

Viewers also liked (19)

PDF
Latches v4
PPTX
Latches and flip flops
PDF
Chapter 4 flip flop for students
PDF
Latch and Flip flop
PDF
Dld lecture module 04 01
PPTX
programmable logic array
PPTX
Counters
PPT
Flipflops JK T SR D All FlipFlop Slides
PPTX
Digital Registers & Counters
PPTX
Latches and flip flop
PPTX
Digital electronics and logic design
DOCX
UNIT-II : SEQUENTIAL CIRCUIT DESIGN
PPTX
Registers
PDF
Sequential circuits in digital logic design
PDF
What is CPU Register? Type of CPU Register.
PPTX
Synchronous counters
PDF
Counters
PDF
Low power vlsi design ppt
Latches v4
Latches and flip flops
Chapter 4 flip flop for students
Latch and Flip flop
Dld lecture module 04 01
programmable logic array
Counters
Flipflops JK T SR D All FlipFlop Slides
Digital Registers & Counters
Latches and flip flop
Digital electronics and logic design
UNIT-II : SEQUENTIAL CIRCUIT DESIGN
Registers
Sequential circuits in digital logic design
What is CPU Register? Type of CPU Register.
Synchronous counters
Counters
Low power vlsi design ppt
Ad

Similar to 12 latches (20)

PPTX
Sequential
PPT
Lect19 Engin112
PPTX
2105_4_Logic of Latchessssssssssssss.pptx
PDF
Latch sequential circuit in Digital Electronics.pdf
PPTX
Latch Introduction & RS Latch
PPT
Sequential circuit-Digital Electronics
PPTX
SEQUENTIAL_CIRCUIT digital logic design.pptx
PPTX
B sc3 unit 5 sequencial lc
PPT
Unit IV version I.ppt
PPT
lec7.ppt
PDF
sequential logic circuits- Latch & Flip Flop.pdf
PPTX
Sequential circuits
PPTX
Flipflop & Latches, RS Flipflop, NOR and NAND Gate Circuits
DOCX
Introduction to Sequential DevicesChapter 66.1 M.docx
PPTX
sequential circuits, flip flops and Latches
PPTX
Lecture 5 Synchronous Sequential Logic
PDF
Digital alarm clock- Digital design- Design assignment
PPT
combinatorial circuit design with universal gates
PPT
Sequential circuits
Sequential
Lect19 Engin112
2105_4_Logic of Latchessssssssssssss.pptx
Latch sequential circuit in Digital Electronics.pdf
Latch Introduction & RS Latch
Sequential circuit-Digital Electronics
SEQUENTIAL_CIRCUIT digital logic design.pptx
B sc3 unit 5 sequencial lc
Unit IV version I.ppt
lec7.ppt
sequential logic circuits- Latch & Flip Flop.pdf
Sequential circuits
Flipflop & Latches, RS Flipflop, NOR and NAND Gate Circuits
Introduction to Sequential DevicesChapter 66.1 M.docx
sequential circuits, flip flops and Latches
Lecture 5 Synchronous Sequential Logic
Digital alarm clock- Digital design- Design assignment
combinatorial circuit design with universal gates
Sequential circuits

12 latches

  • 1. Latches • The second part of CS231 focuses on sequential circuits, where we add memory to the hardware that we’ve already seen. • Our schedule will be very similar to before: – We first show how primitive memory units are built. – Then we talk about analysis and design of sequential circuits. – We also see common sequential devices like registers and counters. • In the final third of the semester, we add memory to our ALU to make a complete processor! • But remember that sequential circuits are used for things other than processors Latches 1
  • 2. Combinational circuits Combinational Inputs circuit Outputs • So far we’ve just worked with combinational circuits, where applying the same inputs always produces the same outputs. • This corresponds to a mathematical function, where every input has a single, unique output. • In programming terminology, combinational circuits are similar to “functional programs” that do not contain variables and assignments. Latches 2
  • 3. Sequential circuits Inputs Combinational Outputs circuit Memory • In contrast, the outputs of a sequential circuit depend on not only the inputs, but also the state, or the current contents of some memory. • This makes things more difficult to understand, since the same inputs can yield different outputs, depending on what’s stored in memory. • The memory contents can also change as the circuit runs. • We’ll some need new techniques for analyzing and designing sequential circuits. Latches 3
  • 4. Examples of sequential devices • Many real-life devices are sequential in nature: – Combination locks open if you enter numbers in the right order. – Elevators move up or down and open or close depending on the buttons that are pressed on different floors and in the elevator itself. – Traffic lights may switch from red to green depending on whether or not a car is waiting at the intersection. • Most importantly for us, computers are sequential! For example, key presses and mouse clicks mean different things depending on which program is running and the state of that program. Latches 4
  • 5. What exactly is memory? • A memory should have at least three properties. 1. It should be able to hold a value. 2. You should be able to read the value that was saved. 3. You should be able to change the value that’s saved. • We’ll start with the simplest case, a one-bit memory. 1. It should be able to hold a single bit, 0 or 1. 2. You should be able to read the bit that was saved. 3. You should be able to change the value. Since there’s only a single bit, there are only two choices: – Set the bit to 1 – Reset, or clear, the bit to 0. Latches 5
  • 6. The basic idea of storage • How can a circuit “remember” anything, when it’s just a bunch of gates that produce outputs according to the inputs? • The basic idea is to make a loop, so the circuit outputs are also inputs. • Here is one initial attempt, shown with two equivalent layouts: • Does this satisfy the properties of memory? – These circuits “remember” Q, because its value never changes. (Similarly, Q’ never changes either.) – We can also “read” Q, by attaching a probe or another circuit. – But we can’t change Q! There are no external inputs here, so we can’t control whether Q=1 or Q=0. Latches 6
  • 7. A really confusing circuit • Let’s use NOR gates instead of inverters. The SR latch below has two inputs S and R, which will let us control the outputs Q and Q’. • Here Q and Q’ feed back into the circuit. They’re not only outputs, they’re also inputs! • To figure out how Q and Q’ change, we have to look at not only the inputs S and R, but also the current values of Q and Q’: Qnext = (R + Q’current)’ Q’next = (S + Qcurrent)’ • Let’s see how different input values for S and R affect this thing. Latches 7
  • 8. Storing a value: SR = 00 • What if S = 0 and R = 0? • The equations on the right reduce to: Qnext = (0 + Q’current)’ = Qcurrent Q’next = (0 + Qcurrent)’ = Q’current • So when SR = 00, then Qnext = Qcurrent. Whatever value Q has, it keeps. Qnext = (R + Q’current)’ • This is exactly what we need to store values in Q’next = (S + Qcurrent)’ the latch. Latches 8
  • 9. Setting the latch: SR = 10 • What if S = 1 and R = 0? • Since S = 1, Q’next is 0, regardless of Qcurrent: Q’next = (1 + Qcurrent)’ = 0 • Then, this new value of Q’ goes into the top NOR gate, along with R = 0. Qnext = (R + Q’current)’ Qnext = (0 + 0)’ = 1 Q’next = (S + Qcurrent)’ • So when SR = 10, then Q’next = 0 and Qnext = 1. • This is how you set the latch to 1. The S input stands for “set.” • Notice that it can take up to two steps (two gate delays) from the time S becomes 1 to the time Qnext becomes 1. • But once Qnext becomes 1, the outputs will stop changing. This is a stable state. Latches 9
  • 10. Latch delays • Timing diagrams are especially useful in understanding how sequential circuits work. • Here is a diagram which shows an example of how our latch outputs change with inputs SR=10. 0. Suppose that initially, Q = 0 and Q’ = 1. Qnext = (R + Q’current)’ 1. Since S=1, Q’ will change from 1 to 0 Q’next = (S + Qcurrent)’ after one NOR-gate delay (marked by vertical lines in the diagram for clarity). 0 1 2 3 4 2. This change in Q’, along with R=0, causes Q to become 1 after another gate delay. S 3. The latch then stabilizes until S or R R change again. Q Q’ Latches 10
  • 11. Resetting the latch: SR = 01 • What if S = 0 and R = 1? • Since R = 1, Qnext is 0, regardless of Qcurrent: Qnext = (1 + Q’current)’ = 0 • Then, this new value of Q goes into the bottom NOR gate, where S = 0. Qnext = (R + Q’current)’ Q’next = (0 + 0)’ = 1 Q’next = (S + Qcurrent)’ • So when SR = 01, then Qnext = 0 and Q’next = 1. • This is how you reset, or clear, the latch to 0. The R input stands for “reset.” • Again, it can take two gate delays before a change in R propagates to the output Q’next. Latches 11
  • 12. SR latches are memories! • This little table shows that our latch S R Q provides everything we need in a 0 0 No change memory: we can set it, reset it, and 0 1 0 (reset) remember the current value. 1 0 1 (set) • The output Q represents the data stored in the latch. It is sometimes called the state of the latch. Inputs Current Next • We can expand the table above into a S R Q Q’ Q Q’ state table, which explicitly shows that 0 0 0 1 0 1 the next values of Q and Q’ depend on 0 0 1 0 1 0 their current values, as well as on the 0 1 0 1 0 1 inputs S and R. 0 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 Latches 12
  • 13. SR latches are sequential! • Notice that for inputs SR = 00, the S R Q next value of Q could be either 0 or 1, 0 0 No change depending on the current value of Q. 0 1 0 (reset) • So the same inputs can yield different 1 0 1 (set) outputs, depending on whether the latch was previously set or reset. • This is very different from the combinational circuits that we’ve seen so far, where the same inputs always yield the same outputs. Inputs Current Next S R Q Q’ Q Q’ 0 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 1 0 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 Latches 13
  • 14. What about SR = 11? • Both Qnext and Q’next will become 0. Qnext = (R + Q’current)’ • This contradicts the assumption that Q and Q’ are always complements. Q’next = (S + Qcurrent)’ • Another problem is what happens if we then make S = 0 and R = 0 together. 0 0 Qnext = (0 + 0)’ = 1 Q’next = (0 + 0)’ = 1 0 0 • But these new values go back into the NOR gates, and in the next step we get: Qnext = (0 + 1)’ = 0 Q’next = (0 + 1)’ = 0 0 1 • The circuit enters an infinite loop, where Q and Q’ cycle between 0 and 1 forever. 1 • This is actually the worst case, but the 0 moral is don’t ever set SR=11! Latches 14
  • 15. S’R’ latch • There are several varieties of latches. • You can use NAND instead of NOR gates to get a S’R’ latch. S’ R’ Q 1 1 No change 1 0 0 (reset) 0 1 1 (set) 0 0 Avoid! • This is just like an SR latch, but with inverted inputs, as you can see from the table. • You can derive this table by writing equations for the outputs in terms of the inputs and the current state, just as we did for the SR latch. Latches 15
  • 16. An SR latch with a control input • Here is an SR latch with a control input C. C S R S’ R’ Q 0 x x 1 1 No change 1 0 0 1 1 No change 1 0 1 1 0 0 (reset) 1 1 0 0 1 1 (set) 1 1 1 0 0 Avoid! • Notice the hierarchical design! – The dotted blue box is the S’R’ latch from the previous slide. – The additional NAND gates are simply used to generate the correct inputs for the S’R’ latch. • The control input acts just like an enable. Latches 16
  • 17. D latch • Finally, a D latch is based on an S’R’ latch. The additional gates generate the S’ and R’ signals, based on inputs D (“data”) and C (“control”). – When C = 0, S’ and R’ are both 1, so the state Q does not change. – When C = 1, the latch output Q will equal the input D. • No more messing with one input for set and another input for reset! C D Q 0 x No change 1 0 0 1 1 1 • Also, this latch has no “bad” input combinations to avoid.17 of the Latches Any
  • 18. D latch • Finally, a D latch is based on an S’R’ latch. The additional gates generate the S’ and R’ signals, based on inputs D (“data”) and C (“control”). – When C = 0, S’ and R’ are both 1, so the state Q does not change. – When C = 1, the latch output Q will equal the input D. • No more messing with one input for set and another input for reset! C D Q 0 x No change 1 0 0 1 1 1 • Also, this latch has no “bad” input combinations to avoid.18 of the Latches Any
  • 19. Sequential circuits and state diagrams • To describe combinational circuits, we used Boolean expressions and truth tables. With sequential circuits, we can still use expression and tables, but we can also use another form called a state diagram. • We draw one node for each state that the circuit can be in. Latches have only two states: Q=0 and Q=1. • Arrows between nodes are labeled with “input/output” and indicate how the circuit changes states and what its outputs are. In this case the state and the output are the same. • If you’ve taken CS273, this is basically the same as the finite state automata you saw there. • Here’s a state diagram for a D latch with inputs D and C. 0x/0 0x/1 11/1 Q=0 Q=1 10/0 Latches 19
  • 20. Using latches in real life • We can connect some latches, acting as memory, to an ALU. +1 S ALU G X D Q Latches C • Let’s say these latches contain some value that we want to increment. – The ALU should read the current latch value. – It applies the “G = X + 1” operation. – The incremented value is stored back into the latches. • At this point, we have to stop the cycle, so the latch value doesn’t get incremented again by accident. • One convenient way to break the loop is to disable the latches. Latches 20
  • 21. The problem with latches +1 S ALU G X D Q Latches C • The problem is exactly when to disable the latches. You have to wait long enough for the ALU to produce its output, but no longer. – But different ALU operations have different delays. For instance, arithmetic operations might go through an adder, whereas logical operations don’t. – Changing the ALU implementation, such as using a carry-lookahead adder instead of a ripple-carry adder, also affects the delay. • In general, it’s very difficult to know how long operations take, and how long latches should be enabled for. Latches 21
  • 22. Summary • A sequential circuit has memory. It may respond differently to the same inputs, depending on its current state. • Memories can be created by making circuits with feedback. – Latches are the simplest memory units, storing individual bits. – It’s difficult to control the timing of latches in a larger circuit. • Next, we’ll improve upon latches with flip-flops, which change state only at well-defined times. We will then use flip-flops to build all of our sequential circuits. Latches 22