Lab 4: Interrupt. CS4101 Introduction to Embedded Systems. Prof. Chung-Ta King. Department of Computer Science National Tsing Hua University, Taiwan

Similar documents
Interrupts CS4101 嵌入式系統概論. Prof. Chung-Ta King. Department of Computer Science National Tsing Hua University, Taiwan

Lab 4 Interrupts ReadMeFirst

Lecture 5: MSP430 Interrupt

CPE 323: MSP430 Timers

Timers and Clocks CS4101 嵌入式系統概論. Prof. Chung-Ta King. Department of Computer Science National Tsing Hua University, Taiwan

Interrupts, Low Power Modes

What is an Interrupt?

Timer Module Timer A. ReadMeFirst

ECE PRACTICE EXAM #2 Clocks, Timers, and Digital I/O

Texas Instruments Mixed Signal Processor Tutorial Abstract

// Conditions for 9600/4=2400 Baud SW UART, SMCLK = 1MHz #define Bitime_5 0x05*4 // ~ 0.5 bit length + small adjustment #define Bitime 13*4//0x0D

MSP430 Interrupts. Change value of internal variable (count) Read a data value (sensor, receive) Write a data value (actuator, send)

University of Texas at El Paso Electrical and Computer Engineering Department. EE 3176 Laboratory for Microprocessors I.

Hacettepe University

Wireless Sensor Networks (WSN)

Hacettepe University

ECE2049: Embedded Computing in Engineering Design C Term Spring Lecture #11: More Clocks and Timers

Lab 1: I/O, timers, interrupts on the ez430-rf2500

15.1 Timer_A Introduction

2.996/6.971 Biomedical Devices Design Laboratory Lecture 6: Microprocessors II

Lecture test next week

IV B.Tech. I Sem (R13) ECE : Embedded Systems : UNIT -2 1 UNIT 2

CPE 325: Embedded Systems Laboratory Laboratory #7 Tutorial MSP430 Timers, Watchdog Timer, Timers A and B

MSP430 Teaching Materials

LECTURE - 4 Programming MSP430 using Code Composer Studio(CCS)

ECE2049: Embedded Computing in Engineering Design C Term Spring 2019 Lecture #22: MSP430F5529 Operating Mode & the WDT

2006 Mixed Signal Products SLAU049F

2006 Mixed Signal Products SLAU144B

Today's plan: Announcements General Strategy Microcontroller programming concepts/last bits of assembly Activity 2

ECE2049: Embedded Computing in Engineering Design A Term Fall 2017 Lecture #16: Interrupts and Event Driven Code

CPE 323 Introduction to Embedded Computer Systems: MSP430 System Architecture An Overview

Block diagram of processor (Harvard)

Designing for Ultra-Low Power with MSP430

2006 Mixed Signal Products SLAU049F

Copyright 2015 by Stephen A. Zajac & Gregory M. Wierzba. All rights reserved..spring 2015.

6. General purpose Input/Output

The 16-bit timer/counter register, TAR, increments or decrements (depending on mode of operation) with each rising edge of the clock signal.

MSP430x43x1, MSP430x43x, MSP430x44x1, MSP430x44x MIXED SIGNAL MICROCONTROLLER

CPE 323 Introduction to Embedded Computer Systems: ADC12 and DAC12. Instructor: Dr Aleksandar Milenkovic Lecture Notes

Interrupt Driven Programming in MSP430 Assembly (ESCAPE) *

CONTENTS: Program 1 in C:

ECSE-426. Microprocessor Systems. 2: Assembly + C 1

TAxCTL Register

Grundlagen Microcontroller Interrupts. Günther Gridling Bettina Weiss

MSP430. More on MSP430

5xx Active & Low Power Mode Operation

University of Texas at El Paso Electrical and Computer Engineering Department. EE 3176 Laboratory for Microprocessors I.


Using peripherals on the MSP430 (if time)

Reading: Davies , 8.3-4, , MSP430x55xx User's Guide Ch. 5,17, MSP430F5529 Launchpad User's Guide

ECGR 4101/5101, Fall 2016: Lab 1 First Embedded Systems Project Learning Objectives:

MSP430FG4618 Programming Reference Revision 3

CPE/EE 421 Microcomputers

Microprocessors B (17.384) Spring Lecture Outline

CPE 325: Embedded Systems Laboratory Laboratory #11 Tutorial Analog-to-Digital Converter and Digital-to-Analog Converter

Towards Hard Real-time Performance in a Highly Asynchronous Multitasking MSP430 Application Andrew E. Kalman, Ph.D.

Timer 32. Last updated 8/7/18

Reading: Davies , 8.3-4, , MSP430x55xx User's Guide Ch. 5,17

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

Embedded Systems. 3. Hardware Software Interface. Lothar Thiele. Computer Engineering and Networks Laboratory

Microcontrollers. vs Microprocessors

Introduction to the Texas Instruments ez430. By: Naren Anand

CPE/EE 421 Microcomputers

Alex Milenkovich 1. CPE/EE 421 Microcomputers. Course Administration. Review: Outline. Getting Started with EasyWeb2. Review: MSP bit RISC

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

Create and Add the Source File

Week 4: Embedded Programming Using C

ECE 485/585 Microprocessor System Design

12. Interrupts and Programmable Multilevel Interrupt Controller

Design and Implementation Interrupt Mechanism

Fall. Accelerometer RGB LED control Vishal Shah Rebel Sequeira Pratiksha Patil Pranali Dhuru Chris Blackden. George Mason University

University of Texas at El Paso Electrical and Computer Engineering Department. EE 3176 Laboratory for Microprocessors I.

University of Texas at El Paso Electrical and Computer Engineering Department. EE 3176 Laboratory for Microprocessors I.

Digital Control of Electric Drives

Interrupts and Using Them in C

Getting Started with the Texas Instruments ez430

UNIVERSITY OF CONNECTICUT. ECE 3411 Microprocessor Application Lab: Fall Quiz III

Interfacing CMA3000-D01 to an MSP430 ultra low-power microcontroller

Interrupts. Why Interrupts

PHYS 319. Things to do before next week's lab Whirlwind tour of the MSP430 CPU and its assembly language Activity 1.

EE4390 Microprocessors

ATmega Interrupts. Reading. The AVR Microcontroller and Embedded Systems using Assembly and C) by Muhammad Ali Mazidi, Sarmad Naimi, and Sepehr Naimi

Physics 319 Spring 2015: Introduction to the Programming and Use of Microprocessors

Types of Interrupts:

CHAPTER 11 INTERRUPTS PROGRAMMING

Hacettepe University

IAR PowerPac RTOS for Texas Instruments MSP430 Microcontroller Family

INTERRUPTS in microprocessor systems

Getting Started with the MSP430 LaunchPad

ECE2049 Homework #2 The MSP430 Architecture & Basic Digital IO (DUE Friday 9/8/17 at 4 pm in class)

Interfacing CMR3000-D01 to an MSP430 ultra low-power microcontroller

Newbie s Guide to AVR Interrupts

Copyright 2009 Texas Instruments All Rights Reserved

Why embedded systems?

Interrupts & Interrupt Service Routines (ISRs)

Before next weeks lab:

Embedded Technosolutions

Lab 4 Interrupt-driven operations

The digital I/O is configured with user software. The setup and operation of the digital I/O is discussed in the following sections.

Hi Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

Transcription:

CS4101 Introduction to Embedded Systems Lab 4: Interrupt Prof. Chung-Ta King Department of Computer Science, Taiwan

Introduction In this lab, we will learn interrupts of MSP430 Handling interrupts in MSP430 Handling interrupts of Timer_A in MSP430 Handling interrupts of port P1 in MSP430 Writing an interrupt service routine 1

Three 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 2

Know When an Interrupt Occurs On MSP430, an interrupt will be detected and serviced if The global interrupt-enable (GIE) bit in Status Register (SR) in CPU is set A peripheral device enables interrupt For Timer_A: TAIE bit in TACTL register, CCIE bit in TACCTLx register The peripheral signals an interrupt For Timer_A: TAIFG, CCIFG 3

Ex: Timer_A Interrupt Enabling TACTL TACCTL 4

When an Interrupt Is Requested Any currently executing instruction is completed. MCLK is started if the CPU was off. The PC, which points to the next instruction, is pushed onto the stack. The 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. The 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 5

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 restores 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. 6

Where to Find ISRs? The MSP430 uses vectored interrupts Each ISR has its own vector, which is stored at a predefined address in a vector table at the end of the program memory (addresses 0xFFC0 ~ 0xFFFF). The vector table is at a fixed location, but the ISRs themselves can be located anywhere in memory. 7

Interrupt Source Power-up/external reset/watchdog Timer+/flash key viol./pc out-of-range NMI/Oscillator Fault/ Flash access viol. Interrupt Flag PORIFG RSTIFG WDTIFG KEYV NMIIFG/OFIFG/ ACCVIFG System Interrupt Reset Word Address 0FFFEh Priority 31 (highest) Non-maskable 0FFFCh 30 Timer1_A3 TA1CCR0 CCFIG maskable 0FFFAh 29 Timer1_A3 TA1CCR1/2 CCFIG, TAIFG maskable 0FFF8h 28 Comparator_A+ CAIFG maskable 0FFF6h 27 Watchdog Timer+ WDTIFG maskable 0FFF4h 26 Timer0_A3 TA0CCR0 CCIFG maskable 0FFF2h 25 Timer0_A3 TA0CCR1/2 CCIFG, TAIFG maskable 0FFF0h 24 0FFEEh 23 0FFECh 22 ADC10 ADC10IFG maskable 0FFEAh 21 0FFE8h 20 I/O Port P2 (8) P2IFG.0 to P2IFG.7 maskable 0FFE6h 19 I/O Port P1 (8) P1IFG.0 to P1IFG.7 maskable 0FFE4h 18 Unused 0FFE2h 17 0FFE0h 16 0FFDEh 0FFCDh 15-8 0

Outline Handling interrupts in MSP430 Handling interrupts of Timer_A in MSP430 Handling interrupts of port P1 in MSP430 Writing an interrupt service routine 9

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

Two Interrupt Vectors for Timer_A For TACCR0 CCIFG (high priority): CCIFG0 flag is cleared automatically when serviced 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: Timer_A interrupt vector register (TAIV) 11

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 12

Sample Code for Timer_A Interrupt 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 = TIMER0_A0_VECTOR interrupt void TA0_ISR (void){ P1OUT ˆ= LED1; // Toggle LED } 13

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 14

Outline Handling interrupts in MSP430 Handling interrupts of Timer_A in MSP430 Handling interrupts of port P1 in MSP430 Writing an interrupt service routine 15

Interrupts on Port 1 Ports P1 and P2 can request an interrupt when the value on an input pin changes 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) 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. 16

Interrupts on Port 1 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 17

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); // Loop forever } #pragma vector=port1_vector interrupt void Port_1(void) { P1OUT ^= 0x01; // P1.0 = toggle P1IFG &= ~0x10; // P1.4 IFG cleared } 18

Lab 4: Basic 1 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; please check the header file for the correct Interrupt Vectors name. 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. List the assembly code and observe the location of ISR. 19

Lab 4: Basic 2 Flash green LED at 0.2 Hz (e.g. turn on for 2.5 sec, turn off 2.5 sec, and so on) based on the interrupt from Timer_A, which is driven by SMCLK sourced by VLO. Record TAR in ISR of Timer_A. In ISR of P1, record TAR second time and use expression window to see the difference between first and second records. Set a break point in the end of P1 ISR and see how fast you can push the button after the LED is off! 20

Lab 4 Bonus Flash both red and green LEDs at 1 Hz. The green LED should be on for 0.5 sec and off for 0.5 sec. The red LED should be on for 0.2 sec and off for 0.8 sec. After button pushed, switch the behavior of two LED (e.g. Red LED on for 0.5 sec and off for 0.5 sec and green LED on for 0.2 sec and off for 0.8 sec) using the interrupt. 21

Lab 4 Bonus hint The name of the interrupt vector for TACCR1, TACCR2, and TAR is TIMER0_A1_VECTOR. All three interrupts will cause the CPU to run the same ISR at TIMER0_A1_VECTOR. To detect whether it is TACCR1, TACCR2, or TAR that causes the interrupt, please check the register TA0IV. Note that TA0IV will be reset automatically when you read it. Thus, you need to read TA0IV into a local variable first before you check its bits. 22