Try   HackMD

Combinational 和 Sequential circuits

前者沒有記憶性,後者有記憶性。而所謂的記憶性就是可以記住前一個「狀態 State」的資訊。
而達成的方式很簡單,就是把 Combinational 的 Output 再拉回 Input。

Feedback

要如何記憶過去呢?單單只把輸出再拉回輸入是不夠的,還有一個特性,就是延遲;以下面簡單的例子舉例:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

我們都知道,NOT 閘具有延遲,同時還是個 Buffer;假設這個 NOT 一開始有值,則這個封閉迴路就會這樣子循環。

當然也可以接很多個起來,如下面:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

這就是我們產生記憶性的大致構想。

Set-Reset Latch / SR Latch

老朋友了,計概就跟他見過面了;不過這次更加深入,之前計概只有講過 NOR 的版本,這裡也會連 NAND 的版本一起提到。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

可以看到 NAND 的版本,Q 的位置交換了,而原先的 S 跟 R 上面都多加了 BAR。
而我們可以把 NOR 的那顆 NOT 給往前推,就會得到 NAND 的樣子。

下面是常用的模組化表示法,不過其實我不太確定為甚麼 NAND 的模組化在輸入端又會多 NOT,而已其他人也都是這樣畫的,但總之以上面的圖最準,上面就是它實際的長相。

要注意 Q 的位置,NOR 是對到 R,NAND 是對到 S

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

真值表

我們來看看真值表;對於 NOR 的來說,就跟以前一樣

  • 同時為 0 保持不變
  • S 為 1 代表設為 1 (Set to 1)
  • R 為 1 代表設為 0 (Reset to 0)
  • 「Not allowed 不允許」同時為 1

首先可以發現為甚麼叫做 SR Latch,就是因為這兩個 Input 很像是扮演這兩個功能的輸入
再來是「不允許」這個詞,不可以跟「不等於」混用,因為這個電路只是「不允許」有這種情形,但不代表它不會有這種情形。

要避免同時為 1 的原因有兩個:

  1. 如果同時為 1,然後同時轉成 0 的時候,輸出的結果會 0 跟 1 之間震盪。
  2. 如果同時為 1,會導致兩個結果同時為 1,但這不符合一個為
    Q
    另一個為
    Q
    的 設計。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

最後是有關 NAND 的部分,在其他地方的話,上面的圖片中 S 跟 R 上面其實不會有 Bar,所以他們就會反者講 NAND 的情況。

  • 同時為 1 保持不變
  • S 為 1 代表設為 0
  • R 為 1 代表設為 1
  • 「Not allowed 不允許」同時為 0

但是為了方便理解,所以這裡才把它看作是有 Bar,例如說不允許

S
R
同時為 0, 其實就是不允許
S
R
同時為 1,這樣就跟以前 NOR 是一樣的了。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Switch Debouncing

這裡的 Switch 是指 「double throw switch」,也就是只會切換兩條路的;之前上課出現,只有一條電路的是「single throw switch」。
假如說一開始接在 a ,也就是說一開始 a 是 1,當切換電路的時候,會有一小段時間 a 會不確定是 1 或 0 的,所以就會有一個震盪的情形,但是我們的 SR Latch 可以完美的消除掉她的影響。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →


Gated D Latch

在 SR Latch 之上建立的 Latch,用以避免同時為 1 的情況。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

利用 G 當作一個控管人員,或者說 Gate;而 D 是我們的資料 Data。
可以看到這樣我們就避免了 S 跟 R 同時為 1 的情況。

但是 Gated D Latch 有個缺點,就是當 G 一變成 1,有資料的話就會立刻改變,於是我們有了下面的酷東西。

Edge-Triggered D Flip-Flops

簡稱 D Flip-Flop;顧名思義,他只有在 Edge 變化的時候才會讀值。具體是怎麼做到的呢?

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

就是把兩個 Gated D latch 串起來!並且多了一個 CLK 控制兩者的 G。
可以看到兩者的 G 一個是接取反過的 CLK,一個則沒有;不過如果在 CLK 的前面再加一個 NOT 會讓效果相反。
總之他造成的效果是在「上升」或「下降」的那一瞬間,才讓值改變。

可以自己推推看。當 CLK 從 0 變成 1,也就是所謂的「上升」,對於 G1來說是從 1 變成 0,也就是把資料攔在 L1 前面,而原先卡在兩個 Latch 中間的資料 P,就會流過L2變成 Q。所以上面的那是個 「Rising-Edge Triggered DFF」

下面是模組化表示方法,可以看到沒有 NOT 的就是上面的版本,如果取了 NOT,就會變成「Falling-Edge Triggered」

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

下面是 Falling-Edge Triggered 的波形圖示意圖,圖中有小小的延遲;可以發現只有當「下降的瞬間」,Q 的值才會改變成 D 的值。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

下面是 Rising-Edge Triggered 的波形圖示意圖,圖中有小小的延遲;可以發現只有當「上升的瞬間」,Q 的值才會改變成 D 的值。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Setup Times 和 Hold Times

既然 DFF 是在瞬間會改變值,那麼我們必須要確保在那個瞬間,D 的值不能改變,也就是說要 Stable,這樣才能如實的呈現 D 的值。
因此這個瞬間就分成 Setup(之前) 和 Hold(之後) 的兩個時間。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →


接下來會介紹更多種 Latch,下面是計概沒有介紹過的。

S-R Flip-Flop

前面的 DFF 是利用 Gated D Latch 製作的 DFF,這裡則是用 SR Latch 製作的。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

可以看到架構長得很像。首先它的 CLK 一樣也是分別接到兩個 Latch,但是不像 Gated D Latch,所以 CLK 都會接上兩個 AND。
然後由於他本身還是個 SR Latch,所以一樣「不允許」S 跟 R 同時為 1。

最後可以看到,由於 CLK 前面並沒有 NOT ,所以可以知道這是一個「上升改變」的 FF;當上升的那一個瞬間,中間的 P 就會流過 AND 閘,把結果送到後面的 SR Latch。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

這是波形圖:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

J-K Flip-Flop

這是由 SR FF 延伸而來的,兩者長得很像。
可以看到一樣是由 SR Latch 構成,然後一樣是上升改變的 CLK。

但是,最後 Q 跟 Q' 的結果被拉回到一開始的 AND 閘;這造就了他有一個特殊的功能「反轉 Toggle」。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

而會反轉的情況是出現在 J 跟 K 同時為 1 的情況,也就是原先 SR Latch 要避免的狀況;可是我們的 JK Latch 他巧妙的把 Q 跟 Q' 分別拉回到了 L 跟 J,也就是說如果 Q 是 1 的話就是進行 Reset,如果是 0 的話就是進行 Set,也就是所謂的反轉。

從下面的真值表可以看到,達成了反轉之外也避免了同時為 1 的情形。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

而這裡 J 跟 K 對應之前的 S 跟 R,但是現在他們有了新的名字,Jump (to 1)跟 Keep (at 0)。

下面是波形圖:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

T Flip-Flop

算是一種特殊的 Latch,它的目的只是要進行「反轉」。

那個 T 就是 Toggle,當你想要 Toggle 的時候(T = 1 的時候),Q 就會 Toggle,當你不想 Toggle 的時候(T = 0 的時候),Q 就不會 Toggle,保持原樣。

那要怎麼實作出來呢?下面有兩個例子。

左邊的就是將 JK FF 的輸入給他固定下來,也就是不讓 JK 兩個值可能不一樣,現在都統一由 T 控制。

右邊則是將 D FF 跟 T 進行 XOR,因此當你要反轉時(T=1),如果 Q 等於 1 XOR 就會是 0,Q 等於 0 就會是 1;當你不想反轉時(T=0),則情況相反。

可以發現 XOR 閘擔任了反轉的重要腳色;而前面的 JK 則是藉由 Q 跟 Q' 的「反著接回去」達到反轉的功能。

下面是波形圖,注意,他是下降改變。

不確定為甚麼是下降改變


有其他 Input 的 Flip-Flops

Preset 跟 Clear

假如我多了兩個輸入 PreN 跟 ClrN;首先我們先看兩者都是 1 的情況。

從真值表可以看到,如果兩者都是 1,那麼這就是一個正常的上升改變的 DFF;
但是如果 PreN 為 1 ClrN 為 0,則 Q 會被強制更改為 0,也就是給他 Preset;
如果 PreN 為 0 ClrN 為 1,則 Q 會被強制更改為 1,也就是給他 Clear。

然後跟 SR Latch 很像,PreN 跟 ClrN 是「不允許」同時為 0 的。

Clock Enable

用意就是決定「要不要讓 Clock 運作」;如果不讓 CLK 運作的話,就是保持原本的值不變;如果讓 CLK 運作的話就是原本正常的 DFF。

從上圖可以看到我們用了一個 MUX 達到 CE 的功能。如果我不想讓 CLK 運作,則我 CE 會是 0,那麼 DFF 的輸入永遠會是從 Q 拉回來的結果,當我想讓 CLK 運作時,就是正常的讓 Din 通過 MUX。


總結

翻譯如下:

  • SR Latch
    • 如果 S 是 1 (Set to 1),或者 S 跟 R 是 0 且 Q 是 1 (Unchanged and Q is 1)
    • 則輸出就會是 1
  • Gated D Latch
    • 如果 G 是 0 且 Q 是 1 (unchanged and Q is 1)
    • 或者 G 是 1 且 D 是 1 (allow data pass and data is 1)
    • 則輸出就會是 1
  • D Flip-Flop
    • 如果 D (資料)是 1 輸出就是 1
  • SR Flip-Flop
    • 如果 S 是 1 (Set to 1),或者 S 跟 R 是 0 且 Q 是 1 (Unchanged and Q is 1)
    • 則輸出就會是 1 (本質上就是 SR Latch)
  • JK Flip-Flop
    • 如果 J 是 1 且 K 是 0 (Jump to 1)
    • 則輸出就會是 1
      • 如果 JK 都是 1 則取決於 Q' (Toggle)
      • 如果 JK 都是 0 則取決於 Q (Unchanged)
  • T Flip-Flop
    • 如果 T 是 1 則取決於 Q' (Toggle)
    • 如果 T 是 0 則取決於 Q (Unchanged)
  • D-CE Flip-Flop
    • 如果 CE 是 0 則取決於 Q (Unchanged)
    • 如果 CE 是 1 則取決於 D (Allow Data pass)