41

Click here to load reader

CH.2 Introduction to Microprocessor-Based Control

Embed Size (px)

DESCRIPTION

CH.2 Introduction to Microprocessor-Based Control. 2.1 微處理器系統硬體簡介. Microprocessor 微處理器 (CPU). Microcontroller 微控制器. Microprocessor (CPU) : 數位 IC 晶片 IC: I ntegrated C ircuit 數位控制優勢 數位信號可遠距傳輸 不產生誤差 可執行複雜計算 & 實施複雜控制策略 ( 軟體 ) 具長期記憶能力 變動控制策略 僅需更動軟體 無需變動硬體 可連線網路 執行遠端控制或無人控制. - PowerPoint PPT Presentation

Citation preview

Page 1: CH.2   Introduction to  Microprocessor-Based Control

CH.2 Introduction to Microprocessor-Based Control

Page 2: CH.2   Introduction to  Microprocessor-Based Control

Microprocessor

微處理器 (CPU)

Microcontroller 微控制器

2.1 2.1 微處理器系統硬體簡介微處理器系統硬體簡介

Page 3: CH.2   Introduction to  Microprocessor-Based Control

• Microprocessor (CPU) : 數位 IC 晶片• IC: Integrated Circuit

• 數位控制優勢1. 數位信號可遠距傳輸 不產生誤差2. 可執行複雜計算 & 實施複雜控制策略 ( 軟

體 )

3. 具長期記憶能力4. 變動控制策略 僅需更動軟體 無需變動硬

體5. 可連線網路 執行遠端控制或無人控制

Page 4: CH.2   Introduction to  Microprocessor-Based Control

Microcontroller 硬體架構

Page 5: CH.2   Introduction to  Microprocessor-Based Control

• 數位信號 5 Vdc = logic 1 ; 0 Vdc = logic 0

• Byte = 8 bits

Words = 8 bits; 16 bits; 32 bits

• LSB: Least Significant Bit

MSB: Most Significant Bit

• 11111111 = 255 decimal MSB LSB

Page 6: CH.2   Introduction to  Microprocessor-Based Control

• ALU (arithmetic logic unit)

執行算數運算 (+ ; -)

邏輯運算 (AND ; OR)

• Control section: 執行軟體指令、處理 data flow

e.g. 讀 input data;

hand data to ALU for processing

• 記憶體 each byte (8 bits) 均被付予 位址 (address)

Page 7: CH.2   Introduction to  Microprocessor-Based Control
Page 8: CH.2   Introduction to  Microprocessor-Based Control

• Addressable Memory:

RAM: 可被讀、寫至任意位址 關機 資料被清除洗掉 ROM: 可被讀取、無法寫入 關機 資料被保存 製造商寫入資料• EPROM: Erasable Programmable ROM

可被讀、寫,但由特殊設備執行• I/O : 連接 PC 及外界的裝置 (circuit)

Page 9: CH.2   Introduction to  Microprocessor-Based Control

I/O 具位址 , CPU 視其為 memory location;

I/O 接到 CPU 的位址指令 , I/O 成通路 , 信號可input/output; I/O 自動關閉。

• Address bus

單向傳送位址指令;由 CPU → memory & I/O

• Data bus ( 雙向傳輸信號 )

信號輸入 : 經 data bus 由 I/O 至 CPU ;

信號儲存 : 經 data bus, CPU 先送記憶體的位址 打開記憶單元 , 再送 data 到記憶單元儲存 ;

• Control bus

供 CPU 傳送指令

Page 10: CH.2   Introduction to  Microprocessor-Based Control

• Registers:

含 Accumulator & Program counter

• 指令分類 :

1. 移動 data; 2. 執行數學或邏輯運算 ;

3. 控制 program flow, 如 jump forward

Page 11: CH.2   Introduction to  Microprocessor-Based Control

• Accumulator 功能 : data 進 CPU 第一站 (data holding register) data 離 CPU 最後一站 ALU 數學運算結果亦存於此

Page 12: CH.2   Introduction to  Microprocessor-Based Control

• Program counter 功能 :

Special address-storage register; 特殊的位址儲存區

用於追蹤指令執行的進程 ( 於軟體中 );

( 永遠儲存下一個執行指令的位址 )

軟體存在於記憶體中 ;

一經起動 , 指令執行完全自動化 ;

指令的執行 , 是一連串的 fetch-execute cycle 。 ( 取 -執行 )

Page 13: CH.2   Introduction to  Microprocessor-Based Control

• 軟體 Run• Program counter → 取入 00( 第一條指令之位址 )

• 微處理器由微處理器由 0000 位址的記憶體 取得第一位址的記憶體 取得第一條指令指令 DBDB ;;

Program counter → 取入 01 ( 第二條指令之位址 )

• 執行執行第一第一條指令指令 DBDB 。。 DB DB (1 byte long)(1 byte long): input data from a port: input data from a port

2.22.2  微處理器軟體執行案例說明 微處理器軟體執行案例說明

Page 14: CH.2   Introduction to  Microprocessor-Based Control
Page 15: CH.2   Introduction to  Microprocessor-Based Control

• 微處理器由微處理器由 0101 位址的記憶體 取得第二位址的記憶體 取得第二條指令 指令 0101 ;;

Program counter → 取入 02 ( 第三條指令之位址 ) • 執行執行第二第二條指令指令 0101 。。 01 01 (1 byte long)(1 byte long): port to read from: port to read from• 微處理器由微處理器由 0202 位址的記憶體 取得第三位址的記憶體 取得第三條指令 指令 3C3C ; ;

Program counter → 取入 03 ( 第四條指令之位址 )• 執行執行第三第三條指令指令 3C3C 。。 3C: 3C: accumulatoraccumulator 值送至值送至 ALU ALU 加加 11 後再回存後再回存 accumulaccumul

atorator

Page 16: CH.2   Introduction to  Microprocessor-Based Control

• 微處理器由微處理器由 0303 位址的記憶體 取得第四位址的記憶體 取得第四條指令 指令 D3D3 ;;

Program counter → 取入 04 ( 第五條指令之位址 )

• 執行執行第四第四條指令指令 D3D3 。。 D3 D3 (1 byte long)(1 byte long): send data to output port : send data to output port • 微處理器由微處理器由 0404 位址的記憶體 取得第五位址的記憶體 取得第五條指令 指令 O2O2 ; ;

Program counter → 取入 05 ( 第六條指令之位址 )

• 執行執行第五第五條指令指令 O2O2 。。 O2: output port, accumulatorO2: output port, accumulator 值送至值送至 port 02port 02

Page 17: CH.2   Introduction to  Microprocessor-Based Control

• 微處理器由微處理器由 0505 位址的記憶體 取得第六位址的記憶體 取得第六條指令 指令 7766 ;;

Program counter → 取入 06 ( 第七條指令之位址 )

• 執行執行第六第六條指令指令 7676 。。 76 76 (1 byte long)(1 byte long): Halt,: Halt, 微處理器停止操作微處理器停止操作。。

Page 18: CH.2   Introduction to  Microprocessor-Based Control

2.3 並列埠介面並列埠介面 (parallel interface)(parallel interface) 88 位元並列介面 位元並列介面 : : 使用八條線同時傳送使用八條線同時傳送 88位元資料。位元資料。 data busdata bus 與外界的溝通介面。與外界的溝通介面。(( 對對 ON-OFFON-OFF 裝置裝置,,並列介面是輸入輸出的理想介面並列介面是輸入輸出的理想介面 ))

每每 11 位元信號被稱為位元信號被稱為 11 個邏輯變數 個邏輯變數 (logic (logic variable)variable) ;; 88 位元並列埠位元並列埠、、提供八個提供八個 logic logic variablevariable 。。

e.g. Limit switch e.g. Limit switch 用用 1 input bit1 input bit ;; 控制一 控制一 ON-OFFON-OFF 馬達用馬達用 1 output b1 output b

it.it.

2.3 2.3 微控制器的微控制器的 I/OI/O 介面介面

Page 19: CH.2   Introduction to  Microprocessor-Based Control

88 位元位元 DAC DAC (Digital-to-Analog Converter)(Digital-to-Analog Converter)outputoutput 信號由信號由 I/OI/O 出電腦前 需先經出電腦前 需先經 DACDAC 轉換轉換

VV

outref

輸入256

輸入 : binary input (decimal value)

Page 20: CH.2   Introduction to  Microprocessor-Based Control

範例範例 2.22.2

一個一個 88 位元位元 DACDAC 之 為之 為 10 V10 V ,二進位輸入是,二進位輸入是1001101110011011 ,求類比輸出電壓。,求類比輸出電壓。

解:解:二進位輸入二進位輸入 1001101110011011 的十進位值為的十進位值為 155155 ,應用式,應用式可計算出類比輸出電壓:可計算出類比輸出電壓:

VV 10 V

outref

輸入256

155

2566 05 V.

Vref

Page 21: CH.2   Introduction to  Microprocessor-Based Control

P31P31

150 ns 轉換速度

16- pin DIP

Page 22: CH.2   Introduction to  Microprocessor-Based Control

ADC ADC 類比數位轉換類比數位轉換器器 (analog-to-digital converter)(analog-to-digital converter)將類比電壓轉換成數位字組的電路。將類比電壓轉換成數位字組的電路。

須介於 0 –Vref 間

輸出對 位元

V Vin ref

255

8( )輸出 : binary output

Page 23: CH.2   Introduction to  Microprocessor-Based Control

範例範例 2.42.4

一個一個 88 位元位元 ADCADC 的 是的 是 7 Vdc7 Vdc ,類比輸入,類比輸入是是 2.5 Vdc2.5 Vdc 。。 ADCADC 二進位輸出碼是多少?二進位輸出碼是多少?解:解:一個一個 88 位元字組,當 時,其最位元字組,當 時,其最大十進位的輸出值是大十進位的輸出值是 255255 ,所以,類比輸入電,所以,類比輸入電壓壓 7 Vdc7 Vdc 可轉換成可轉換成 255 ( 255 ( 十進位 十進位 )) 。使用輸入 。使用輸入 / / 輸出資料的關係,可得一個比值,然後,使用輸出資料的關係,可得一個比值,然後,使用來求此特定輸入來求此特定輸入 2.5 Vdc2.5 Vdc 的輸出:的輸出:

V Vin ref

輸出V

255

7 Vdcin

Vref

Page 24: CH.2   Introduction to  Microprocessor-Based Control

P34P34

100 us 轉換速度較 DAC0808 慢 700倍

20- pin DIP

Page 25: CH.2   Introduction to  Microprocessor-Based Control

P35P35

轉速控制

logic 1 CW

Logic 0 CCW

Page 26: CH.2   Introduction to  Microprocessor-Based Control

串列介面 串列介面 (serial interface)(serial interface) •傳送一連串單一位元資料。傳送一連串單一位元資料。•只需“資料”和“返回 只需“資料”和“返回 (return)(return) ” ” 兩條線。兩條線。•能運用現有的電話系統傳送資料。能運用現有的電話系統傳送資料。

Page 27: CH.2   Introduction to  Microprocessor-Based Control

電腦內,資料以電腦內,資料以並列型式並列型式出現出現 UART UART (universal asynchronous receiver transmitter)(universal asynchronous receiver transmitter)

並列資料並列資料←→←→串串列資料 轉換列資料 轉換

Page 28: CH.2   Introduction to  Microprocessor-Based Control

•圖圖 2.11 2.11 非同步串列資料的標準格式。非同步串列資料的標準格式。 一個開始位元一個開始位元 (start bit)(start bit) ,然後資,然後資 料,然後一個偵錯位元料,然後一個偵錯位元 (parity) (parity) ,及一個停,及一個停 止位元。止位元。

標準的位元傳輸速率 :

300 bps ( 每秒位元數 ) , 1200 bps 、 2400 bps 、 9600 bps 、 14,400 bps 、 28,800bps 、 33,600 bps 、 57,600 bps 。

Page 29: CH.2   Introduction to  Microprocessor-Based Control
Page 30: CH.2   Introduction to  Microprocessor-Based Control

串列傳輸介面 串列傳輸介面 ((RS-232 RS-232 標準標準 ))

分為分為資料終端裝備資料終端裝備 (DTE: data terminal equipment)(DTE: data terminal equipment)

和和資料通訊裝備資料通訊裝備 (DCE: data communication)(DCE: data communication) , , DTEDTE 通常是電腦,而通常是電腦,而 DCEDCE 通常是通常是 modemmodem

圖圖 2.122.12 ,, RS-232 RS-232 介面有七條訊號線介面有七條訊號線 接腳接腳 2 2 送串列資料,接腳送串列資料,接腳 3 3 接收資料,接腳接收資料,接腳 4 4 要要 求傳送 求傳送 (request to send)(request to send) 資料資料、、接腳接腳 5 5 清除傳送 清除傳送 (clear to send)(clear to send) 資料等。資料等。

Page 31: CH.2   Introduction to  Microprocessor-Based Control

網路 網路 (Networking)(Networking) 遠端控制遠端控制區域網路 區域網路 (LAN: local area network)(LAN: local area network) 最常被用最常被用

Page 32: CH.2   Introduction to  Microprocessor-Based Control

2.42.4 控制程式的規畫 控制程式的規畫

Page 33: CH.2   Introduction to  Microprocessor-Based Control

2.5 2.5 微控制器 微控制器 (( 單晶片微電腦 單晶片微電腦 ))特別為控制運用所設計。包括一個微處理器,記特別為控制運用所設計。包括一個微處理器,記憶體 憶體 (RAM(RAM 及及 ROM)ROM) ,輸入 ,輸入 / / 輸出埠,及其它輸出埠,及其它獨特的特色元件。獨特的特色元件。

Motorola 68HC1lMotorola 68HC1l (8 (8 位元微控制器位元微控制器 ))

Intel 8051 Intel 8051 (8(8 位元微控制器位元微控制器 ))

Microchip Technology PIC 16C72 Microchip Technology PIC 16C72 (8(8 位元位元 ))

Parallax Inc. BASIC StampParallax Inc. BASIC Stamp

Page 34: CH.2   Introduction to  Microprocessor-Based Control

Motorola 68HC1lMotorola 68HC1l (8 (8 位元微控制器位元微控制器 ): ): 有有 256K 256K

RAMRAM ,, 8K ROM8K ROM ,, 512K EPROM ( 512K EPROM ( 如圖如圖 2.152.15

(a))(a)) 。它同時也有五個。它同時也有五個 88 位元的埠且具有內建的位元的埠且具有內建的序列資料傳輸和序列資料傳輸和 ADCADC功能。功能。

Page 35: CH.2   Introduction to  Microprocessor-Based Control

Microchip Technology PIC 16C72Microchip Technology PIC 16C72

Intel 8051Intel 8051

Page 36: CH.2   Introduction to  Microprocessor-Based Control

Parallax Inc. BASIC Stamp Parallax Inc. BASIC Stamp (( 微控制器微控制器 ))

Page 37: CH.2   Introduction to  Microprocessor-Based Control

單板電腦 單板電腦 (single-board computer) (single-board computer)

Zilog Z80Zilog Z80 ,, Intel 8085Intel 8085 或或 80888088 ,, Motorola 68000Motorola 68000

同時包含同時包含 ADCADC 、、 DACDAC

Page 38: CH.2   Introduction to  Microprocessor-Based Control

可程式邏輯控制器可程式邏輯控制器 (PLC, programmable logic controller) (PLC, programmable logic controller)

執行程序控制。執行程序控制。能直接與系統元件相接,如開關、繼電器、小型能直接與系統元件相接,如開關、繼電器、小型馬達和指示燈等。馬達和指示燈等。

Page 39: CH.2   Introduction to  Microprocessor-Based Control

個人電腦控制系統 個人電腦控制系統 ((價格便宜價格便宜 ) ) 個人電腦具有四到八個擴充槽 個人電腦具有四到八個擴充槽 (expansion slot)(expansion slot) ,,擴充卡 擴充卡 (expansion card) (expansion card) 插入槽內,連結電腦插入槽內,連結電腦和外面世界。和外面世界。

Page 40: CH.2   Introduction to  Microprocessor-Based Control

總結總結 微控制器廣泛應用微控制器廣泛應用的的數位控制元件。數位控制元件。微控制器的微控制器的三項三項基本單元:基本單元: (1) CPU ( (1) CPU ( 微微處理器 處理器 ) ) ;; (2) (2) 記憶體; 記憶體; (3) (3) 輸入 輸入 / / 輸輸出。出。資料傳輸介面有二種:資料傳輸介面有二種:並列和串列並列和串列。串列。串列資料傳輸距離較長。資料傳輸距離較長。 須使用類比須使用類比、數位、數位信號介面;信號介面; ADCADC ( ( 類類比數位轉換器 比數位轉換器 ) ) 或或 DACDAC ( ( 數位類比轉換器 數位類比轉換器 ) ) 。。

Page 41: CH.2   Introduction to  Microprocessor-Based Control

總結 總結 (( 續續 2)2)

以微處理器為基礎架構的控制器以微處理器為基礎架構的控制器 ::微控制器微控制器,全部都在單一,全部都在單一 ICIC上上;;單板電腦單板電腦,,組合於單一印刷電路板上組合於單一印刷電路板上;;個人電腦個人電腦,,利用擴充介面卡,將個人電利用擴充介面卡,將個人電腦變成一個控制器腦變成一個控制器;;可程式邏輯控制器可程式邏輯控制器。。