Microcontroller systems Lec 2 PIC18LF8722 Microcontroller s s core

Similar documents
TKT-3500 Microcontroller systems

AVR Microcontrollers Architecture

ME 475 Lab2 Introduction of PIC and Programming. Instructor: Zhen Wang

ATmega128. Introduction

EE 308: Microcontrollers

Embedded Systems Lab Lab 1 Introduction to Microcontrollers Eng. Dalia A. Awad

DERTS Design Requirements (1): Microcontroller Architecture & Programming

Ali Karimpour Associate Professor Ferdowsi University of Mashhad

MICROPROCESSOR BASED SYSTEM DESIGN

FIFTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLOGY-MARCH 2014 EMBEDDED SYSTEMS (Common for CT,CM) [Time: 3 hours] (Maximum marks : 100)

Chapter 2 Sections 1 8 Dr. Iyad Jafar

Ali Karimpour Associate Professor Ferdowsi University of Mashhad

Midrange 8b PIC Microcontrollers. ECE Senior Design 14 February 2017

Microcontroller. Microcontroller systems Lec 1 Introduction to Microcontrollers. Microcontroller (2) Microcontroller (2)

Mod-5: PIC 18 Introduction 1. Module 5

Laboratory: Introduction to Mechatronics. Instructor TA: Edgar Martinez Soberanes Lab 2. PIC and Programming

Computer Hardware Requirements for ERTSs: Microprocessors & Microcontrollers

ARDUINO MEGA INTRODUCTION

Lesson 14. Title of the Experiment: Introduction to Microcontroller (Activity number of the GCE Advanced Level practical Guide 27)

Microcontrollers. Microcontroller

Lecture (02) PIC16F84 (I)

Embedded Systems. PIC16F84A Internal Architecture. Eng. Anis Nazer First Semester

ME 515 Mechatronics. A microprocessor

VLSI Design Lab., Konkuk Univ. Yong Beom Cho LSI Design Lab

Professor E. Ambikairajah UNSW Sydney

PIC Microcontroller and

8051 Microcontroller


Basic Components of Digital Computer

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING. EE6008 Microcontroller based system design

PIC Microcontroller Introduction

Chapter 1. Microprocessor architecture ECE Dr. Mohamed Mahmoud.

2011 Pearson Higher Education, Mazidi, Naimi, and Naimi Pearson Higher Education, 2011 Pearson Higher Education,

CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT. Spring 2006

PIC Architecture & Assembly Language Programming. Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

AVR Training Board-I. VLSI Design Lab., Konkuk Univ. LSI Design Lab

Lecture 14. Ali Karimpour Associate Professor Ferdowsi University of Mashhad

CN310 Microprocessor Systems Design

PIC16F87X. 28/40-pin 8-Bit CMOS FLASH Microcontrollers. Devices Included in this Data Sheet: Pin Diagram PDIP. Microcontroller Core Features:

The Microcontroller. Lecture Set 3. Major Microcontroller Families. Example Microcontroller Families Cont. Example Microcontroller Families

Microcontrollers. Introduction to the PIC 8-bit Midrange Family. ECE Senior Design 15 February 2017

Understanding the basic building blocks of a microcontroller device in general. Knows the terminologies like embedded and external memory devices,

Micro II and Embedded Systems

Microprocessors/Microcontrollers

Introduction to the PIC18 Microcontroller 1.1 Objectives

ECE 471 Embedded Systems Lecture 2

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: 8051 Architecture Module No: CS/ES/5 Quadrant 1 e-text

Module 2: Introduction to AVR ATmega 32 Architecture

Microcontroller: CPU and Memory

Z8 Encore! XP F1680 Series 8-Bit Flash Solution with Extended Peripherals

Embedded Systems. Software Development & Education Center. (Design & Development with Various µc)

Introduction to Microcontrollers

An Arduino Controlled 1 Hz to 60 MHz Signal Generator

MT2 Introduction Embedded Systems. MT2.1 Mechatronic systems

Embedded systems. Exercise session 3. Microcontroller Programming Lab Preparation

EE 354 Fall 2015 Lecture 1 Architecture and Introduction

acret Ameya Centre for Robotics & Embedded Technology Syllabus for Diploma in Embedded Systems (Total Eight Modules-4 Months -320 Hrs.

Embedded Systems Design (630414) Lecture 1 Introduction to Embedded Systems Prof. Kasim M. Al-Aubidy Computer Eng. Dept.

Mechatronics and Microcomputers. Stipendium Hungaricum 2018/2019 Autumn Semester Szilárd Aradi, PhD

Interconnects, Memory, GPIO

ECE 471 Embedded Systems Lecture 2

AVR MICROCONTROLLER ARCHITECTURTE

CN310 Microprocessor Systems Design

Department of Electronics and Instrumentation Engineering Question Bank

2. List the five interrupt pins available in INTR, TRAP, RST 7.5, RST 6.5, RST 5.5.

The University of Texas at Arlington Lecture 3

BASIC INTERFACING CONCEPTS

Outline. Micriprocessor vs Microcontroller Introduction to PIC MCU PIC16F877 Hardware:

AVR XMEGA Product Line Introduction AVR XMEGA TM. Product Introduction.

Question Bank Microprocessor and Microcontroller

Lecture 1. Course Overview and The 8051 Architecture

MICROCONTROLLERS 8051

Computer Organization and Microprocessors SYLLABUS CHAPTER - 1 : BASIC STRUCTURE OF COMPUTERS CHAPTER - 3 : THE MEMORY SYSTEM

Choosing a Micro for an Embedded System Application

Microcontroller Systems

Course Introduction. Purpose: Objectives: Content: Learning Time:

Introduction to 8051 microcontrollers

Computer Architecture 2/26/01 Lecture #

Directives & Memory Spaces. Dr. Farid Farahmand Updated: 2/18/2019

Control Unit: The control unit provides the necessary timing and control Microprocessor resembles a CPU exactly.

Laboratory: Introduction to Mechatronics. Instructor TA: Edgar Martinez Soberanes Lab 1.

Introduction to Embedded Systems

Embedded programming, AVR intro

EE 308: Microcontrollers

Introduction to Embedded Systems and Chapter 1: Introduction to HCS12/MC9S12. EE383: Introduction to Embedded Systems University of Kentucky

EE 3170 Microcontroller Applications

Arduino Uno R3 INTRODUCTION

TEVATRON TECHNOLOGIES PVT. LTD Embedded! Robotics! IoT! VLSI Design! Projects! Technical Consultancy! Education! STEM! Software!

Am186ER/Am188ER AMD continues 16-bit innovation

Universität Dortmund. ARM Architecture

Lecture Objectives. Introduction to Computing Chapter 0. Topics. Numbering Systems 04/09/2017

Mercury System SB310

SYLLABUS UNIT - I 8086/8088 ARCHITECTURE AND INSTRUCTION SET

Introduction to ARM LPC2148 Microcontroller

Fig 1. Block diagram of a microcomputer

SECURE DIGITAL ACCESS SYSTEM USING IBUTTON

Clock and Fuses. Prof. Prabhat Ranjan Dhirubhai Ambani Institute of Information and Communication Technology, Gandhinagar

LAMPIRAN. Universitas Sumatera Utara

UNIT IV MICROCONTROLLER

The MAXQ TM Family of High Performance Microcontrollers

Transcription:

TKT-3500 Microcontroller systems Lec 2 PIC18LF8722 Microcontroller s s core Erno Salminen Copyright notice Some figures by Robert Reese, from supplementary CD of the course book from PIC18F8722 Family Data Sheet, Microchip Technology Inc. Thanks also to Juha Onkila Department of Computer Systems Tampere University of Technology Fall 2008 Last week Microcontrollers integrate many units into same chip processor, memories, timers, IO devices, AD converters... Often used in embedded systems that sense environment and control other devices Modest performance, cheap price, high volume Programmability allows fast development and upgrading Brief introduction to exercise platform TUTWSN node with PIC + multiple sensors Reminder: PIC18LF8722 8 bit RISC microcontroller with Harvard architecture High End 8-bit microcontroller Accumulator Assembly programming complicated 128 kb program memory, 4 kb SRAM, 1kB EEPROM Operating voltage: 2.0 5.5 V Max. Power dissipation 1 W Min. Power dissipation (@1 Mhz): 3 mw Compare: Normal red led 2V and max 20 ma Image: www.futurlec.com

80-pin TQFP package Many pins have multiple functions 8 Vdd or Vss (GND) pins AVdd and AVss 16 Address and data 2 Address 4 Ext. Interrupt pins 2 Prim. oscillator pins up to 70 GPIO-pins Reminder: PIC18LF8722 (2) Plenty of peripherals SPI, i2c, USART 16 channel 10-bit AD-converter 5 timers and capture/compare/pwm module HW 8-bit multiplier Watchdog, Brown-out Max. Frequency: 40 Mhz Many power management modes Clock sources on platform: Low frequency external clock Internal clock PIC Microarchitecture Defines the internal structure: data path control internal memories peripherals input/output ports Their type, count, widths, connections control mem peripherals data path mem I/O ports PIC18 Data path instruction register (IR) Data path to/from data mem #7/38 #8/38 Image: www.microchip.com to/from peripherals

PIC18 data path W = work register, i.e. accumulator Basic case: operands come from W and data memory and result goes W Result often overwrites one of the operands 8-bit operands instruction register (IR) Data path to/from data mem Operand storage No general purpose registers in PIC18 Data SRAM used instead Different scheme from many CPUs Data memory accesses are banked because 16-bit instruction can hold only a small address (8b) Hence, each bank contains 2 8 =256 bytes Hence, 4 KB RAM has 16 banks (0 to 15) 4 bits are needed for 16 banks One byte of a bank is called file register, f #9/38 to/from peripherals #10/38 Banked access: Bank selection File register, f is a SRAM location corresponds to a general-purpose register of other CPU architectures Banking only for data memory A special register defines which bank is used. Three choices 1. BSR = bank selection register 2. FSR = file selection reg (for pointers) 3. Access bank = fast access to ctrl registers These registers are updated with move instructions Banked data memory access Op.code defines how to form the SRAM address: a) BSR + 8-bit address b) whole 12 bit address in FSRx c) Access bank + 8 bit address 8-bit address comes from IR (instr. reg.) table latch ROM latch data bus instruction register (IR) #11/38 #12/38

Banked memory access (2) Address is simply concatenated from two parts BSR is one example of special function register (SFR) In contrast to general purpose register, i.e. file register In-Direct accessing Means that a pointer is used to access data Addr not defined in the instruction Instruction defines the register that contains the address pointer registers FSR0, FSR1 and FSR2 These are also special function registers In many CPUs, any register can be used for in-direct accesses Increment/decrement instructions can be used #13/38 #14/38 Special function register Special Function Registers (SFR) are addressed like normal data memory locations but have specified functionality tied to hardware subsystems in the processor They control and report the state of microcontroller and it s peripherals Status regs/bits cannot be written In PIC18LF8722, there are 160 SFRs, located in Bank15 Special function register (2) Purposes: Program counter Interupts Stack Memory-related: BSR, FSR0/1/2, EEPROM Digital-IO settings/status for ports A,B,C,D Status of arithmetic operations Peripherals: Timers, Serial IO, PWM.. Typically referred to by their name (BSR, W0, T3CON, STATUS, etc) instead of address #15/38 #16/38

SFR example: Arithmetic op status STATUS Address 0xFD8 in bank15 5 bits are used [4] Negative [3] Overflow [2] Zero [1] Carry from 4th bit [0] Carry from MSbit SFR example2: Timer 0 control T0CON Address 0xFD5 of bank15 8 bits used: [7] ON/OFF [6] 8b/16b [5] Clk src [4] pos/neg edge [3:0] Clk scaling #17/38 #18/38 Access bank Register Access Bank selects 96 lowest bytes of Bank0 and all 160 SFRs Fast access to SFR without modifying BSR Whole memory could be reached via BSR Assembly instruction s operand is either BANKED = uses BSR, for regular data ACCESS = uses access bank, for SFR Data memory map in PIC18 a) general-purpose regs (GPR, aka. file registers) for variables b) special function regs (SFR) for control/status 0x59 0x60 Addressable contents with access bank #19/38 #20/38

#21/38 PIC18 Program memory map 21b address bus Space 0x0 0x1FFFF 131 072 locations 128 K locations K = 2 10 = 1024 Reset and interrupt vectors contain addresses of special functions The return addresses of function calls reside special stack regs program counter #22/38 Address space vs. memories Address width defines the address space i.e. how many addresses the CPU can access 8b 2 8 =256 addresses 32b 2 32 = 4G addresses It is mapped to memory banks Each physical mem component implements part of the addr space Note that addr width may be different from data width variables (data) code rst vector Address space 0x0 The data width of a mem location is casedependent (8b, 16b, 32b...) Mapping Physical memory banks separate memories single memory Option A (blue) Option B (red) Option C... External memory interface For cases where 128 Kbytes of program memory is inadequate for an application Allows the controller s internal program counter to address a memory space of up to 2 Mbytes ( 21-bit addresses, 2 21 2M Larger level of data access that most 8-bit devices 4 operating modes (SFR CONFIG3L) 1. Operating entirely from external memory 2. Using combinations of on-chip and external memory, up to the 2-Mbyte limit 3. Using external Flash memory for reprogrammable application code or large data tables 4. Using external RAM devices for storing large amounts of variable data Memory configurations #23/38 #24/38

Instruction Cycle PIC18 is pipelined so that fetch takes one instruction cycle, while the decode and execute take another instruction cycle. each instruction effectively executes in one cycle. Changes to PC (e.g., GOTO), require two cycles to complete Instruction Cycle (2) Consists of four Q cycles: Q1-Q4 A fetch cycle begins with incrementing PC in Q1 In the execution cycle, Q1: the fetched instruction is latched into the Instruction Register (IR) Q2,Q3,A4: This instruction is then decoded and executed Data memory is read during Q2 #25/38 #26/38 Storage of instructions Program memory is addressed in bytes Instructions are stored as 2 bytes or 4 bytes in prog. memory The Least Significant Byte of an instruction word is always stored at an even address (LSb = 0) PC increments in steps of 2 Branch instructions take two program words absolute program memory address embedded into the instruction (CALL, GOTO) relative address (BNZ) PIC18 Assembly 16 bit program word in most cases Some instructions need two words 75 standard (PIC18) +8 extended instructions but they cannot be used due to limitations of student version compiler 5 types of operations 1. Byte-oriented 31 instr. 2. Bit-oriented 5 instr. 3. Literal operations 10 instr. 4. Control operations - 23 instr. 5. (Mem read/write 8 instr.) #27/38 #28/38

Assembly 1-1 Byte-oriented operations Typically 3 operands ADDWF f,d,a Add-W-to-F, f=file register, d=destination (WREG or f), a=accessed memory bank ADDWF 0x20, 0, 0 adds (implicit) WREG to contents of RAM location 0x20 (f) Result stored into register W (=0) and Access bank (=0) is used Probably most used instruction type Accumulator machine lots of traffic between WREG and SRAM Assembly 2 - Bit-oriented operations Three operands, b= bit in file register BCF f,b,a Bit-Clear-in-Filereg, f=file register, b=index of affected bit, a=accessed memory bank BCF 0x20, 7, 0 clears bit 7 in file register 0x20 cleared. Access bank is used #29/38 #30/38 Assembly 3 - Literal operations Typically 1 operand; the literal ADDLW k Add-Literal-to-W, literal k=8,12 or 20 bit value ADDLW 12 adds WREG and number 12 together. Value is stored to WREG. Operand k (in this example 12) has to be between 0 and 256 Assembly 4 - Control operations Typically 1 operand BNZ n Brach-if-Zot-Zero, n=relative address BNZ 200 moves execution to program memory address 200 if the zero bit in status register is zero #31/38 #32/38

Assembly 5 Read/write operations Typically no operands TABLRD - Reads from program memory location into SFR called table latch The Flash program memory and data EEPROM are readable, writable and erasable during normal operation 1a. 1b. 2. General instruction formats 4. 3. #33/38 #34/38 Compare PIC18 with ATMEGA128 8-bit Harvard architecture with RISC instruction set, Program word 16 bits, max. 16 MIPS 128 kb PM, 4kB SRAM and EEPROM 32 General purpose registers 133 Instructions 53 GPIO-lines 4 Timers with compare/pwm SPI, i2c, 2*USART 8 channel 10 bit ADC Simplified AVR block diagram AVR may stand for a) Advanced Virtual RISC b) Alf and Vegard's RISC c) something completely different Image:www.atmel.com #35/38 JTAG Interface #36/38

ASM comparison Add constants 2 and 3, store result in Access Bank s file register 20 (or register number 20) PIC AVR Conclusions PIC is somewhat un-orthodox CPU architecture, e.g. Accumulator Use of SRAM as registers Special registers for in-direct addressing Several Special function registers Some of these issues can be neglected with high-level languages However, they are necessary to understand some forthcoming examples Most examples will be generalized and not PIC-specific #37/38 #38/38