Chung-Ta King National Tsing Hua University

Slides:



Advertisements
Similar presentations
UBI >> Contents Chapter 7 Timers Laboratories MSP430 Teaching Materials Texas Instruments Incorporated University of Beira Interior (PT) Pedro Dinis Gaspar,
Advertisements

Interrupts, Low Power Modes and Timer A (Chapters 6 & 8)
Chung-Ta King National Tsing Hua University
Chung-Ta King National Tsing Hua University
ECE 447 Fall 2009 Lecture 9: TI MSP430 Interrupts & Low Power Modes.
68HC11 Polling and Interrupts
ECE 372 – Microcontroller Design Parallel IO Ports - Interrupts
Notes on the ez430-RF2500. Sources
6-1 I/O Methods I/O – Transfer of data between memory of the system and the I/O device Most devices operate asynchronously from the CPU Most methods involve.
CS4101 嵌入式系統概論 Timers and Clocks 金仲達教授 國立清華大學資訊工程學系 Materials from MSP430 Microcontroller Basics, John H. Davies, Newnes, 2008.
The 8051 Microcontroller and Embedded Systems
INTERRUPTS PROGRAMMING
Chung-Ta King National Tsing Hua University
Timers. Range of timers Watchdog timer: Included in all devices (watchdog timer+). Its main function is to protect the system against malfunctions but.
LAB 7: WDT+ and Low-Power Optimization
T IMERS - 2. O UTPUT U NIT Each capture/compare block contains an output unit. The output unit is used to generate output signals such as PWM signals.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
A Simple Tour of the MSP430. Light LEDs in C LEDs can be connected in two standard ways. Active high circuit, the LED illuminates if the pin is driven.
MSP430 Mixed Signal Microcontroller – Parte 2 Afonso Ferreira Miguel Source: slau056d – Texas instruments.
Revised: Aug 1, ECE 263 Embedded System Design Lessons 23, 24 - Exceptions - Resets and Interrupts.
CPE 323 Introduction to Embedded Computer Systems: Watchdog Timer, Timer A Instructor: Dr Aleksandar Milenkovic Lecture Notes.
MICROPROCESSOR INPUT/OUTPUT
CoE3DJ4 Digital Systems Design Chapter 6: Interrupts.
Khaled A. Al-Utaibi  Interrupt-Driven I/O  Hardware Interrupts  Responding to Hardware Interrupts  INTR and NMI  Computing the.
ECE 447 Fall 2009 Lecture 10: TI MSP430 Timers and Capture Modes.
Lecture 11: TI MSP430 Timers Compare Modes
LAB 8: Program Design Pattern and Software Architecture
Microprocessors 1 MCS-51 Interrupts.
1 © Unitec New Zealand Interrupt Lecture 6 Date: - 20 Sept, 2011 Embedded Hardware ETEC 6416.
1 Interrupts, Resets Today: First Hour: Interrupts –Section 5.2 of Huang’s Textbook –In-class Activity #1 Second Hour: More Interrupts Section 5.2 of Huang’s.
ECE 447 Fall 2009 Lecture 7: MSP430 Polling and Interrupts.
Interrupts  An interrupt is any service request that causes the CPU to stop its current execution stream and to execute an instruction stream that services.
Network and Systems Laboratory nslab.ee.ntu.edu.tw.
Embedded Systems Design 1 Lecture Set 8 MCS-51 Interrupts.
CS4101 嵌入式系統概論 Interrupt 金仲達教授 國立清華大學資訊工程學系 ( Materials from MSP430 Microcontroller Basics, John H. Davies, Newnes, 2008 )
CS-280 Dr. Mark L. Hornick 1 Sequential Execution Normally, CPU sequentially executes instructions in a program Subroutine calls are synchronous to the.
The 8051 Microcontroller Chapter 6 INTERRUPTS. 2/29 Interrupt is the occurrence of a condition an event that causes a temporary suspension of a program.
UNIT 2. CPUXV2 20-bit addressing User-definable Boot Strap Loader RAM starts at 0x1C00 Beginning of MAIN flash moves according to RAM Vector table starts.
ECE 382 Lesson 32 Lesson Outline Lab 6 Introduction Pulse Width Modulation Capture / Compare Example Lab 6 Tips Admin Lab#6 “prelab” due BOC lesson 33.
Lecture 10: TI MSP430 Timers and Capture Modes
Introduction Why low power?
ECE 3430 – Intro to Microcomputer Systems
Lecture 8: TI MSP430 Interrupts, ISRs
CS4101 嵌入式系統概論 Interrupts Prof. Chung-Ta King
Lesson Outline Interrupts Admin Assignment #9 due next lesson
CS4101 Introduction to Embedded Systems Lab 6: Low-Power Optimization
68HC11 Interrupts & Resets.
Microprocessor Systems Design I
CS4101 嵌入式系統概論 Interrupts Prof. Chung-Ta King
CS4101 Introduction to Embedded Systems Lab 1: General Purpose IO
Prof. Chung-Ta King Department of Computer Science
ECE 3430 – Intro to Microcomputer Systems
Interrupts In 8085 and 8086.
MSP432 ARM Timer Programming
8085 Interrupts.
National Tsing Hua University CS4101 Introduction to Embedded Systems Lab 2: Timer and Clock Prof. Chung-Ta King Department of Computer Science National.
National Tsing Hua University CS4101 Introduction to Embedded Systems Lab 3: Interrupt Prof. Chung-Ta King Department of Computer Science National Tsing.
National Tsing Hua University CS4101 Introduction to Embedded Systems Lab 6: Serial Communication Prof. Chung-Ta King Department of Computer Science National.
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
CS4101 Introduction to Embedded Systems Lab 7: Serial Communication
CS4101 Introduction to Embedded Systems Lab 4: Interrupt
ECE 3430 – Intro to Microcomputer Systems
CS4101 Introduction to Embedded Systems Lab 7: Serial Communication
ECE 3430 – Intro to Microcomputer Systems
Lecture 9: TI MSP430 Interrupts & Low Power Modes
ECE 3430 – Intro to Microcomputer Systems
CS4101 Introduction to Embedded Systems Lab 2: Basic IO and Timer
Prof. Chung-Ta King Department of Computer Science
MSP430 Clock System and Timer
Presentation transcript:

Chung-Ta King National Tsing Hua University CS 4101 Introduction to Embedded Systems LAB 4: Interrupt Chung-Ta King National Tsing Hua University

Introduction In this lab, we will learn The interrupt of Timer_A in MSP430 The interrupt of port P1 in MSP430 How to write an interrupt service routine

Enabling Interrupts in MSP430 P1IE TACTL TACCTL GIE TAIE TAIFG CCIE CCIFG (General Interrupt Enable)

3 Types of Interrupts in MSP430 System reset: Power-up, external reset, Watchdog Timer, flash key violation, PC out-of-range, etc. Always take (Non)-maskable interrupt (NMI): RST/NMI pin, oscillator fault, flash access violation Cannot be masked by clearing the GIE bit; but still need bits to be set in special peripheral registers Maskable interrupt

When an Interrupt Is Requested Any currently executing instruction is completed PC, pointing to next instruction, is pushed onto stack SR is pushed onto the stack The interrupt with the highest priority is selected The interrupt request flag is cleared automatically for vectors that have a single source SR is cleared, and maskable interrupts are disabled The interrupt vector is loaded into the PC and the CPU starts to execute the ISR at that address These operations take about 6 cycles

After an Interrupt Is Serviced An interrupt service routine must always finish with the return from interrupt instruction reti: The SR pops from the stack. All previous settings of GIE and the mode control bits are now in effect.  enable maskable interrupts and restore the previous low-power mode if there was one. The PC pops from the stack and execution resumes at the point where it was interrupted. Alternatively, the CPU stops and the device reverts to its low-power mode before the interrupt.

Interrupt Vectors The MSP430 uses vectored interrupts The address (vector) of each ISR is stored in a vector table at a fixed memory location (0xFFC0–0xFFFF) A vector is usually associated with a unique interrupt, but some sources share a vector and software (the ISR) must locate the source of interrupts Each interrupt vector has a distinct priority, which is used to select which vector is taken if more than one interrupt is active. The priorities are fixed in hardware, given simply by the address of the vector

Interrupt Source Interrupt Flag System Interrupt Word Address Priority Power-up/external reset/Watchdog Timer+/flash key viol./PC out-of-range PORIFG RSTIFG WDTIFG KEYV reset 0FFFEh 31 (highest) NMI/Oscillator Fault/ Flash access viol. NMIIFG/OFIFG/ ACCVIFG non-maskable 0FFFCh 30 0FFFAh 29 0FFF8h 28 0FFF6h 27 Watchdog Timer+ WDTIFG maskable 0FFF4h 26 Timer_A TACCR0 CCIFG 0FFF2h 25 TACCR1 CCIFG, TAIFG 0FFF0h 24 0FFEEh 23 0FFECh 22 ADC10 ADC10IFG 0FFEAh 21 USI USIIFG USISTTIFG 0FFE8h 20 I/O Port P2 (2) P2IFG.6, P2IFG.7 0FFE6h 19 I/O Port P1 (8) P1IFG.0 to P1IFG.7 0FFE4h 18 0FFE2h 17 0FFE0h 16 Unused 0FFDEh 0FFCDh 15 - 0 The MSP430 uses vectored interrupts, which means that the address of each ISR—its vector—is stored in a vector table at a defined address in memory. In most cases each vector is associated with a unique interrupt but some sources share a vector. The ISR itself must locate the source of interrupts that share vectors. For example, TAIFG shares a vector with the capture/compare interrupts for all channels of Timer_A other than 0. Channel 0 has its own interrupt flag TACCR0 CCIFG and separate vector. 8

Interrupts from Timer_A Interrupts can be generated by the timer itself (flag TAIFG) and each capture/compare block (flag TACCRn CCIFG) TAIFG TACTL CCIFG TACCTL

2 Interrupt Vectors for Timer_A 1. For TACCR0 CCIFG (high priority): CCIFG0 flag is cleared automatically when serviced 2. For all other CCIFG flags and TAIFG In compare mode, any CCIFG flag is set if TAR counts to the associated TACCRx value Flags are not cleared automatically, because need to determine who made the interrupt request Can use software (ISR) to poll the flags  slow Use hardware: interrupt vector register (TAIV)

TAIV On an interrupt, TAIV contains a number indicating highest priority enabled interrupt Any access of TAIV resets the highest pending interrupt flag. If another interrupt flag is set, another interrupt is immediately generated

Sample Code for Timer_A Toggle LEDs using interrupts from Timer_A in up mode #include <io430x11x1.h> // Specific device #include <intrinsics.h> // Intrinsic functions #define LED1 BIT0 void main (void) { WDTCTL = WDTPW|WDTHOLD; // Stop watchdog timer P1OUT = ˜LED1; P1DIR = LED1; TACCR0 = 49999; // Upper limit of count for TAR TACCTL0 = CCIE; // Enable interrupts TACTL = MC_1|ID_3|TASSEL_2|TACLR; // Up mode, divide clock by 8, clock from SMCLK, clear __enable_interrupt(); // Enable interrupts (intrinsic) for (;;) { // Loop forever doing nothing } } // Interrupt service routine for Timer_A #pragma vector = TIMERA0_VECTOR __interrupt void TA0_ISR (void){ P1OUT ˆ= LED1; // Toggle LED The code is for different device 12 12

Sample Code Explained #pragma line associates the function with a particular interrupt vector __interrupt keyword names the function Compiler will generate code to store address of the function in the vector and to use reti rather than ret at the end of the function An intrinsic function, __enable_interrupt() sets the GIE bit and turn on interrupts It is declared in intrinsics.h

Interrupts on Digital Inputs We have seen that port P1 has several registers associate with it P1IN, P1OUT, P1DIR, P1REN In fact, it has more registers; some are used for interrupts Yes, ports P1 and P2 can request an interrupt when the value on an input pin changes!

Interrupts on Digital Inputs Registers of P1 for interrupt: Port P1 interrupt enable, P1IE: enables interrupts when the value on an input pin changes, by setting appropriate bits of P1IE to 1; off (0) by default Port P1 interrupt edge select, P1IES: can generate interrupts either on a positive edge (0), when the input goes from low to high, or on a negative edge (1)

Interrupts on Digital Inputs Registers of P1 for interrupt (cont’d): Port P1 interrupt flag, P1IFG: a bit is set when the selected transition has been detected on the input, and an interrupt is requested if it has been enabled. A single vector for the port The user must check P1IFG to determine the bit that caused the interrupt. This bit must be cleared explicitly

Sample Code for P1 A hi/low transition on P1.4 triggers P1_ISR to toggles P1.0 void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P1DIR = 0x01; // P1.0 output, else input P1OUT = 0x10; // P1.4 set, else reset P1REN |= 0x10; // P1.4 pullup P1IE |= 0x10; // P1.4 interrupt enabled P1IES |= 0x10; // P1.4 Hi/lo edge P1IFG &= ~0x10; // P1.4 IFG cleared _BIS_SR(GIE); // Enter interrupt while(1); } // Port 1 interrupt service routine #pragma vector=PORT1_VECTOR __interrupt void Port_1(void) { P1OUT ^= 0x01; // P1.0 = toggle P1IFG &= ~0x10; // P1.4 IFG cleared 17 17

Sample Code #include <msp430g2231.h> (#include <msp430g2553.h>) void ConfigWDT(void); void ConfigClocks(void); void ConfigLEDs(void); void ConfigTimerA2(void);   void main(void) { ConfigWDT(); ConfigClocks(); ConfigLEDs(); // enable and turn off LED ConfigTimerA2(); _BIS_SR(GIE); // Turn on Interrupts // GIE: general iterrupt enable while(1) P1OUT |= BIT0; // turn on red LED }

Basic Lab Complete the functions in the sample code. Flash green LED at 1 Hz based on the interrupt from Timer_A, which is driven by SMCLK sourced by VLO. Hint: For different devices, the "Interrupt Vectors name" may be different; plz check the header file for the correct Interrupt Vectors name. While keeping the green LED flashing at 1 Hz, use polling to monitor the activity of the button. Pushing the button turns on the red LED and releasing the button turns it off.

Bonus Write an ISR for the button , and whenever the button is pushed, make the blinking LED into red LED and vice versa. Hint: PORT1_VECTOR as interrupt type, P1IFG as interrupt flag, P1IE to enable interrupt for port 1, BIT3 to represent the 3rd bit.