Lecture 5: MSP430 Interrupt

Similar documents
Interrupts, Low Power Modes

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

Lab 4 Interrupts ReadMeFirst

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

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

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

Texas Instruments Mixed Signal Processor Tutorial Abstract

CPE 323: MSP430 Timers

What is an Interrupt?

Timer Module Timer A. ReadMeFirst

// 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

Wireless Sensor Networks (WSN)

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

Lecture test next week

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

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

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

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

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

Hacettepe University

Block diagram of processor (Harvard)

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

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

MSP430. More on MSP430

Hacettepe University

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

6. General purpose Input/Output

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

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

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

15.1 Timer_A Introduction

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

Grundlagen Microcontroller Interrupts. Günther Gridling Bettina Weiss

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

CHAPTER 11 INTERRUPTS PROGRAMMING

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

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

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

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

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

TAxCTL Register

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

Microprocessors & Interfacing

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

Why embedded systems?

Introduction to Embedded Systems

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

ECE 492 WINTER 2015 GROUP 2. Texas Instruments MSP430-FR Bit ADC Setup Guide

Interrupt Driven Programming in MSP430 Assembly (ESCAPE) *

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

ECE2049: Embedded Computing in Engineering Design A Term Fall Lecture #8: Making it work: LEDs, Buttons & Keypad

Before next weeks lab:

Embedded Systems and Software

Using peripherals on the MSP430 (if time)

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

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

063[[[0LFURFRQWUROOHUV /RZ3RZHU0RGHV &3($GYDQFHG0LFURFRPSXWHU7HFKQLTXHV 'U(PLO-RYDQRY /RZ3RZHU. Power: A First-Class Architectural Design Constraint

MSP430xxxx Microcontrollers Low Power Modes

Designing for Ultra-Low Power with MSP430

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

CONTENTS: Program 1 in C:

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

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

MSP430 Teaching Materials

MIDTERM#1. 2-(3pts) What is the difference between Von Neumann & Harvard processor architectures?

Micro-Controller: PIC16C74 < Part 5: Interrupt >

Getting Started with the Texas Instruments ez430

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

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

Interrupts and Using Them in C

Introduction to the Texas Instruments ez430. By: Naren Anand

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

ECE2049: Embedded Computing in Engineering Design C Term Spring Lecture #7: More Digital IO

TPL5000EVM User's Guide

12. Interrupts and Programmable Multilevel Interrupt Controller

Review Activity 1 CALL and RET commands in assembler

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

5xx Active & Low Power Mode Operation

e-pg Pathshala Subject: Computer Science Paper: Embedded System Module: Interrupt Programming in Embedded C Module No: CS/ES/20 Quadrant 1 e-text

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

Reset, Interrupts, Exceptions, and Break ECE 3534

Alex Milenkovich 1. CPE/EE 421 Microcomputers: The MSP430 Introduction. Outline

Interrupts in Zynq Systems

Digital Control of Electric Drives

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

By the end of Class. Outline. Homework 5. C8051F020 Block Diagram (pg 18) Pseudo-code for Lab 1-2 due as part of prelab

Fundamental concept in computation Interrupt execution of a program to handle an event

These 3 registers contain enable, priority,

Micro computer Organization

Timer 32. Last updated 8/7/18

CPE/EE 421 Microcomputers

Create and Add the Source File

Interrupt Basics Karl-Ragmar Riemschneider

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

EE Embedded Systems Design. Lessons Exceptions - Resets and Interrupts

Interrupts. Why Interrupts

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

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: Interrupt Handling Module No: CS/ES/13 Quadrant 1 e-text

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

Transcription:

ECE342 Intro. to Embedded Systems Lecture 5: MSP430 Interrupt Ying Tang Electrical and Computer Engineering Rowan University 1

How A Computer React to Inputs? Polling: the processor regularly looks at the input and react accordingly Easy to implement and debug Intensive processing If an event is rare, CPU wastes lots of time checking Processor can t go into low-power mode Interrupt: the processor is interrupted by an event Time effective Energy saving: processor can be asleep most of time Hard to debug 2

Polling vs. Interrupt void main (void) { int j; WDTCTL = WDTPW WDTHOLD; P1SEL =0; P2SEL=0; P1DIR =BIT0; P2DIR&=~BIT1; P2REN =BIT1; P2OUT =BIT1; P1OUT &=~(BIT0); } while (1){ j= P1IN&BIT1; if(j!=2) P1OUT^=0x01; else P1OUT &=~(BIT0); } void main(void) { WDTCTL = WDTPW WDTHOLD;// Stop watchdog timer P1SEL =0; P1DIR =BIT0; //set Port 1.0 output ---LED P1DIR &=~(BIT1); //set Port 1.1 input --- pushbutton } P1REN =BIT1;//enable pull-up resistor on P1OUT =BIT1; P1IE =BIT1;//enable the interrupt on Port 1.1 P1IES =BIT1;//set as falling edge P1IFG &=~(BIT1);//clear interrupt flag //enter LPM4 mode and enable global interrupt _BIS_SR(LPM4_bits + GIE); //Port 1 ISR #pragma vector=port1_vector _interrupt void PORT_1(void) { P1OUT ^=0x01; P1IFG &=~(BIT1); } The details are not important now, we will come back to the interrupt version later and go over it line by line, bit by bit 3

What is an Interrupt Interrupt is an event that will cause the CPU to stop the normal program execution and provide some service to the event Internal interrupt: generated by the hardware circuitry inside the chip and caused by software errors External interrupt: generated when the external hardware asserts an interrupt signal to the CPU Software interrupt: dealing with abnormal situations that occur during program execution, such as illegal opcodes, overflows, divide-by-zero, and underflow 4

Applications Coordinate I/O activities and prevent CPU from being tied up during the data transfer process. Perform time-critical operation one example is process control. Provide a graceful way to exit from the application when a software error occurred. Remind the CPU to perform routine tasks: Keep track of time of day Periodic data acquisition Task switching in a multi-tasking operating system Others 5

Attributes Maskability Maskable interrupts: not desirable under some situations and should be ignored by the CPU Effective only if the general interrupt enable (GIE) bit is set in the status register (SR); otherwise the interrupt is ignored Nonmaskable interrupts: can t be suppressed by clearing GIE Nonmaskable interrupts also require bits to be set/clear in special function or peripheral registers to enable/disable 6

Attributes Priority The MSP430 uses vectored interrupts, each of which has a distinct priority based on its address (higher address, higher priority) Each vector is associated with a unique interrupt in most cases, but some sources share a vector (e.g., TAIFG shares a vector with the capture/compare interrupts for all channels of Timer_A) The priorities are fixed in hardware and can t be changed by the user 7

8

What Happens on Interrupts Interrupt Acceptance 9

What Happens on Interrupts Return From Interrupt (c) After return from interrupt return address status register 10

Operating Modes MSP430 is designed for ultra-low-power applications w/ different operating modes The low-power modes LPM0 ~LPM4 are configured w/ the CPUOFF, OSCOFF, SCG0, and SCG1 bits in SR 11

Getting In/Out of LPM An enabled interrupt event wakes the MSP430 from any of the low-power modes Enter an interrupt service routine (ISR): The PC and SR are stored on the stack The CPUOFF, OSCOFF, and SCG1bits are automatically reset Return from the interrupt service routine (ISR): The SR is popped from the stack, restoring the previous operating mode The SR bits stored on the stack can be modified within the ISR returning to a different operating mode when RETI instruction is executed 12

Getting In/Out of LPM Code Example 13

Getting In/Out of LPM Code Example Enter LPM0 Mode Set CPUOFF bit in SR (see ASM code) There is no C instruction to change the value of status register as it does not know about any process registers To do the same, the compiler adds intrinsic called pseudo function to perform a specific function outside of the C language scope (e.g., bis_sr_register()) Check io430.h for such intrinsic functions Exit LPM0 Mode Clear CPUOFF bit in SR (see ASM code) 14

Interrupts on Port 1/Port 2 P1IE, P1IFG, P1IES If a bit in P1IES is set 0, the corresponding bit in P1IFG is set on rising edge on corresponding input pin (P1IN); otherwise, P1IFG is set on falling edge If the interrupt enable bit in P1IE is set, and global interrupts are enabled (i.e., GIE is SR), an interrupt is requested when the corresponding interrupt flag is set. P2IE, P2IFG, P2IES Port 2 interrupt is similar to Port 1 described above 15

Port 1 Interrupt Example Toggle Port 1.0 on each push of Port 1.1 void main(void) { WDTCTL = WDTPW WDTHOLD;// Stop watchdog timer P1SEL =0; P1DIR =BIT0; //set Port 1.0 output ---LED P1DIR &=~(BIT1); //set Port 1.1 input --- pushbutton P1REN =BIT1;//enable pull-up resistor on P1OUT =BIT1; Information for interrupt vectors can be found in msp430f5529.h } P1IE =BIT1;//enable the interrupt on Port 1.1 P1IES =BIT1;//set as falling edge P1IFG &=~(BIT1);//clear interrupt flag //enter LPM4 mode and enable global interrupt _BIS_SR(LPM4_bits + GIE); //Port 1 ISR #pragma vector=port1_vector _interrupt void PORT_1(void) { P1OUT ^=0x01; P1IFG &=~(BIT1); } 16

Port 1 Interrupt Example C ASM 17

Time A 18

Time A Operations 16-bit timer counter Register TAxR increments/decrements (depending on the mode of operation) with the rising edge of the clock signal TAxR can be read or written w/ software Clock sources can be chosen by setting TASSEL bits The chosen clock source can be further divided using TAIDEX bits 19

Time A Operations (cont.) Timer Mode Control Timer Start Timer counts when MC >{0} and the clock source is active When timer mode is either up or up/down, the timer is stopped by setting TAxCCR0=0; otherwise the timer starts when TAxCCR0= nonzero value 20

Time A Registers 21

TAxCTL Time A Control Register 22

TAxCCTLn Time A Capture/Compare Control 23

TAxCCTLn Time A Capture/Compare Control 24

TAxCCRn Register 25

TAxR Register Time A Counter Register 26

TAxIVRegister Time A Interrupt Vector 27

Time A Interrupts Two Interrupt Vectors TAxCCR0 interrupt vector for TAxCCR0 CCIFG TAxIV interrupt vector for all other CCIFG flags and TAIFG Interrupt Priorities TAxCCR0 interrupt has the highest Timer_A priority TAxCCR0 CCIFG flag is automatically reset when the TAxCCR0 interrupt request is served TAxCCRy CCIFG flags and TAIFG flags are prioritized (1-6 in the descending order) 28

Time A Interrupts Compare Mode CAP =0 CCIFG flag is set when TAxR counts to the associated TAxCCRn value This mode is used to generate periodic signals of whose frequency and duty cycle can be altered Capture Mode CAP =1 CCIFG flag is set when a timer value is captured in the associated TAxCCRn register 29

Time A Interrupts Vectors Each timer block has two sets of vectors Timerx_A0 for CCR0; Timerx_A1 for others (x=0, 1, 2) Timer0_A0_Vector Timer0_A1_Vector Timer1_A0_Vector Timer1_A1_Vector Timer2_A0_Vector Timer2_A1_Vector 30

Example Use Timer A CCR0 in the compare mode to trigger LED blink Step 1 set up Timer A0 control register. Let s choose a clock source Set up Timer A0 in Up mode TA0CTL=TASSEL_1+MC_UP Step 2 set up LEDs. A LED is connected with PORT1.0 P1DIR =BIT0 31

Step 3 set up Timer A0 interrupt Enable compare/capture interrupt Set up Timer A0 in the compare mode TA0CCTL0 = 0x10 Step 4 set up TA0CCR0, and have Timer A0 (TA0R) to count to its contents TA0CCR = 12000; Step 5 write the interrupt routine and put it in the predefined program memory #pragma vector=timer0_a0_vector _interrupt void Timer_A(void) { PIOUT^=0x01; } 32