• AVR Freaks

Hot!Help to understand what is happening in ISR

Author
Sophi
Starting Member
  • Total Posts : 16
  • Reward points : 0
  • Joined: 2020/02/22 19:49:07
  • Location: 0
  • Status: offline
2020/05/23 09:00:03 (permalink)
0

Help to understand what is happening in ISR

Hi,
I'm working with PIC16LF1708, MPLabX v5.3, and MCC. My hardware is a Curiosity board.
 
I'm building an IR receiver NEC decoder using the EXT_INT pin (A2) and toggling on interrupt (to trigger on both edges).
The intent is to measure pulses using Timer0, set at time period 65ms. I do not have Timer0 interrupt set.
Each NEC signal is approximately 65ms, so I realize that I might need to move to Timer1.
On the scope, I see the correct pulses (previous thread here with image). 
 
post edited by Sophi - 2020/05/23 09:01:34
#1

6 Replies Related Threads

    Sophi
    Starting Member
    • Total Posts : 16
    • Reward points : 0
    • Joined: 2020/02/22 19:49:07
    • Location: 0
    • Status: offline
    Re: Help to understand what is happening in ISR 2020/05/23 09:02:59 (permalink)
    +1 (1)
    NEC pulses begin with a pulse at9ms, then 4.5ms.
    I wrote some code within the ISR to try and detect this and wondered if anyone could help me to understand what is going on.
    I *think* I should first see approximately the number 37 (for 9ms): which I do.
    Then I think I should see the number  18, which I don't.
     
    I thought that the ISR would run through all the way, go back to main, then return back to the ISR. 
    What seems to be happening is that multiple pulses happen in one ISR.
    One of the settings in MCC for Interrupt Module is "Single ISR per interrupt": I don't know what this means.
     
    void INT_DefaultInterruptHandler(void){
    // Goal: measure the first and second pulse to find the 9ms then 4.5 ms
        OPTION_REGbits.INTEDG ^= 1;
        count = count + 1;
        timer_value = TMR0;
        printf("\n %d", count);
        printf(": ");
        printf("%d", timer_value);
    }

     
     
    #2
    Sophi
    Starting Member
    • Total Posts : 16
    • Reward points : 0
    • Joined: 2020/02/22 19:49:07
    • Location: 0
    • Status: offline
    Re: Help to understand what is happening in ISR 2020/05/23 09:06:06 (permalink)
    +1 (1)
    I keep getting this error that says:
    Access Denied
    You don't have permission to access" http:www.microchip.com/forums.post.aspx?" on this server 
    post edited by Sophi - 2020/05/23 09:10:14
    #3
    dan1138
    Super Member
    • Total Posts : 3496
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: Help to understand what is happening in ISR 2020/05/23 10:16:07 (permalink)
    +2 (2)
    Sophi
    I keep getting this error that says:
    Access Denied
    You don't have permission to access" http:www.microchip.com/forums.post.aspx?" on this server



    This is one of the annoying things that this forum does when the spam filter detects suspicious content.
     
    Some of the things that are in the class of suspicious content are:
    Links, pictures, words from a list of band words and just being moody.
     
    This has been going on for years and Microchip seems unable to change it.
    #4
    ric
    Super Member
    • Total Posts : 27022
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Help to understand what is happening in ISR 2020/05/23 14:53:08 (permalink)
    0
    note all, this is a continuation of the question at https://www.microchip.com/forums/m1140265.aspx
     
    Sophi
    The intent is to measure pulses using Timer0, set at time period 65ms. I do not have Timer0 interrupt set.

    HOW have you set Timer0 to "a time period 65ms" ?
    If it's via MCC, it would usually use an interrupt to reload Timer0 for a particular period, as that timer lacks a hardware reload capability (which Timer 2 has)
     
    Also note. NEVER do something slow like a printf inside an ISR!
    An ISR must do the minimum possible to service the interrupt, and get out again ASAP.
    Forget about taking any time measurements if you do printf there.
     

    One of the settings in MCC for Interrupt Module is "Single ISR per interrupt": I don't know what this means.

    You are not writing the true ISR here. MCC is supplying one, and calling your code from their code.
    (Which all goes towards adding latency to your interrupt service to shield you from the real hardware)
    Your PIC only has a single hardware interrupt vector, which services all enabled interrupts. So, the MCC code will be checking all the enabled interrupt flags each time an interrupt occurs, to see which service routine to call.
    I would imagine that setting means it exits as soon as one of the interrupts is invoked. If it's off, then it will probably keep checking for other interrupts after one has matched.

    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!
    #5
    ric
    Super Member
    • Total Posts : 27022
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Help to understand what is happening in ISR 2020/05/23 14:55:06 (permalink)
    +1 (1)
    Sophi
    I keep getting this error that says:
    Access Denied
    You don't have permission to access" http:www.microchip.com/forums.post.aspx?" on this server

    Your probably including one of the expressions which triggers the web server firewall. Most likely "char" followed by "(".
    This is a nasty bug in this forum that Microchip are incapable of fixing. See: Expressions which trigger the firewall

    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
    AndersG
    Super Member
    • Total Posts : 200
    • Reward points : 0
    • Joined: 2008/08/05 04:51:24
    • Location: 0
    • Status: offline
    Re: Help to understand what is happening in ISR 2020/05/24 05:10:36 (permalink)
    0
    FWIW, what I do is to create a routine called Trigger(int n), that wiggles a free pin, n times. That way it is easy to see what goes on inside an ISR, without disturbing timing too much.
     
     
    #7
    Jump to:
    © 2020 APG vNext Commercial Version 4.5