08 Latches and Flip-Flops

Updated 4 Oct 2026

Combinational VS Sequential Logic Circuits

  • Up to this point, we have focused on combinational logic circuits (i.e. the output of the circuit depends on ONLY the current inputs).
  • Now we will shift our focus to sequential logic circuits (i.e. the output of the circuit depends on BOTH the current and past inputs).
  • Sequential logic circuits are used in certain types of computer memory (SRAMs), finite state machines, delay and storage elements.
  • The basic building blocks for sequential logic circuits are latches and flip-flops, which are essential components of timing and memory devices.
  • ตราบใดที่ยังมี Power ก็ส่งข้อมูล Feedback Mechanism ได้เรื่อย ๆ

Latches

  • ถือว่าเป็น Asynchronous devices (ไม่ขึ้นอยู่กับ Clock) แต่ว่า แค่หัวข้อสุดท้าย 08 Latches and Flip-Flops มันคือการเอาทั้ง Latch กับ Flip-flop มารวมร่างกัน เป็น Last boss 🧌

S-R Latch

  • The latch is a type of temporary memory storage device that has two stable states.
  • The S-R (set-reset) latch can be constructed using
    • 2 NOR (active-high) or 2 NAND (active-low) gates, as shown below.
  • Notice that the output of each gate is connected to the input of the opposite gate, creating a regenerative feedback that is characteristic of all latches and flip-flops.
    • This allow latch to keep store the information inside

  • Set will always set QQ to 1 — เปลี่ยน SS เป็น 1 (Active-high)
  • Reset will reset QQ to 0 — เปลี่ยน RR เป็น 1 (Active-high)

ถ้าเป็น Active Low ก็แค่ตรงกันข้าม ทำหน้าที่เดียวกัน (it doesn’t change the meaning of set and reset) แค่ต้องปรับ Switch เป็น 0

  • 1 and 1 is unstable. (oscillating 0 and 1 back and forth)
  • Part 1 of #FinalExam— Initial State ต้องให้มา

Gated S-R Latch

  • A gated latch requires an enable input (GG or ENEN) to operate. The logic diagram for an active-high gated S-R latch is shown below.
  • When the enable input is HIGH, the gated S-R latch behaves like a regular S-R latch where the value of the output QQ depends on the inputs QQ and RR.
  • When the enable input is LOW, the output QQ will always stay the same, no matter the current values of the inputs SS and RR.

ถ้า Enable is HIGH มันก็จะเป็นเหมือน S-R latch ธรรมดา แต่ถ้า Enable is LOW, QQ ก็จะยังคงเป็นเหมือนเดิม ไม่ว่าจะเปลี่ยน SS, RR มากมายเท่าไหร่ก็ตาม

เผลอ ๆ อันนี้ง่ายกว่า S-R Latch ธรรมดาด้วยซ้ำ ก็ดู Enable เป็นตัวช่วยที่สามารถ Ignore ได้บาง Part ถ้า ENEN เป็น 0 มันก็จะ Keep QQ ให้อยู่คงเดิม

Gated D Latch

  • The last type of latch is called the gated D latch, which uses only one data input signal (DD) and the enable signal (ENEN).
  • When the enable input is HIGH, the output QQ will follow the input DD.
  • When the enable input is LOW, the output QQ will always stay the same, no matter the current value of the input DD.

แบบนี้ก็ไม่เกิด 1, 1 (Invalid Condition) แน่นอน เพราะว่ามันสลับกันตลอดอยู่แล้ว

Timing Analysis ของ Gated D Latch ก็ง่ายมาก ๆ กราฟของ QQ จะเหมือนกับ DD เลย ตราบใดก็ตามที่ Enable is HIGH นะ!


Flip Flops

  • Flip flops are very similar to gated latches but they are considered as synchronous devices.
  • The output of a synchronous device will only change at a specific point of the triggering input, often referred to as the clock signal (CLKCLK or CC).
  • Most flip-flops are edge-triggered, which means that the output will only change at the transition of the clock signal.
    • Positive (rising) edge-triggered flip flops will change only when the clock signal goes from LOW to HIGH.
    • Negative (falling) edge-triggered flip flops will change only when the clock signal goes from HIGH to LOW.

S-R Flip Flop

ดูด้วยว่าเค้ากำหนดมาให้รึเปล่าว่าเป็น Positive-edge หรือ Negative-edge trigger (เค้าต้องกำหนด หรือไม่เราก็ต้องดูสัญลักษณ์เอาเองตรง CLKCLK ว่ามี Bubble หรือไม่มี)

  • The S-R flip flop is actually a gated S-R latch with the enabling signal provided by a pulse transition detector.
  • In this case, SS and RR are considered as synchronous input signals because they effect the output QQ only at the triggering edge of the clock signal.
    • If CLKCLK is rising/falling, QQ is SET or RESET according to SS and RR
    • If CLKCLK is not transitioning, QQ remains unchanged.

Pulse Transition Detector

#NotOnTheExam

Look (Detect) for the exact moment when CLKCLK signal goes up or down.

  • A pulse transition detector for the positive-edge of a clock signal can be constructed as shown above.
  • The inverter introduces a small delay to the inverted clock pulse, which arrives at the NAND gate input a few nanoseconds after the true clock pulse.
  • This produces a short-duration spike on the positive transition of the clock pulse.
  • A negative-edge pulse transition detector can also be constructed in a similar manner.
  • In practice, they take time to switch to the other state 06 Digital Integrated Circuits

เวลาทำ Timing Diagram ก็ทำเฉพาะตรงที่ CLKCLK เปลี่ยน ไม่ต้องกังวลระหว่างนั้น มันจะเปลี่ยนเฉพาะเวลา CLKCLK เปลี่ยน! ยิ่งง่ายขึ้นไปอีก เพราะตอนนี้เรารู้ทันทีว่าต้องทำตรงไหน

D Flip Flop

  • The D flip-flop is very useful for storing a single bit of data. Similar to the S-R flip flop, it is actually a gated D latch with the enabling signal provided by a pulse transition detector.
  • It has only a data input signal (𝐷𝐷) in addition to the clock pulse and is edge-triggered.
    • If CLKCLK is rising/falling, QQ will follow the data input DD.
    • If CLKCLK is not transitioning, QQ remains unchanged.

D Flip Flop ต้องดูด้วยว่าเค้ากำหนดมาให้รึเปล่าว่าเป็น Positive-edge หรือ Negative-edge trigger

J-K Flip Flop

J-K Flip Flop ต้องดูด้วยว่าเค้ากำหนดมาให้รึเปล่าว่าเป็น Positive-edge หรือ Negative-edge trigger เหมือนกันนะะ!

  • The J-K flip flop is a versatile and widely-used device that functions exactly the same as an S-R flip-flop, except that it has no invalid state.
  • Instead, it is able to toggle the output. It is sometimes called the T flip flop.
  • JJ มีค่าเท่ากับ SS ส่วน KK มีค่าเท่ากับ RR — ทำงานคล้าย ๆ S-R Flip Flop เลย แต่อันนี้จะไม่มี Invalid Condition แต่ Outputs ที่ได้จะใส่ NOT แทน เมื่อถ้าสัญญาณ CLKCLK ก็จะเปลี่ยนไปเรื่อย ๆ เหมือน .toggle() 55555

Warning


มันมีแค่อย่างใดอย่างหนึ่งนะ ว่าจะเป็น Negative-edge trigger หรือว่า Positive-edge trigger ไม่ได้เปลี่ยนทุก CLKCLK นะ ดูดี ๆ ด้วย เป็นทั้งคู่ไม่ได้


Asynchronous Inputs

  • So far, we have only seen flip flops with synchronous inputs that transfer data to the output only at the triggering edge of a clock pulse.
  • In reality, most IC flip flops also contain asynchronous inputs that affect the state of the flip flop independent of the clock. They are normally labelled as preset (PRE‾\overline{PRE}) and clear (CLR‾\overline{CLR}), which are ==active-LOW signals.==
    • Preset will set Q=1Q = 1 no matter what the clock signal is.
    • Clear will reset Q=0Q = 0 no matter what the clock signal is

ก็คือเหมือนมาเหนือ CLKCLK อีก (Overwrite) ไม่แคร์ด้วยซ้ำว่า Clock Signal เป็นยังไง กูจะเปลี่ยนหมด
Present ทำงานคล้าย ๆ SS— ส่วน Clear ทำงานคล้าย ๆ RR

  • ถ้าเป็น 0, 0 ก็จะเป็น Invalid Condition อยู่ดีนะ อันนี้อะ ระวังออกสอบ!


เวลาทำ Timing Diagram ให้ Priority PRE‾\overline{PRE} กับ CLR‾\overline{CLR} ก่อน เขียนไปเลยว่าตอนที่ either one active ก็ให้ QQ เป็นค่านั้น ๆ ไปเลย