🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

Module2_PIC_Architecture_Updated.pdf

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

Embedded Systems Design PIC Architecture Dr. Bilal Arain Based on slides from Dr. Bassel Soudan Course Syllabi, Assessment Plan and Lab Groups Assessment Embedded Systems Microcontroller- Microcontroller- (1502334) based Des...

Embedded Systems Design PIC Architecture Dr. Bilal Arain Based on slides from Dr. Bassel Soudan Course Syllabi, Assessment Plan and Lab Groups Assessment Embedded Systems Microcontroller- Microcontroller- (1502334) based Design based Design Lab (1502336) (1502337) Lecture Quizzes 10% 25% - Lecture Midterm Exam 20% 30% - Lecture Final Exam 40% 45% - Lab Quizzes 10% - 10% Lab Project (Student 20% - 20% groups) Lab Midterm - - 30% Lab Final Exam - - 40% Components for a typical control system What is a Microcontroller? A microcontroller is a single-chip system that contains: A simple processor. Memory to hold the data and the program. Input and Output interfaces. Timers. Internal and external interrupt handling mechanism. all integrated into a single chip. Block Diagram of a typical Microcontroller The microcontroller operates on data that is fed in through its serial or parallel input ports controlled by the software stored in the on-chip memory. Microcontroller It contains timers for time intervals Registers It contains counters to count events I/O It contains complex interrupt circuits to Memory Ports allow performing multiple tasks ALU in parallel Timing & Interrupt Counters Control Circuits Definition of a Microcontroller The microcontroller is a programmable device that receives values from sensors, performs simple arithmetic or logical operations according to the program and data stored in memory and then produces directives to the rest of the system as a result. Programmable Device Let's expand each of the underlined words: Programmable device: A microcontroller can perform different sets of operations on the data it receives depending on the sequence of instructions supplied in the given program. By changing the program, the microcontroller manipulates different types of data in different ways. Instructions: Each microcontroller is designed to execute a specific group of operations. This group of operations is called an instruction set. This instruction set defines what the microcontroller can and cannot do. PIC Microcontroller PIC microcontrollers can be classified into three major categories: 8-bit microcontrollers, 16-bit microcontrollers, and 32-bit microcontrollers. Each category is further subdivided into product families as shown in the following table: The PIC Microcontrollers The PIC Microcontrollers PIC10 through PIC14 families are considered low-end microcontrollers. PIC16 and PIC18 families are considered mid-level microcontrollers, while 16-bit and 32-bit PICs are considered high-end microcontrollers The majority of students and projects will require mid-level microcontrollers. The most popular PIC used in senior design projects is the PIC16F877. You need to understand what your application will need so you can choose the microcontroller with the proper features. Microcontroller Features Microcontrollers will have all or part of these features: – On-chip RAM – On-chip ROM – Special instructions (multiply, divide, etc.) – Internal / External interrupts – Counters – Timers – Analog comparator – Analog to digital converter – Digital to analog converter – Serial Communication – different protocols are available – USB connectivity – Capture/Compare PWM – LCD Driver The PIC16F877 The Microcontroller and Memory To reduce the physical size of the system, a microcontroller integrates a CPU and a “reasonable” amount of memory into the same chip. – The definition of “reasonable” depends on the application. Members of the 8051 microcontroller family have from 0K to 4K of memory on-chip. Members of the PIC microcontroller family have from 4K to 1M of memory on-chip. – Based on how large your program will be, you choose a microcontroller with the right amount of memory. The Microcontroller and the External Memory Some microcontrollers allow Other microcontroller designs interfacing external memory to don't have an interface for expand the memory space of the external memory microcontroller Limits the size of the program The PIC Microcontroller’s Memory Organization PIC Microcontrollers use a Harvard Architecture Von Neumann Architecture Fetches instructions and data from a single memory space Typical of microprocessors Harvard Architecture Uses two separate memory spaces for program instructions and data Typical of microcontrollers The PIC Microcontroller’s Memory Organization Memory on PIC microcontrollers is split into two types: Program Memory and Data Memory. Instructions are stored in program memory, which is non-volatile (contents are retained when power is lost). The PIC architecture can support up to 1M x 16 (2M bytes) of program memory. Data currently in use is kept in RAM data memory, also known as the file registers, which is volatile (contents are lost when power is lost). Some members of the PIC family may contain EEPROM data memory. Used for data that needs to be kept for a long time such as initialization values. EEPROM data memory is non-volatile. Memory Memory - RAM Memory – RAM - DRAM Memory – RAM - SRAM Memory - ROM Memory - PROM Memory - EPROM Memory - EEPROM Memory – Flash Memory Program Memory Program Memory Different members of the PIC family contain different amounts of program memory. – The PIC 16F873/16F874 contain 4K words of program memory – The PIC 16F876/16F877 contains 8K words of program memory So, choose the appropriate PIC family member that supports the size of your program. Keep in mind that program memory in the PIC is measured by “words”. – These are “instruction words” – Instruction words are: 12-bit wide for PIC12 series 14-bit wide for PIC16 series 16-bit wide for PIC17 and PIC18 series. Program Memory Program Memory structure of PIC16F877 Total Program Memory: 8K words (each word is 14 bits) Number of Pages: 4 Size of Each Page: 2K × 14 bits Hexadecimal representation of 8K 1K in binary is 1024 (which is 210 ). This means that with 10 bits, we can address 210 memory locations. 8K means 8 x 1024, which is from 0 to 8191. If convert 8191 to hexadecimal it is 0x1FFF. 213 is 8192. Therefore, with 13 bits, we can address 8192 memory locations. How are the instructions stored in Program memory? The PIC16F877 microcontroller has 8192 (8K) memory locations, and each location can store a 14-bit instruction. This means the program memory can store up to 8192 instructions, with each instruction being 14 bits wide. Program Memory Addressing the Program Memory Why a 14-bit bus when 13 bits are sufficient to address 8192 locations? The 14-bit program counter (and also the 13-bit as well) can address each memory location directly. That is from 0x0000 to 0x1FFF. The program memory is structured and divided into pages as follows: Page 0: 0x0000 to 0x07FF 0 to 2047 in decimal and 2047 in hexadecimal is 0x07FF Page 1: 0x0800 to 0x0FFF 2048 to 4095 in decimal where 0x0800 = 2048. In total, it is 0 to 2047 locations. Page 2: 0x1000 to 0x17FF Page 3: 0x1800 to 0x1FFF Each page is addressed using 11 bits. That is 211 = 2048. What about the remaining bits? (the answer is on the next slide) Program Memory Let's break down the memory organization of PIC16F877 1. The program counter is responsible for keeping track of the instruction currently being executed. 2. It is divided into 4x2K pages. 3. It consists of 14 bits, where: 11 bits [10:0] are used to address words within each page. 2 bits [11:12] are used to select the page. Note that, we have 4 pages. 1 bit is reserved as an extra addressing bit, control bit, or sometimes it’s unused depending on the specific architecture. Program Memory The visual representation of how 14 bits are laid out in the program memory is shown in the table below: Bit Function 13 Reserved / Extended addressing 12 Page selection (Bit 1) 11 Page selection (Bit 0) 10 Address within page (Bit 10) 9 Address within page (Bit 9) 8 Address within page (Bit 8) 7 Address within page (Bit 7) 6 Address within page (Bit 6) 5 Address within page (Bit 5) 4 Address within page (Bit 4) 3 Address within page (Bit 3) 2 Address within page (Bit 2) 1 Address within page (Bit 1) 0 Address within page (Bit 0) Program Memory Program Memory Organization Section 2.1: Page 11 of the PIC16F877 datasheet Program Memory Paging Section 2.4: Page 26 of the PIC16F877 datasheet Instruction Set Section 13: Page 136 of the PIC16F877 datasheet Program memory (8K words) is divided into four 2k×14 pages Linear code execution crosses page boundaries The PIC16F877 without problems Page select bits need to Program be programmed when Memory jumping to code on a different page using “CALL” or “GOTO” instructions This is all taken care of when using high- level programming languages such as C/C++, etc. Data Memory PICs have a set of registers that function as general-purpose RAM. They are registers, but each of them has an address and the registers are accessed through this address. Working register and File Register The working register (often referred to as W) is a special-purpose register used in the PIC16F877 microcontroller as an accumulator for performing arithmetic and logical operations. The W register acts as a temporary storage area where data can be manipulated before being stored in other memory locations or used for further processing. The file register refers to the general-purpose memory locations and the special-function registers (SFRs) in the PIC16F877 microcontroller. These registers store data, configuration bits, and other information necessary for the operation of the microcontroller. Data Memory Some PIC models have as few as 32 bytes of RAM while others can reach up to 4K bytes. – PIC16F877 has 512 bytes of internal RAM, divided into 4 banks. – Data memory is not expandable by external memory. While the PIC16 has a relatively large internal RAM, it is not all accessible at the same time. – Internal RAM in the PIC is broken down into “banks” – The number of banks and the number of registers in each bank depend on the PIC model. PIC 16 has 4 banks each of which containing 128 registers. PIC 18 has 16 banks each of which containing 256 registers. Data Memory RAM/Data Memory The contents of RAM are cleared when the power goes off. It consists of two parts: general-purpose registers and special-function registers (SFR). All these registers are divided into four memory banks, each 128 bytes 368 are general-purpose registers, and the remaining are special function registers or reserved. Address range: GPRs are located from 0x20 to 0x7F in each bank (there are 4 banks in total), giving a total of 368 bytes. Data Memory Registers General-purpose registers are used for storing temporary data and results created during operation. Special-function registers are also RAM memory locations and their purpose is predetermined during manufacturing process and cannot be changed. Since SFR bits are connected to particular circuits on the chip (A/D converter, serial communication module, etc.), any change of their contents directly affects the operation of the microcontroller or some of its circuits. RAM Memory Banks The 512 bytes of internal RAM in the PIC 16 are broken down into 4 banks. Each bank contains 128 registers The address of the 1st register is 000H and that of the last register is 1FFH Two bits in the STATUS register determine the bank currently in use Special Function Registers The Special Function Registers are registers used by the CPU and peripheral modules for controlling the desired operation of the device. The Special Function Registers can be classified into two sets: Core (CPU) and, Peripheral. Special Function Registers Status Register The STATUS register in the PIC16F877 microcontroller is an 8-bit special function register (SFR) It reflects the results of arithmetic and logic operations. It also controls important aspects of the microcontroller, such as the selection of the memory bank. Status Register Status Register Example Use Cases of Status Register Addition Operation If you add two 8-bit numbers and the result exceeds 255 (i.e., a carry is generated), the C (Carry) bit will be set to 1. Subtraction operation If you subtract one number from another and the result is negative (in 8-bit arithmetic, this causes a borrow), the C (Carry) bit will be cleared to 0, indicating a borrow occurred. Checking for Zero Result After a comparison (e.g., subtraction), if the result is zero, the Z (Zero) flag will be set, allowing you to check whether two numbers were equal. Switching between memory banks By setting or clearing the RP1 and RP0 bits, you can switch between the four banks of general-purpose and special-function registers. Numbers Numbers A byte consists of eight bits grouped together. The greatest value has the leftmost bit called the most significant bit (MSB). The rightmost bit has the least value and is therefore called the least significant bit (LSB). Data Types Data Types BCD Representation Meanings of Data

Use Quizgecko on...
Browser
Browser