• AVR Freaks

Hot!dsPIC33EP: Change Notifications Interrupt

Author
TS9
Super Member
  • Total Posts : 908
  • Reward points : 0
  • Joined: 2010/05/07 10:52:22
  • Status: offline
2020/06/10 21:16:03 (permalink)
0

dsPIC33EP: Change Notifications Interrupt

Hi,


I am using dsPIC33EP Series MCU.

If this any way to distinguish between Rising and Falling Edges in ISR with Change Notification Interrupt.

ISR ()
{
If(RisingEdge)
// Do this
If(Falling Edge)
// Do this
}

Thanks in advance..

--
TS9
#1

19 Replies Related Threads

    ric
    Super Member
    • Total Posts : 28321
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: dsPIC33EP: Change Notifications Interrupt 2020/06/10 21:35:08 (permalink)
    1 (1)
    In those PICs, you have to save the state of the PORTx register on each interrupt, and compare the new value with the previous value.
     

    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
    TS9
    Super Member
    • Total Posts : 908
    • Reward points : 0
    • Joined: 2010/05/07 10:52:22
    • Status: offline
    Re: dsPIC33EP: Change Notifications Interrupt 2020/06/10 21:56:57 (permalink)
    0
    ric
    In those PICs, you have to save the state of the PORTx register on each interrupt, and compare the new value with the previous value. 

    Thanks..

    On Startup , How to detect which edge first come?
    I am using dsPIC33EP256MC502 MCU.

    --
    TS9
    #3
    ric
    Super Member
    • Total Posts : 28321
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: dsPIC33EP: Change Notifications Interrupt 2020/06/10 22:00:01 (permalink)
    0
    Read and save the port value before you enable interrupts.

    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!
    #4
    TS9
    Super Member
    • Total Posts : 908
    • Reward points : 0
    • Joined: 2010/05/07 10:52:22
    • Status: offline
    Re: dsPIC33EP: Change Notifications Interrupt 2020/06/10 22:05:38 (permalink)
    0
    ric
    Read and save the port value before you enable interrupts.

    Thanks
    But how to read and save port value without enabling interrupt?
    #5
    ric
    Super Member
    • Total Posts : 28321
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: dsPIC33EP: Change Notifications Interrupt 2020/06/10 22:11:26 (permalink)
    0
    I can't believe you are asking this.
    How about
    unsigned int sav_portb;    // global variable to hold the previous port state
     
     
    sav_portb = PORTB;  // code executed during 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!
    #6
    TS9
    Super Member
    • Total Posts : 908
    • Reward points : 0
    • Joined: 2010/05/07 10:52:22
    • Status: offline
    Re: dsPIC33EP: Change Notifications Interrupt 2020/06/10 22:23:56 (permalink)
    0
    ric
    I can't believe you are asking this.How about
    unsigned int sav_portb;    // global variable to hold the previous port state
    sav_portb = PORTB;  // code executed during your initialisation
      


    Thanks..
    But I think External Interrupt has better option rather than CN? For my application.
    Is it..?

    --TS9
    #7
    ric
    Super Member
    • Total Posts : 28321
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: dsPIC33EP: Change Notifications Interrupt 2020/06/10 22:31:41 (permalink)
    2 (1)
    Why have you suddenly changed the question?
    I can't get much more specific if you don't reveal WHICH dsPIC33EP you are talking about.
     

    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!
    #8
    JPortici
    Super Member
    • Total Posts : 1153
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: Grappaland
    • Status: offline
    Re: dsPIC33EP: Change Notifications Interrupt 2020/06/10 22:33:50 (permalink)
    0
    Ric he wrote that a couple of posts ago :) or edited the comment including the partnumber, whatever
     
    What does it mean on startup?
    can you explain better?
    #9
    TS9
    Super Member
    • Total Posts : 908
    • Reward points : 0
    • Joined: 2010/05/07 10:52:22
    • Status: offline
    Re: dsPIC33EP: Change Notifications Interrupt 2020/06/10 22:35:01 (permalink)
    0
    TS9
    ric
    In those PICs, you have to save the state of the PORTx register on each interrupt, and compare the new value with the previous value. 

    Thanks..

    On Startup , How to detect which edge first come?
    I am using dsPIC33EP256MC502 MCU.

    --
    TS9



    Already Written dsPIC33EP256MC502..
    I have to detect rising and falling edges in every
    10ms.
    #10
    ric
    Super Member
    • Total Posts : 28321
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: dsPIC33EP: Change Notifications Interrupt 2020/06/10 22:36:26 (permalink)
    5 (1)
    I give up.
    You don't seem to have the slightest idea about writing code yourself.
     

    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!
    #11
    TS9
    Super Member
    • Total Posts : 908
    • Reward points : 0
    • Joined: 2010/05/07 10:52:22
    • Status: offline
    Re: dsPIC33EP: Change Notifications Interrupt 2020/06/10 22:37:23 (permalink)
    0
    Jack_M
    Ric he wrote that a couple of posts ago :) or edited the comment including the partnumber, whatever What does it mean on startup?can you explain better?

    Thanks
    Not Edited.. startup means when program execute
    first time.

    --
    TS9
    #12
    TS9
    Super Member
    • Total Posts : 908
    • Reward points : 0
    • Joined: 2010/05/07 10:52:22
    • Status: offline
    Re: dsPIC33EP: Change Notifications Interrupt 2020/06/10 22:39:13 (permalink)
    2 (1)
    ric
    I give up.You don't seem to have the slightest idea about writing code yourself. 

    Ok..Thanks..BTW How did you Judge that?
    #13
    ric
    Super Member
    • Total Posts : 28321
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: dsPIC33EP: Change Notifications Interrupt 2020/06/10 22:47:29 (permalink)
    4 (1)
    TS9
    ric
    I give up.You don't seem to have the slightest idea about writing code yourself. 

    Ok..Thanks..BTW How did you Judge that?

    By your inability to even write a single line to "read and save a port value".
    If that's beyond you, I can't explain harder concepts.
     

    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!
    #14
    TS9
    Super Member
    • Total Posts : 908
    • Reward points : 0
    • Joined: 2010/05/07 10:52:22
    • Status: offline
    Re: dsPIC33EP: Change Notifications Interrupt 2020/06/10 22:51:46 (permalink)
    0
    ric
    TS9
    ric
    I give up.You don't seem to have the slightest idea about writing code yourself. 

    Ok..Thanks..BTW How did you Judge that?

    By your inability to even write a single line to "read and save a port value".If that's beyond you, I can't explain harder concepts. 

    No No I want to know the better method according to my application
    Whether CN or External Interrupt?
    That's it .


    --
    TS9
    #15
    JPortici
    Super Member
    • Total Posts : 1153
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: Grappaland
    • Status: offline
    Re: dsPIC33EP: Change Notifications Interrupt 2020/06/10 22:53:32 (permalink)
    0
    TS9
    Jack_M
    Ric he wrote that a couple of posts ago :) or edited the comment including the partnumber, whatever What does it mean on startup?can you explain better?

    Thanks
    Not Edited.. startup means when program execute
    first time.

    --
    TS9



    You can use more words, this ain't twitter :)
    From what you are writing i understand that you want to know the state of a Pin when the program starts.
     
    Why don't you just read the port right after you enter main?
     
    All pins are configured as inputs (and the analog capable ones as analog inputs) at every reset, including POR (power on reset) so depending on the pin you may have to set it to digital mode, then read its value.
    #16
    ric
    Super Member
    • Total Posts : 28321
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: dsPIC33EP: Change Notifications Interrupt 2020/06/10 23:09:03 (permalink)
    0
    Jack_M
    ...
    Why don't you just read the port right after you enter main?

    Which might be what I was getting at back in post#4 ;)
     

    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!
    #17
    du00000001
    Just Some Member
    • Total Posts : 3942
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: dsPIC33EP: Change Notifications Interrupt 2020/06/11 02:46:15 (permalink)
    0
    This started as an X-Y problem, getting worse then ...
     
    Provided the microcontroller is fast enough and CN is active for both edges on a single pin,
    • following a rising edge the port pin will be high when read in the ISR.
    • following a falling edge the port pin will be low then.
    Again: if it's only about a single pin: no need for some kind of edge detection in software.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #18
    JPortici
    Super Member
    • Total Posts : 1153
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: Grappaland
    • Status: offline
    Re: dsPIC33EP: Change Notifications Interrupt 2020/06/11 03:03:02 (permalink)
    0
    I know. I'm trying to get the OP to explain what he wants to do exactly, in more than five words
    #19
    du00000001
    Just Some Member
    • Total Posts : 3942
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: dsPIC33EP: Change Notifications Interrupt 2020/06/11 03:15:58 (permalink)
    0
    Jack_M
    I know. I'm trying to get the OP to explain what he wants to do exactly, in more than five words



    Extrapolating the initial post and simplifying a bit:
    he might want to light a LED when the light switch has been toggled from OFF to ON,
    ssitching the LED off again when the light switch is toggled ON -> OFF.
    Seems to be the classical X-Y...

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #20
    Jump to:
    © 2020 APG vNext Commercial Version 4.5