30
16-bit MCU 新增的 PPS 功能 © 2005 Microchip Technology Incorporated. All Rights Reserved. Slide 1

16-bit MCU 新增的 PPS 功能 - Microchip · 2012-04-18 · PPS - Peripheral Pin SelectPeripheral Pin Select What it isWhat it is… −讓使用者可以自行為內建的純數位周邊指定

  • Upload
    others

  • View
    16

  • Download
    0

Embed Size (px)

Citation preview

  • 16-bit MCU 新增的 PPS 功能

    © 2005 Microchip Technology Incorporated. All Rights Reserved. Slide 1

  • Microchip 16-bit MCU 的 PPSMicrochip 16 bit MCU 的 PPS

    PPS Peripheral Pin Select� PPS - Peripheral Pin Select− 什麼是 PPS ?− PPS 帶來的好處與便利性?

    PPS 如何工作?− PPS 如何工作?� 如何為內建周邊指定輸入接腳

    如何為內建周邊指定輸出接腳� 如何為內建周邊指定輸出接腳

    � 實例演練� 實例演練

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 2

  • PIC24F 與其他 16-bit MCU 的比較dsPIC3340 MIPS18 100 i

    dsPICdsPIC®® DSC DSC FamiliesFamilies

    dsPIC30F30 MIPS18 – 80 pinsUp to 144KB Flash

    18 – 100 pinsUp to 256KB Flash

    ATIO

    N

    a esa esPIC24H40 MIPS18 100 pins

    Up to 144KB Flash

    EGR

    A 18 – 100 pinsUp to 256KB FlashPIC24F16 MIPS

    PICPIC®® MCUMCUIN

    TE

    PIC1810 MIPS

    16 MIPS28 –100 pinsUp to 128 KB Flash

    FamiliesFamiliesPIC10, PIC12, PIC16 5 MIPS

    10 MIPS18 – 100 pinsUp to 128KB Flash

    PIC16: 5 MIPS6 – 64 pins< 16KB Flash

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 3

    PERFORMANCE

  • PPS - Peripheral Pin SelectPPS Peripheral Pin Select

    What it is� What it is…−讓使用者可以自行為內建的純數位周邊指定讓使用者可以自行為內建的純數位周邊指定

    輸出及輸入接腳

    達到內建周邊功能的最佳化使用方式−達到內建周邊功能的最佳化使用方式−允許接腳的使用能經由軟體來重新定義

    � What it is not …−並非用來達成接腳相容性之用−Analog的周邊以及特殊的功能腳位 (e g−Analog的周邊以及特殊的功能腳位 (e.g.,

    PMP & I2C™) 仍然位於固定腳位

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 4

  • 為何我們需要 PPS ?假設在實際的應用案例我們須要以下資源假設在實際的應用案例我們須要以下資源

    Memory Serial Channels� Memory−64K Flash

    � Serial Channels− I2C™ x 264K Flash

    −8K RAMI C x 2

    − SPI x 2� Analog

    2 ch ADC− UART x 2

    −2 ch ADC −Vref +&-−Comparator x 2Di it l I/O� Digital I/O−4 I/O

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 5

    −4 I/O

  • 為何我們需要 PPS 的實例我們可以選擇 High-Pin Count 的 MCU !我們可以選擇 High-Pin Count 的 MCU !

    � Application− 64 KB Flash, 8 KB RAM

    2 ch A/D Ext VREF− 2 ch A/D, Ext. VREF− 2 Comparators− UART x 2, I2C™, SPI x 2 − 4 Digital I/O

    � Pin multiplexing blocks functionsfunctions− UART1 and SPI1− Comparator2 and SPI1

    � 25 spare pins− Must use even larger pin

    count devicecount device− Or write SPI in software

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 6

  • 為何我們需要 PPS 的實例為何我們需要 PPS 的實例

    會選用 Pi C t 較高的 MCU 通常是因為� 會選用 Pin-Count 較高的 MCU , 通常是因為接腳衝突的關係而不得不選用腳數較多的來避免

    選擇 High Pin Count 的 MCU 之缺點� 選擇 High Pin-Count 的 MCU 之缺點− 占用較大的 PCB 資源− Power Consumption

    P i $$− Price $$� 如果 …. 選用的 MCU 有豐富的內建周邊而且� 如果 …. 選用的 MCU 有豐富的內建周邊而且

    接腳數很小

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 7

  • 周邊接腳可自行對應的優點周邊接腳可自行對應的優點

    解決產品設計上的一般考量� 解決產品設計上的一般考量

    設計彈性− 設計彈性− 規劃時的簡易性− 規劃時的簡易性− 周邊安排有衝突時的優先順序考量周邊安排有衝突時的優先順序考量− 特定周邊的限制 (Analog 腳位)( g )− 安全與保密性

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 8

  • Remappable Functions16 bit MCU and dsPIC® DSC16-bit MCU and dsPIC® DSC

    All SPI & UART Functions� All SPI & UART Functions� Timer & External Interrupt Inputs� Timer & External Interrupt Inputs� Input Capture & Output Comparesp p p p� Analog Comparator outputs� PWM Fault Input pins

    Quadrature Encoder Interface Inputs� Quadrature Encoder Interface Inputs� Data Converter Interface� Data Converter Interface� CAN

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 9

  • PPS Implementation DetailsPPS Implementation Details

    可被 的內建周邊都可以被指定於任何 RP� 可被 remap 的內建周邊都可以被指定於任何 RP pin− 多個 functions 對應至同一 pin 是被支援的

    Inputs vs Outputs� Inputs vs. Outputs − 輸入的設定方式為指定某一 Pin 腳給指定的周邊− 輸出設定方式為指定某一周邊功能給指定的 Pin 腳

    Pin 腳的安排由軟體設定� Pin 腳的安排由軟體設定− 可選擇 on-the-fly 的設定或單次的設定方式

    � 使用 Configuration Bits 裡的 IOLOCK 選項

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 10

  • 周邊輸入在做 Remap 時要參考的暫存器列表暫存器列表

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 11

  • Remappable InputsRemappable InputsPeripheral Input Pin Select Bits

    RP0 Pad Logic

    Pin Select Bits

    RP1 Pad Logic

    RP2 Pad Logic

    Input to Peripheral

    RPnPad

    Logic

    // C Example – Map U1RX // 每周邊有對應的 RPINRx 暫存器 , 例如 UART1 RX 對應到 RPINR18 的 bit 0 ~ 5// RPINR18 中的 6 個位元 用來設定 UART1 RX 要接收哪一個 RP 接腳的輸入信號RP8

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 12

    // RPINR18 中的 6 個位元 , 用來設定 UART1 RX 要接收哪一個 RP 接腳的輸入信號RP8RPINR18bits.U1RXR = 8;

  • Remappable InputsRemappable Inputs

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 13

    Define the location of each function used by modifying xxxxR bits in RPINRn registers

  • Remappable OutputsRemappable Outputs

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 14

  • Remappable OutputsRemappable Outputs

    Peripheral Output Select Bits

    Peripheral 1 Output

    Peripheral 2 Output

    RP0Pad Logic

    Peripheral 3 Output

    Logic

    Peripheral N OutputPeripheral N Output

    // C Example – Map U1TX to RP1// 每個 RP Pin 有對應的 RPORx 暫存器 , 例如 RP1 有 RPOR0// RPOR0 中有 5 個 bit ( Bit-8 ~ Bit-12 ) 用來指定要由 RP1 輸出的周邊

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 15

    // UART1 TX 的編號為 3 號RPOR0bits.RP1R = 3

  • Remappable OutputsRemappable Outputs

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 16

    Define the output functionality on each pin by modifying RPnR bits in RPORn registers

  • Remapping Pins with VDIRemapping Pins with VDI

    Color coding shows what pins are used and where conflicts may exist

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 17

  • 使用 MPLAB C30 內建的Peripherals Library 來設定Peripherals Library 來設定

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 18

  • PPS 設定輸出的函數PPS 設定輸出的函數

    說明檔的位置� 說明檔的位置

    − C:\Program Files\Microchip\MPLAB C30\docsC:\Program Files\Microchip\MPLAB C30\docs� iPPSOutput(pin,fn)

    − 將選定的輸出腳指定給某一 Function− Pin =− Pin =

    � OUT_PIN_PPS_RP0 .. OUT_PIN_PPS_RP31定義的眾多− fn = PPS.h 定義的眾多 Function

    � e.g. OUT FN PPS OC1 g _ _ _OUT_FN_PPS_U1TX

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 19

  • PPS 設定輸入的函數PPS 設定輸入的函數

    說明檔的位置� 說明檔的位置

    − C:\Program Files\Microchip\MPLAB C30\docsC:\Program Files\Microchip\MPLAB C30\docs� iPPSInput(fn,pin)

    − 將某一 Function 的輸入指 定給某一 接腳− fn = PPS h 定義的眾多 Function− fn = PPS.h 定義的眾多 Function

    � e.g. IN_FN_PPS_IC1 IN FN PPS U1RXIN_FN_PPS_U1RX

    − Pin =� IN_PIN_PPS_RP0 .. IN_PIN_PPS_RP31� IN PIN PPS RPI32 .. IN PIN PPS RPI45

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 20

    _ _ _ _ _ _

  • 使用 MPLAB C30 Peripheral Library 設定 PPS 範例Library 設定 PPS 範例

    #define USE AND OR /* To enable AND OR mask setting */#define USE_AND_OR / To enable AND_OR mask setting /#include void PPS_init(void)

    { /* Configure Peripheral pin for UART1*/iPPSInput(IN_FN_PPS_U1RX,IN_PIN_PPS_RP10); iPPSInput(IN_FN_PPS_U1CTS,IN_PIN_PPS_RPI32); iPPSOutput(OUT_PIN_PPS_RP17,OUT_FN_PPS_U1TX); iPPSOutput(OUT_PIN_PPS_RP31,OUT_FN_PPS_U1RTS);

    }

    // 設定 UART1 的 TX 與 RTS 分別輸出至 RP17 & RP31// 設定 UART1 的 RX 與 CTS 分別由 RP10 及RPI 輸入信號// 設定 UART1 的 RX 與 CTS 分別由 RP10 及RPI 輸入信號// RPIx : 只能 remap INPUT 的功能接腳

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 21

  • PPS Register Protection

    HW i t it h ki

    PPS Register Protection

    � HW integrity checking− Bit flip will cause device resetBit flip will cause device reset

    � 任何位元的非預期改變都會造成 RESET

    I/O l k f t� I/O lock feature− RPINRn/RPORn can only be written to whileRPINRn/RPORn can only be written to while

    OSCCON[IOLOCK] = 0; once the IOLOCK is set, the registers cannot be writtenset, the registers cannot be written

    � IOLOCK Protection− The state of the IOLOCK bit can only be

    changed with an unlocking sequence

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 22

    g g q− Protection selectable by configuration bit

  • Pin Function PriorityPin Function Priority

    如果功能重疊時的優先順序� 如果功能重疊時的優先順序 :

    1. Analog Functions ANx, Vref+/-UART TX SDO OC2. PPS Outputs

    3 PPS InputsUART TX, SDO, OC

    UART RX, SDI, IC3. PPS Inputs4 Fixed Digital

    , ,

    I2C PMP4. Fixed Digital Peripheral Outputs

    I2C, PMP

    5. Fixed Digital Peripheral Inputs

    I2C, PMP

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 23

    Peripheral Inputs

  • Initializing a PPS ApplicationInitializing a PPS Application1. Design Decision: Static or Dynamic RPn

    ?g y

    assignment?• Set IOL1WAY config bit accordinglyg g y

    2. Initialize the pin out by mapping the RPn pins to the desired peripheralRPn pins to the desired peripheral input/output functions

    • Map RPn pin(s) Peripheral Input Function(s)Map RPn pin(s) Peripheral Input Function(s)• Map Peripheral Output Function(s) RPn

    pin(s)pin(s)• Lock the RPn SFRs using ‘lock’ sequence

    3 Configure Peripherals3. Configure Peripherals4. Enable Interrupts (if required)

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 24

  • Cool ByproductsCool Byproducts� Increase drive strength by outputting same� Increase drive strength by outputting same

    peripheral on multiple pins

    RP1

    PadLogic

    Peripheral Output

    e.g. OC1

    RP2

    PadLogic

    P d

    RP3

    PadLogic

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 25

  • Cool ByproductsCool ByproductsConnect one signal to multiple peripheral� Connect one signal to multiple peripheral inputs

    Pad Input to Peripheral #1RP0 Pad LogicInput to Peripheral #1

    e.g. U1CTS

    Input to Peripheral #2

    1e.g. INT1

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 26

  • Cool ByproductsCool Byproducts

    Connect peripheral output to another� Connect peripheral output to another input (Loopback) for debugging( ) gg g

    RP0 Pad LogicInput to Peripheral

    e.g. SDI

    Output to Peripheral

    e.g. SDO

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 27

  • 原先須使用 64-pin MCU 的應用現在因為利用 PPS 所以只需 44 i MCU因為利用 PPS 所以只需 44-pin MCU

    � 應用需求−64 KB Flash, 8 KB RAM6 as , 8

    −2 ch A/D, Ext. VREF−2 Comparatorsp−UART x 2, I2C™, SPI x 2 −4 Digital I/O

    � 使用只有 44-Pin 的� 使用只有 44-Pin 的PIC24FJXXGA004

    �還可以有 3 Spare Pins�還可以有 3 Spare Pins

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 28

    Smaller packages, simplified design and lower cost!

  • Application Example #2Application Example #2

    Comm nicating ith m ltiple� Communicating with multiple UART Devices

    � Standard Options:UART

    p

    U1TX U3TX

    UART Device #1

    U1TX

    Really Big

    UART Device #1

    UART Device #3

    U1TX

    U1RXU3TXU3RX

    Micro

    UART Device #2

    U1RX

    Micro

    UART Device #2

    UART Device #4

    U2TX

    U2RXU4TXU4RX

    Micro

    UART Device #3

    UART使用有 PPS 功能並內建多個 使用傳統 MCU 並搭配多工器完

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 29

    UART Device #4

    使用有 PPS 功能並內建多個UART 的 PIC24FJ 系列

    使用傳統 MCU 並搭配多工器完成多 UART 的應用

  • Application Example #2Application Example #2Communicating with multiple UART� Communicating with multiple UART Devices

    � Dynamic Peripheral Remapping:

    UART D i #1

    UART D i #3

    U1TX U1TX

    Device #1 Device #3U1RX U1RX

    PIC24FJ64GA004

    UART Device #2

    UART Device #4

    U1TX

    U1RX

    U1TX

    U1RX

    © 2008 Microchip Technology Incorporated. All Rights Reserved. C30 入門及應用 Slide 30