Resets and Interrupts

Document Sample
Resets and Interrupts Powered By Docstoc
					                      Resets and Interrupts
    • Resets
            – Why are resets necessary?
            – What are the various sources of reset in an
              HCS08 processor?
    • Interrupts
            – What are interrupts?
            – How are they implemented on the GT16
            – IRQ pin

R. Verrinder (2008)
                      What is a Reset?
    • As with logic circuits, it is important to
      initialize the device into a known state
    • The processor also must know where to
      find the first program instruction
    • This is the purpose of a reset

R. Verrinder (2008)
                      Resetting the GT16
    • Resetting a microcontroller, starts processing
      from a known set of initial conditions
    • During a reset the following occurs
            – Most control and status registers are forced into a
              known state
            – The program counter is loaded from the reset vector
            – On chip peripheral modules are disabled
            – Input/Output pins are configured as inputs
            – All maskable interrupts are blocked by setting the I bit
              in the CCR
            – The SP is forced to $00FF

R. Verrinder (2008)
        MT9S08GT16 Reset Sources
    • These are reset sources for the GT16:
            – Power on Reset (POR)
            – Low-voltage detect (LVD)
            – Computer operating properly (COP) watch
              dog timer
            – Illegal opcode executed
            – Illegal address executed
            – CPU clock error
            – RESET pin is asserted (pulled LOW)

R. Verrinder (2008)
           System Reset Status Register
           External Reset Pin
                          Illegal opcode Internal Low Generation Module
    Power On ResetWatch Dog Timer timed out Reset Voltage Detect Reset Reset

    • This register contains six read only flags which
      show the most resent reset source

R. Verrinder (2008)
                      Reset Properties
    • Here are a few points to remember about
            – They are asynchronous and are recognized
              when asserted
            – Exiting a reset is always synchronous
            – Resets are not maskable

R. Verrinder (2008)
    • In order to understand interrupts it is
      important to know what types of program
      flow we have encountered so far

R. Verrinder (2008)
                        Programs so far
    • Programs are lists of instructions to be executed in a
      certain order
    • We have seen four different ways in which the processor
      reaches the next instruction
            – Processor moves directly to next instruction in memory
            – Processor might perform a relative branch. i.e. branch forwards
              or backwards by a certain number of instructions
            – Processor might perform an absolute jump
            – Processor might encounter an instruction which tells it to execute
              a procedural call. The processor then saves its current position
              onto the stack and jumps off to another point in the list of
    • In all of these cases the programmer tells the processor
      when to move to the next instruction and where it is
R. Verrinder (2008)
                      Interrupt Analogy
 •          Lets say that you               START
            required to sit and read
            through a pile of
            textbooks. You pick up       Pick up a book
            the first book flip
            through and read the
            pages, lay the book        Read current page
            down and pick up the
            next book
                                       Turn over the page
 •          This can be
            represented by the
                                             Book           N
            following program
                                              Pile          N
R. Verrinder (2008)
                      Interrupt Analogy cont.
    • Now lets say the phone rings during this process.
      You stand up walk to the phone pick it up answer
      it. Once the call is finished you return back to
      where you left your reading
    • This is an unscheduled event
    • You did not know when or even if it was going to
    • But when it did you knew how to handle the
    • This “interrupt” source interrupted the normal
      program flow and initiated a different set of
R. Verrinder (2008)
     Interrupts in Microprocessors
    • Interrupts provide a way to suspend normal
      program operation temporarily so that the CPU
      can be freed to handle the interrupt
    • In order to work with interrupts we need to
            – What events might cause interrupts
            – What our behavior will be when an interrupt occurs
    • The GT16 microcontrollers has a limited number
      of possible interrupt sources. These include:
            – A dedicated pin going low ( IRQ pin)
            – The ADC finishing a conversion
            – Numerous different timer events
R. Verrinder (2008)
                      Interrupt Handling
    • The way in which a MCU will behave when
      it receives an interrupt is contained in a
      section of code known as:
            – Interrupt handler or
            – Interrupt Service Routine (ISR)
    • This section of code will execute fully
      whenever an interrupt occurs

R. Verrinder (2008)
                      Interrupt Vector Tables
    • We need to define what Interrupt Service
      Routines are linked to the events that will trigger
    • This is done in an Interrupt Vector Table
    • The interrupt vector table contains the address
      or function name of the ISR
    • The processor can then:
            – Jump to the appropriate ISR
            – Execute it
            – Return to where it left off before the interrupt was

R. Verrinder (2008)
             Interrupt Request Process
    • When the CPU receives an interrupt
      request it does the following
            – Completes current instruction
            – Saves the CPU registers onto the stack
            – Sets the I bit in the CCR to mask further
            – Fetches the interrupt vector for the highest
              priority interrupt that is currently pending
            – Completes the ISR
R. Verrinder (2008)
                  Interrupts and the Stack
                         MCU receives RTI Interrupt

                      ADDRESS                      DATA
 SP                    0x00FA
 SP                    0x00FB   Condition Code Register
 SP                    0x00FC   Accumulator
 SP                    0x00FD   Index Register (Low Byte X)
 SP                    0x00FE   Program Counter High
 SP                    0x00FF   Program Counter Low

R. Verrinder (2008)
                         The IRQ Pin
  • The IRQ pin is a dedicated
    interrupt pin
  • If the pin is pulled to a logic
    LOW and interrupt will occur

R. Verrinder (2008)
                      Using the IRQ Pin
            Enable the IRQ IRQ PinEnable IRQ Pin0 clears IRQ Either
                    IRQ Pin pin
                            Flag Acknowledge.     Detection Mode.
    Interrupt request edge select. Set to 0 for fallingInterrupts Flag level or Edge
    edge                                     Triggered

    • This pin can be enabled and configured by
      setting bits in the IRQSC register

R. Verrinder (2008)
                      IRQ Pin Example
    • This program demonstrates the use of the IRQ pin. When the IRQ
      pin is pulled LOW an LED will be switched on and stay high in

IRQ                                                              LED1

R. Verrinder (2008)
                         IRQ Pin Example
          XDEF _Startup, IRQ_vector
          INCLUDE         '‘
          org   ROM1Start

        LDHX #$047F               ;Initialize the stack pointer
        LDA #$53
        STA   SOPT                ;Disable the watchdog timer
        MOV   #$80,PTADD          ;Make PTA7 an output
        MOV   #$FF,PTAD           ;LED's are off for a logic high
        MOV   #$16,IRQSC          ;00011010
        CLI                       ;Enable global interrupts

    mainLoop:                     ;Main loop does nothing, ISR does all the work
        BRA   mainLoop

        BSET 2,IRQSC ;Acknowledge the interrupt
        BCLR 7,PTAD    ;Turn on an LED
        RTI                      ;Return to the main loop

R. Verrinder (2008)
                      Interrupt Priority
    • Interrupts can come from multiple different
    • If several interrupts occur at once, the
      processor must know which interrupt to
      deal with first
    • We can therefore set the priority of the
      interrupt handlers, in other words in which
      order the interrupts need to be dealt with

R. Verrinder (2008)

Shared By: