How to configure an interrupt service
2 posters
Page 1 of 1
How to configure an interrupt service
I'm new to Microchip dsPIC30F series chip programming. I need to use interrupt service in my application, but I don't know what control registers need to be configured, and how an interrupt service routine (ISR) gets invoked. Can you please take external interrupt INT2 as an example to show how to program an ISR? Thanks.
lyh8- Posts : 14
Join date : 2008-08-25
Re: How to configure an interrupt service
dsPIC30F has a series of user programmable interrupt sources. The configuration of the interrupts is grouped in the following control registers.
INTCON1, INTCON2: Global Interrupt Control Registers
IPCx: Interrupt Priority Control Registers
IFSx: Interrupt Flag Status Registers
IECx: Interrupt Enable Control Registers
SR: CPU Status Register, CPU Interrupt Priority Level (IPL)
CORCON: Core Control Register, IPL3, read only
Assume you use MPLAB development tool and C language, below is the interrupt setup procedure for INT2.
1. Set the NSTDIS bit (INTCON1<15>) if no nested interrupts are allowed.
INTCON1bits.NSTDIS = 1;
2. Set up INT2 to interrupt on rising edge
INTCON2bits.INT2EP = 0;
3. Set up interrupt priority level for INT2 per application
IPC5bits.INT2IP = INT2_ISR_PRIORITY;
4. Reset INT2 interrupt flag
IFS1bits.INT2IF = 0;
5. Enable INT2 interrupt
IEC1bits.INT2IE = 1;
6. Enable global interrupt
SRbits.IPL = 0; //The value must be less than INT2_ISR_PRIORITY, but doesnt have to be 0.
7. Set up INT2 ISR
void __attribute__((interrupt, no_auto_psv)) _INT2Interrupt( void )
{
//do your work
//Clear the INT2 interrupt flag
IFS1bits.INT2IF = 0;
}
Hope that helps. Thanks for posting.
INTCON1, INTCON2: Global Interrupt Control Registers
IPCx: Interrupt Priority Control Registers
IFSx: Interrupt Flag Status Registers
IECx: Interrupt Enable Control Registers
SR: CPU Status Register, CPU Interrupt Priority Level (IPL)
CORCON: Core Control Register, IPL3, read only
Assume you use MPLAB development tool and C language, below is the interrupt setup procedure for INT2.
1. Set the NSTDIS bit (INTCON1<15>) if no nested interrupts are allowed.
INTCON1bits.NSTDIS = 1;
2. Set up INT2 to interrupt on rising edge
INTCON2bits.INT2EP = 0;
3. Set up interrupt priority level for INT2 per application
IPC5bits.INT2IP = INT2_ISR_PRIORITY;
4. Reset INT2 interrupt flag
IFS1bits.INT2IF = 0;
5. Enable INT2 interrupt
IEC1bits.INT2IE = 1;
6. Enable global interrupt
SRbits.IPL = 0; //The value must be less than INT2_ISR_PRIORITY, but doesnt have to be 0.
7. Set up INT2 ISR
void __attribute__((interrupt, no_auto_psv)) _INT2Interrupt( void )
{
//do your work
//Clear the INT2 interrupt flag
IFS1bits.INT2IF = 0;
}
Hope that helps. Thanks for posting.
lzmind- Posts : 18
Join date : 2008-08-20
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|