Interrupts and Gosubs


+ Reply to Thread
Results 1 to 13 of 13

Thread: Interrupts and Gosubs2037 days old

  1. #1
    Willi Grundmann
    Guest Willi Grundmann's Avatar

    0 Not allowed!

    Default Interrupts and Gosubs

    Hi,

    I have upgraded the Proton compiler to version 3.5.6.7.

    The manual for this version states, that compiler system variables and SFRs are only saved, if the code is located between the context save and context restore commands. It will not track any code executed by goto and gosub commands.

    In previous compiler versions there was the facility to place the interrupt code between HIGH_INT_SUB_START and HIGH_INT_SUB_END statements. Both the HIGH_INT_SUB_START and HIGH_INT_SUB_END statements are still listed in the manual as protected compiler words. Are they still operational for the saving of compiler system variables?

    If not, can the structure in the following example be used as a workaround?

    IntHandler:
    Context Save
    PrintString="Hello World"
    gosub PrintProg
    goto IntHandlerEnd

    PrintProg:
    print PrintString
    return

    IntHandlerEnd:
    context restore

    Above code still creates a warning that system variables and SFRs cannot be tracked, when a call is made from within an interrupt handler.

    We have a large number of programs for different products, which use gosubs in the interrupt routine. Therefore it is important to know, if the later compiler versions can still be used.

    Best Regards

    Willi Grundmann

  2. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,352
    Thumbs Up
    Received: 83
    Given: 183
    Total Downloaded
    5.30 GB

    0 Not allowed!

    Default Re: Interrupts and Gosubs

    As the commands are no longer listed (except as protected words) you should should assume they are no longer available. Look at the ASM and see what is generated when you use those old commands. I imagine that once the compiler detects a GOSUB in-between save and restore context it just gives up.

    It really begs the question, why would you ever need to GOSUB in an ISR? ISRs should be as short (execution time) as possible, set flags and get out. While you're in the ISR, interrupts are disabled and you are potentially missing events. Do the donkey work in your main loop. I know its an example but you don't run PRINT inside your ISR do you?

    But if thats the way your legacy programs are written it's probably best if you run multiple versions of PDS. Unless there is a really good reason (porting to a new PIC perhaps) use the same version of the compiler as the legacy product was originally compiled with.

    If you want a definitive answer I suggest you email Crownhill.

    George

  4. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    Senior Member Mellbreak's Avatar
    Join Date
    Jun 2012
    Posts
    571
    Thumbs Up
    Received: 36
    Given: 27
    Total Downloaded
    4.63 GB

    0 Not allowed!

    Default Re: Interrupts and Gosubs

    The following link might prove helpful (?)....

    http://www.protonbasic.co.uk/showthr..._Int_Sub_Start

    Bob

  6. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    Willi Grundmann
    Guest Willi Grundmann's Avatar

    0 Not allowed!

    Default Re: Interrupts and Gosubs

    Thanks Guys,

    Looks like that this is still some sort of grey area.

    I definitely will need gosubs in interrupt routines. If this is not available in the Proton/PIC combination, then I will have to move very quickly to another platform. With 18F micros running at 64MHZ there is not much of a time contraint. I have project with timer interrupts ticking over every 125 microseconds. With careful programming it is possible to have quite a bit of code in the interrupt routine including a few gosubs.

    Having the time critical stuff in the interrupt routine frees up the mainloop. The mainloop can be slow and do all the time consuming routines.

    Still it would be good to have a definite answer on the gosub-in-interrupts issue. Looking at the assembler code is fine. However the need for having to do this for every project would to some degree reduce the benefit of having a compiler.

    More comments are greatly appreciated.

    Best Regards

    Willi Grundmann

  8. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  9. #5
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,352
    Thumbs Up
    Received: 83
    Given: 183
    Total Downloaded
    5.30 GB

    0 Not allowed!

    Default Re: Interrupts and Gosubs

    I think the point here is that you are free to use GOSUB or any other construction that you please, but the compiler will not protect you from the possible consequences. Provided that you do not perform any operation that changes system data (the string being PRINTED for example) all will be OK.

    Short of saving every system variable on entry to the ISR, I don't see how any compiler for any device could provide unconditional protection, even though it is logically possible. When I get a chance I'll look at some other PIC Basic compilers and see how they handle this situation.

    Perhaps you should consider a more powerful PIC, Proton does have a 24 bit compiler.

    George

  10. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  11. #6
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,557
    Thumbs Up
    Received: 76
    Given: 33
    Total Downloaded
    6.56 GB

    0 Not allowed!

    Default Re: Interrupts and Gosubs

    Willi,

    The compiler can handle what you requested. Check out this thread from post #3 onwards. It should make things clearer.

    You can use the Gosub (or Goto) within an interrupt.
    Regards

    Joseph

  12. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  13. #7
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,584
    Thumbs Up
    Received: 337
    Given: 161
    Total Downloaded
    1.99 GB

    0 Not allowed!

    Default Re: Interrupts and Gosubs

    Gosubs and calls within an interrupt will not be tracked for variable usage. Therefore, they are not safe to use within an interrupt, hence the warning that the compiler gives.

    "The compiler cannot track system variables and SFRs used when a call is made from within an interrupt handler!"

    This also applies to jumps outside of the interrupt handler.

  14. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  15. #8
    Willi Grundmann
    Guest Willi Grundmann's Avatar

    0 Not allowed!

    Default Re: Interrupts and Gosubs

    Hi to everyone,

    Thank you for your comments.

    Looks like that the current version of the compiler is not designed for the use of gosubs in interrupts. In previous versions there were the High_Int_Sub_Start and High_Int_Sub_End statements to define the interrupt routine and the associated sub routines. I guess this was needed to work out, which system variables needed to be saved during the context switching.

    Over the years I have produced a large number of products using the Proton compiler. We still have to support these products and release new firmware from time to time. Can anyone please let me know the last version of the compiler, where the High_Int_Sub_Start and High_Int_Sub_End statements were effective. I assume that the use of gosubs in interrupts was ok with these versions.

    Best Regards

    Willi Grundmann

  16. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  17. #9
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,352
    Thumbs Up
    Received: 83
    Given: 183
    Total Downloaded
    5.30 GB

    0 Not allowed!

    Default Re: Interrupts and Gosubs

    I know this doesn't help now but for the future and for any compiler, always a good idea to include the compiler version in your source. Les would save himself a lot of headaches if he added the option to embed the compiler version in the .HEX file.

    George

  18. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  19. #10
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,584
    Thumbs Up
    Received: 337
    Given: 161
    Total Downloaded
    1.99 GB

    0 Not allowed!

    Default Re: Interrupts and Gosubs

    The use of the High_Int_Sub_Start/High_Int_Sub_End directives has never supported Gosubs and calls within an interrupt.

    The directives were taken out of the compiler in 2012 and replaced by an automatic system that did the same thing, but with more efficiency.

    An extract from the whats new.htm file that accompanies every compiler build:

    Additions, Amendments and Fixes made in version 3.5.2.9 beta of the Proton Compiler. (2nd February 2012)

    Amendments
    Altered the use of Context Save and Context Restore. They now save all compiler system variables and major SFRs that a compiler command may use while inside an interrupt handler.
    This is a major upgrading of the compiler's interrupt handling capabilities and allows a much more flexible and safe method of using interrupts. See the revised manual sections: Context and On_Hardware_Interrupt.
    The use of the directives High_Int_Sub_Start and High_Int_Sub_End etc are now redundant and are ignored by the compiler.



    The compiler can only track the code within the Context Save and Context Restore, any gosub, call or goto that jumps out of the code cannot be tracked. It is then up to the user to save/restore any variables or SFRs required.

  20. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  21. #11
    Willi Grundmann
    Guest Willi Grundmann's Avatar

    0 Not allowed!

    Default Re: Interrupts and Gosubs

    Hi Les,

    Thank you for providing the details.

    Just wondering, if the following structure can be used as a work-around.

    IntHandler:
    Context Save
    PrintString="Hello World"
    gosub PrintProg
    goto IntHandlerEnd

    PrintProg:
    print PrintString
    return

    IntHandlerEnd:
    context restore


    Above example puts the subroutine between the context save and context restore.

    I assume that the compiler looks at the code located between the context save and context restore in order to find out, which system variables need to be saved.

    Or are there also other reasons for not having gosubs in interrupts?

    Best Regards

    Willi


  22. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  23. #12
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,584
    Thumbs Up
    Received: 337
    Given: 161
    Total Downloaded
    1.99 GB

    0 Not allowed!

    Default Re: Interrupts and Gosubs

    There is a mechanism in place that will allow Gosubs and Calls to be made from within an interrupt, and have the relevant subroutine's system variables and SFRs tracked on 8-bit devices. But it has not been robustly tested.

    It was added on the request of Johnb.

    Each subroutine that is called from the interrupt must be wrapped in High_Int_Sub_Start/High_Int_Sub_End or Low_Int_Sub_Start/Low_Int_Sub_End depending on the interrupt type.

    For example:

    Code:
        Device = 18F25K20
        Declare Xtal = 16
        Declare Optimiser_Level = 1
        On_Hardware_Interrupt GoTo MyInt
        
        GoTo Main  
    '--------------------------------------------------------------
    ' Interrupt handler
    '
    Declare Warnings= Off  ' Disable the compiler's warnings
    MyInt:
        Context Save
    
        GoSub MySub1        ' Call a subroutine
        GoSub MySub2        ' Call a subroutine
    
        Context Restore 
    Declare Warnings= On   ' Enable the compiler's warnings
    
    '-------------------------------------------------------------- 
    ' Subroutine 1
    ' The subroutine is wrapped so that the compiler knows that it belongs to an interrupt
    '
    High_Int_Sub_Start      ' Enable system variable and SFR tracking for a High priority Interrupt
    MySub1:
        HRSOut "Hello From Subroutine 1", 13
        Return
    High_Int_Sub_End        ' Disable system variable and SFR tracking for a High priority Interrupt
    
    '-------------------------------------------------------------- 
    ' Subroutine 2
    ' The subroutine is wrapped so that the compiler knows that it belongs to an interrupt
    '
    High_Int_Sub_Start      ' Enable system variable and SFR tracking for a high priority interrupt
    MySub2:
        HRSOut "Hello From Subroutine 2", 13
        Return
    High_Int_Sub_End        ' Disable system variable and SFR tracking for a High priority Interrupt
    
    '--------------------------------------------------------------    
    Main:
    As I stated, the mechanism has not been robustly tested, but it uses the same mechanism as the Context Save/Context Restore so it should be perfectly safe to use.

    A word of caution when using subroutine calls from within an interrupt. Be careful not to overflow the microcontroller's call stack. The interrupt takes up one position within the stack, and it is unknown how many positions are already taken up when the interrupt fires.
    Last edited by top204; 7th November 2014 at 13:40.

  24. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  25. #13
    Willi Grundmann
    Guest Willi Grundmann's Avatar

    0 Not allowed!

    Default Re: Interrupts and Gosubs

    Hi Les,

    Thank you very much for the advise. I appreciate this greatly.

    We have designed over the last years several products for our customers. Most use gosubs in interrupts. Especially the code of one product using the PIC18F67K22 is 121KByte long - with approx. 20% in the interrupt. It would create enormous problems, if we could not support these products in the future.

    Using the structure with the HIGH_INT_SUB_START and HIGH_INT_SUB_END we had no problems so far. However we have to be careful. If the context saving is not working correctly, then this opens the door for intermittent problems. I somewhat understand the need and mechanism for the context saving of the system variables. The context saving of the SFR is more complex and I guess there could be serious fish hooks. Perhaps I need to read through the .lst file and check, which SFRs are used in the interrupt routine and the main program. That could indicate, if there is a potential for problems.

    I will keep using the HIGH_INT_SUB_START and HIGH_INT_SUB_END and either turn the warnings off or ignore them.

    Thanks also for the advise with the stack. With PIC18F devices the stack is larger. I am also aware, that the debug function of the emulator uses the stack.

    Best Regards

    Willi Grundmann

  26. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Them interrupts, them interrupts, they drive me mad!
    By Mellbreak in forum Proton Plus Compiler v3
    Replies: 10
    Last Post: 7th April 2018, 15:17
  2. how to use interrupts?
    By Zain in forum Interrupt Sources
    Replies: 16
    Last Post: 27th September 2013, 16:12
  3. Interrupts
    By dmTulsa in forum Proton Plus Compiler v3
    Replies: 5
    Last Post: 27th May 2010, 23:46
  4. Program Structure Question - Gosubs
    By tgonser in forum Proton Plus Compiler v3
    Replies: 3
    Last Post: 10th May 2008, 19:07
  5. [SOLVED !] nested gosubs
    By Lester Sanders in forum Proton Plus Compiler v3
    Replies: 4
    Last Post: 15th September 2006, 09:14

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts