External Interrupt check

General discussion on mikroC PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
divivoma
Posts: 20
Joined: 12 Dec 2013 19:15

External Interrupt check

#1 Post by divivoma » 09 May 2016 19:18

Hello All,

I'm trying to use the EXT INT1 and EXT_INT2 of PIC24FJ256GB110.
I'm using PPS in order to map these 2 interrupt to pin RD11 (RDP12) and RD10 (RP3).

I've followed the datasheet instruction by setting them as input in TRISD and then calling the proper ISR on a simple button press (rising edge), but it's not working..

Below the code...any errors?
Thank you for the advices.

Code: Select all


 void EXT_INT1() iv IVT_ADDR_INT1INTERRUPT ics ICS_AUTO 
{
	switch_1 = 1;
	IFS1.INT1IF =0;			//Clear INT1	
}

void EXT_INT2() iv IVT_ADDR_INT2INTERRUPT ics ICS_AUTO 
{

switch_2 = 1;
IFS1.INT2IF =0;			//Clear INT2

} 

void main()
 {

    LATD = 0x00;
    TRISD = 0x0C00;  //RD11 , RD10 AS EXTERNAL INTERRUPT INPUT

Unlock_IOLOCK();

PPS_Mapping(12, _INPUT, _INT1);   //pin 71 is PORTD.RD11 that has RP12--> assign ext INT 1 
PPS_Mapping(3, _INPUT, _INT2);   // pin 70 is PORTD.RD10 that has RP3--> assign ext INT 2
		
 Lock_IOLOCK();
	//1- Nested interrupt enabled
        INTCON1.NSTDIS = 0;   

	INTCON2.INT1EP 	= 0; 	//rising edge		
	INTCON2.INT2EP 	= 0;	//rising edge 
		
        INTCON2.ALTIVT 	= 0;	//Disabled Alternate interrupt vector table
	INTCON2.DISI 		= 0;	//DISI function enabled to count the right amount of cycle with interrupt disabled
		
	IPC5 = 0x0006;	//priorita int 1 e 2
	IPC7 = 0x0060;

 	IFS1.INT1IF =0;			//Clear INT1
	IFS1.INT1IE =1;			//Enable external interrupt INT1 
	
	IFS1.INT2IF =0;			//Clear INT2
	IFS1.INT2IE =1;			//Enable external  interrupt INT2
	
  while(1)
   {
     
			
		 if(switch_1)
		 {
								
				LED_ROSSO = 1;
				Delay_ms(500);
				LED_ROSSO = 0;
				switch_1 = 0;				 
		 }
		 if(switch_2)
		 {
				LED_VERDE = 1;
				Delay_ms(500);
				LED_VERDE = 0;
				switch_2 = 0; 	 
		 }
  
    
  }


divivoma
Posts: 20
Joined: 12 Dec 2013 19:15

Re: External Interrupt check

#2 Post by divivoma » 10 May 2016 17:44

Hello all,
I've found the first error here and it was the wrong register used:

IEC1.INT1IE =1; //Enable external interrupt INT1
IEC1.INT2IE =1; //Enable external interrupt INT2

Instead of IFS1.INT1IE =1;

With this modification I'm able to trigger only the INT1 but not the INT2.

I think the problem is to the I/O pin configuration.
If I invert the PPS by changing:

PPS_Mapping(12, _INPUT, _INT1); --> with --> PPS_Mapping(12, _INPUT, _INT2); --> always on RD11

I'm always getting the _INT2 working but not the other interrupt on RD10.
So both the interrupt are configurated properly (I guess..) but I have some issue on the edge recognition on RD10..

Any help please?
Thank you.

Marco

divivoma
Posts: 20
Joined: 12 Dec 2013 19:15

Re: External Interrupt check

#3 Post by divivoma » 11 May 2016 15:59

PROBLEM SOLVED:

By manually setting the RPn :

Code: Select all

Unlock_IOLOCK();
RPINR0bits.INT1R = 12;
RPINR1bits.INT2R = 3;
Lock_IOLOCK();
Calling the PPS function in the way listed above is not working..
Maybe there is some special way to call the PPS function properly?

Thank you,

Marco

Post Reply

Return to “mikroC PRO for dsPIC30/33 and PIC24 General”