introducing: enhanced 8-bit mid-range pic ® microcontroller (mcu) core detailed technical overview

69
INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

Upload: audrey-jenkins

Post on 26-Mar-2015

249 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

INTRODUCING:Enhanced 8-bit Mid-Range

PIC® Microcontroller (MCU) Core

Detailed Technical Overview

Page 2: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

2

Agenda

Introducing the PIC16F1XXX

Migration to the PIC16F1XXX

New Coding Tricks

Advanced Capabilities

Page 3: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

Introducing the PIC16F1XXX

Page 4: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

4

Introducing the PIC16F1XXX

Overview

Memory Map

New Instructions

Enhanced Indirect Memory Features

Page 5: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

5

PIC® Microcontroller Family Roadmap

PIC10/12PIC10/12(12-bit instruction word)(12-bit instruction word)

PIC10/12PIC10/12(12-bit instruction word)(12-bit instruction word)

PIC16PIC16(14-bit instruction word)(14-bit instruction word)

PIC16PIC16(14-bit instruction word)(14-bit instruction word)

Enhanced PIC16Enhanced PIC16(14-bit instruction word)(14-bit instruction word)

Enhanced PIC16Enhanced PIC16(14-bit instruction word)(14-bit instruction word)

PIC18PIC18(16-bit instruction word)(16-bit instruction word)

PIC18PIC18(16-bit instruction word)(16-bit instruction word)

PIC24PIC24PIC24PIC24

dsPICdsPIC®® DSC DSCdsPICdsPIC®® DSC DSC

PIC32PIC32PIC32PIC32

Mem

ory

/Per

form

ance

Mem

ory

/Per

form

ance

PricePrice

Page 6: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

6

PIC16 Enhancement GOALS

Increase maximum program memory

Increase space for peripherals

Increase maximum data memory

Reduce penalty for paging/banking

Improving ‘C’ efficiency

Minimize difficulty of migration

Maintain Maintain 14-bit program memory,14-bit program memory,

to keep cost lowto keep cost low

Page 7: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

7

Front Page Comparison of PIC16XXX and PIC16F1XXX

OLD NEWHigh-Performance RISC CPU:

Only 35 instructionsAll single-cycle instructions except branches

Operating speed:DC – 20 MHz oscillator/clock inputDC – 200 ns instruction cycle

Interrupt capability

8-level-deep hardware stack

Direct, Indirect and Relative Addressing modes

High-Performance RISC CPU:

Only 49 instructionsAll single-cycle instructions except branches

Operating speed:DC – 32 MHz oscillator/clock inputDC – 125 ns instruction cycle

Interrupt capability with automatic context saving

16-level-deep hardware stack with Overflow/Underflow Reset

Direct, Indirect and Relative Addressing modesTwo full 16-bit File Select Registers (FSRs)read program and data memory

Page 8: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

8

Quick Comparison

PIC16 Enhanced PIC16 PIC18

Max GPR/SFR 336 / 110 2496 / 316 4096/159+more, if the SFRs are outside of the access bank.

Max Program 8Kx14 32Kx1416K is likely the largest device

1Mx16

FSRs 1 2 can access program memory

3

Instruction Count

35 49 75 83 including the optional extended instructions

Stack 8 16with over/underflow Reset

31with over/underflow Reset

Interrupts 1 1hardware context save

2optional hardware context save

Program Memory Read

All devices via RETLW. Some devices via EEPROM interface

All devices via RETLW or FSR. All devices via EEPROM interface.

All devices via TABLRD instructions.

Page 9: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

9

New Data Memory Map

32 Banks of File Registers- 15 banks are reserved for the future

The Memory Map is Simplified- Bottom 16 bytes of each bank are common- First 12 bytes of each bank are for the CPU registers- SFRs are located at address 12-31

New Features- W is mapped to “w reg”- Banks 16-30 are reserved for future fun- Bank 31 has advanced functions

Page 10: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

10

Data Memory Map

GPR80 Bytes

Common Memory (16 bytes)

12 Common CORE SFRs

Bank 31Special

Functions

Stack Accessand

DebuggingRegisters

SFRs20

GPR80 Bytes

SFRs20

GPR80 Bytes

SFRs20

GPR80 Bytes

SFRs20

GPR80 Bytes

SFRs20

GPR80 Bytes

SFRs20

Banks

6-3

0

Bank 0 Bank 1 Bank 2 Bank 3 Bank 4 Bank 5 Bank 310x000

0x00B0x00C

0x01F0x020

0x06F0x070

0x07F

Page 11: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

11

Program Counter Latch High

Common Core Registers

0x0B

0x0A

0x09

0x08

0x07

0x06

0x05

0x04

0x03

0x02

0x01

0x00

Address

Interrupt Control RegisterINTCON

PCLATH

Working RegisterWREG

Bank Select RegisterBSR

File Select Register 1 High ByteFSR1 High

File Select Register 1 Low ByteFSR1 Low

File Select Register 0 High ByteFSR0 High

File Select Register 0 Low ByteFSR0 Low

Status RegisterSTATUS

Program Counter LowPCL

Indirect Register 1INDF1

Indirect Register 0INDF0

FunctionRegister

NEWNEW

NEWNEW

NEWNEW

NEWNEW

NEWNEW

NEWNEW

NEWNEW

Page 12: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

12

IRPIRP RP1RP1 RP0RP0 CCDCDCTOTO ZZPDPD

Data Memory Banking The old device required banking via RP0 and RP1 in the Status

Register.

These bits NO LONGER EXIST.

Now the BSR register handles all banking.

The new MOVLB instruction selects the bank in one instruction.

0101 10100000 1111

-- -- CCDCDCTOTO ZZ-- PDPD

-- -- 002244 11-- 33

STATUSSTATUS

BSRBSR

OLDOLD NEWNEW

11 2200 33 44 3131

Page 13: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

13

Program Memory

Program Memory Extended to 16 Pages of 2 Kbytes

Paging Simplified with MOVLP Instruction

66 55 001144 2277 33-- -- 88991212 1010-- 1111

PCLATHPCLATH PCLPCL

66 55 001144 2277 3388991010 GOTO/CALLGOTO/CALL

66 55 001144 2277 33889910101212 1111 ProgramProgramCounterCounter

1414 1313

1414 1313

66 55 001144 2233 MOVLPMOVLP

Page 14: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

14

New FSR 2 x 16-bit FSRs

Access All File Registers and All Program Memory

New FSRs Allow 1 Data Pointer for All Memory

FSRs Are Now Supported By New Instructions

SFRsSFRsandand

GPRsGPRs

RESERVEDRESERVED

PROGRAMPROGRAMMEMORYMEMORY

0x00000x0000

0x0FFF0x0FFF

0x10000x1000

0x7FFF0x7FFF

0x80000x8000

0xFFFF0xFFFF

0x00000x0000

0x7FFF0x7FFF

FSR FSR AddressesAddresses

Program Program Counter Counter AddressesAddresses

BSR + File BSR + File Register Register AddressesAddresses

0x00000x0000

0x0FFF0x0FFF

FSR FSR AddressesAddresses

Linear GPR RegionLinear GPR Region

Reach

able

by

Reach

able

by

FSR only

FSR only

0x29FF0x29FF

0x3A000x3A00

RESERVEDRESERVED0x1FFF0x1FFF

0x20000x2000

FSR MSb is set

Page 15: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

16

Linear GPR Region Shadows 80 byte GPR blocks into linear array Keeps FSR operations inside GPR area Allows large stacks, arrays, buffers, etc. Access is via the FSR and a second address range

Common Memory (16 bytes)

Bank 31Special

Functions

Stack Accessand

DebuggingRegisters

SFRs20

SFRs20

SFRs20

SFRs20

SFRs20

SFRs20

Banks

6-3

0

12 Common CORE SFRs

BANK 0GPR

80 Bytes

BANK 1GPR

80 Bytes

BANK 2GPR

80 Bytes

BANK 3GPR

80 Bytes

BANK 4GPR

80 Bytes

BANK 5GPR

80 Bytes

0x20000x2000

0x204F0x204F

0x20500x2050

0x20A00x20A0

0x209F0x209F

0x20EF0x20EF0x20F00x20F0

0x213F0x213F

0x21400x2140

0x218F0x218F

BANK 0BANK 0

BANK 1BANK 1

BANK 2BANK 2

BANK 3BANK 3

BANK 4BANK 4

0x21900x2190

0x21DF0x21DFBANK 5BANK 5

FSRFSRAddressesAddresses

BANK 0GPR

80 Bytes

BANK 2GPR

80 Bytes

BANK 3GPR

80 Bytes

BANK 4GPR

80 Bytes

BANK 1GPR

80 Bytes

BANK 5GPR

80 Bytes

Page 16: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

17

Fast Context Save

Interrupts automatically save the context- W- STATUS- BSR- FSRs- PCLATH

RETFIE automatically restores the context

You cannot disable fast context save

Page 17: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

18

Stack

16 Stack Entries Over/Underflow

Reset (optional) User/ICD Stack

Access in Bank 31- Read/Write the Stack

in Bank 31▪ Useful for RTOS or

Safety Critical Debugging

00112233445566778899

101011111212131314141515

Page 18: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

19

Stack Reset Mode

The STRVEN (Stack Reset Violation Enable) Config bit enables the Stack Reset mode

Stack Reset Mode causes:- Return when stack is empty

- Call or interrupt when stack is full

- Reading the top of stack when stack is empty returns 0

Page 19: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

20

Normal Mode

The stack works exactly as the legacy device, plus the following features

16-entry stack

Stack access via STKPTR and TOSH/TOSL

Page 20: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

21

New Instructions

Mnemonic DescriptionADDWFC Add W+F with Carry

SUBWFB Subtract F-W with Borrow

LSLF Logical Shift Left

LSRF Logical Shift Right

ASRF Arithmetic Shift Right

MOVLP Move Literal to PCLATH

MOVLB Move Literal to BSR

BRA Branch Relative (signed)

BRW Branch PC + W (unsigned)

CALLW Call PCLATH:W

ADDFSR Add Literal to FSRn (signed)

MOVIW Move Indirect to W

MOVWI Move W to Indirect

RESET Reset Hardware and Software

Page 21: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

22

Arithmetic with Carry

ADDWFC- Add with Carry

SUBWFB- Subtract with Borrow

Literal Operations with Carry or Borrow Are Not Supported

Original Add and Subtract Operations Still Available- Existing algorithms will still work!

Page 22: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

23

Shift Instructions

ASRF - Arithmetic Right Shift

LSRF- Logical Right Shift

LSLF - Logical Left Shift- (This is the same as Arithmetic Shift Left.)

Page 23: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

24

Shift Instructions

ASRF - Arithmetic Right Shift

0 1 1 1 1 1 1 1

CARRY BITCARRY BIT

REGISTERxREGISTERx

0X7F0X7F1616

Page 24: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

25

Shift Instructions

ASRF - Arithmetic Right Shift

0 0 1 1 1 1 1 1

11CARRY BITCARRY BIT

REGISTERxREGISTERx

0X3F0X3F1616

MSB DuplicatedMSB Duplicated

Page 25: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

26

Shift Instructions

ASRF - Arithmetic Right Shift

1 0 0 0 0 0 0 0

CARRY BITCARRY BIT

REGISTERxREGISTERx

0X800X801616

Page 26: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

27

Shift Instructions

ASRF - Arithmetic Right Shift

1 1 0 0 0 0 0 0

00CARRY BITCARRY BIT

REGISTERxREGISTERx

0XC00XC01616

MSB DuplicatedMSB Duplicated

Page 27: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

28

Shift Instructions

LSRF- Logical Right Shift

0 1 1 1 1 1 1 1

CARRY BITCARRY BIT

REGISTERxREGISTERx

0X7F0X7F1616

Page 28: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

29

Shift Instructions

LSRF- Logical Right Shift

0 0 1 1 1 1 1 1

11CARRY BITCARRY BIT

REGISTERxREGISTERx

0X3F0X3F1616

ZERO SHIFTED INZERO SHIFTED IN

Page 29: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

30

Shift Instructions

LSRF- Logical Right Shift

1 0 0 0 0 0 0 0

CARRY BITCARRY BIT

REGISTERxREGISTERx

0X800X801616

Page 30: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

31

Shift Instructions

LSRF- Logical Right Shift

0 1 0 0 0 0 0 0

00CARRY BITCARRY BIT

REGISTERxREGISTERx

0X3F0X3F1616

ZERO SHIFTED INZERO SHIFTED IN

Page 31: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

32

Shift Instructions

0 1 1 1 1 1 1 1

CARRY BITCARRY BIT

REGISTERxREGISTERx

0X7F0X7F1616

LSLF - Logical Left Shift

Page 32: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

33

Shift Instructions

1 1 1 1 1 1 1 0

00CARRY BITCARRY BIT

REGISTERxREGISTERx

0XFE0XFE1616

ZERO SHIFTED INZERO SHIFTED IN

LSLF - Logical Left Shift

Page 33: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

34

Shift Instructions

1 0 0 0 0 0 0 0

CARRY BITCARRY BIT

REGISTERxREGISTERx

0X800X801616

LSLF - Logical Left Shift

Page 34: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

35

Shift Instructions

0 0 0 0 0 0 0 0

11CARRY BITCARRY BIT

REGISTERxREGISTERx

0X000X001616

LSLF - Logical Left Shift

ZERO SHIFTED INZERO SHIFTED IN

Page 35: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

36

Paging/Banking

MOVLP- Places 7-bit literal in PCLATH

MOVLP HIGH LABEL

- PAGESEL in 1 cycle

- MOVLP + CALL/GOTO takes 3 cycles and 2 instructions, but reaches ANYWHERE in memory

MOVLB- Places 5-bit literal in BSR.

- BANKSEL in 1 cycle for ANY number of banks

- IRP, RP0, RP1 are obsolete and have been removed

Page 36: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

37

Relative Branching

Relative Branching allows MOST code to eliminate the paging concerns.

BRA N (Branch Relative)- Always branch to PC + N- Range is -256 <= N <= 255- PC + N is 15-bit math, so no paging issues

BRW (Branch Relative with W)- Always branch to PC + W (unsigned)- Fast Lookup Tables/State Machines- PC + W is 15-bit math, so no paging issues

CALLW (Call Absolute with W)- Call to PCLATH, W- Fast Lookup Tables/State Machines/Function Pointers- PCLATH:W direct address

Page 37: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

38

FSR Support Instructions

ADDFSR instruction- Adds a signed literal to the selected FSR- Literal range is -32 to +31

MOVIW/MOVWI – Move Indirect to W and Move W to Indirect- Special Modes

▪ Pre/Post-Increment▪ Pre/Post-Decrement▪ Relative Offset

Same range as ADDFSR

Page 38: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

39

MOVIW/MOVWI Syntax

StandardMOVWI 0[INDF0]

Pre IncrementMOVIW ++INDF0

Post IncrementMOVWI INDF0++

Pre DecrementMOVIW --INDF0

Post DecrementMOVWI INDF0--

OffsetMOVWI k[INDF0]-32 <= k <= 310

Modifies FSRModifies FSR Does not modify FSRDoes not modify FSR

Page 39: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

40

Misc. Features

RESET instruction- No more GOTO 0- All peripherals are reset- Software version of MCLR Reset- Another PCON bit is available to indicate a software

Reset

Program Memory Read (PMR) is in every device.- Full 14-bit read of program memory for check summing

Device ID, User ID and Config Word are now readable by the firmware.- User ID can be used for a serial number

Page 40: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

Migration to the PIC16F1XXX

Page 41: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

42

Migration

Paging

Banking

Interrupts

Indirect Memory

Page 42: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

43

Paging Use the PAGESEL macro

- Automatically uses MOVLP

OR

Update all PCLATH code- Assure 7-bit data in PCLATH

Convert to relative branches- This will eliminate most paging issues.

Page 43: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

44

PAGESEL

My_FunctionMy_Function

movlw 0x04movlw 0x04

movwf delay_cntrmovwf delay_cntr

My_function_loopMy_function_loop

decfsz delay_cntrdecfsz delay_cntr

goto My_function_loopgoto My_function_loop

returnreturn

MainMain

do lots of stuffdo lots of stuff

PAGESEL My_FunctionPAGESEL My_Function

call My_Functioncall My_Function

do lots of other stuffdo lots of other stuff

endend

My_FunctionMy_Function

movlw 0x04movlw 0x04

movwf delay_cntrmovwf delay_cntr

My_function_loopMy_function_loop

decfsz delay_cntrdecfsz delay_cntr

goto My_function_loopgoto My_function_loop

returnreturn

MainMain

do lots of stuffdo lots of stuff

bsf PCLATH,5 bsf PCLATH,5

bcf PCLATH,4bcf PCLATH,4

call My_Functioncall My_Function

do lots of other stuffdo lots of other stuff

endend

My_FunctionMy_Function

movlw 0x04movlw 0x04

movwf delay_cntrmovwf delay_cntr

My_function_loopMy_function_loop

decfsz delay_cntrdecfsz delay_cntr

goto My_function_loopgoto My_function_loop

returnreturn

MainMain

do lots of stuffdo lots of stuff

movlp high My_Functionmovlp high My_Function

call My_Functioncall My_Function

do lots of other stuffdo lots of other stuff

endend

My ASSEMBLY CodeMy ASSEMBLY Code PAGESEL MACRO PAGESEL MACRO PIC16PIC16

PAGESEL MACROPAGESEL MACROENHANCED PIC16ENHANCED PIC16

MaintainsMaintains PortabilityPortability

Page 44: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

45

Banking

Use BANKSEL macro,

- Automatically uses MOVLB

OR Replace writes to STATUS with

writes to BSR

Page 45: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

46

BANKSEL

datadataVar1 res 1Var1 res 1Var2 res 1Var2 res 1Var3 res 1Var3 res 1

codecode

MainMain do lots of stuffdo lots of stuff BANKSEL Var1BANKSEL Var1 addwf Var1 addwf Var1 do lots of other stuffdo lots of other stuff

endend

datadataVar1 res 1Var1 res 1Var2 res 1Var2 res 1Var3 res 1Var3 res 1

codecode

MainMain do lots of stuffdo lots of stuff bsf STATUS,RP0bsf STATUS,RP0 bcf STATUS,RP1bcf STATUS,RP1 addwf Var1 addwf Var1 do lots of other stuffdo lots of other stuff

endend

datadataVar1 res 1Var1 res 1Var2 res 1Var2 res 1Var3 res 1Var3 res 1

codecode

MainMain do lots of stuffdo lots of stuff movlb Var1 >> 7movlb Var1 >> 7 addwf Var1 addwf Var1 do lots of other stuffdo lots of other stuff

endend

My ASSEMBLY CodeMy ASSEMBLY Code BANKSEL MACROBANKSEL MACROPIC16PIC16

BANKSEL MACROBANKSEL MACROENHANCED PIC16ENHANCED PIC16

Saves 1 Saves 1 instructioninstruction

and accesses and accesses more banks of more banks of

memorymemory

Always worksAlways works

Page 46: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

47

Interrupts

RETFIE works a little differently

Interrupts should not pass parameters with W (bad practice)- W will be restored!

Remove core context save/restore software

PCL

Program Counter Latch High0x0A

0x09

0x08

0x07

0x06

0x05

0x04

0x03

0x02

PCLATH

Working RegisterWREG

Bank Select RegisterBSR

File Select Register 1 High ByteFSR1 High

File Select Register 1 Low ByteFSR1 Low

File Select Register 0 High ByteFSR0 High

File Select Register 0 Low ByteFSR0 Low

Status RegisterSTATUS

Program Counter Low

Page 47: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

48

Indirect Memory

IRP bit is gone

Accessing > 256 bytes requires an update to FSRxH Register

Fastest Method Update FSRxH Register- Requires modifying W- For example, MOVLW and MOVWF

BANKISEL is Portable- Performs 8 bcf’s or bsf’s (e.g., 8 TCY)- Does not preserve W

Page 48: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

49

Migration Summary

Migrating to the PIC16F1xxx should be simple.

Using the BANKSEL and PAGESEL macros will be a big help.

Page 49: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

New Coding Tricks

Page 50: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

51

New Code Tricks

Relative Branching

Table Reads

16-bit Arithmetic

Robust Techniques

Page 51: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

52

Relative Branches

My_FunctionMy_Function

movlw 0x04movlw 0x04

movwf delay_cntrmovwf delay_cntr

My_function_loopMy_function_loop

decfsz delay_cntrdecfsz delay_cntr

goto My_function_loopgoto My_function_loop

returnreturn

My_FunctionMy_Function

movlw 0x04movlw 0x04

movwf delay_cntrmovwf delay_cntr

My_function_loopMy_function_loop

decfsz delay_cntrdecfsz delay_cntr

bra My_function_loopbra My_function_loop

returnreturn

MainMain

do lots of stuffdo lots of stuff

PAGESEL My_FunctionPAGESEL My_Function

call My_Functioncall My_Function

do lots of other stuffdo lots of other stuff

endend

ORIGINAL ASSEMBLY CodeORIGINAL ASSEMBLY Code NEW ASSEMBLYNEW ASSEMBLYENHANCED PIC16ENHANCED PIC16

Page Boundary at Page Boundary at this point will force this point will force

the need for a the need for a PAGESELPAGESEL

Before Before My_function_loopMy_function_loop

Relative branch Relative branch makes this code makes this code ALWAYS work ALWAYS work with no paging with no paging

issues.issues.

No relative No relative CALL support.CALL support.CALLW is not CALLW is not

relative.relative.MainMain do lots of stuffdo lots of stuff

Additional CodeAdditional Code

PAGESEL My_FunctionPAGESEL My_Function call My_Functioncall My_Function do lots of other do lots of other stuffstuff

Page 52: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

53

Table Reads

The PIC16F1XXX Has New ROM Table Access Methods- FSR

- Relative Branch

Page 53: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

54

Tables using FSR

Long setup The_CODE

movlw high Table_start

movwf FSR0H

movlw low Table_start

movwf FSR0L

movlw 3

addwf FSR0L

movf INDF0,w

Table_start

DT 3,4,5,6,7,8,9

Page 54: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

55

Fast Call Tables

This code returns a constant from a table aligned on a 256 word boundary

The_CODE

movlw 3

movlp high Table_start

callw

Table_start

DT 3,4,5,6,7,8,9

The_CODE

movlw 3

call Table_Function

Table_Function

movwf temp

movlw high Table_start

movwf PCLATH

movf temp,w

movwf PCL

Table_start

DT 3,4,5,6,7,8,9

Page 55: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

56

More Fast Tables

Returns a const from a table. NO Alignment Issues. Table Start Can Occur ANYWHERE

The_CODE

movlw 3

call Table_Function

Table_Function

movlp high Table_start

brw

Table_start

DT 3,4,5,6,7,8,9

The_CODE

movlw 3

call Table_Function

Table_Function

movwf temp

movlw high Table_start

movwf PCLATH

movlw low Table_start

addwf temp,w

btfss STATUS,C

incf PCLATH,f

movwf PCL

Table_start

DT 3,4,5,6,7,8,9

Page 56: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

57

16-bit Arithmetic

Carry Support Speeds 16-bit Math

movf lsb_a,w

addwf lsb_b,f

movf msb_a,f

btfsc STATUS,C

addlw 0x01

addwf msb_b,f

movf lsb_a,w

addwflsb_b,f

movf msb_a,w

addwfc msb_b,f

OLDOLD NEWNEW

6T6TCYCY 4T4TCYCY

Page 57: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

58

Robust Techniques

RESET instruction Stack Over/Underflow Reset

Page 58: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

Advanced Topics

Page 59: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

60

Advanced Topics

Accessing the Stack

Accessing the Context Shadows

Reading the Device ID

Preemptive Multitasking

Error Diagnostics

Page 60: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

61

Accessing the Stack

Available through the TOS and STKPTR registers

STKPTR is current value of the Stack Pointer

TOS points to the TOP of the STACK

Both registers are read/writeable

TOS is split into TOSH and TOSL, due to the 15-bit size of the PC

Page 61: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

62

Stack Access

The STKPTR indicates current stack position

TOSH,TOSL is the stack at the SPTR position

Changing SPTR will move TOSH,TOSL.

SPTR is 5 bits

55

STACKSTACK

Level 15Level 15

Level 14Level 14

Level 13Level 13

Level 12Level 12

Level 11Level 11

Level 10Level 10

Level 9Level 9

Level 8Level 8

Level 7Level 7

Level 6Level 6

Level 4Level 4

Level 3Level 3

Level 2Level 2

Level 1Level 1

Level 0Level 0

Level 5Level 5 TOSH,TOSLTOSH,TOSL

STKPTRSTKPTR

TOSHTOSH TOSLTOSL

Page 62: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

63

Accessing the Context Save Shadow

The interrupt context save registers are read/writeable in bank 31

PCLATH_SHADPCLATH

WREG_SHADWREG

BSR_SHADBSR

FSR1H_SHADFSR1 High

FSR1L_SHADFSR1 Low

FSR0H_SHADFSR0 High

FSR0L_SHADFSR0 Low

STATUS_SHADSTATUS

Page 63: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

64

Device ID

Select registers in the Configuration memory are now accessible via the EE interface

The User ID, Device ID and Configuration Word can be read

Page 64: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

65

Preemptive Multitasking

Access to the stack and shadows allows an interrupt to replace the current task with a second task

This allows easier RTOS programming for these devices

Page 65: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

66

Error Diagnostics

Access to the stack and context shadows also allows more extensive self-check

Stack verification is critical for some safety-critical applications

Page 66: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

Summary

Page 67: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

68

Summary

Enhanced Core Features:- Program Memory Extended to

32 KB

- Data Memory Extended to 2 KB

- 14 New Instructions

- Simplified Core Register Map

- Enhanced Indirect Addressing

- Automatic Interrupt Context Saving

Page 68: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

Thank You!

Page 69: INTRODUCING: Enhanced 8-bit Mid-Range PIC ® Microcontroller (MCU) Core Detailed Technical Overview

70

Trademarks The Microchip name and logo, the Microchip logo, Accuron, dsPIC,

KeeLoq, KeeLoq logo, MPLAB, PIC, PICmicro, PICSTART, rfPIC, SmartShunt and UNI/O are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries.

FilterLab, Linear Active Thermistor, MXDEV, MXLAB, SEEVAL, SmartSensor and The Embedded Control Solutions Company are registered trademarks of Microchip Technology Incorporated in the U.S.A.

Analog-for-the-Digital Age, Application Maestro, CodeGuard, dsPICDEM, dsPICDEM.net, dsPICworks, dsSPEAK, ECAN, ECONOMONITOR, FanSense, In‑Circuit Serial Programming, ICSP, ICEPIC, Mindi, MiWi, MPASM, MPLAB Certified logo, MPLIB, MPLINK, mTouch, PICkit, PICDEM, PICDEM.net, PICtail, PIC32 logo, PowerCal, PowerInfo, PowerMate, PowerTool, REAL ICE, rfLAB, Select Mode, Total Endurance, WiperLock and ZENA are trademarks of Microchip Technology Incorporated in the U.S.A. and other countries.

SQTP is a service mark of Microchip Technology Incorporated in the U.S.A.

All other trademarks mentioned herein are property of their respective companies.

© 2008, Microchip Technology Incorporated, All Rights Reserved.