Tutorial Introduction

Similar documents
M68HC08 Microcontroller The MC68HC908GP32. General Description. MCU Block Diagram CPU08 1

ME 4447 / ME 6405: Introduction to Mechatronics

SECTION 5 RESETS AND INTERRUPTS

Module Introduction. PURPOSE: The intent of this module is to explain MCU processing of reset and interrupt exception events.

Introduction to Mechatronics. Fall Instructor: Professor Charles Ume. Interrupts and Resets

ECE 372 Microcontroller Design Parallel IO Ports - Interrupts. ECE 372 Microcontroller Design Parallel IO Ports - Interrupts

Interrupts. Interrupts Resets Low Power Modes. Resets Low Power Modes

Chapter 7 Central Processor Unit (S08CPUV2)

Menu. Polling Example

MC68HC908GR16 Data Sheet

EEL 4744C: Microprocessor Applications. Lecture 7. Part 2. M68HC12 Interrupt. Dr. Tao Li 1

MC68HC908GR8A MC68HC908GR4A Data Sheet

Interrupts (I) Lecturer: Sri Notes by Annie Guo. Week8 1

EXCEPTIONS ON THE 9S12

CS/ECE 5780/6780: Embedded System Design

Microprocessors & Interfacing

MC68HC908KX8 MC68HC908KX2 MC68HC08KX8. Technical Data M68HC08. Microcontrollers. MC68HC908KX8/D Rev. 1, 2/2002

ECE/CS 5780/6780: Embedded System Design

General Features of Interrupts. ECE/CS 5780/6780: Embedded System Design. Stack Before and After an Interrupt. Sequence of Events During Interrupt

What Happens When You Reset the MC9S12?

MC68HC05J1A/D Rev. 1.0 HC 5 MC68HC05J1A MC68HCL05J1A MC68HSC05J1A. HCMOS Microcontroller Units TECHNICAL DATA

SECTION 4 I/O INTERFACE

538 Lecture Notes Week 5

538 Lecture Notes Week 5

CPU08RM/AD REV 3 8M68HC08M. CPU08 Central Processor Unit. Reference Manual

ECE/CE 3720: Embedded System Design

General Features of Interrupts. ECE/CS 5780/6780: Embedded System Design. Sequence of Events During Interrupt. Stack Before and After an Interrupt

INTERRUPTS in microprocessor systems

ECE/CS 3720: Embedded System Design (ECE 6960/2 and CS 6968)

MC68HC908JB8 MC68HC08JB8 MC68HC08JT8

MC68HC908QY4 MC68HC908QT4 MC68HC908QY2 MC68HC908QT2 MC68HC908QY1 MC68HC908QT1

Input / Output. School of Computer Science G51CSA

CMS-8GP32. A Motorola MC68HC908GP32 Microcontroller Board. xiom anufacturing

Freescale Semiconductor, I SECTION 6 PROGRAM CONTROL UNIT

M68HC08. Microcontrollers MC68HC908RF2. Data Sheet. Freescale Semiconductor, I. MC68HC908RF2/D Rev. 4 5/2004

EEL 4744C: Microprocessor Applications. Lecture 7. Part 1. Interrupt. Dr. Tao Li 1

Reading Assignment. Interrupt. Interrupt. Interrupt. EEL 4744C: Microprocessor Applications. Lecture 7. Part 1

Computer Architecture 5.1. Computer Architecture. 5.2 Vector Address: Interrupt sources (IS) such as I/O, Timer 5.3. Computer Architecture

Interrupt/Timer/DMA 1

2.0 Installation & Quick Testing The following two sections will help you boot up your UF 6812 Development Board.

MC68HC908GR8 MC68HC908GR4. Technical Data M68HC08. Microcontrollers. MC68HC908GR8/D Rev. 4, 6/2002

ME 4447/6405. Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics. Instructor: Professor Charles Ume LECTURE 6

HC05 MC68HC05P18 MC68HC805P18. Advance Information. Freescale Semiconductor, Inc. Archived Order this document by MC68HC805P18/D Rev. 2.

Types of Interrupts:

COSC 243. Input / Output. Lecture 13 Input/Output. COSC 243 (Computer Architecture)

M68HC08. Microcontrollers MC68HC908QY4 MC68HC908QT4 MC68HC908QY2 MC68HC908QT2 MC68HC908QY1 MC68HC908QT1. Data Sheet MOTOROLA.

These three counters can be programmed for either binary or BCD count.

PC Interrupt Structure and 8259 DMA Controllers

Real Time Embedded Systems. Lecture 1 January 17, 2012

Hello and welcome to this Renesas Interactive module that covers the Independent watchdog timer found on RX MCUs.

SECTION 4 EXTERNAL MEMORY INTERFACE

Course Introduction. Purpose: Objectives: Content: 27 pages 4 questions. Learning Time: 20 minutes

PROGRAM CONTROL UNIT (PCU)

Section 8. Reset. Reset HIGHLIGHTS. This section of the manual contains the following topics:

Freescale Semiconductor, I SECTION 7 PROCESSING STATES NORMAL EXCEPTION MOTOROLA PROCESSING STATES 7-1

FLASH: FASTER WAIT MODE WAKEUP RECOVERY TIME FOR FLASH AR457 ATD: CONVERSION OF THE (V RH V RL )/2 INTERNAL REF VOLTAGE RETURNS $7F, $80 OR $81

AVR Microcontrollers Architecture

eaymanelshenawy.wordpress.com

Interrupt is a process where an external device can get the attention of the microprocessor. Interrupts can be classified into two types:

MACHINE CONTROL INSTRUCTIONS: 1. EI

Freescale Semiconductor, I

SECTION 8 EXCEPTION PROCESSING

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

The Purpose of Interrupt

1 MALP ( ) Unit-1. (1) Draw and explain the internal architecture of 8085.

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 09, SPRING 2013

Interrupts. How can we synchronize with a peripheral? Polling

Infineon C167CR microcontroller, 256 kb external. RAM and 256 kb external (Flash) EEPROM. - Small single-board computer (SBC) with an

Lecture 10 I/O and Interrupts

Interrupt and Timer ISRs. Student's name & ID: Partner's name(s) & ID(s): Your Section number & TA's name

MC68HC908AS60/D REV 1 8M68HC08M HC08M68HC. MC68HC908AS60 Technical Data. HCMOS Microcontroller Unit

Lab 9: On-Board Time Generation and Interrupts

Fredrick M. Cady. Assembly and С Programming forthefreescalehcs12 Microcontroller. шт.

Hello, and welcome to this presentation of the STM32 I²C interface. It covers the main features of this communication interface, which is widely used

Architecture of 8085 microprocessor

AN1298. Variations in the Motorola MC68HC(7)05Cx Family By Joanne Field CSIC Applications. Introduction

Question Bank Microprocessor and Microcontroller

Systems Programming and Computer Architecture ( ) Timothy Roscoe

SECTION 5 PROGRAM CONTROL UNIT

Interrupts Peter Rounce - room 6.18

A. This Errata sheet represents the known bugs, anomalies and work-arounds for the ADuC812 MicroConverter.

8085 Interrupts. Lecturer, CSE, AUST

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

Section 8. Reset HIGHLIGHTS. Reset. This section of the manual contains the following major topics:

MEMORY, OPERATING MODES, AND INTERRUPTS

Microcontrollers. Program organization Interrupt driven I/O. EECE 218 Microcontrollers 1

AN-HK-32. In-Circuit Programming of FLASH Memory in the MC68HC908GP32. nc... Freescale Semiconductor, I. PART 1 Introduction

VORAGO VA108x0 I 2 C programming application note

EE 3170 Microcontroller Applications

Design with Microprocessors

AN Kbyte Addressing with the M68HC11. Overview

Review for Exam 3. Write 0x05 to ATD0CTL4 to set at fastest conversion speed and 10-bit conversions

Lecture 10 Exceptions and Interrupts. How are exceptions generated?

Design and Implementation Interrupt Mechanism

EE Embedded Systems Design. Lessons Exceptions - Resets and Interrupts

8. Power Management and Sleep Modes

HCS12 Serial Communications Interface (SCI) Block Guide V02.06

SCI Serial Communication Interface

QUESTION BANK. EE 6502 / Microprocessor and Microcontroller. Unit I Processor. PART-A (2-Marks)

MC68HC05SR3 MC68HC705SR3

Transcription:

Tutorial Introduction PURPOSE: - To explain MCU processing of reset and and interrupt events OBJECTIVES: - Describe the differences between resets and interrupts. - Identify different sources of resets and interrupts. - Describe the MCU reset recovery process. - Identify the steps to configure and service an interrupt event. - Describe MCU exception processing. CONTENT: - 20 pages - 3 questions LEARNING TIME: - 25 minutes PREREQUESITE: - The 68HC08 CPU training module and a basic understanding of reset and interrupt events Slide #1 of 15 Welcome to this tutorial on resets and interrupts. The tutorial describes the different sources of reset and interrupt events and provides detailed training on 68HC08 MCU exception processing. Please note that on subsequent pages, you will find reference buttons in the upper right of the content window that access additional content. Upon completion of this tutorial, you ll be able to describe the differences between resets and interrupts, identify different sources of reset and interrupt events, and describe MCU exception processing. The recommended prerequisite for this tutorial is the 68HC08 CPU training module. It is also assumed that you have a basic knowledge of reset and interrupt events. Click the Forward arrow when you re ready to begin the tutorial. 1

Overview Reset sources: - External - power on, reset pin driven low - Internal - COP, LVI, illegal opcode, illegal address Resets initialize the MCU to startup condition. Interrupt sources: - Hardware - Software Interrupts vector the program counter to a service routine. Slide #2 of 15 Resets and interrupts are responses to exceptional events during program execution. Resets can be caused by a signal on the external reset pin or by an internal reset signal. Internal reset signals can be generated by the Computer Operating Properly Module or the Low Voltage Inhibit Module. Other internal reset sources include an illegal opcode and an illegal address. A reset stops MCU program execution. Once the reset is processed, the MCU immediately returns to a known startup condition and starts program execution from a user-defined memory location. There are two types of interrupts, hardware interrupts and software interrupts. An interrupt doesn t stop the MCU or the operation of the instruction being executed. It vectors the program counter to an interrupt service routine. When an interrupt event occurs, the MCU first completes the current instruction and then changes the sequence of program execution to respond to the event. An interrupt is similar to a reset in that it causes the MCU to fetch a new address for the program counter and sets the interrupt mask bit, or I-bit. Unlike a reset, interrupts suspend normal program execution only temporarily so the the processor can service the interrupt. After the interrupt is serviced, the processor is returned to where it left off executing normal program code. Let s take a detailed look at resets and interrupts, beginning with resets. 2

Internal Reset Sources ILLEGAL ADDRESS RST ILLEGAL OPCODE RST COPRST LVI POR INTERNAL RESET (RST) Slide #3 of 15 First, let s review the different sources of internal resets. An illegal address reset is generated when the CPU attempts to fetch an instruction from an address that isn t defined in the memory map. This type of reset provides additional system protection, returning the CPU to a known state when an invalid address is used. An illegal opcode reset is generated when the CPU decodes an instruction that is not defined in the opcode set. Excessive noise or code that tries to execute incorrectly from data space may cause this event, returning the CPU to a known state. The Computer Operating Properly (COP) reset is generated by an overflow of the COP counter, indicating that the COP timer was not serviced on-time and therefore expired. This is another system protection feature that will return the CPU to a known state in a runaway code scenario. For more information on the COP, see the COP tutorial. The Low Voltage Inhibit (LVI) reset can optionally be generated when V DD has dropped below a selected trip point. This feature protects against incorrect MCU operation during brown-outs or low-voltage power conditions. For the LVI reset, the reset line remains low for 4096 CGMXCLK cycles after V DD is restored, allowing the clock to stabilize. Power-On reset (POR) is an internal reset caused by a positive transition from 0 on the V DD pin. All internal clocks to the CPU and MCU Modules are held inactive for 4096 CGMXCLK clock cycles to allow the oscillator to stabilize. During this time, the RST pin is driven low. The POR reset can only be activated when V DD drops to 0 volts. The POR is not a brown-out detector, low-voltage detector, or glitch detector. 3

SIM Reset Status Register (SRSR) POR Power-On Reset Flag 1 = Power-on reset since last read of SRSR 0 = Read of SRSR since last power-on reset Slide #4 of 15 The SIM reset status register, SRSR, contains six flags that show the source of the last reset. If the power-on reset bit, POR, is set, the last reset was caused by the POR circuit. If the external reset pin bit, PIN, is set, the last reset was caused by an external device pulling the reset pin low. If the Computer Operating Properly bit (COP) is set, the last reset was caused by the COP counter timing out before it was serviced. If the illegal opcode bit (ILOP) is set, the last reset was caused by an illegal opcode. If the illegal address bit (ILAD bit) is set, the last reset was caused by an opcode fetch from an illegal address. If the low voltage inhibit bit (LVI) is set, the last reset was caused by the LVI detecting a voltage below the selected trip point. The flags in the SIM reset status register are cleared when the register is read. If the SIM reset status register has not been read after multiple reset sources, it may have multiple sources indicated. The register can help you to debug code problems. For example, if your application is unintentionally being reset, the reset source can be determined and corrective action taken. In the event of an in-application reset, the register helps you determine which action to take. The application may require additional set-up and initialization for a POR reset that is not required with a COP reset. Other reset sources may require unique diagnostics or servicing. 4

Internal Reset Timing RST PIN CGMXCLK PULLED LOW BY MCU 32 CYCLES 32 CYCLES INTERNAL RESET Slide #5 of 15 Now that we ve identified the different sources of internal resets, let s look at internal reset timing. All internal reset sources, except POR, pull the RST pin low for 32 CGMXCLK clock cycles to allow resetting of external devices. The MCU is held in reset for an additional 32 CGMXCLK clock cycles after releasing the RST pin to allow external devices to stabilize. The RST pin is then tested to check if if the RST pin is still being pulled low. If so, it indicates that an external reset has occurred. If not, it indicates that an internal reset occurred and the appropriate internal reset bit is set in the SIM reset status register. 5

Interrupt Processing Overview Hardware Interrupt Initiated by hardware pin or Module Uses an interrupt vector and a service routine Can be masked Software Interrupt (SWI) Executed as part of the instruction flow Processed like a hardware interrupt Can t be masked Slide #6 of 15 Next, we ll discuss interrupt events. Recall that interrupt events can be generated by either hardware or software sources. A hardware interrupt is generated by internal or external hardware conditions and can be initiated by a hardware pin or Module. When a hardware interrupt occurs, the program context is stacked, the I-bit in the condition code register is set, and the interrupt vector is fetched. Hardware interrupts can be masked. This means that hardware interrupts can be recognized only when the I-bit is cleared. A software interrupt occurs as a result of the SWI instruction. A software interrupt is always executed as part of the instruction flow. The important difference between software and hardware interrupts is that software interrupts can t be masked. This means that the value of the I-bit has no effect on software interrupts. Otherwise, a software interrupt is processed the same way as a hardware interrupt. Let s take a closer look at hardware interrupts sources. 6

Hardware Interrupt Sources IRQ pin I/O port pins Timer Interface Module (TIM) SCI/I ports Slide #7 of 15 The IRQ pin can be used to trigger external hardware interrupts. Depending on the MCU configuration, an IRQ interrupt is generated by a logic low or a high-to-low transition on the IRQ pin. This type of interrupt can be used to monitor external systems or events. In most 68HC08 MCUs, you can also generate an interrupt using additional I/O port pins. This is referred to as keyboard interrupts (KBI) and is commonly used to interface with key pad inputs. These inputs have programmable pullups that generate an interrupt when pulled low. For example, a 16 key input pad is commonly organized as 4 rows by 4 columns. The four rows can be connected to the KBI inputs. When a key is pushed, the corresponding row input is pulled low, and an interrupt will be generated without glue logic. The interrupt service routine would debounce the key and determine which key was pressed by scanning the columns. The 16-bit timer of the the Timer Interface Module (TIM) can generate several different interrupts depending on the particular model. The output compare, input capture, and timer overflow functions can generate interrupts. Some models also have a real-time interrupt feature. These types of interrupts can be used to process events based on a time reference. For MCUs equipped with a Serial Communications Interface Module (SCI) or a Serial Peripheral Interface Module (I), the serial ports can generate a variety of interrupts depending on the model. SCI and I interrupts include receive register full, transmit register empty, and transmission complete. These types of interrupts can be used to process serial communications events. Other peripherals, such as the Controller Area Network (CAN) and the Universal Serial Bus (USB), can also generate interrupts. 7

Interrupt Sources Source TimeBase ADC Conv. Complete Keyboard Pin SCI Trans. Complete SCI Transmitter Empty SCI Input Idle SCI Receiver Full SCI Receiver Overrun SCI Noise Flag SCI Framing Error SCI Parity Error I Transmitter Empty I Receiver Full I Overflow I Mode Fault TIM2 Overflow TIM2 Channel 1 TIM2 Channel 0 TIM1 Overflow TIM1 Channel 1 TIM1 Channel 0 PLL IRQ SWI Reset Vector Address $FFDC - $FFDD $FFDE - $FFDF $FFE0 - $FFE1 $FFE2 - $FFE3 $FFE4 - $FFE5 $FFE6 - $FFE7 $FFE8 - $FFE9 $FFEA - $FFEB $FFEC - $FFED $FFEE - $FFEF $FFF0 - $FFF1 $FFF2 - $FFF3 $FFF4 - $FFF5 $FFF6 -$FFF7 $FFF8 - $FFF9 $FFA - $FFFB $FFFC - $FFFD $FFFD - $FFFF Flag TBIF COCO KEYF TC SCTE IDLE SCRF OR NF FE PE TE RF OVRF MODF TOF CH1F CH0F TOF CH1F CH0F PLLF IRQF None None Mask TBIE AIEN IMASKK TCIE SCTIE ILIE SCRIE ORIE NEIE FEIE PEIE TIE RIE ERRIE ERRIE TOIE CH1IE CH0IE TOIE CH1IE CH0IE PLLIE IMASK1 None None INT Reg Flag IF16 IF15 IF14 IF13 IF12 IF11 IF10 IF9 IF8 IF7 IF6 IF5 IF4 IF3 IF2 IF1 None None Priority 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 0 Slide #8 of 15 Interrupt sources are serviced using a vector address and a priority. The table summarizes the 16 different interrupt sources associated with the 68HC908GP32 MCU. The 68HC08 architecture can handle up to 128 different reset and interrupt sources. For more information about interrupt implementations in specific 68HC08 derivatives, check the device technical data book. Each interrupt source has its own unique vector address. This can eliminate the need of software polling within a service routine to determine the correct source of the interrupt, resulting in faster interrupt servicing. Each source also has its own unique interrupt status register flags that can be polled. You can disable an interrupt source by resetting the source s unique interrupt bit. Each interrupt type has a pre-defined priority associated with it. The Timebase Module (TBM) interrupt has the lowest priority and the external IRQ has the highest priority. When multiple interrupts occur, the CPU looks at the priority of the events and services the event with the highest priority first, with the others pending. Notice that a reset event has priority over all interrupt events. Recall that the global interrupt mask I-bit enables or disables all interrupt processing with the exception of the software interrupt, SWI. Interrupt events generated by on-chip peripheral Modules can be masked and are recognized only if the I-bit is cleared. These peripherals typically have local masks to enable or disable specific types of interrupts. For example, the Timer Interface Module, TIM, has a separate interrupt mask and enable bit for overflow and for each timer channel. Resets can t be masked, but some internal Modules can be disabled so that they can t generate a reset. The COP and LVI Modules are examples of potential reset sources that can be disabled out of reset. 8

Context Switching Recognition Arbitration Stacking - Saving Context (set I-bit = 1) Vector Fetching Interrupt Servicing Slide #9 of 15 Next, we ll cover how the SIM Module uses this information to service interrupts. Determining which type of handling is required is called exception processing. Exception processing is handled through discrete tasks sometimes called context switching. Exception processing is different for resets and interrupts. However, the processing tasks are the same. First, the SIM Module recognizes the events and performs arbitration. The highest priority event is processed first. Before the vector is fetched, the I-bit is set to 1 to prevent further interrupt events and the current CPU context is saved on the stack. Finally, the interrupt service routine or exception handler is executed. Let s take a closer look at the exception processing tasks, beginning with recognition. 9

Recognition Resets - Recognized and acted on immediately Interrupts - Recognized during last cycle of current instruction - Acted on after last cycle of the current instruction Slide #10 of 15 During the recognition phase, all resets are recognized and acted upon immediately once asserted. Interrupts are recognized during the last cycle of instruction execution. The timing of interrupt recognition depends on when the interrupt occurs. If an interrupt occurs before the last cycle of the current instruction, it will be recognized during the last cycle and then acted on. If an interrupt occurs during the last cycle of the current instruction, it won t be recognized until the last cycle of the next instruction. 10

Arbitration Source Priority L 16 15 14 13 TimeBase ADC Conv. Complete Keyboard Pin SCI Trans. Complete SCI Transmitter Empty SCI Input Idle SCI Receiver Full SCI Receiver Overrun SCI Noise Flag SCI Framing Error SCI Parity Error I Transmitter Empty I Mode Fault I Overflow I Mode Fault TIM2 Overflow TIM2 Channel 1 TIM2 Channel 0 TIM1 Overflow TIM1 Channel 1 TIM1 Channel 0 PLL IRQ SWI Reset 12 11 10 9 8 7 6 5 4 3 2 1 0 0 H Slide #11 of 15 After recognition, the next phase is arbitration. During the arbitration phase, the SIM Module determines the source of the exception and prioritizes the interrupt events for processing. All resets are considered equal and have higher priority over all interrupt sources. In the case of resets, no arbitration is required. Whichever reset occurs first will be acted on immediately and reflected in the SIM reset status register. Interrupts are arbitrated using pre-defined priority levels associated with the different interrupt sources. The SIM provides the CPU with information about which sources generated the exception requests. The 68HC908GP32 has a total of 16 possible interrupt sources associated with the different on-chip Modules. If the interrupt mask is cleared, the CPU will check all pending interrupts after every instruction. If more than one interrupt is pending when an instruction is complete, the highest priority interrupt will be serviced first. Once an interrupt is recognized as the highest priority interrupt, no new interrupt can take precedence regardless of its priority. 11

Stacking Stack Pointer Stacking Order 5 4 3 2 1 CCR A X PC_H PC_L Slide #12 of 15 Once the MCU has identified which interrupt to service, it sets the I-bit to prevent additional interrupt events while saving context. In the stacking phase, critical CPU information is saved to the stack. All CPU registers, including PC, X, A, and CCR are stacked. The H register is not stacked for 68HC05 compatibility reasons. Note that the stack pointer always points to the next available byte on the stack. Because a reset event causes the CPU and stack to reset, stacking isn t performed for reset events. 12

Vector Fetching Source TimeBase ADC Conv. Complete Keyboard Pin SCI Trans. Complete SCI Transmitter Empty SCI Input Idle SCI Receiver Full SCI Receiver Overrun SCI Noise Flag SCI Framing Error SCI Parity Error I Transmitter Empty I Receiver Full I Overflow I Mode Fault TIM2 Overflow TIM2 Channel 1 TIM2 Channel 0 TIM1 Overflow TIM1 Channel 1 TIM1 Channel 0 PLL IRQ SWI Reset Vector Address $FFDC - $FFDD $FFDE - $FFDF $FFE0 - $FFE1 $FFE2 - $FFE3 $FFE4 - $FFE5 $FFE6 - $FFE7 $FFE8 - $FFE9 $FFEA - $FFEB $FFEC - $FFED $FFEE - $FFEF $FFF0 - $FFF1 $FFF2 - $FFF3 $FFF4 - $FFF5 $FFF6 -$FFF7 $FFF8 - $FFF9 $FFA - $FFFB $FFFC - $FFFD $FFFD - $FFFF Slide #13 of 15 After all of the CPU registers are saved to the stack, the program counter is loaded with a user-defined vector address and begins processing. This 16-bit address is the start address for the interrupt service routine or exception handler. 13

Executing Exception Handler Exception Handler PSHH Stacking Order 7 6 5 4 3 2 1 H CCR A X PC_H PC_L L H Stack Pointer Slide #14 of 15 Notice the stacking order of the registers. The registers are stacked from the highest to the lowest address. We mentioned before that the H register is not automatically saved by the CPU. Therefore, it must be saved at the beginning of the exception handler by executing a PSHH instruction. This means that we will have to restore it prior to exiting the exception handler. 14

Restoring Old Context Exception Handler PSHH Unstacking Order PULH RTI 1 2 3 4 5 H CCR A X PC_H L Stack Pointer 6 PC_L H Slide #15 of 15 Before we restore the old context, note the order for the unstacking operation. We start by executing the PULH instruction to restore H. Next, execute the RTI instruction to restore the remaining registers, starting with the CCR register. Note that when the CCR register is restored, the global interrupt mask bit is also restored to it s original cleared condition, enabling interrupts. When the old context is restored, normal Operation of the application program is then resumed. If additional interrupts are pending, the process will begin again. 15

Example: Unused Interrupts Trap ;* Using a Trap with a COP Watchdog ;* Unused Vectors TRAP: bra TRAP ; wait for a COP reset org $1FF8 ; Timer Vector fdb TRAP ; Points to TRAP org $1FFC ; Software Interrupt fdb TRAP ; Points to TRAP Slide #16 of 15 A more fault-tolerant method for handling unused interrupt vectors is to use a trap with the COP watchdog timer. With the COP Module enabled, this method uses a loop to trap unwanted interrupts. The COP will reset the part after it times out. This provides a way to reset the MCU when an unexpected or spurious interrupt condition occurs. Note that in some 68HC08 MCUs, the user-defined vector values are used for security. Assigning identical address values to unused interrupts may not be acceptable. If this is a consideration, you can duplicate the trap code in different memory locations to further enhance security. 16

Question Which of the following exceptions can t be masked? Click on your BEST choice. a) Software interrupts b) TIM overflow c) SCI parity error d) Internal resets e) b and c f) a and d Slide #17 of 15 Let s complete this tutorial with a few questions to check your understanding of the material. Which of the following exceptions can t be masked? Click on your best choice. Answer: Both software interrupts and internal resets can t be masked. All hardware interrupts can be masked using the I-bit, and most hardware interrupt sources also have a local interrupt mask. 17

Question When does the interrupt service routine begin executing? Click on your choice. a) Immediately b) In the next clock cycle c) After the current instruction is finished executing d) During last cycle of the current instruction Slide #18 of 15 When does the interrupt service routine begin executing? Click on your choice. Answer: Interrupt service processing always begins after the current instruction is finished executing. First the CPU context is stacked, and then the first instruction of the interrupt service routine is executed. 18

Question If these five hardware interrupts occurred at the same time, which interrupt event would be serviced first? Click on your choice. a) SCI Receiver Full b) PLL c) IRQ d) TIM 2 Channel 0 e) ADC Conversion Complete Slide #19 of 15 If these five hardware interrupts occurred at the same time, which interrupt event would be serviced first? Click on your choice. Answer: Since the IRQ interrupt has the highest priority of the five interrupt sources, it would serviced first. The five interrupts would be serviced in this order: IRQ, PLL, TIM 2 Channel 0, SCI Receiver Full, ADC Conversion Complete. 19

Tutorial Completion - Reset and Interrupt Sources - Reset Recovery - MCU Exception Processing - Interrupt Servicing Slide #20 of 15 In this tutorial, you ve had an opportunity work with resets and interrupts. You ve learned about sources of resets and interrupts and the differences between these types of exceptions. You ve also learned about MCU exception processing, including reset recovery and interrupt servicing. 20