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

Similar documents
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

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

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

ME 4447 / ME 6405: Introduction to Mechatronics

MC68HC12 Parallel I/O

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

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

538 Lecture Notes Week 5

538 Lecture Notes Week 5

Microprocessors & Interfacing

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

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

Menu. Polling Example

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

Grundlagen Microcontroller Interrupts. Günther Gridling Bettina Weiss

Lab 9: On-Board Time Generation and Interrupts

Lecture 10 I/O and Interrupts

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

PC Interrupt Structure and 8259 DMA Controllers

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

Tutorial Introduction

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

Interrupts. How can we synchronize with a peripheral? Polling

What Happens When You Reset the MC9S12?

Introduction to Embedded Systems. Lab Logistics

SECTION 5 RESETS AND INTERRUPTS

Types of Interrupts:

Week 11 Programmable Interrupt Controller

Introduction to the MC9S12 Hardware Subsystems

ECE 367 -Experiment #1 Fall 2012

ECE/CE 3720: Embedded System Design

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

HC11 Instruction Set

INTERRUPTS in microprocessor systems

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

EE4390 Microprocessors

CS/ECE 5780/6780: Embedded System Design

EE Embedded Systems Design. Lessons Exceptions - Resets and Interrupts

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

8086 Interrupts and Interrupt Responses:

AN Kbyte Addressing with the M68HC11. Overview

HC12 Built-In Hardware

Chapter 7 Central Processor Unit (S08CPUV2)

Interrupt/Timer/DMA 1

Reset, Interrupts, Exceptions, and Break ECE 3534

CHAPTER 11 INTERRUPTS PROGRAMMING

8085 Interrupts. Lecturer, CSE, AUST

Interrupts. by Rahul Patel, Assistant Professor, EC Dept., Sankalchand Patel College of Engg.,Visnagar

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

UNIVERSITY OF HONG KONG DEPARTMENT OF ELECTRICAL AND ELECTRONIC ENGINEERING. Principles of Computer Operation

UNIVERSITY OF HONG KONG DEPARTMENT OF ELECTRICAL AND ELECTRONIC ENGINEERING

Lecture #13 Interrupts Embedded System Engineering Philip Koopman Monday, 29-Feb-2016

EKT222 Miroprocessor Systems Lab 5

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

What happens when an HC12 gets in unmasked interrupt:

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

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

MACHINE CONTROL INSTRUCTIONS: 1. EI

ECE/CE 3720: Embedded System Design

Procesory Sygnałowe w aplikacjach przemysłowych

I/O - input/output. system components: CPU, memory, and bus -- now add I/O controllers and peripheral devices. CPU Cache

Real Time Embedded Systems. Lecture 10 January 31, 2012 Interrupts

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

Programming Book for 6809 Microprocessor Kit

MC9S12 Assembler Directives A Summary of MC9S12 Instructions Disassembly of MC9S12 op codes. Summary of HCS12 addressing modes ADDRESSING MODES

EE 308 Spring A software delay. To enter a software delay, put in a nested loop, just like in assembly.

Wed. Aug 23 Announcements

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

ECE332, Week 8. Topics. October 15, Exceptions. Hardware Interrupts Software exceptions

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

EC2304-MICROPROCESSOR AND MICROCONROLLERS 2 marks questions and answers UNIT-I

Mark II Aiken Relay Calculator

EE 5340/7340 Motorola 68HC11 Microcontroler Lecture 1. Carlos E. Davila, Electrical Engineering Dept. Southern Methodist University

Microcontrollers. Microcontroller

Mark Redekopp, All rights reserved. EE 357 Unit 10b. Interrupts Timers

Lecture-51 INTEL 8259A Programmable Interrupt Controller

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

Input/Output Modes Chapter 8

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

ECE/CS 5780/6780: Embedded System Design

Chapter 1: Basics of Microprocessor [08 M]

1 Execution of main program is suspended. 2 All registers are pushed onto the stack. 3 The ISR, or background thread, is executed.

ECE 485/585 Microprocessor System Design

Microprocessor Architecture

Select the single most appropriate response for each question. Note that none of the above MAY be a VALID ANSWER.

S12CPUV2. Reference Manual HCS12. Microcontrollers. S12CPUV2/D Rev. 0 7/2003 MOTOROLA.COM/SEMICONDUCTORS

EE319 K Lecture 3. Introduction to the 9S12 Lab 1 Discussion Using the TExaS simulator. University of Texas ECE

Introduction to the 9S12 Microcontroller

CPEG300 Embedded System Design. Lecture 6 Interrupt System

2. Arithmetic Instructions addition, subtraction, multiplication, divison (HCS12 Core Users Guide, Sections 4.3.4, and ).

Operating System: Chap13 I/O Systems. National Tsing-Hua University 2016, Fall Semester

Introduction to Embedded Systems

Process Context & Interrupts. New process can mess up information in old process. (i.e. what if they both use the same register?)

Module 3. Embedded Systems I/O. Version 2 EE IIT, Kharagpur 1

Exam I Review February 2017

SECTION 5 PROGRAM CONTROL UNIT

original M68K requests/priorities Interrupts to execute important code interrupts (n will always be I) I-bits bits in SR accomplish this

Accumulator and memory instructions 1. Loads, stores, and transfers 2. Arithmetic operations 3. Multiply and divide 4. Logical operations 5. Data test

Transcription:

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

Reading Assignment Software and Hardware Engineering (New version): Chapter 12 or SHE (old version) Chapter 8 And CPU12 Reference Manual Chapter 7 And HC12 Data Sheet Chapter 4 Dr. Tao Li 2

What is an Interrupt? an asynchronous event that stops normal program execution performs a Service Route (i.e., executes some code) returns program to where it left off Why have IRQ's? Interrupts (IRQ) 1) Good for Asynchronous Events - that must be serviced - don't want to use main CPU cycles to continually check 2) Good for Synchronizing with external processes - if CPU is faster than peripherals (printer, A/D, etc ) - peripherals notify CPU when they're ready - CPU doesn t waste time "waiting" 3) Good for timed events - "Real Time Systems" events happen periodically - Multi-tasking Dr. Tao Li 3

Interrupt 101 Priority - interrupts can occur at the same time - some interrupts are more important than others (ex, fire alarm) - to handle this, all interrupts are given a default priority - some priorities can be changed Interrupt Service Route (ISR) - this is the code to be executed when an IRQ occurs - each individual IRQ has an ISR if it is being used - this is similar to a subroutine, it is code written by us Interrupt Vector Address - each IRQ has a unique Vector Address - this holds the address of ISR to be executed if that IRQ occurs Dr. Tao Li 4

HC12B32 Interrupt Overview Uses vectored interrupts, but polling used when multiple external sources on IRQ* line Features h/w priority resolution that can be customized via s/w External Internal IRQ* and XIRQ* (NMI), plus other signals w/ timer subsystem, serial interface, and A/D converter that we ll see in later chapters Special interrupts including s/w, illegal opcode, watchdog timer, and clock failure interrupts Dr. Tao Li 5

Interrupt vector is address of start of particular ISR Interrupt Vectors When interrupt generated, CPU fetches this address from vector location Interrupt vector table for HC12B32 IRQ* Pin XIRQ* Pin RESET* Dr. Tao Li 6

What Happens When an IRQ Happens IRQ detected CPU finished current instruction CPU pushes all registers onto the STACK this includes the Program Counter, which is where the program will return to after the ISR CPU grabs the ISR address from the "Vector Table" and loads into the PC ISR is executed and completes CPU pulls all registers from the STACK this includes the Program Counter CPU returns to executing code as it was before Dr. Tao Li 7

Terminology Request: IRQ occurs and indicates to CPU that it needs attention Pending: IRQ that is waiting to be serviced Service: Process of executing the ISR Latency: The delay between the Request and the beginning of Service Finish executing current instruction Storing CPU registers to STACK Retrieve ISR address from Vector Table + Latency Dr. Tao Li 8

Enabling Interrupts Upon External Reset, IRQ's are disabled "Maskable" IRQ's are enabled by: 1) A Global Interrupt Mask - these are the X and I bits in the CCR - initially set, we clear then in our code if we want IRQ's - this enables a group of IRQ's 2) A Local Interrupt Mask - each individual IRQ has an enable bit - this must be enabled in the configuration registers - also called "device interrupt enable Some IRQ's cannot be disabled, these are called "Non-Maskable" IRQ's (e.g. RESET) Dr. Tao Li 9

Using an IRQ There are ALWAYS 3 things that must be done to use an IRQ 1) Initialize the Vector Address for that IRQ 2) Write ISR 3) Enable the IRQ Dr. Tao Li 10

Using an IRQ Step 1: Initialize Interrupt Vector Table Step 2: Write Interrupt Service Routine We can put them after our main code or of a place of the programmers choosing My_ISR code.. RTI - RTI = "Return from Interrupt" - indicates end of service routine (similar to RTS). However it indicates that all of the registers must be pulled from STACK - an ISR can call subroutines Dr. Tao Li 11

Interrupt Vector Initialization Interrupt vector is address of start of particular ISR and must be initialized An example: invect1c.asm Assembled with CASM 05/28/1998 01:33 PAGE 1 1 ; Initializing M68HC12 interrupt vectors 2 ; Initialize Timer Channel 0 Interrupt vector 0000 3 TC0: EQU $FFEE ; Address of the vector 0000 4 PROG: EQU $E000 ; Program location 5 ;... E000 6 org PROG 7 ; Main program E000 A7 8 nop 9 ;... 10 ; The interrupt service routine starts with a label 11 ; at the first op code to be executed. 12 TC0ISR: E001 A7 13 nop 14 ;... 15 ; The isr ends with a RTI E002 0B 16 rti 17 ;... 18 ; Locate the vector FFEE 19 ORG TC0 FFEE E001 20 DW TC0ISR ; The label is the address 21 ; of the isr Dr. Tao Li 12

Using an IRQ Step 3: Enable Interrupt I-bit - this is a Global Mask for all "Maskable" Interrupts in the HC12 I=1 (Maskable IRQ's are Disabled, default @ reset) I=0 (Maskable IRQ's are Enabled, we manually clear this bit to enable IRQ's to alter the I-bit, we write code to clear the bit: to clear/enable ANDCC #%11101111 or CLI to set/disable ORCC #%00010000 or SEI Dr. Tao Li 13

Enable Interrupt (Contd.) When an ISR is called, the I-bit is automatically set so that other interrupts don't occur We can choose to allow interrupts by enabling them first thing in the ISR, but BE CAREFUL "Non-Maskable" Interrupts are always enabled Local Enable: each of the "Maskable IRQ's" have a local enabled (aka device IRQ enable) - See Tables 8-1, 8-2 (SHE, old version) Local enable bit for value Dr. Tao Li 14

The Stack and IRQ s Upon IRQ, the following 9 bytes are pushed onto the stack: CCR B A SP during ISR XH XL YH YL RTNH RTNL SP before and after IRQ The RTI command PULLS this information off the stack Dr. Tao Li 15

Interrupt Priorities Interrupt priorities fixed in h/w; see Table 8-4 (SHE, old version) However, any single interrupting source can be elevated to highest-priority status Set by writing low byte of desired vector to HPRIO control register But, should only be done when interrupts masked via I=1 in CCR Default on CPU reset is HPRIO = $F2 giving IRQ preference Dr. Tao Li 16

Setting Interrupt Priorities Raise Timer Channel 2 to the highest priority position IRQ* Pin HPRIO: EQU $1F ; HPRIO address TC2VECT: EQU $FFEA ; Channel 2 Vector ;... ; Mask interrupts while setting HPRIO sei ; Set I-bit ; Raise Timer Channel 2 to the highest priority ldd #TC2VECT stab HPRIO cli ; Clear interrupt mask Dr. Tao Li 17

NMI Sources Six sources (from highest to lowest priority) High RESET* Low XIRQ* Dr. Tao Li 18

NMI Sources 1. RESET* 2. Clock monitor fail (if CPU s clock signals slow down or fail) 3. Computer Operating Properly (COP) failure Watchdog timer used in dedicated applications to help when power surges or programming errors lead to program getting lost ; When COP enabled, program must periodically pulse the COPRST reg. by writing $55 followed by $AA before at specified interval expires; Timeout period controllable in COPCTL control register, from ~1 ms to ~1 sec. Often disabled in development board s/w, but potent for real embedded systems. Dr. Tao Li 19

NMI Sources 4. Unimplemented opcode trap (happens when lost program starts executing data) 5. SWI (one-byte indirect branch to ISR via fixed vector location for SWI) 6. XIRQ* (more later) Initially masked to allow time to initialize SP, etc. Then can unmask by clearing X bit in CCR via ANDCC #%10111111 Once unmasked, cannot be masked again except on reset or during execution of XIRQ* s ISR (when masked and unmasked automatically to avoid nested NMI) Dr. Tao Li 20

External Interrupt Sources IRQ* signal generated by external device; may choose level-activate (default: good for shared wired-or line) or negative-edge-triggered response (unshared) via setting in INTCR reg. Polling can be used w/ multiple devices on IRQ* line; HC12 has no INTA signal to reset interrupt request, so if needed by external device then output port bit may be used Dr. Tao Li 21

An external IRQ available to the HC12 is a physical pin on the device can be used for sensors, external signals, buttons Sensitivity IRQ* External Interrupt can be "Level" or "Negative Edge" sensitive we use the IRQE bit in the INTCR register to configure this IRQE = 0 IRQE = 1 "Active Low" "Negative Edge Active" Dr. Tao Li 22

IRQ* Active Low Operation When the ISR is executing, IRQ's are disabled Sometimes, the IRQ* line will still be low when the completed this can be caused by a human pushed button (slow) or a slower peripheral this can cause the IRQ* to trigger again when the ISR is completed IRQ ISR IRQ ISR IRQ ISR IRQ ISR Dr. Tao Li 23

IRQ* Negative Edge Operation IRQ Request on falling edge will only occur once on edge sometimes better for a one-time event like a button IRQ ISR IRQ ISR Dr. Tao Li 24

IRQ* Details "Global Enable" - I-bit in CCR I-bit I-bit 1 = Disabled (default or SEI) 0 = Enabled (manually clear with CLI) "Local Enable" - IRQEN bit of the INTCR Register IRQEN IRQEN 0 = Disabled (default) 1 = Enabled "Vector Address" $FFF2:$FFF3 "Priority" highest of Maskable IRQ's, default value in HPRIO Dr. Tao Li 25

IRQ* Example 1 Latch the contents of Port A on the falling edge of IRQ* and store in "Temp (this will make the HC12 into an 8-bit D-flip-flop) Step 1 : Initialize the Vector Table IRQ_Vector EQU $FFF2 ORG IRQ_Vector DW My_ISR Step 2 : Write ISR (Registers are already preserved so don't need to push) My_ISR: LDAA PortA STAA Temp RTI Dr. Tao Li 26

IRQ* Example 1 Step 3 : Enable Interrupt a) configure IRQ b) Local enable c) Global enable SEI ; disable Maskable IRQ's BSET INTCR, IRQE ; setup IRQ* to edge sensitive BSET INTCR, IRQEN ; Local enable IRQ* CLI ; Global enable for IRQ* INTCR EQU $001E IRQE EQU %10000000 IRQEN EQU %01000000 (See SHE pp 202 for more information on INTCR) Dr. Tao Li 27

IRQ* Example 2 We have a sensor at a door and want to flash an LED if the door is open We can use IRQ* in "Level Sensitive" Mode IRQ will continue to trigger as long as the signal is asserted Step 1 : Initialize the Vector Table IRQ_Vector EQU $FFF2 ORG IRQ_Vector DW My_ISR Step 2 : Write ISR (Registers are already preserved so don't need to push) My_ISR: LDAA #~LED1 STAA PortA JSR Delay LDAA #LED1 STAA PortA RTI Dr. Tao Li 28

IRQ* Example 2 Step 3 : Enable Interrupt a) configure IRQ b) Local enable c) Global enable SEI ; disable Maskable IRQ's BCLR INTCR, IRQE ; setup IRQ* to level sensitive BSET INTCR, IRQEN ; Local enable IRQ* CLI ; Global enable for IRQ* INTCR EQU $001E IRQE EQU %10000000 IRQEN EQU %01000000 (See SHE pp 202 for more information on INTCR) Dr. Tao Li 29

XIRQ* External Interrupt XIRQ* Details An external IRQ available to the HC12 Is a physical pin on the device Psuedo Non-Maskable Interrupts: we CAN enable it, but only once. After we enable it, it is always going Global EN = X-bit X=1, disabled (default) (ANDCC #%1011 1111) X=0, enabled Local EN = NONE during XIRQ ISR, CPU will disable other XIRQ Interrupts (X=1), we can't control this after XIRQ ISR, CPU will enabled XIRQ interrupts (X=0) automatically Dr. Tao Li 30

XIRQ* Details XIRQ* External Interrupt - Vector = $FFF4:$FFF5 - Priority = #6 : non-maskable > Maskable, Priority can't be changed or promoted XIRQ_L Sensitivity - Level Sensitive Only (active LOW) - Typically used for gross failures like "low power" or "fire alarm" Dr. Tao Li 31

XIRQ* Example 1 Step 1 : Initialize the Vector Table XIRQ_Vector EQU $FFF4 ORG XIRQ_Vector DW My_ISR Step 2 : Write ISR (Registers are already preserved so don't need to push) My_ISR: ; Code RTI Step 3 : Enable Interrupt ANDCC #%1011 1111 Note: a) no configuration needed b) Local enable = NONE c) Global enable = X-bit NOTE: Do this right before your main program loop. Once you enable it, interrupts may start occurring immediately Dr. Tao Li 32

Advanced Interrupt What to do in s/w when waiting on an interrupt: Spin loop spin:bra spin Use WAI instruction to wait on interrupt (pushes regs. on stack in prep. for later interrupt to reduce its latency, then puts CPU into WAIT mode to conserve power) Use STOP instruction to stop HC12 clocks and dramatically conserve power; S bit in CCR must be 0 for instruction to operate Dr. Tao Li 33

WAI - "Wait for Interrupt" - Low Power Mode WAI - This instruction : 1) Stacks the Return Address; 2) Stacks the CPU Registers; 3) Stops executing instructions and waits for an IRQ - System Clocks are all still running - Good for Real Time programs where main loop does nothing, all functionality is handled by IRQs Dr. Tao Li 34

WAI Example ; Example of the WAI instruction in ; a foreground job. ; foreground: ; Here is the code to be done in the ; foreground. When all is complete, ; wait for the next interrupt. ;... wai ; When come out of the interrupt branch ; back to the foreground job. bra foreground Dr. Tao Li 35

STOP - "Stop CPU" - Low Power Mode, similar to WAI - This instruction :1) Stacks the Return Address; 2) Stacks the CPU Registers; 3) Stops executing instructions and waits for an IRQ or Reset - CPU Clock is STOPPED STOP - Takes more time to recover after IRQ/RESET due to waiting for X-tal to reach full-speed - We enabled this in the CCR, S-bit: S=1, disabled (default), instruction treated as NOP; S=0, enabled Dr. Tao Li 36