• AVR Freaks

Hot!External Interrupt not working PIC24FJ1024GB610

Author
hichamrol
Starting Member
  • Total Posts : 84
  • Reward points : 0
  • Joined: 2019/07/10 07:22:53
  • Location: 0
  • Status: offline
2019/09/16 05:39:43 (permalink)
0

External Interrupt not working PIC24FJ1024GB610

Hello word , i am trying to use the INT0 of PIC24FJ1024GB610 100pin, i want to trigger the interrupt from an external signal on the  falling edge , but its' not working , but when i set the interrupt flag by software: everything is fine , 
 i dont know where is the problem exactly , 
here my configuration , any help .... thank you 
 
void __attribute__((interrupt, no_auto_psv)) _INT0Interrupt(void)
{
    INTCON2bits.GIE=0;
    LED_D9_LAT=1; // On led
    IFS0bits.INT0IF =0; // clear flag INT0
    INTCON2bits.GIE=1;


    
}

int main(void)
{
INTCON2bits.GIE=1; // enable all interrupt
INTCON2bits.INT0EP=0; // interrupt on positive edge
IEC0bits.INT0IE=1; // enable INT0 interrupt
IPC0bits.INT0IP=3; // INT0 lv 3 priority
TRISBbits.TRISB0=1; // input pin
IFS0bits.INT0IF =0; // clear flag interrupt

    while(1)
{

}
return 1;
}

#1

9 Replies Related Threads

    ric
    Super Member
    • Total Posts : 23893
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: External Interrupt not working PIC24FJ1024GB610 2019/09/16 06:17:54 (permalink)
    0
    You set pin RB0 as input, but INT0 is on pin RD0.
    (Should not matter though, all pins default to input.)
    Which pin are you actually switching externally?
     
    Do NOT twiddle the GIE bit inside the interrupt service. That WILL cause problems later.
    Do not set the GIE bit in your main code until AFTER you have done all your initialisation.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    hichamrol
    Starting Member
    • Total Posts : 84
    • Reward points : 0
    • Joined: 2019/07/10 07:22:53
    • Location: 0
    • Status: offline
    Re: External Interrupt not working PIC24FJ1024GB610 2019/09/16 06:31:10 (permalink)
    0
    ric
    You set pin RB0 as input, but INT0 is on pin RD0.

     Yes thank you Sir , the probem was that , it worked now ... thank you again 
    #3
    hichamrol
    Starting Member
    • Total Posts : 84
    • Reward points : 0
    • Joined: 2019/07/10 07:22:53
    • Location: 0
    • Status: offline
    Re: External Interrupt not working PIC24FJ1024GB610 2019/09/16 06:32:53 (permalink)
    0
    RIC if i  NOT twiddle the GIE bit inside the interrupt service... and another interrupt triggered , that will get out from the interrupt service and go to the other or what ?
     
     
    #4
    MBedder
    Circuit breaker
    • Total Posts : 6796
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    Re: External Interrupt not working PIC24FJ1024GB610 2019/09/16 07:01:23 (permalink)
    0
    Nevermind, already answered.
    post edited by MBedder - 2019/09/16 07:05:17
    #5
    ric
    Super Member
    • Total Posts : 23893
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: External Interrupt not working PIC24FJ1024GB610 2019/09/16 13:10:06 (permalink)
    0
    hichamrol
    RIC if i  NOT twiddle the GIE bit inside the interrupt service... and another interrupt triggered , that will get out from the interrupt service and go to the other or what ?

    No it won't.
    The hardware turns GIE off for you on entry, and re-enables it when the ISR exits.
    You will cause exactly that problem if YOU enable it before the exit.
    There is an assembly instruction which pops the return stack and re-enables GIE all in one instruction specifically to avoid that problem. The compiler uses it, but YOU are spoiling the show by doing it in the wrong order.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #6
    MBedder
    Circuit breaker
    • Total Posts : 6796
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    Re: External Interrupt not working PIC24FJ1024GB610 2019/09/16 14:08:48 (permalink)
    0
    ricThe hardware turns GIE off for you on entry, and re-enables it when the ISR exits.
    You will cause exactly that problem if YOU enable it before the exit.
    There is an assembly instruction which pops the return stack and re-enables GIE all in one instruction specifically to avoid that problem. The compiler uses it, but YOU are spoiling the show by doing it in the wrong order.
    Ric, this is [partially] true for AVR but totally wrong for PIC24/dsPIC. Clean up your brain and RTFM LoL


    #7
    dan1138
    Super Member
    • Total Posts : 3232
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: External Interrupt not working PIC24FJ1024GB610 2019/09/16 14:49:26 (permalink)
    4 (1)
    MBedder
    Ric, this is [partially] true for AVR but totally wrong for PIC24/dsPIC.

    @MBedder,
    Perhaps you could tryout the solution you suggest for Ric.
     
    Microchip with traditional and near God like wisdom added the GIE bit to the PIC24FJ:
     

     
    Previous versions of the PIC24FJ have no easy way to implement an atomic method to enter a critical section.
     
    It appears that enough developers whined about not understand how to use the DISI opcode that Microchip introduced an architecture change so everyone gets another way to screw up interrupt handling.
    post edited by dan1138 - 2019/09/16 16:38:11
    #8
    hichamrol
    Starting Member
    • Total Posts : 84
    • Reward points : 0
    • Joined: 2019/07/10 07:22:53
    • Location: 0
    • Status: offline
    Re: External Interrupt not working PIC24FJ1024GB610 2019/09/17 00:25:50 (permalink)
    0
    thank you guys , things are cleared now ... Have a good Day 
     
    #9
    MBedder
    Circuit breaker
    • Total Posts : 6796
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    Re: External Interrupt not working PIC24FJ1024GB610 2019/09/17 01:19:43 (permalink)
    0
    dan1138Microchip with traditional and near God like wisdom added the GIE bit to the PIC24FJ
    I do not deny the GIE existence but I do deny it gets automatically set/cleared by hardware.


    #10
    Jump to:
    © 2019 APG vNext Commercial Version 4.5