• AVR Freaks

Hot!MCC interrupt callback code

Author
theozed
New Member
  • Total Posts : 23
  • Reward points : 0
  • Joined: 2010/03/09 20:01:12
  • Location: New Zealand
  • Status: offline
2019/08/01 17:14:01 (permalink)
0

MCC interrupt callback code

Hi All,
 
MCC seems to be inconsistent in the code that it generates for handling interrupts for different peripherals.
 
I plan on using the ADC interrupt, and wondering where to place my own ISR code since I don't want to modify any MCC generated files if I can avoid it.
 
In the Developer Help, in the section on implementing MCC interrupts, it uses timer1 as an example, where you can register a callback using a generated function called TMR1_SetInterruptHandler(myTimerISR) in your main.c file. This seems like a good way of doing things to me.
 
I expected something similar for the ADC, but no such code is generated. There seems to be no ADC_SetInterruptHandler() or method to register a callback. The way I see it, I either have to modify the ADC_ISR() function in adc.c directly, or the INTERRUPT_InterruptManager() function in interrupt_manager.c to call my own function instead. Both of these are generated files which I don't want to touch. I also checked the comparitor and it is like the ADC.
 
Why is timer interrupt code generated different to other peripherals? Would it not be a good idea to be able to register a callback for all peripherals in the same way?
 
I am using the online MPLAB Xpress with a PIC16F18345 Xpress evaluation board.
 
Thank you.
#1

5 Replies Related Threads

    OscarTheGrouch
    Super Member
    • Total Posts : 306
    • Reward points : 0
    • Joined: 2010/11/29 18:07:28
    • Location: 0
    • Status: offline
    Re: MCC interrupt callback code 2019/08/04 13:08:42 (permalink)
    0
    theozed
    I plan on using the ADC interrupt, and wondering where to place my own ISR code since I don't want to modify any MCC generated files if I can avoid it.
     
    In the Developer Help, in the section on implementing MCC interrupts, it uses timer1 as an example, where you can register a callback using a generated function called TMR1_SetInterruptHandler(myTimerISR) in your main.c file. This seems like a good way of doing things to me.
     
    I expected something similar for the ADC, but no such code is generated. There seems to be no ADC_SetInterruptHandler() or method to register a callback. The way I see it, I either have to modify the ADC_ISR() function in adc.c directly, or the INTERRUPT_InterruptManager() function in interrupt_manager.c to call my own function instead. Both of these are generated files which I don't want to touch. I also checked the comparitor and it is like the ADC.
     
    Why is timer interrupt code generated different to other peripherals? Would it not be a good idea to be able to register a callback for all peripherals in the same way?
     

    I am no expert on this but I will give you my opinion.
    In my experience, I don't use an interrupt for the ADC. I call the provided API to get the current value of the Analog input when I need it. This could be the reason there is no interrupt code provided.
     
    The timers on the other hand are often used to give the main program a consistent, timely notice that it is time to do something .. like maybe do your ADCs on all or some of the channels.
     
    Hope this is of some help.
    OtG
    #2
    du00000001
    Just Some Member
    • Total Posts : 3008
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: MCC interrupt callback code 2019/08/04 15:38:42 (permalink)
    4 (1)
    When considering using peripheral events, delay is an issue in most cases. Adding the overhead for a callback is somewhat counter-productive.
    Timers (and their interrupts) OTOH are mostly used to implement some kind of scheduling, Here, a bit of overhead (in addition to the scheduling overhead) usually doesn't hurt that much. So functions to register a callback function may be restricted to timers and low-frequency peripheral interrups (e.g. CAN RX/TX).

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #3
    theozed
    New Member
    • Total Posts : 23
    • Reward points : 0
    • Joined: 2010/03/09 20:01:12
    • Location: New Zealand
    • Status: offline
    Re: MCC interrupt callback code 2019/08/05 16:16:52 (permalink)
    0
    Hi guys, thanks for the reply's.
     
    My plan was to use a timer as the trigger for the ADC. I would then get a regular ADC interrupt when the conversion is ready. That way I don't need an extra isr routine from the timer, or have to start the adc manually, or anything like that. My application is actually super simple and if I use the peripherals cleverly I will have a surprisingly small amount of code.
     
    My thoughts were more to do with MCC and how it handles interrupt routines. The decision to use callbacks and the extra jump they cause is made by the authors of MCC as a level of abstraction between MCC and the user code. See here. It's just that it seems to be implemented for the timers but not all interrupts. I'm just in the process of learning MCC.
    #4
    ric
    Super Member
    • Total Posts : 23591
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: MCC interrupt callback code 2019/08/05 16:19:43 (permalink)
    5 (1)
    Lower your expectations, and don't expect full consistency from the myriad of authors who did different bits of MCC, and you'll have an easier time. :)
     

    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
    theozed
    New Member
    • Total Posts : 23
    • Reward points : 0
    • Joined: 2010/03/09 20:01:12
    • Location: New Zealand
    • Status: offline
    Re: MCC interrupt callback code 2019/08/05 16:37:32 (permalink)
    0
    OK. I will lower my expectations.
    #6
    Jump to:
    © 2019 APG vNext Commercial Version 4.5