dspic Interrupts The Interrupt Control and Staus Registers are :- ENG721-S2 Mixed Signal Processing : Hassan Parchizadeh Page 1

Similar documents
Microprocessors B (17.384) Spring Lecture Outline

Interrupts. Embedded Systems Interfacing. 08 September 2011

Section 6. Interrupts

Section 32. Interrupts (Part III)

Section 28. Interrupts (Part 2)

UNCA CSCI 255 Exam 3 Fall 2011

Capture Mode of Pic18F252

Microcomputers. Polled IO versus Interrupt Driven IO

Basic Embedded Software C Review Using MPLAB SIM. Loops. Embedded Systems Interfacing. 25 August 2011

11010 SBC 16-bit Architecture, C30 & Standard Peripherals Hand Out

EE4390 Microprocessors

Section 30. I/O Ports with Peripheral Pin Select

EE Embedded Systems Design. Lessons Exceptions - Resets and Interrupts

Interrupts on PIC18F252 Part 2. Interrupts Programming in C Language

dspic30f6010 Family Silicon Errata and Data Sheet Clarification (1) Revision ID for Silicon Revision (2)

Using Timers of Microchip PIC18F Microcontrollers

CENG-336 Introduction to Embedded Systems Development. Timers

REPORT MICROCHIP CONTROLLER UNITS AND DIGITAL TECHNICS PRACTICING. Student : Đỗ Thành Trung Student Number : Class : 14146CL2 CONTENT :

EE6008-Microcontroller Based System Design Department Of EEE/ DCE

Timer0..Timer3. Interrupt Description Input Conditions Enable Flag

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

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

INTERRUPTS in microprocessor systems

ME 6405 Introduction to Mechatronics

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

PIC32&Overview& E155&

Embedded systems. Exercise session 3. Microcontroller Programming Lab Preparation

Interrupt/Timer/DMA 1

What happens when an HC12 gets in unmasked interrupt:

Interrupts on PIC18F252 Part 2

Department of Electronics and Instrumentation Engineering Question Bank

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

Section 10. Watchdog Timer and Power Saving Modes

ARM Embedded Systems: ARM Design philosophy, Embedded System Hardware, Embedded System Software

AVR XMEGA Product Line Introduction AVR XMEGA TM. Product Introduction.

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

dspic30f6011/ 6012/6013/6014

Section 38. Direct Memory Access (DMA) (Part III)

Fredrick M. Cady. Assembly and С Programming forthefreescalehcs12 Microcontroller. шт.

Section 11. Timer0. Timer0 HIGHLIGHTS. This section of the manual contains the following major topics:

The University of Texas at Arlington Lecture 21_Review

/*Algorithm: This code display a centrifuge with five variable speed RPM by increaseing */

UNIT - II PERIPHERAL INTERFACING WITH 8085

Chapter 9 Interrupt Controller

Signals, Instruments, and Systems W8. More on Embedded Systems. Embedded Software

Understanding the basic building blocks of a microcontroller device in general. Knows the terminologies like embedded and external memory devices,

Types of Interrupts:

Design and Implementation Interrupt Mechanism

Analog Output with a Digital to Analog Converter

SECTION 5 RESETS AND INTERRUPTS

Section 20. Serial Peripheral Interface (SPI)

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

AVR XMEGA TM. A New Reference for 8/16-bit Microcontrollers. Ingar Fredriksen AVR Product Marketing Director

Chapter 2. Overview of Architecture and Microcontroller-Resources

PIC Microcontroller Introduction

Product Update. Errata to Z8 Encore! 8K Series Silicon. Z8 Encore! 8K Series Silicon with Date Codes 0402 and Later

Introduction to ARM LPC2148 Microcontroller

Section 30. I/O Ports with Peripheral Pin Select (PPS)

AVR42772: Data Logger Demo Application on XMEGA A1U Xplained Pro. Introduction. Features. AVR XMEGA Microcontrollers APPLICATION NOTE

Chapter 6 PROGRAMMING THE TIMERS

UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING CMPE13/L: INTRODUCTION TO PROGRAMMING IN C SPRING 2013

acret Ameya Centre for Robotics & Embedded Technology Syllabus for Diploma in Embedded Systems (Total Eight Modules-4 Months -320 Hrs.

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

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

MICROPROCESSOR BASED SYSTEM DESIGN

CN310 Microprocessor Systems Design

Speed Control of a DC Motor using Digital Control

The MC9S12 Timer Input Capture Function

The MC9S12 Timer Output Compare Function Making an event happen at specific time on the HC12 The MC9S12 Output Compare Function

Capturing the Time of an External Event Input Capture Subsystem

AVR Timers TIMER0. Based on:

The K Project. Interrupt and Exception Handling. LSE Team. May 14, 2018 EPITA. The K Project. LSE Team. Introduction. Interrupt Descriptor Table

SYLLABUS UNIT - I 8086/8088 ARCHITECTURE AND INSTRUCTION SET

Grundlagen Microcontroller Interrupts. Günther Gridling Bettina Weiss

MPLAB SIM. MPLAB IDE Software Simulation Engine Microchip Technology Incorporated MPLAB SIM Software Simulation Engine

PPG Function of F2MC-16LX MCU Series as PWM

Microprocessors & Interfacing

8-bit Microcontroller. Application Note. AVR134: Real-Time Clock (RTC) using the Asynchronous Timer. Features. Theory of Operation.

#include "p30f3011.h" #include "svm3011 v1.2.h"

INTERRUPT, TIMER/COUNTER. KONKUK UNIV. VLSI Design Lab. LSI Design Lab

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

Section 9. Watchdog Timer (WDT) and Power-Saving Modes

Interrupts, timers and counters

8. Power Management and Sleep Modes

CPEG300 Embedded System Design. Lecture 6 Interrupt System

Microcontroller Overview

CPUs. Input and output. Supervisor mode, exceptions, traps. Co-processors. Computers as Components 4e 2016 Marilyn Wolf

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

Timer2 Interrupts. NDSU Timer2 Interrupts September 20, Background:

which means that writing to a port implies that the port pins are first read, then this value is modified and then written to the port data latch.

Design with Microprocessors

EE 308 Spring A software delay

Introduction. Prerequisites: Procedure Steps. Step1: Downloading and Adding the MCC Plugin

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

VORAGO VA108x0 I 2 C programming application note

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

dspic LANGUAGE TOOLS GETTING STARTED

Microprocessors and Microcontrollers (EE-231)

CPEG300 Embedded System Design. Lecture 8 Timer

HC12 Built-In Hardware

Transcription:

dspic Interrupts The dspic30f4012 has 30 interrupt sources which 3 are external interrupts and 4 processor exception traps. There are 8 user selectable priority levels for each interrupt source. These interrupts are executed according to the priority level set for them. During an Interrupt, the CPU fetches the interrupt address from the Interrupt Vector Table(IVT) and place it into the Program Counter. The Interrupt Vector table is placed at the program memory 0x000004 near the beginning. Here is the dspic30f4012 Interrupt Vector Table. Interrupt Vector Interrupt Source Number Number Highest Natural Order Priority 0 8 INT0 External Interrupt 0 1 9 IC1 Input Capture 1 2 10 OC1 Output Compare 1 3 11 T1 Timer 1 4 12 IC2 Input Capture 2 5 13 OC2 Output Compare 2 6 14 T2 Timer 2 7 15 T3 Timer 3 8 16 SPI1 9 17 U1RX UART1 Receiver 10 18 U1TX UART1 Transmitter 11 19 ADC ADC Convert Done 12 20 NVM NVM Write Complete 13 21 SI2C I2C Slave Interrupt 14 22 MI2C I2C Master Interrupt 15 23 Input Change Interrupt 16 24 INT1 External Interrupt 1 17 25 IC7 Input Capture 7 18 26 IC8 Input Capture 8 19 27 OC3 Output Compare 3 20 28 OC4 Output Compare 4 21 29 T4 Timer4 22 30 T5 Timer5 23 31 INT2 External Interrupt 2 24 32 U2RX UART2 Receiver 25 33 U2TX UART2 Transmitter 27 35 C1 Combined IRQ for CAN1 39 47 PWM PWM Period Match 40 48 QEI QEI Interrupt 43 51 FLTA PWM Fault A The peripheral interrupts (i.e. ADC, timers, PWMs. UART and etc) and exceptions (i.e. traps) are activated by configuring appropriate special function registers. The Interrupt Control and Staus Registers are :- ENG721-S2 Mixed Signal Processing : Hassan Parchizadeh Page 1

INTCON1,INTCON2 global INTerrupt CONtrol Registers. INTCON1 conatains the interrupt NeSting DISable bit, as well as status flags for the processor trap sources. The INCON2 register controls the external interrupt request signal and the use of the alternative vector table. IFS0,IFS1,IFS2 Interrupt Flag Status Registers conatain all the interrupt request flags. Each source of interrupt has a status bit, which is set by it s respective peripherals or external signal and is cleared via software. IEC0,IEC1,IEC2 Interrupt Enable Control Registers contain all the interrupt enable bits. These bits are used to individually enable interrupts from the peripherals or external signals. IPC0 IPC11 Interrupt Priority Control Registers are used to set each user interrupt source to one of the eight priority levels. ENG721-S2 Mixed Signal Processing : Hassan Parchizadeh Page 2

SR The Status Register is NOT specifically part of the interrupt controller hardware, but if contains the IPL<2:0> status bits that indicates the current CPU priority level. The user may change the current CPU priority by to these IPL bits. CORCON CORe CONtrol register is NOT specifically part of the interrupt controller hardware, but if contains the IPL3 status bit which indicates the current CPU priority level. IPLs is a Read ONLY bit so that trap events can not be masked by the user software. Interrupt initialization 1. Set the NSTDIS (NeSTed DISabled) in INTCON1<15> if nested interrupts are not required. 2. Select the user assigned priority level for the interrupt source (if more than one interrupt is used and the priority of the interrupt events are essential) by writing the control bits in the appropriate IPCx Control register. 3. Clear the interrupt flag status bit associated with the peripheral in the associated IFSx Stauts register. 4. Enable the interrupt source by setting the interrupt enable control bit associated with the source in the appropriate IECx Control register. Interrupt enable bits in IEC0,IEC1,IEC2 registers are set to enable appropriate interrupt. The dspic30f keeps all interrupt vectors in Interrupt Vector Table (IVT) ENG721-S2 Mixed Signal Processing : Hassan Parchizadeh Page 3

MPLAB XC16 compiler automatically associates interrupt vectors with special user defined C functions as long as : They do not return any value (use type void). No parameter can be passed to the function (use parameter void). They cannot be called directly by other functions. The following example illustrates the syntax that could be used to associate a function to the Timer1 interrupt vector: void attribute (( interrupt)) _T1Interrupt ( void) { // interrupt service routine code here... } // InterruptVector In practice, to avoid the verbose syntax attribute (( interrupt)), it is more convenient to use the predefined macro _ISR as in the following example: void _ISR _T1Interrupt (void) { // interrupt service routine code here... } // InterruptVector ENG721-S2 Mixed Signal Processing : Hassan Parchizadeh Page 4

/* File: newmainxc16.c * Author: parchizh * * Created on 02 March 2015, 13:28 */ #include "p30f4012.h" //---------------------------------------------------------------------------- // Macros for Configuration Fuse Registers _FOSC(CSW_FSCM_OFF & XT_PLL16); /* Set up for Crystal */ _FWDT(WDT_OFF); /* Turn off the Watch-Dog Timer. */ /* Enable MCLR reset pin and turn off the power-up timers. */ _FBORPOR(PBOR_OFF & MCLR_EN); _FGS(CODE_PROT_OFF); /* Disable Code Protection */ /* Global Variables and Functions */ // #define _ISR attribute ((interrupt)) void main(void) { // setting up the Timer 1 TRISEbits.TRISE0 = 0; // Configure Port RE0 to be output PR1 = 15151; // set PR1 for 0.5 ms T1CONbits.TSIDL = 0; // off in idle mode T1CONbits.TCS = 0; // use internal clock Tcy T1CONbits.TCKPS = 0; // prescalar 1:1 T1CONbits.TGATE = 0; // no gated operation T1CONbits.TON = 1; // turn the timer ON // Setting up the Interrupt for the Timer 1 IFS0bits.T1IF = 0; // T1 interrupt flag cleared IEC0bits.T1IE = 1; // T1 interrupt enabled } while(1){ } void _ISR _T1Interrupt (void) {// interrupt service routine code here... PORTEbits.RE0 ^=1; // toggle the port pin IFS0bits.T1IF = 0; // clear timer1 flag } // _InterruptVector //************************************************************* //void attribute (( interrupt)) _T1Interrupt ( void) //{ // interrupt service routine code here... // PORTEbits.RE0 ^=1; // toggle the port pin // IFS0bits.T1IF = 0; // clear timer1 flag //} // _InterruptVector //*************************************************************/ /* * File: T12345_Interrupt_Pulse_mainXC16.c * Author: parchizh * * Created on 03 March 2015, 14:39 */ ENG721-S2 Mixed Signal Processing : Hassan Parchizadeh Page 5

#include "p30f4012.h" _FOSC(CSW_FSCM_OFF & XT_PLL16); /* Set up for Crystal */ _FWDT(WDT_OFF); /* Turn off the Watch-Dog Timer. */ /* Enable MCLR reset pin and turn off the power-up timers. */ _FBORPOR(PBOR_OFF & MCLR_EN); _FGS(CODE_PROT_OFF); /* Disable Code Protection */ /* Global Variables and Functions */ // #define _ISR attribute ((interrupt)) [ macro example ] void main(void) { TRISB = 0x0000; ADPCFG = 0xFFFF; //Port B is outputs //1st channel is sampled and coverted // Configure Timer1 to sample at 2KHz // Period1 = PR1 * prescaler * Tcy = 15151 * 1 * 33ns = 0.50000 ms (2KHz) PR1 = 15151; T1CON = 0b1000000000000000; // Type A timer = timer 1 // 1X-XXXXXX---X--X TON 1 = timer1 ON // -X0XXXXXX---X--X TSIDL 0 = operate during idle // -X-XXXXXX0--X--X TGATE 0 = Gated Time accumulation disabled // -X-XXXXXX-00X--X TCKPS 00= Timer input prescale 1:1 // -X-XXXXXX---X0-X TSYNC 0 = Do not Sync External clock(when TCS = 1) // -X-XXXXXX---X-0X TCS 0 = Clock source 0=internal(fosc/4) // Configure Timer2 to sample at 4KHz // Period1 = PR2 * prescaler * Tcy = 7575 * 1 * 33ns = 0.25000 ms (4KHz) PR2 = 7575; T2CON = 0b1000000000000000; // Type B timer = timer 2 // 1X-XXXXXX----X-X TON 1 = timer2 ON // -X0XXXXXX----X-X TSIDL 0 = operate during idle // -X-XXXXXX0---X-X TGATE 0 = Gated Time accumulation disabled // -X-XXXXXX-00-X-X TCKPS 00= Timer input prescale 1:1 // -X-XXXXXX---0X-X T32 0 = Timers 2/3 form separate 16-bit timers // -X-XXXXXX----X-X TCS 0 = Clock source 0=internal(fosc/4) // Configure Timer1 to sample at 8KHz // Period3 = PR3 * prescaler * Tcy = 3788 * 1 * 33ns = 0.12500 ms (8KHz) PR3 = 3788; T3CON = 0b1000000000000000; // Type C timer = timer 3 // 1X-XXXXXX---XX-X TON 1 = timer3 ON // -X0XXXXXX---XX-X TSIDL 0 = operate during idle // -X-XXXXXX0--XX-X TGATE 0 = Gated Time accumulation disabled // -X-XXXXXX-00XX-X TCKPS 00= Timer input prescale 1:1 // -X-XXXXXX---XX0X TCS 0 = Clock source 0=internal(fosc/4) // Configure Timer2 to sample at 16KHz // Period4 = PR4 * prescaler * Tcy = 1894 * 1 * 33ns = 0.06250 ms (16KHz) PR4 = 1894; T4CON = 0b1000000000000000; // Type B timer = timer 4 // 1X-XXXXXX----X-X TON 1 = timer4 ON // -X0XXXXXX----X-X TSIDL 0 = operate during idle // -X-XXXXXX0---X-X TGATE 0 = Gated Time accumulation disabled // -X-XXXXXX-00-X-X TCKPS 00= Timer input prescale 1:1 // -X-XXXXXX---0X-X T32 0 = Timers 4/5 form separate 16-bit timers // -X-XXXXXX----X-X TCS 0 = Clock source 0=internal(fosc/4) // Configure Timer1 to sample at 32KHz // Period5 = PR5 * prescaler * Tcy = 947 * 1 * 33ns = 0.03125 ms (32KHz) PR5 = 947; ENG721-S2 Mixed Signal Processing : Hassan Parchizadeh Page 6

T5CON = 0b1000000000000000; // Type C timer = timer 5 // 1X-XXXXXX---XX-X TON 1 = timer3 ON // -X0XXXXXX---XX-X TSIDL 0 = operate during idle // -X-XXXXXX0--XX-X TGATE 0 = Gated Time accumulation disabled // -X-XXXXXX-00XX-X TCKPS 00= Timer input prescale 1:1 // -X-XXXXXX---XX0X TCS 0 = Clock source 0=internal(fosc/4) // Configure Interrupt Priority IPC0 = 0b0001000000000000; //X001X---X---X--- timer 1 IP level 1 IPC1 = 0b0001000100000000; // timer 3 IP level 1, timer 2 IP level 1 IPC5 = 0b0000000100010000; // timer 5 IP level 1, timer 4 IP level 1 // Clear Interrupt Flags IFS0 = 0b0000000000000000; // T3IF = 0, T2IF = 0 IFS1 = 0b0000000000000000; // T5IF = 0, T4IF = 0 // Enable Interrupts IEC0 = 0b0000000011001000; // T3IE = 1, T2IE = 1, T1IE = 1 IEC1 = 0b0000000001100000; // T5IE = 1, T4IE = 1 } while(1) {} // Timer 1 interrupt service routine toggles RB0 void _ISR _T1Interrupt(void) { _LATB0 = ~_LATB0; _T1IF = 0; } // Timer 2 interrupt service routine toggles RB1 void _ISR _T2Interrupt(void){ _LATB1 = ~_LATB1; _T2IF = 0; } // Timer 3 interrupt service routine toggles RB2 void _ISR _T3Interrupt(void){ _LATB2 = ~_LATB2; _T3IF = 0; } // Timer 4 interrupt service routine toggles RB3 void _ISR _T4Interrupt(void){ _LATB3 = ~_LATB3; _T4IF = 0; } // Timer 5 interrupt service routine toggles RB4 void _ISR _T5Interrupt(void){ _LATB4 = ~_LATB4; _T5IF = 0; } // Timer 1 interrupt service routine toggles RB0 //void attribute ((interrupt)) _T1Interrupt(void){ // _LATB0 = ~_LATB0; // _T1IF = 0; //} ENG721-S2 Mixed Signal Processing : Hassan Parchizadeh Page 7

ENG721-S2 Mixed Signal Processing : Hassan Parchizadeh Page 8

ENG721-S2 Mixed Signal Processing : Hassan Parchizadeh Page 9

ENG721-S2 Mixed Signal Processing : Hassan Parchizadeh Page 10

ENG721-S2 Mixed Signal Processing : Hassan Parchizadeh Page 11

ENG721-S2 Mixed Signal Processing : Hassan Parchizadeh Page 12

ENG721-S2 Mixed Signal Processing : Hassan Parchizadeh Page 13

ENG721-S2 Mixed Signal Processing : Hassan Parchizadeh Page 14

errupt is generated. ENG721-S2 Mixed Signal Processing : Hassan Parchizadeh Page 15