Interrup C I Ones
Interrup C I Ones
Interrup C I Ones
Interrupts (Part 2)
HIGHLIGHTS
This section of the manual contains the following topics:
28
Interrupts
28.1 Introduction
The dsPIC® DSC SMPS (Switched Mode Power Supply) Interrupt controller reduces numerous
peripheral interrupt requests to a single interrupt request signal to the CPU, and has the following
features:
• Up to eight processor exceptions and software traps
• Eight user-selectable priority levels
• Interrupt Vector Table (IVT) with up to 62 vectors
• A unique vector for each interrupt or exception source
• Fixed priority within a specified user priority level
• Alternate Interrupt Vector Table (AIVT) for debugging support
• Fixed interrupt entry and return latencies
Note: Any unimplemented or unused vector locations in the IVT and AIVT should be
programmed with the address of a default interrupt handler routine that contains a
RESET instruction.
Decreasing Natural
Stack Error Trap Vector
Order Priority
Arithmetic Error Trap Vector
IVT Reserved
Reserved
Reserved
Interrupt Vector 0 0x000014
Interrupt Vector 1
—
—
—
Interrupt Vector 52
Interrupt Vector 53 0x00007E
Reserved 0x000080
Reserved 0x000082
Reserved 0x000084
Oscillator Fail Trap Vector
See Table 28-2 for Interrupt
Stack Error Trap Vector Vector details.
Address Error Trap Vector
Arithmetic Error Trap Vector
Reserved
AIVT
Reserved
Reserved 28
Interrupt Vector 0 0x000094
Interrupt Vector 1
—
Interrupts
—
—
Interrupt Vector 52
Interrupt Vector 53 0x0000FE
Note: The IPL<2:0> bits become read-only bits when interrupt nesting is disabled. See 28
Section 28.2.4.2 “Interrupt Nesting” for more information.
Interrupts
Each peripheral interrupt source can be assigned to one of seven priority levels. The user
assignable interrupt priority control bits for each individual interrupt are located in the Least
Significant 3 bits of each nibble within the Interrupt Priority Control (IPCx) register(s). Bit 3 of each
nibble is not used and is read as ‘0’. These bits define the priority level assigned to a particular
interrupt. The usable priority levels start at level 1 (the lowest priority) and end at level 7 (the high-
est priority). If the IPC bits associated with an interrupt source are all cleared, the interrupt source
is effectively disabled.
Note: If the application program re-configures the interrupt priority levels on the fly, it must
disable the interrupts while doing so. Failure to disable interrupts can produce
unexpected results.
Since more than one interrupt request source can be assigned to a specific priority level, a
means is provided to resolve priority conflicts within a given user-assigned level. Each source of
interrupt has a natural order priority based on its location in the IVT. Table 28-2 shows the
location of each interrupt source in the IVT. The lower numbered interrupt vectors have higher
natural priority, while the higher numbered vectors have lower natural priority. The overall priority
level for any pending source of interrupt is determined first by the user-assigned priority of that
source in the Interrupt Priority Control (IPCx) register, and then by the natural order priority within
the IVT.
Natural order priority is used only to resolve conflicts between simultaneous pending interrupts
with the same user-assigned priority level. Once the priority conflict is resolved and the exception
process begins, the CPU can only be interrupted by a source with higher user-assigned priority.
Interrupts with the same user-assigned priority but a higher natural order priority, which become
pending after the exception process begins, remain pending until the current exception process
completes.
Assigning each interrupt source to one of seven priority levels enables the user application to
give an interrupt with a low natural order priority a very high overall priority level. For example,
Timer2 can be given a priority of 7 and the External Interrupt 0 (INT0) can be assigned to priority
level 1, thus giving it a very low effective priority.
Note: The peripherals and sources of interrupt available in the IVT will vary depending on
the specific dsPIC DSC SMPS device. The sources of interrupt shown in this
document represent a comprehensive listing of all interrupt sources found on dsPIC
DSC SMPS devices. Refer to the specific device data sheet for further details.
28.2 Non-Maskable Traps
Traps are non-maskable, nestable interrupts that adhere to a fixed priority structure. Traps
provide a means to correct erroneous operation during debugging and operation of the
application. If the user application does not intend to correct a trap error condition, these vectors
must be loaded with the address of a software routine that will reset the device. Otherwise, the
user application programs the trap vector with the address of a service routine that corrects the
trap condition.
The dsPIC DSC SMPS devices have four implemented sources of non-maskable traps:
• Oscillator Failure Trap
• Stack Error Trap
• Address Error Trap
• Arithmetic Error Trap
For many of the trap conditions, the instruction that caused the trap is allowed to complete before
exception processing begins. Therefore, the user application may have to correct the action of
the instruction that caused the trap.
Each trap source has a fixed priority as defined by its position in the IVT. An oscillator failure trap
has the highest priority. In addition, trap sources are classified into two distinct categories: hard
traps and soft traps.
The stack is initialized to 0x0800 during a Reset. A stack error trap is generated if the stack
pointer address is less than 0x0800.
A Stack Limit (SPLIM) register that is associated with the stack pointer is uninitialized at Reset.
The stack overflow check is not enabled until a word is written to the SPLIM register.
All Effective Addresses (EA) generated using W15 as a source or destination pointer are
compared against the value in the SPLIM register. If the EA is greater than the contents of the
SPLIM register, a stack error trap is generated. In addition, a stack error trap is generated if the
EA calculation wraps over the end of data space (0xFFFF).
A stack error can be detected in software by polling the Stack Error Trap (STKERR) status bit in
the Interrupt Control Register 1 (INTCON1<2>). To avoid re-entering the trap service routine, the
STKERR status flag must be cleared in software before exiting the stack error trap.
Interrupts
iteration of the REPEAT loop that executes the divide instruction. The Math Error Status
(DIV0ERR) bit (INTCON1<6>) is set when this trap is detected.
Accumulator shift traps cannot be disabled. The SFTAC instruction can be used to shift the
accumulator by a literal value or a value in one of the W registers. If the shift value exceeds
±16 bits, an arithmetic trap is generated and the Shift Accumulator Error Status (SFTAERR) bit
(INTCON1<7>) is set. The SFTAC instruction executes, but the results of the shift are not written
to the target accumulator.
A math error trap can be detected in software by polling the Math Error Status (MATHERR) bit
(INTCON1<4>). To avoid re-entering the trap service routine, the MATHERR status flag must be
cleared in software before exiting the math error trap. Before the MATHERR status bit can be
cleared, all conditions that caused the trap to occur must also be cleared. If the trap was due to
an accumulator overflow, the OA and OB status bits (SR<15:14>) must be cleared. The OA and
OB status bits are read-only, so the user software must perform a dummy operation on the
overflowed accumulator (such as adding ‘0’), which will cause the hardware to clear the OA or
OB status bit.
If a higher-priority trap occurs while any lower-priority trap is in progress, processing of the trap
with lower priority is suspended. The trap with higher priority is acknowledged and processed.
The trap with lower priority remains pending until the higher priority trap is processed.
Each hard trap that occurs must be acknowledged before code execution of any type can
continue. If a lower-priority hard trap occurs while a higher-priority trap is pending, acknowledged
or is being processed, a hard-trap conflict occurs because the lower-priority trap cannot be
acknowledged until processing for the higher priority trap completes.
The device is automatically reset in a hard-trap conflict condition. The Trap Reset Flag (TRAPR)
status bit in the Reset Control (RCON<15>) register in the Reset module is set when the Reset
occurs, so that the condition can be detected in software.
An oscillator failure trap event is generated for any of the following reasons:
• The Fail-Safe Clock Monitor (FSCM) is enabled and has detected a loss of the system
clock source.
• A loss of PLL lock has been detected during normal operation using the PLL.
• The FSCM is enabled and the PLL fails to achieve lock at a Power-On Reset (POR).
An oscillator failure trap event can be detected in software by polling the Oscillator Failure Trap
(OSCFAIL) status bit (INTCON1<1>) or the Clock Fail (CF) status bit (OSCCON<3>) in the
Oscillator module. To avoid re-entering the Trap Service Routine, the OSCFAIL status flag must
be cleared in software before exiting the oscillator failure trap.
Operating conditions that can generate an address error trap include the following:
• A misaligned data word fetch is attempted. This condition occurs when an instruction
performs a word access with the LSb of the effective address set to ‘1’. The dsPIC DSC
SMPS device requires all word accesses to be aligned to an even address boundary.
• A bit manipulation instruction uses the Indirect Addressing mode with the LSb of the
effective address set to ‘1’.
• A data fetch is attempted from unimplemented data address space.
• Execution of a BRA #literal instruction or a GOTO #literal instruction, where
literal is an unimplemented program memory address.
• Execution of instructions after the Program Counter has been modified to point to
unimplemented program memory addresses. The Program Counter can be modified by
loading a value into the stack and executing a RETURN instruction.
When an address error trap occurs, data space writes are inhibited so that data is not destroyed.
An address error can be detected in software by polling the Address Error Trap Status
(ADDRERR) bit (INTCON1<3>). To avoid re-entering the Trap Service Routine, the ADDRERR
status flag must be cleared in software before exiting the address error trap.
Note: In the MAC class of instructions, the data space is split into X and Y spaces. In these
instructions, unimplemented X space includes all of Y space, and unimplemented Y
space includes all of X space.
Interrupts
All interrupt event flags are sampled during each instruction cycle. A pending Interrupt Request
(IRQ) is indicated by the flag bit being equal to ‘1’ in an Interrupt Flag Status (IFSx) register. The
IRQ causes an interrupt if the corresponding bit in the Interrupt Enable (IECx) registers is set.
For the rest of the instruction cycle in which the IRQ is sampled, the priorities of all pending
interrupt requests are evaluated.
No instruction is aborted when the CPU responds to the IRQ. The instruction in progress when
the IRQ is sampled is completed before the ISR is executed.
If there is a pending IRQ with a user-assigned priority level greater than the current processor
priority level, indicated by the IPL<2:0> status bits (SR<7:5>), an interrupt is presented to the
processor. The processor then saves the following information on the software stack:
• Current PC value
• Low byte of the Processor Status register (SRL)
• IPL3 status bit (CORCON<3>)
These three values allow the return PC address value, MCU status bits and the current processor
priority level to be automatically saved.
After this information is saved on the stack, the CPU writes the priority level of the pending
interrupt into the IPL<2:0> bit locations. This action disables all interrupts of lower or equal
priority until the ISR is terminated using the RETFIE (Return from Interrupt) instruction.
15 0
The RETFIE (Return from Interrupt) instruction clears the stack of the PC return address, the
IPL3 status bit and the SRL register to return the processor to the state and priority level that
existed before the interrupt sequence.
Interrupts, by default, can be nested. Any ISR in progress can be interrupted by another source
of interrupt with a higher user-assigned priority level. Interrupt nesting can be disabled by setting
the Interrupt Nesting Disable (NSTDIS) control bit (INTCON1<15>). When the NSTDIS control
bit is set, all interrupts in progress force the CPU priority to level 7 by setting IPL<2:0> = 111.
This action effectively masks all other sources of interrupt until a RETFIE instruction is executed.
When interrupt nesting is disabled, the user-assigned interrupt priority levels have no effect
except to resolve conflicts between simultaneous pending interrupts.
The IPL<2:0> bits (SR<7:5>) become read-only when interrupt nesting is disabled. This prevents
the user software from setting IPL<2:0> to a lower value, which would effectively re-enable
interrupt nesting.
Note: User interrupt sources that are assigned to CPU priority level 0 cannot wake the
CPU from Sleep or Idle mode, because the interrupt source is effectively disabled.
To use an interrupt as a wake-up source, the CPU priority level for the interrupt must
be assigned to CPU priority level 1 or greater.
Interrupts
Tcy 1 2 3 4
INST Fetch
Executed INST(PC-2) INST(PC) FNOP Vector FNOP ISR ISR + 2 ISR + 4
Interrupt Flag
Status bit
CPU Priority 4 4 4 4 6 6 6 6
Tcy 1 2 3 4
INST
Executed INST(PC-2) INST(PC) INST(PC) Fetch FNOP ISR ISR + 2 ISR + 4
1st cycle 2nd cycle Vector
Interrupt Flag
Status bit
CPU Priority 4 4 4 4 6 6 6 6
Figure 28-5: Interrupt Timing, Interrupt Occurs During 1st Cycle of a Two-Cycle Instruction
Tcy 1 2 3 4
Interrupt Flag
Status bit
CPU Priority 4 4 4 4 6 6 6 6
Tcy
PC ISR ISR + 2 PC PC + 2 PC + 4 PC + 6
CPU
6 6 6 4 4 4 4
Priority
Interrupts
28.3.4 Special Conditions for Interrupt Latency
The dsPIC DSC SMPS device allows the current instruction to complete when a peripheral
interrupt source becomes pending. The interrupt latency is the same for both one- and two-cycle
instructions. However, certain conditions can increase interrupt latency by one cycle, depending
on when the interrupt occurs. If a fixed latency is critical to the application, you should avoid the
following conditions:
• Executing a MOV.D instruction that uses PSV to access a value in program memory space
• Appending an instruction stall cycle to any two-cycle instruction
• Appending an instruction stall cycle to any one-cycle instruction that performs a PSV
access
• A bit test and skip instruction (BTSC, BTSS) that uses PSV to access a value in the program
memory space
Note: The total number and type of interrupt sources will depend on the device variant.
Refer to the specific device data sheet for further details.
Lower Byte:
R/W-0 R/W-0 R/W-0 R-0 R/W-0 R/W-0 R/W-0 R/W-0
IPL<2:0> RA N OV Z C
bit 7 bit 0
Interrupts
bit 4-0 Not used by the Interrupt Controller
(See the “dsPIC30F/33F Programmer’s Reference Manual” (DS70157) for descriptions of the SR bits.)
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-0 R/W-0 R/W-1 R/W-0 R/C-0 R/W-0 R/W-0 R/W-0
SATA SATB SATDW ACCSAT IPL3 PSV RND IF
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-0-0 R/W-0-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0 U-0
SFTACERR DIV0ERR — MATHERR ADDRERR STKERR OSCFAIL —
bit 7 bit 0
Interrupts
1 = Trap was caused by catastrophic overflow of Accumulator B
0 = Trap was not caused by catastrophic overflow of Accumulator B
bit 10 OVATE: Accumulator A Overflow Trap Enable bit
1 = Trap overflow of Accumulator A
0 = Trap disabled
bit 9 OVBTE: Accumulator B Overflow Trap Enable bit
1 = Trap overflow of Accumulator B
0 = Trap disabled
bit 8 COVTE: Catastrophic Overflow Trap Enable bit
1 = Trap on catastrophic overflow of Accumulator A or B enabled
0 = Trap disabled
bit 7 SFTACERR: Shift Accumulator Error Status bit
1 = Math error trap was caused by an invalid accumulator shift
0 = Math error trap was not caused by an invalid accumulator shift
bit 6 DIV0ERR: Math Error Status bit
1 = Math error trap was caused by an invalid accumulator shift
0 = Math error trap was not caused by an invalid accumulator shift
bit 5 Unimplemented: Read as ‘0’
bit 4 MATHERR: Arithmetic Error Status bit
1 = Overflow trap has occurred
0 = Overflow trap has not occurred
bit 3 ADDRERR: Address Error Trap Status bit
1 = Address error trap has occurred
0 = Address error trap has not occurred
bit 2 STKERR: Stack Error Trap Status bit
1 = Stack error trap has occurred
0 = Stack error trap has not occurred
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
U-0 U-0 U-0 U-0 U-0 R/W-0 R/W-0 R/W-0
— — — — — INT2EP INT1EP INT0EP
bit 7 bit 0
Interrupts
1 = Interrupt on negative edge
0 = Interrupt on positive edge
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-0 R/W-0 R/W-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0
T3IF T2IF OC2IF — T1IF OC1IF IC1IF INT0IF
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
28
Interrupts
Lower Byte:
U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
— PWM4IF PWM3IF PWM2IF PWM1IF PSEMIF INT2IF INT1IF
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-0 R/W-0 R/W-0 U-0 U-0 U-0 U-0 R/W-0
ADCP2IF ADCP1IF ADCP0IF — — — — AC4IF
bit 7 bit 0
Interrupts
1 = Interrupt request has occurred
0 = Interrupt request has not occurred
bit 5 ADCP0IF: ADC Pair 0 Conversion Done Interrupt Flag Status bit
1 = Interrupt request has occurred
0 = Interrupt request has not occurred
bit 4-1 Unimplemented: Read as ‘0’
bit 0 AC4IF: Analog Comparator #4 Interrupt Flag Status bit
1 = Interrupt request has occurred
0 = Interrupt request has not occurred
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-0 R/W-0 R/W-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0
T3IE T2IE OC2IE — T1IE OC1IE IC1IE INT0IE
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
28
Interrupts
Lower Byte:
U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
— PWM4IE PWM3IE PWM2IE PWM1IE PSEMIE INT2IE INT1IE
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
R/W-0 R/W-0 R/W-0 U-0 U-0 U-0 U-0 R/W-0
ADCP2IE ADCP1IE ADCP0IE — — — — AC4IE
bit 7 bit 0
Interrupts
1 = Interrupt request has occurred
0 = Interrupt request has not occurred
bit 5 ADCP0IE: ADC Pair 0 Conversion Done Interrupt Enable bit
1 = Interrupt request has occurred
0 = Interrupt request has not occurred
bit 4-1 Unimplemented: Read as ‘0’
bit 0 AC4IE: Analog Comparator #4 Interrupt Enable bit
1 = Interrupt request has occurred
0 = Interrupt request has not occurred
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
U-0 R/W-1 R/W-0 R/W-0 U-0 R/W-1 R/W-0 R/W-0
— IC1IP<2:0> — INT0IP<2:0>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
U-0 R/W-1 R/W-0 R/W-0 U-0 U-0 U-0 U-0
— OC2IP<2:0> — — — —
bit 7 bit 0
Interrupts
001 = Interrupt is priority 1
000 = Interrupt source is disabled
bit 7 Unimplemented: Read as ‘0’
bit 6-4 OC2IP<2:0>: Output Compare Channel 2 Interrupt Priority bits
111 = Interrupt is priority 7 (highest priority interrupt)
•
•
•
001 = Interrupt is priority 1
000 = Interrupt source is disabled
bit 3-0 Unimplemented: Read as ‘0’
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
U-0 R/W-1 R/W-0 R/W-0 U-0 R/W-1 R/W-0 R/W-0
— U1RXIP<2:0> — SPI1IP<2:0>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
U-0 R/W-1 R/W-0 R/W-0 U-0 R/W-1 R/W-0 R/W-0
— SI2CIP<2:0> — NVMIP<2:0>
bit 7 bit 0
Interrupts
001 = Interrupt is priority 1
000 = Interrupt source is disabled
bit 3 Unimplemented: Read as ‘0’
bit 2-0 NVMIP<2:0>: Non-Volatile Memory Write Interrupt Priority bits
111 = Interrupt is priority 7 (highest priority interrupt)
•
•
•
001 = Interrupt is priority 1
000 = Interrupt source is disabled
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
U-0 R/W-1 R/W-0 R/W-0 U-0 R/W-1 R/W-0 R/W-0
— INT2IP<2:0> — INT1IP<2:0>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
U-0 R/W-1 R/W-0 R/W-0 U-0 R/W-1 R/W-0 R/W-0
— PWM3IP<2:0> — PWM2IP<2:0>
bit 7 bit 0
Interrupts
001 = Interrupt is priority 1
000 = Interrupt source is disabled
bit 3 Unimplemented: Read as ‘0’
bit 2-0 PWM2IP<2:0>: PWM Generator #2 Interrupt Priority bits
111 = Interrupt is priority 7 (highest priority interrupt)
•
•
•
001 = Interrupt is priority 1
000 = Interrupt source is disabled
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
U-0 U-0 U-0 U-0 U-0 U-0 U-0 U-0
— — — — — — — —
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
U-0 R/W-1 R/W-0 R/W-0 U-0 U-1 U-0 U-0
— AC1IP<2:0> — — — —
bit 7 bit 0
Interrupts
001 = Interrupt is priority 1
000 = Interrupt source is disabled
bit 7 Unimplemented: Read as ‘0’
bit 6-4 AC1IP<2:0>: Analog Comparator 1 Interrupt Priority bits
111 = Interrupt is priority 7 (highest priority interrupt)
•
•
•
001 = Interrupt is priority 1
000 = Interrupt source is disabled
bit 3-0 Unimplemented: Read as ‘0’
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
U-0 U-0 U-0 U-0 U-0 R/W-1 R/W-0 R/W-0
— — — — — AC4IP<2:0>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
U-0 R/W-1 R/W-0 R/W-0 U-0 U-0 U-0 U-0
— ADCP0IP<2:0> — — — —
bit 7 bit 0
Interrupts
001 = Interrupt is priority 1
000 = Interrupt source is disabled
bit 7 Unimplemented: Read as ‘0’
bit 6-4 ADCP0IP<2:0>: ADC Pair 0 Conversion Done Interrupt Priority bits
111 = Interrupt is priority 7 (highest priority interrupt)
•
•
•
001 = Interrupt is priority 1
000 = Interrupt source is disabled
bit 3-0 Unimplemented: Read as ‘0’
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
U-0 R/W-1 R/W-0 R/W-0 U-0 R/W-1 R/W-0 R/W-0
— ADCP4IP<2:0> — ADCP3IP<2:0>
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Lower Byte:
U-0 R-0 R-0 R-0 R-0 R-0 R-0 R-0
— VECNUM<6:0>
bit 7 bit 0
Interrupts
0000001 = Interrupt Vector pending is number 9
0000000 = Interrupt Vector pending is number 8
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
28.5.1 Initialization
The following steps describe how to configure a source of interrupt:
1. Set the NSTDIS Control bit (INTCON1<15>) if nested interrupts are not desired.
2. Select the user assigned priority level for the interrupt source by writing the control bits in
the appropriate IPCx Control register. The priority level will depend on the specific
application and type of interrupt source. If multiple priority levels are not desired, the IPCx
register control bits for all enabled interrupt sources may be programmed to the same
non-zero value.
Note: At a device Reset, the IPC registers are initialized, such that all user interrupt
sources are assigned to priority level 4.
3. Clear the interrupt flag status bit associated with the peripheral in the associated IFSx
Status register.
4. Enable the interrupt source by setting the interrupt enable control bit associated with the
source in the appropriate IECx Control register.
28
INTCON1bits.NSTDIS = 0;
/* Set Timer3 interrupt priority to 3 (level 7 is highest) */
IPC1bits.T3IP = 3;
/* Set Timer2 interrupt priority to 5 */
IPC1bits.T2IP = 5;
Interrupts
/* Set Change Notice interrupt priority to 4 */
IPC6bits.CNIP = 4;
/* Set Timer1 interrupt priority to 2 */
IPC0bits.T1IP = 2;
/* Reset Timer1 interrupt flag */
IFS0bits.T1IF = 0;
/* Reset Timer2 interrupt flag */
IFS0bits.T2IF = 0;
/* Reset Timer3 interrupt flag */
IFS0bits.T3IF = 0;
/* Enable CN interrupts */
IEC1bits.CNIE = 1;
/* Enable Timer1 interrupt */
IEC0bits.T1IE = 1;
/* Enable Timer2 interrupt (PWM time base) */
IEC0bits.T2IE = 1;
/* Enable Timer3 interrupt (Replacement for Timer2)*/
IEC0bits.T3IE = 1;
/* Reset change notice interrupt flag */
IFS1bits.CNIF = 0;
return;
}
void __attribute__((__interrupt__)) _T1Interrupt(void)
{
/* Insert ISR Code Here*/
/* Clear Timer1 interrupt */
IFS0bits.T1IF = 0;
}
SFR
ADR Bit 15 Bit 14 Bit 13 Bit 12 Bit 11 Bit 10 Bit 9 Bit 8 Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Reset State
Name
INTCON1 0080 NSTDIS OVAERR OVBERR COVAERR COVBERR OVATE OVBTE COVTE SFTACERR DIV0ERR — MATHERR ADDRERR STKERR OSCFAIL — 0000 0000 0000 0000
INTCON2 0082 ALTIVT DISI — — — — — — — — — — — INT2EP INT1EP INT0EP 0000 0000 0000 0000
IFS0 0084 — MI2CIF SI2CIF NVMIF ADIF U1TXIF U1RXIF SPI1IF T3IF T2IF OC2IF — T1IF OC1IF IC1IF INT0IF 0000 0000 0000 0000
IFS1 0086 AC3IF AC2IF AC1IF — CNIF — — — — PWM4IF PWM3IF PWM2IF PWM1IF PSEMIF INT2IF INT1IF 0000 0000 0000 0000
IFS2 0088 — — — — — ADCP5IF ADCP4IF ADCP3IF ADCP2IF ADCP1IF ADCP0IF — — — — AC4IF 0000 0000 0000 0000
IEC0 0094 — MI2CIE SI2CIE NVMIE ADIE U1TXIE U1RXIE SPI1IE T3IE T2IE OC2IE — T1IE OC1IE IC1IE INT0IE 0000 0000 0000 0000
IEC1 0096 AC3IE AC2IE AC1IE — CNIE — — — — PWM4IE PWM3IE PWM2IE PWM1IE PSEMIE INT2IE INT1IE 0000 0000 0000 0000
IEC2 0098 — — — — — ADCP5IE ADCP4IE ADCP3IE ADCP2IE ADCP1IE ADCP0IE — — — — AC4IE 0000 0000 0000 0000
IPC0 00A4 — T1IP<2:0> — OC1IP<2:0> — IC1IP<2:0> — INT0IP<2:0> 0100 0100 0100 0100
IPC1 00A6 — T31P<2:0> — T2IP<2:0> — OC2IP<2:0> — — — — 0100 0100 0100 0000
IPC2 00A8 — ADIP<2:0> — U1TXIP<2:0> — U1RXIP<2:0> — SPI1IP<2:0> 0100 0100 0100 0100
IPC3 00AA — — — — — MI2CIP<2:0> — SI2CIP<2:0> — NVMIP<2:0> 0000 0000 0000 0100
IPC4 00AC — PWM1IP<2:0> — PSEMIP<2:0> — INT2IP<2:0> — INT1IP<2:0> 0100 0100 0100 0100
IPC5 00AE — — — — — PWM4IP<2:0> — PWM3IP<2:0> — PWM2IP<2:0> 0000 0000 0000 0100
IPC6 00B0 — CNIP<2:0> — — — — — — — — — — — — 0100 0000 0000 0000
IPC7 00B2 — AC3IP<2:0> — AC2IP<2:0> — AC1IP<2:0> — — — — 0100 0100 0100 0000
IPC8 00B4 — — — — — — — — — — — — — AC4IP<2:0> 0000 0000 0000 0100
IPC9 00B6 — ADCP2IP<2:0> — ADCP1IP<2:0> — ADCP0IP<2:0> — — — — 0100 0100 0100 0000
28
Interrupts
dsPIC30F Family Reference Manual
Question 1: What happens when two sources of interrupt become pending at the same
time and have the same user-assigned priority level?
Answer: The interrupt source with the highest natural order priority will take precedence. The
natural order priority is determined by the Interrupt Vector Table (IVT) address for that source.
Interrupt sources with a smaller IVT address have a higher natural order priority.
Question 2: Can the DISI instruction be used to disable all sources of interrupt and
traps?
Answer: The DISI instruction does not disable traps or priority level 7 interrupt sources.
However, the DISI instruction can be used as a convenient way to disable all interrupt sources
if no priority level 7 interrupt sources are enabled in the user’s application.
Note: Please visit the Microchip web site (www.microchip.com) for additional Application
Notes and code examples for the SMPS dsPIC DSC family of devices.
28
Interrupts