Techniques to Disable Global Interrupts

Similar documents
FIGURE 1 - TABLE READ

AN551. Serial EEPROM Solutions vs. Parallel Solutions. Serial EEPROM Solutions vs. Parallel Solutions PARALLEL NON-VOLATILE MEMORIES SERIAL EEPROMS

ICSP Socket Module User s Guide

TB011. Using SRAM With A PIC16CXXX IMPLEMENTATION INTRODUCTION BLOCK DIAGRAM OF MULTIPLEXED ADDRESS/DATA BUS ON A PIC16C74

M Floating Point to ASCII Conversion

TB004. Automatic Calibration of the WDT Time-out Period CONCLUSION INTRODUCTION IMPLEMENTATION FIGURE 1: PROGRAM FLOWCHART

Electromechanical Switch Replacement Smart Switch for Automotive Applications and More

AN514. Software Interrupt Techniques CREATING CONSTANT TIME POLLING INTRODUCTION THEORY OF OPERATION

28C64A. 64K (8K x 8) CMOS EEPROM PACKAGE TYPE FEATURES DESCRIPTION BLOCK DIAGRAM

Electromechanical Switch Replacement Smart Switch for Car Windscreen Wiper Control

PIC16C5X Disassembler

59C11. 1K 5.0V Microwire Serial EEPROM PACKAGE TYPES FEATURES DESCRIPTION BLOCK DIAGRAM. This document was created with FrameMaker 404

16K (2K x 8) CMOS EEPROM I/O0 I/O1 I/O2. Vcc NC NC A7 A6 A5 A4 A3 A Microchip Technology Inc. DS11125G-page 1

How to Implement ICSP Using PIC17CXXX OTP MCUs PIC17CXXX IN-CIRCUIT SERIAL PROGRAMMING USING TABLE WRITE INSTRUCTIONS VPP 13V

PIC16F84A. PIC16F84A Errata Sheet

28C17A. 16K (2K x 8) CMOS EEPROM PACKAGE TYPES FEATURES DESCRIPTION BLOCK DIAGRAM. This document was created with FrameMaker 404

TC642DEMO FAN CONTROL MODULE FOR TC642/646 FEATURES GENERAL DESCRIPTION BOARD SCHEMATIC

TB026. Calculating Program Memory Checksums Using a PIC16F87X ACCESSING MEMORY INTRODUCTION. PIC16C7X vs. PIC16F87X. Microchip Technology Inc.

PIC17C7XX. PIC17C7XX Data Sheet Errata. Voltage. Frequency. Voltage. Frequency. Clarifications/Corrections to the Data Sheet:

Using the 8-Bit Parallel Slave Port

Electromechanical Timer Replacement

Section 35. Glossary

AN602. How to get 10 Million Cycles out of your Microchip Serial EEPROM 10 MILLION CYCLE GUARENTEE INTRODUCTION ENDURANCE. Thi d t t d ith F M k 4 0 4

TB033. Using the PIC16F877 To Develop Code For PIC16CXXX Devices INTRODUCTION. Stan D Souza, Rodger Richey Microchip Technology Inc.

TB004. Automatic Calibration of the WDT Time-out Period CONCLUSION INTRODUCTION IMPLEMENTATION FIGURE 1: PROGRAM FLOWCHART

AN536. Basic Serial EEPROM Operation. Basic Serial EEPROM Operation BASIC SERIAL EEPROM OPERATION CONTENTS SERIAL EEPROM APPLICATIONS

PIC16F872 Rev. A2 Silicon Errata Sheet. As with any windowed EPROM device, please cover the window at all times, except when erasing.

Optimizing Serial Bus Operations with Proper Write Cycle Times

PIC16F872 Rev. A0 Silicon Errata Sheet. As with any windowed EPROM device, please cover the window at all times, except when erasing.

Serial Port Utilities

PIC16C54C/55A/56A/57C/58B

PS4200EV. PS4200 Evaluation Kit 1.0 INTRODUCTION. 1.1 Evaluation Kit Contents

AN519. Implementing a Simple Serial Mouse Controller. Implementing a Simple Serial Mouse Controller INTRODUCTION THEORY OF OPERATION

PIC16F87X. PIC16F87X Rev. B3 Silicon Errata Sheet DC SPECIFICATION CHANGES FROM DATA SHEET

93C66A/B. 4K 5.0V Automotive Temperature Microwire Serial EEPROM FEATURES PACKAGE TYPE BLOCK DIAGRAM DESCRIPTION

How to Implement ICSP Using PIC16CXXX OTP MCUs VDD. MCLR/VPP ICSP Connector. To application circuit Isolation circuits

M 25AA640/25LC640/25C640

PIC16C745/765. PIC16C745/765 Rev. A2 Silicon/Data Sheet Errata

M Using Timer1 in Asynchronous Clock Mode

ICSP SOCKET MODULE USER S GUIDE

AN583. Implementation of the Data Encryption Standard Using PIC17C42 KEY SCHEDULE INTRODUCTION THE DATA ENCRYPTION STANDARD

AN767. Interfacing Microchip's Fan Speed Controllers to a SPI Port STANDARD IMPLEMENTATION INTRODUCTION

TB028. Technique to Calculate Day of Week DESCRIPTION OF SOFTWARE INTRODUCTION THEORY OF CALCULATION. Microchip Technology Inc.

TB042. Interfacing a KEELOQ Encoder to a PLL Circuit THE RF ENABLE OUTPUT OVERVIEW WHY USE A PLL HCS362 INTERFACE INTERFACING TO PLLS

AN530. Interfacing 93 Series Serial EEPROMs. Interfacing 93CX6 Serial EEPROMs to PIC16C5X Microcontrollers INTRODUCTION THE HARDWARE CONNECTION

FIGURE 1 - TIMER3 WITH PERIOD REGISTER AND SINGLE CAPTURE REGISTER

MPLAB ICE. Processor Module and Device Adapter Specification 2.0 TERMINOLOGY CONTENTS 1.0 INTRODUCTION SYSTEM. 2.1 Host to Pod Cable. 2.

AN713. Controller Area Network (CAN) Basics INTRODUCTION CAN PROTOCOL BASICS CAN OVERVIEW

AN609. Interfacing Microchip Serial EEPROMs to Motorola 68HC11 Microcontroller INTRODUCTION. Thi d t t d ith F M k Memory and ASSP Division

SEEVAL 32 Quick Start Guide

Simplifying External Memory Connections of PIC17CXXX PICmicro Microcontrollers. FIGURE 1: EXTERNAL MEMORY INTERFACE BLOCK DIAGRAM (x16 DEVICES)

EVALUATION KIT FOR TC642/TC646/TC647/TC648/TC649 BDC FAN CONTROLLERS

AN586. Macros for Page and Bank Switching INTRODUCTION

AN613. Using Microchip 93 Series Serial EEPROMs with Microcontroller SPI Ports INTRODUCTION THEORY OF OPERATION. Thi d t t d ith F M k 4 0 4

PICMASTER PICMASTER CE

AN519. Implementing a Simple Serial Mouse Controller INTRODUCTION THEORY OF OPERATION FUNCTIONAL BLOCKS OF A SERIAL MOUSE

TC74 Serial Temperature Sensor Demo Board User s Guide

EPROM Memory Programming Specification TABLE 1-1: PIN DESCRIPTIONS (DURING PROGRAMMING): PIC16C64X/66X

Improving the Susceptibility of an Application to ESD HIGH VOLTAGE POWER SUPPLY 5V POWER SUPPLY PIN VSS

S5U1C88000P Manual (S1C88 Family Peripheral Circuit Board)

In-Circuit Serial Programming (ICSP ) for PIC16C715 OTP MCUs

FLASH Memory Programming Specification

PIC18C601/801. PIC18C601/801 Rev. C0 Silicon/Data Sheet Errata. 3. Module: Interrupts. 1. Module: WDT. 2. Module: I/O

AN537. Serial EEPROM Endurance. Everything a System Engineer Needs to Know About Serial EEPROM Endurance

Data Sheet HDR ECUE FireFly Loopback Cable Assembly

PIC14C000. EPROM Memory Programming Specification PIN DIAGRAM 1.0 PROGRAMMING THE PIC14C000

S1V3G340 External SPI-Flash Select Guide

MPLAB. Processor Module and Device Adapter Specification. Host-to-Pod Processor Module. Logic Probe Connector Indicator Lights

Silicon Epitaxial Planar Zener Diode for Stabilized Power Supply. Type No. Mark Package Code HZS Series Type No. MHD B 7

TB056. Demonstrating the Set_Report Request With a PS/2 to USB Keyboard Translator Example INTRODUCTION THE SET_REPORT REQUEST DESCRIPTORS

S1V30080 Series I2C Interface Sample Program Specifications

Amplifier for versatile fiber-optic links

S1C17 Family Port Nested Interrupt Application Notes

TB079. Programming Baseline Flash Devices with PICkit 1 PIC12F508/509 AND PIC16F505 PROGRAMMING INTRODUCTION. PICkit 1 FIRMWARE VERSION 2.0.

TB082. Understanding Reset Events On The PIC10F20X INTRODUCTION WATCHDOG TIMER OR WDT POWER-ON RESET (POR)

Software Tools.

FSA. Library Link. Rev.1.0

S1C17 Family Application Library S1C17 Series Steps Calculation Library

Programmable Lights. Each Line In and Line Out terminal must have its own grounding terminal.

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

64.5" LCD Display Monitor

Upgrade the Solution With No Changes 2 Upgrade the Solution With No Changes If a Codebase does not contain updates to its properties, it is possible t

Regarding the change of names mentioned in the document, such as Hitachi Electric and Hitachi XX, to Renesas Technology Corp.

Using IIC to Read ADC Values on MC9S08QG8

PCB Layout Guidelines for the MC1321x

AN759. Interface Control Document for the MHz Anti-Collision Interrogator EXTERNAL INTERFACES SCOPE. Electrical Interfaces.

Unit: mm Max Max Max Min 5.06 Max Min ± ± 0.10

32-bit Microcontrollers. PIC32 Microcontroller Family with USB On-The-Go.

HD74HC174. Hex D-type Flip-Flops (with Clear) ADE (Z) 1st. Edition Sep Description. Features. Function Table

HD74HC00. Quad. 2-input NAND Gates. Features. Pin Arrangement

Connecting EPSON Display Controllers to Topway LCD Panels

S1C17 Family EEPROM Emulation Library Manual

1 AS5048 Demoboard. AS5048 Demoboard OPERATION MANUAL. Application Note

Regarding the change of names mentioned in the document, such as Hitachi Electric and Hitachi XX, to Renesas Technology Corp.

AN570. Calibrating the MTA11200 System. Calibrating the MTA11200 System INTRODUCTION THE CALIBRATION SOFTWARE. Notes and Precautions:

CS4220/ Bit Stereo Audio Codec with 3V Interface &5<67$/6(0,&21'8& '8&76',9,6,21 352'8&7,1)250$7,21 CS4220/1 DS284PP1 OCT 98

TCN75. 2-Wire Serial Temperature Sensor and Thermal Monitor. Package Type. Features. General Description. Applications SOIC TCN75MOA MSOP TCN75MUA

HD74HC of-8-line Data Selector/Multiplexer. Description. Features. Function Table

HD74HC09. Quad. 2-input AND Gates (with open drain outputs) Features. Pin Arrangement

Using the Project Board LCD Display at 3.3 volts

Transcription:

Techniques to Disable Global Interrupts AN576 This application brief discusses four methods for disabling global interrupts. The method best suited for the application may then be used. All discussion will be specific to the PIC16CXX family of products, but these concepts are also applicable to the PIC17C42, and are shown in the B examples. To disable interrupts, either the Global Interrupt Enable (GIE) bit must be cleared or all the individual interrupt enable bits must be cleared. An issue arises when an instruction clears the GIE bit and an interrupt occurs "simultaneously". For example, when a program executes the instruction BCF INTCON, GIE (at address PC), there is a possibility that an interrupt will occur during this instruction. If an interrupt occurs during this instruction, the program would complete execution of this instruction, and then immediately branch to the user s interrupt service routine. This occurs because the GIE bit was not clear (disabled) when the interrupt occurred. Normally at the end of the interrupt service routine is the RETFIE instruction. This instruction causes the program to return to the instruction at PC + 1, but also sets the GIE bit (enabled). Therefore the GIE bit is not cleared as expected, and unintended program execution may occur. One method to ensure that the GIE bit is cleared is shown in Example 1, as well as in the PIC16CXX data sheets. This method tests the state of the GIE bit, after clearing, to ensure that it was not accidentally set in the user s interrupt service routine by the RETFIE instruction. If the GIE bit was accidentally set, the program branches back to the instruction that clears the GIE bit. In this method, the time to ensure that the GIE bit is cleared is indeterminate. Depending on the frequency of the enabled interrupts during this code segment, unexpected delays into the following code segment may occur. For some applications, this may be undesirable. The following three methods address this issue. 5 EXAMPLE 1A FORCING THE GIE BIT CLEAR (METHOD 1, PIC16CXX) LOOP BCF INTCON, GIE ; Disable Global Interrupts BTFSC INTCON, GIE ; Global Interrupts Disabled? GOTO LOOP ; NO, try again ; YES, continue with program flow BSF INTCON, GIE ; Re-enable Global Interrupts EXAMPLE 1B FORCING THE GLINTD BIT CLEAR (METHOD 1, PIC17C42) LOOP BSF CPUSTA, GLINTD ; Disable Global Interrupts BTFSS CPUSTA, GLINTD ; Global Interrupts Disabled? GOTO LOOP ; NO, try again ; YES, continue with program flow BSF INTCON, GIE ; Re-enable Global Interrupts 1994 DS00576A-page 1 5-5

The second method is to disable the individual interrupt enable bits. If it is known which bits are enabled at this point, it can easily be done. Example 2 shows the disabling of interrupts, where it is known which sources are enabled (some peripheral interrupts and the T0CKI pin interrupt). This method also requires the same number of instructions for the disabling/enabling of interrupts as method 1, but requires a knowledge of which individual interrupt enable bits need to be disabled and (more importantly) re-enabled. The major advantage of this method is that it can minimizes the time delay entering the code segment which follows the point where interrupts are disabled. EXAMPLE 2A CLEARING KNOWN INDIVIDUAL INTERRUPT ENABLE BITS (METHOD 2, PIC16CXX) MOVLW b 10011111' ; Disable Peripheral and T0CKI pin interrupts, ANDWF INTCON, F ; All other bits unchanged MOVLW b 01100000' ; Re-enable Peripheral and T0CKI pin interrupts, IORWF INTCON, F ; All other bits unchanged EXAMPLE 2B CLEARING KNOWN INDIVIDUAL INTERRUPT ENABLE BITS (METHOD 2, PIC17C42) MOVLW b 11110011' ANDWF INTSTA, F MOVLW b 00001100' IORWF INTSTA, F ; Disable Peripheral and T0CKI pin interrupts, ; All other bits unchanged ; Re-enable Peripheral and RT pin interrupts, ; All other bits unchanged DS00576A-page 2 5-6 1994

Method 3 can be used if the states of the individual interrupt enable bits are unknown. A temporary byte of data RAM is required to store the value of the INTCON register. This method is shown in Example 3. This method also requires more instructions for the disabling/enabling of interrupts than in method 1 or method 2, and also a byte of data RAM to temporarily store the value of the INTCON register. The major advantage of this method is that it minimizes the time delay into the code segment which follows the point where interrupts are disabled. EXAMPLE 3A CLEARING THE INDIVIDUAL INTERRUPT ENABLE BITS (METHOD 3, PIC16CXX) MOVF INTCON, W ; Move the value in INTCON to MOVWF S_INTCON ; a shadow register MOVLW b 10000111' ; Disable all individual interrupts, ANDWF INTCON, F ; All other bits unchanged MOVF S_INTCON, W ; Restore the INTCON register IORWF INTCON, F ; EXAMPLE 3B CLEARING THE INDIVIDUAL INTERRUPT ENABLE BITS (METHOD 3, PIC17C42) MOVPF INTSTA, S_INTSTA ; Move the value in INTSTA to a shadow register MOVLW b 11110000' ; Disable all individual interrupts, ANDWF INTSTA, F ; All other bits unchanged MOVF S_INTSTA, W ; Restore the INTSTA register IORWF INTSTA, F ; 5 1994 DS00576A-page 3 5-7

The final method is to use a RAM location to shadow the value of the GIE bit. This shadow bit can then be used in the interrupt service routine to determine which return instruction to use. That is, either one of the RETURN or the RETFIE (which enables the GIE) instructions. Example 4 shows this implementation, which require that a general purpose bit be available to hold the shadow GIE value. In this example, the shadow GIE (S_GIE) bit is contained in the register FLAG_REG. If an interrupt occurs during the clearing of the shadow GIE, the interrupt is responded to. At the end of the interrupt service routine, the shadow GIE bit is cleared so the RETURN instruction is executed. The GIE bit remains disabled and program execution returns to the instruction which tries to clear the GIE (disable). No interrupts can occur during this instruction since the GIE bit was not re-enabled after the interrupt service routine. This method also requires more instructions for the disabling/enabling of interrupts than in method 1 or method 2, a single bit of data RAM to temporarily store the value of the desired GIE value, and increases the interrupt service routine execution time by one instruction cycle, for most occurrences of interrupts (two cycles worst case). The major advantage of this method is that it minimizes the time delay into the code segment which follows the point where interrupts are disabled. Also, the individual interrupt enable bits need not be modified. EXAMPLE 4A THE SHADOW GIE BIT (METHOD 4, PIC16CXX) org 0x004 INT_SERVICE_ROUTINE BTFSC FLAG_REG, S_GIE ; Is the S_GIE bit enabled? RETFIE ; YES, the GIE should be enabled RETURN ; NO, the GIE should be disabled END_INT_SERVICE_ROUTINE ; MAIN BCF FLAG_REG, S_GIE ; Disable the shadow GIE bit BCF INTCON, GIE ; Disable the GIE bit BSF FLAG_REG, S_GIE ; Enable the shadow GIE bit BSF INTCON, GIE ; Enable the GIE bit END EXAMPLE 4B THE SHADOW GLINTD BIT (METHOD 4, PIC17C42) org 0x004 INT_SERVICE_ROUTINE BTFSS FLAG_REG, S_GLINTD ; Is the S_GLINTD bit enabled? RETFIE ; YES, the GLINTD should be enabled RETURN ; NO, the GLINTD should be disabled END_INT_SERVICE_ROUTINE ; MAIN BSF FLAG_REG, S_GLINTD ; Disable the shadow GLINTD bit BSF CPUSTA, GLINTD ; Disable the GLINTD bit BCF FLAG_REG, S_GLINTD ; Enable the shadow GLINTD bit BCF CPUSTA, GLINTD ; Enable the GLINTD bit END DS00576A-page 4 5-8 1994

In conclusion, different methods exist to ensure that all interrupts are disabled. The requirement(s) of the applications determine which of the methods is the best fit. A comparison of the different methods is shown in Table 1. TABLE 1 COMPARISON OF DIFFERENT METHODS Cycle Delay (Tcy) Program Memory Data Memory Best Case Worst Case Method 1 2 words * N --- 2 Indeterminate Method 2 2 words * N --- 1 1 + Tisr Method 3 - PIC16CXX 4 words * N 1 byte 3 3 + Tisr - PIC17C42 3 words * N 1 byte 2 2 + Tisr Method 4 2 words * N + 2 words 1 bit 1 1 + (Tisr + 2) Legend N - Number of occurances to disable / re-enable interrupts. Tisr - Time to execute the interrupt service routine. This method increases the interrupt service routine time (Tisr) by 1 cycle for most occurances (2 cycles worst case). 5 Author Mark Palmer - Logic Products Division Contributions by Martin Burghardt - Manager Applications (Central Europe) 1994 DS00576A-page 5 5-9

NOTES DS00576A-page 6 5-10 1994

WORLDWIDE SALES & SERVICE AMERICAS Corporate Office 2355 West Chandler Blvd. Chandler, AZ 85224-6199 Tel 602 786-7200 Fax 602 786-7277 Technical Support 602 786-7627 Web http//www.mchip.com/microhip Atlanta 500 Sugar Mill Road, Suite 200B Atlanta, GA 30350 Tel 770 640-0034 Fax 770 640-0307 Boston 5 Mount Royal Avenue Marlborough, MA 01752 Tel 508 480-9990 Fax 508 480-8575 Chicago 333 Pierce Road, Suite 180 Itasca, IL 60143 Tel 708 285-0071 Fax 708 285-0075 Dallas 14651 Dallas Parkway, Suite 816 Dallas, TX 75240-8809 Tel 214 991-7177 Fax 214 991-8588 Dayton 35 Rockridge Road Englewood, OH 45322 Tel 513 832-2543 Fax 513 832-2841 Los Angeles 18201 Von Karman, Suite 455 Irvine, CA 92715 Tel 714 263-1888 Fax 714 263-1338 New York 150 Motor Parkway, Suite 416 Hauppauge, NY 11788 Tel 516 273-5305 Fax 516 273-5335 AMERICAS (continued) San Jose 2107 North First Street, Suite 590 San Jose, CA 95131 Tel 408 436-7950 Fax 408 436-7955 ASIA/PACIFIC Hong Kong Unit No. 3002-3004, Tower 1 Metroplaza 223 Hing Fong Road Kwai Fong, N.T. Hong Kong Tel 852 2 401 1200 Fax 852 2 401 3431 Korea 168-1, Youngbo Bldg. 3 Floor Samsung-Dong, Kangnam-Ku, Seoul, Korea Tel 82 2 554 7200 Fax 82 2 558 5934 Singapore 200 Middle Road #10-03 Prime Centre Singapore 188980 Tel 65 334 8870 Fax 65 334 8850 Taiwan 10F-1C 207 Tung Hua North Road Taipei, Taiwan, ROC Tel 886 2 717 7175 Fax 886 2 545 0139 EUROPE United Kingdom Arizona Ltd. Unit 6, The Courtyard Meadow Bank, Furlong Road Bourne End, Buckinghamshire SL8 5AJ Tel 44 0 1628 851077 Fax 44 0 1628 850259 France Arizona SARL 2 Rue du Buisson aux Fraises 91300 Massy - France Tel 33 1 69 53 63 20 Fax 33 1 69 30 90 79 Germany Arizona GmbH Gustav-Heinemann-Ring 125 D-81739 Muenchen, Germany Tel 49 89 627 144 0 Fax 49 89 627 144 44 Italy Arizona SRL Centro Direzionale Colleoni Palazzo Pegaso Ingresso No. 2 Via Paracelso 23, 20041 Agrate Brianza (MI) Italy Tel 39 039 689 9939 Fax 39 039 689 9883 JAPAN Intl. Inc. Benex S-1 6F 3-18-20, Shin Yokohama Kohoku-Ku, Yokohama Kanagawa 222 Japan Tel 81 45 471 6166 Fax 81 45 471 6122 9/22/95 All rights reserved. 1995, Incorporated, USA. Information contained in this publication regarding device applications and the like is intended through suggestion only and may be superseded by updates. No representation or warranty is given and no liability is assumed by Incorporated with respect to the accuracy or use of such information, or infringement of patents or other intellectual property rights arising from such use or otherwise. Use of Microchip s products as critical components in life support systems is not authorized except with express written approval by Microchip. No licenses are conveyed, implicitly or otherwise, under any intellectual property rights. The Microchip logo and name are registered trademarks of All rights reserved. All other trademarks mentioned herein are the property of their respective companies.