Lab10 - 數位晶片設計實驗室

Download Report

Transcript Lab10 - 數位晶片設計實驗室

Department of Computer Science and Information Engineering
National Cheng Kung University
Experiment on Digital System
Sequential circuit(2)
Introduction to Finite State Machine (FSM)
2014-12-17/18
Digital Integrated Circuit Design Laboratory
Reference Links
Altera Quartus II Handbook
Altera Quartus II Web Edition - Free (Create a user account)
北瀚科技股份有限公司 SMIMS – FPGA Board
數位IC設計入門-Verilog,滄海書局,2008 (ISBN 978-986-6889-90-5)
2
Outline

Counters

Digital Circuit Design

Control Unit

Finite State Machine (FSM)


Examples of Moore Machine

Examples of Mealy Machine
Lab
3
Department of Computer Science and Information Engineering
National Cheng Kung University
Counters
Digital Integrated Circuit Design Laboratory
Counters

計數器



同步計數器


Counters
分為同步、非同步,主要是依據正反器是否同時動作來區別
所有正反器的時脈輸入訊號會被電路共用,且同一時間觸發並改變 (延遲時
間較短)
非同步計數器


除了第一個正反器的時脈輸入訊號由外部輸入之外,其餘每一級時脈輸入
訊號都是來自前一級輸出訊號 (不隨計數脈波做同時變化)
缺點:時間延遲與計數位元之數目成正比
5
Counters

上數計數器




Up Counter
同步計數器 (範圍由 0、1、2、3、4),然後回到 0 重新開始
循環方式計數
時脈輸入訊號的正緣到達時


若 reset 訊號為 1 ,計數器被清除
若 reset 訊號為 0 ,計數器會持續上數
6
Counters
7
Department of Computer Science and Information Engineering
National Cheng Kung University
Digital Circuit Design
Digital Integrated Circuit Design Laboratory
Digital Circuit Design(1/2)

數位電路設計



控制單元



控制單元 (control unit)
資料運算單元 (datapath)
產生控制訊號 (control signals)
控制資料運算單元運算狀態
資料運算單元


產生狀態訊號 (status signals)
作為控制單元部分輸入訊號
9
Digital Circuit Design(2/2)

控制單元與資料運算單元內部電路
10
Department of Computer Science and Information Engineering
National Cheng Kung University
Control Unit
Digital Integrated Circuit Design Laboratory
Control Unit(1/5)

Control unit (依實作方式)



Microprogramming control
Hard-wired control
Microprogramming control



將所有控制訊號儲存於 ROM 中,再傳送至 datapath
缺點:需要較長延遲時間 (delay time),速度慢
彈性較大,若需要更改狀態控制訊號,只需要更新 ROM 內容
12
Control Unit(2/5)

Hard-wired control


亦稱有限狀態機
(finite state machine, FSM)

次狀態邏輯

目前狀態暫存器

輸出邏輯
次狀態邏輯


組合電路 (Combinational CKT)
根據現在輸入 (control inputs)與目前電路狀態 (current state),
產生下一個電路狀態 (next state)
13
Control Unit(3/5)

Hard-wired control


亦稱有限狀態機
(finite state machine, FSM)

次狀態邏輯

目前狀態暫存器

輸出邏輯
目前狀態暫存器


記憶單元 (Sequential CKT)
儲存目前的電路狀態 (需要使用時脈脈波 Clock 來同步)
14
Control Unit(4/5)

Hard-wired control


亦稱有限狀態機
(finite state machine, FSM)

次狀態邏輯

目前狀態暫存器

輸出邏輯
輸出邏輯


組合電路 (Combinational CKT)
根據現在輸入與目前電路狀態,產生輸出控制訊號來控制 datapath 單元
進行所需運算
15
Control Unit(5/5)

Hard-wired control

亦稱有限狀態機 (finite state machine, FSM)

次狀態邏輯、目前狀態暫存器與輸出邏輯

彈性較小,若要更改狀態控制訊號,電路需要重新設計

延遲時間較短,速度快

FSM (依據輸出產生的方式不同)

Moore 機 (Moore machine)

Mealy 機 (Mealy machine)
16
Department of Computer Science and Information Engineering
National Cheng Kung University
Finite State Machine (FSM)
Digital Integrated Circuit Design Laboratory
Finite State Machine(1/2)

Moore machine

其輸出,只與目前的電路狀態有關,與目前輸入訊號(current inputs)無關

最重要的特點:將輸入與輸出訊號隔離

在時脈脈波有效邊緣的有限延遲後,輸出達到穩定值:
『即使在一個時脈週期內輸入訊號發生變化,輸出也會在一個完整
的時脈週期內保持穩定值而不變』

輸入對輸出的影響要到下一個時脈週期才會反應出
next
state
current
state
18
Finite State Machine(2/2)

Mealy machine

其輸出,與目前的電路狀態、目前輸入訊號(current inputs)都有關

輸入訊號一改變,輸出也會馬上跟著改變

Moore machine 則是輸入改變後,輸出會延遲一個時脈週期後才變化
next
state
current
state
19
Examples of Moore Machine(cont.)

電路輸出只與目前狀態有關係的有限狀態機
1/0:
input 為 1
output 為 0
舉例
20
Examples of Moore Machine(cont.)

電路輸出只與目前狀態有關係的有限狀態機
21
Examples of Mealy Machine(cont.)

電路輸出受到目前輸入與目前電路狀態影響
22
Examples of Mealy Machine(cont.)

電路輸出受到目前輸入與目前電路狀態影響
23
Department of Computer Science and Information Engineering
National Cheng Kung University
Lab
Digital Integrated Circuit Design Laboratory
Lab - 1

計數器(Counter)-同步計數器的一種

上數計數器 ,計數範圍由0、1、2、…、8、9,然後回到0重新開始,以
循環的方式計數。




時脈輸入訊號的正緣到達時
若clear訊號為1,計數器會被清除
若clear訊號為0,計數器會持續地上數
下數計數器,計數範圍由9、8、7、…、1、0,然後回到9,以循環的方
式往下計數。



時脈輸入訊號的正緣到達時
若clear訊號為1,計數器會被清除
若clear訊號為0,計數器會持續地下數
25
Lab - 1

題目說明:一個可以上下數的計數器

若一開始 up_down訊號為0,則從9開始下數,到達0時,又回到9開始下
數;在下數的過程,若up_down訊號為1,則將下數的動作改為上數,如
8, 7, 6, 5, 6, 7…

若一開始up_down訊號為1,則從0開始上數,到達9時,又回到0開始上
數;在上數的過程,若up_down訊號為0,則將上數的動作改為下數,如
2, 3, 4, 3, 2, 1…

VeriInstrument裝置模擬


時間週期設為1就好
避免頻率太快
26
Lab - 2

完成一個 Moore machine,其 I/O 與 state 變化如下:



時脈:1 Hz
VeriInstrument 模擬、畫出 FSM、說明運作過程 (輸出結果會根據你跑到的
狀態來決定,例如:S0 輸出 0、S1 輸出 0 …)
Input Clock, Reset, in; / output out
下一個狀態 (next-state)
In=0
In=1
七段顯示器
輸出
(output)
S0
S0
S1
0
S1
S0
S2
1
S2
S3
S4
2
S3
S4
S3
3
S4
S1
S5
4
S5
S2
S5
5
目前狀態
(current-state)
27
Notice

wire and reg type define
 always begin …裡面變數… end ,宣告 reg type
 always begin …… end 外面變數,宣告 wire type
 需搭配 assign 使用

reg == register
 在組合電路中使用 reg type,合成 → 線 (net)
 在循序電路中使用 reg type,合成 → Flip-flop (register)

Inferred latch
 在組合電路中,case、if…else…若沒有寫滿,合成後會產生latch
Notice

建議請勿在 C:\ 與 Desktop 建立專案


請勿命名中文資料夾或數字開頭資料夾
請確認 Device family 是否與 FPGA 晶片符合

Family: Cyclone / Device: EP1C6Q240C8

top module name & project name 需要一致

燒錄檔案至 FPGA 前,Double-check Pin Assignment


設定錯誤的 Pin,會導致 VeriInstrument 無法執行
連接 FPGA 板後,請先確認是否可以正常燒錄與動作



VeriLite USB Driver (For all students)
USB Blaster
如果出現無法辨識硬體裝置,請先將 JTAG 拔除後,先裝 VeriLite USB Driver 後,再裝上去 JTAG,讓電腦去辨
識 USB Blaster 裝置,接著去指定到 USB Blaster Driver目標資料夾 C:\altera\8.0\quartus\drivers\usb-blaster
Number Representation

May be represented using


Format




Binary, decimal, hexadecimal,
<size>’ <base_format> <number>
base_format:
b, d, h,
Example



4'b1111; 16'd255
23456 (32-bit decimal # by default); 'hc3 (32 bit)
12'b1111_0000_1010