###### tags: `數位系統設計`
:::info
[回共筆首頁](https://hackmd.io/zrsmsRtEQ-OrnGslDxT0NQ)
[回科目首頁](https://hackmd.io/vXoSKbhKRV2nufoPIyxgyQ)
:::
[上課投影片](https://moodle2.ntust.edu.tw/pluginfile.php/221739/mod_resource/content/1/L04_reg.pdf)
[TOC]
# Lecture04: Registers and Counters
## Registers
- Register
- A group of **flip-flops** and gates
- Counter
- A register that goes through a **predetermined** sequence of states
- A n-bit register
- Reset signal and CLK is shared.
## Ripple Counter
- 非同步計數器
- 沒有相同的clock
- A n-bit binary counter → n FFs → count from 0 to $2^{n}-1$
## BCD Ripple Counter
![](https://i.imgur.com/kF1miu1.png =90%x)
## Synchronous Counters
1. Ripple Counters(省電)
- 因為沒有共浴的clock,所以變換到下一個狀態時,會從前一個flip-flop變換到下一個flip-flop,**產生不必要的跳動**。
- ![](https://i.imgur.com/gRMqU6G.png)
:::info
DVFS => Dynamic voltage frequency scaling
自動調整電壓及頻率,以免CPU燒毀
:::
2. Synchronous Counters
- 因為有共同的clock,會直接變換到下一個狀態
- ![](https://i.imgur.com/7n5dxEv.png =90%x)
## Sync. Counters using JK FFs
- $A_{0}$在每個CLK變動時,狀態就要反相,所以J=K=1
- $A_{1}$在每狀態改變時,需要J=K=1,我們觀察到$A_{0}$有1可以幫助$A_{1}$改變。
- $A_{2}$狀態改變時,要$A_{0}, A_{1}$皆為1時,會改變。
- $A_{3}$以此類推
- **高位元改變狀態 -> 低位元狀態皆為1**
![](https://i.imgur.com/fmcQNxt.png)
## 4bit UP/DOWN Binary Counter
- UP的優先權比較高
- UP的模式跟上一個電路的設計方式一樣
- DOWN的模式與上一個電路的差別在於「取所有低為元的0」 => 可以直接拉低為元的$\bar Q$
![](https://i.imgur.com/R9kBrK8.png)
## Binary Counter with Parallel Load
- 並行的原因是,有相同的CLK
- Load腳是可以把Data_in的資料放入flip-flop裡面
![](https://i.imgur.com/y53R7Ax.png)
## Extensions of Parallel Load Counter
![](https://i.imgur.com/AoV436V.png)
- (左圖)當count到$9_{(10)}$時,load會為$1_{(10)}$,counter會等待下一次CLK,從$9_{(10)}$ -> $0_{(10)}$。
- (右圖)當count到$10_{(10)}$時,clear會為$0_{(10)}$,counter輸出會瞬間變成$0_{(10)}$。
## Counter with Unused States
- n flip-flops have $2^{n}$ binary states, but we just use some state, so call the state we didn't use => unused state.
- We let unused states to become Don't care, can simplified state circuit.
- Self-correcting counter
- 我們要避免counter掉進Don't care的state迴圈狀態,那就必須要讓counter就self-correcting的功能,使他會自我修正,確保工作正確執行。
- Analyze the circuit to determine the next state from an unused state after it is designed.
## Self-Correcting Counter
- An example
![](https://i.imgur.com/cBeuHa4.png)
- 兩個unused states: 011 & 111
- 假設Present State是 011 or 111,Next State會是Don't care。
- 用卡諾圖化簡Flip-Flop inputs,並且畫出電路
![](https://i.imgur.com/0XBjzAv.png)
- 再針對設計好的電路去分析當Present State,可以得到他們的Next State不會進入unused states的迴圈裡面,所以他有self-correcting的能力
:::info
Soft Error:宇宙射線影響到半導體(電子產品)發生短暫的故障。
可能就是讓暫存的資料 從0變成1 或 從1變成0。
為了解決不可避免的Soft Error,就有了這些方案:
- ECC:修正錯誤代碼,「修正」當記憶體(RAM)發生Soft Error時的錯誤。
:::
## Ring Counter
- 輸入是從最後的輸出,拉回來
![](https://i.imgur.com/rxyMDQf.png)
- ring counter的行為跟decoder很像,但是兩個的差別就在於,ring counter比較在乎時間。
![](https://i.imgur.com/iPg1A9A.png)
- application of ring counter
- **generate timing signal** => control the sequence of operations in a digital system.
## Jonhson Counter
- Switch-tail ring counter
![](https://i.imgur.com/NBfKQAC.png)
:::info
在實務上,倘若發生Soft Error,原本的 Ring counter 或是 Switch-tail counter 都沒辦法使 output 行為回到原本的狀態。
:::
:::success
Johnson Counter 可以利用下面的方法,既能夠維持原本的行為,在受到 Soft Error 時,也可以回到原本的行為(但是也不是各種情況都救的回來)
One correcting procedure: $D_{c}$ = (A + C) B
:::