clear and interrupt handler - problem?


+ Reply to Thread
Results 1 to 13 of 13

Thread: clear and interrupt handler - problem?313 days old

  1. #1
    Member
    Join Date
    Aug 2005
    Posts
    108
    Thumbs Up
    Received: 4
    Given: 0
    Total Downloaded
    4.71 GB

    0 Not allowed!

    Default clear and interrupt handler - problem?

    PIC 24FJ128GA308
    compiler: 1.0.5.9

    When I place the first clear command immediately after the interrupt handler, the interrupt handler does not work or the whole code does not work.
    It does not matter if ISR or ISR- and jumps are being used.
    As soon as the interrupt handler is under the 1st clear command the interrupt handler works.

    With the 8-bit compiler I was able to place the interrupt handler before the clear command.

    This does NOT work:

    Code:
    '-------------------------------------------------------------------------
    ' Timer1 interrupt handler
    Isr T1Interrupt ' Context save
    Toggle LED
    IFS0bits_T1IF = 0 ' Reset the Timer1 interrupt flag
    EndIsr ' Context restore and exit the interrupt
    
    Clear
    MAIN_ROUTINE:
    End
    
    '-------------------------------------------------------------------------
    This DOES work:
    Code:
    Clear
    '-------------------------------------------------------------------------
    ' Timer1 interrupt handler
    Isr T1Interrupt ' Context save
    Toggle LED
    IFS0bits_T1IF = 0 ' Reset the Timer1 interrupt flag
    EndIsr ' Context restore and exit the interrupt
    
    
    MAIN_ROUTINE:
    End
    
    '-------------------------------------------------------------------------
    Can somebody check / confirm / explain please?
    Thanks.

  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
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,515
    Thumbs Up
    Received: 319
    Given: 152
    Total Downloaded
    1.99 GB

    0 Not allowed!

    Default Re: clear and interrupt handler - problem?

    Remember, 8-bit devices and the 16-bit devices are very different when it comes to RAM.

    The 16-bit devices have a RAM based stack set in the user RAM area, and the Clear command will clear ALL RAM, including the stack. Interrupts use the stack to store data and the address of the interrupt etc, so Clear after interrupts or subroutines or procedures is a "VERY BIG" no-no with 16-bit devices.

    The Clear command is not actually required anymore in programs, but if it is used in a 16-bit device's program, it should be used at the very beginning of the code, before "anything" else is done.

    My advice would be to remove it, because it is not actually required in 99.9999% of programs.
    Last edited by top204; 28th May 2019 at 12:51.

  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
    Member
    Join Date
    Aug 2005
    Posts
    108
    Thumbs Up
    Received: 4
    Given: 0
    Total Downloaded
    4.71 GB

    0 Not allowed!

    Thumbs up Re: clear and interrupt handler - problem?

    Thanks a lot for the quick reply and explanation.
    Ok. Will remove the clear command.
    Perhaps worth to mention in the manual in the isr section.
    Until now didn't know about the different dimension of "clear" in 8 and 16 bit devices.
    Thanks again.

  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
    Member
    Join Date
    Aug 2005
    Posts
    108
    Thumbs Up
    Received: 4
    Given: 0
    Total Downloaded
    4.71 GB

    0 Not allowed!

    Default Re: clear and interrupt handler - problem?

    removed "clear" but cannot recommend it.
    All my variables contain rubbish at start.

    Code:
        dim  bIDX0          as byte
        dim  bIDX1          as byte
        dim  wARRAY [4]     as word
    
       delayms 100
        hrsout "bIDX0:", dec bidx0," ARR0:",dec warray[0]," ARR0:",dec warray[1]," ARR0:",dec warray[2]," ARR0:",dec warray[3],13,10
    Result:
    bIDX0:175 ARR0:35144 ARR0:39273 ARR0:43274 ARR0:47403

  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 johngb's Avatar
    Join Date
    Oct 2003
    Posts
    2,171
    Thumbs Up
    Received: 96
    Given: 1
    Total Downloaded
    2.91 GB

    0 Not allowed!

    Default Re: clear and interrupt handler - problem?

    Its always good practice to specifically set variables before using them. There was talk at one to set a variable's value in the Dim statement but looking at the manual this does not seem to be the case.
    JohnB

  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
    Join Date
    Mar 2012
    Posts
    2,318
    Thumbs Up
    Received: 80
    Given: 182
    Total Downloaded
    5.30 GB

    0 Not allowed!

    Default Re: clear and interrupt handler - problem?

    Do the variables contain a known value on power up?

    Personally, I've always considered that it good practice to assume nothing about the initial value of variables, but thats just me.
    George.

  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
    Prolific Poster John Drew's Avatar
    Join Date
    Feb 2002
    Posts
    2,858
    Thumbs Up
    Received: 90
    Given: 34
    Total Downloaded
    4.60 GB

    0 Not allowed!

    Default Re: clear and interrupt handler - problem?

    I haven't checked but I thought it was something like this:
    Dim bVar = 5 as byte
    I probably have it wrong as using my phone to post.
    John

  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
    Senior Member Stephen Moss's Avatar
    Join Date
    Jan 2006
    Posts
    534
    Thumbs Up
    Received: 31
    Given: 7
    Total Downloaded
    3.87 GB

    0 Not allowed!

    Default Re: clear and interrupt handler - problem?

    Close John but it as Dim bVar as Byte = 5

  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 johngb's Avatar
    Join Date
    Oct 2003
    Posts
    2,171
    Thumbs Up
    Received: 96
    Given: 1
    Total Downloaded
    2.91 GB

    0 Not allowed!

    Default Re: clear and interrupt handler - problem?

    Perhaps we should suggest it is added to the manual and the Hint database
    JohnB

  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
    Prolific Poster
    Join Date
    Mar 2012
    Posts
    2,318
    Thumbs Up
    Received: 80
    Given: 182
    Total Downloaded
    5.30 GB

    0 Not allowed!

    Default Re: clear and interrupt handler - problem?

    I wonder does "Dim bVar as Byte = 5" work for a software reset?
    George.

  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
    Prolific Poster John Drew's Avatar
    Join Date
    Feb 2002
    Posts
    2,858
    Thumbs Up
    Received: 90
    Given: 34
    Total Downloaded
    4.60 GB

    1 Not allowed!

    Default Re: clear and interrupt handler - problem?

    A near miss Stephen
    Good question George. My gut says no, but if it didn't what's the point of it. So I'm ignoring the gut and putting money on it does.
    We may have to wait for the master - or heaven forbid, trying it.
    John
    Still on my phone. Been playing with KiCad. Impressed.

  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
    Senior Member
    Join Date
    May 2011
    Posts
    506
    Thumbs Up
    Received: 59
    Given: 0
    Total Downloaded
    408.14 MB

    1 Not allowed!

    Default Re: clear and interrupt handler - problem?

    I wonder does "Dim bVar as Byte = 5" work for a software reset?
    Yes it does. It initializes the variable at the start of the main routine.

  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
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,515
    Thumbs Up
    Received: 319
    Given: 152
    Total Downloaded
    1.99 GB

    0 Not allowed!

    Default Re: clear and interrupt handler - problem?

    Whoops..... You are right John. I thought I had added the assignment loading to the manual a year or so back! I'll take a look in my backups of the manual and see if it was in one that I didn't publish.

    They are a very handy mechanism that allows variables and arrays to have a value when they are created, although it is always a wise programming move to have a Setup procedure or subroutine that sets or clears all the variables used in the program, and explains in a comment why it is the value it is and what it does etc... This makes programs more stable because the writer has initial control of them.

    In any Proton BASIC program, the clear must be the very first command in the program. Before anything else is performed, so the best place to put it is underneath the Device = driective and the Declare Xtal directive. Never have a Clear command being issued by the program itself, because it will wipe everything in RAM. Unless it has a variable or bit name after it, then it simply clears that variable or bit.

  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. Interrupt Problem
    By roger in forum Proton 24
    Replies: 6
    Last Post: 3rd November 2013, 21:14
  2. What does the 'Clear' command actually clear?
    By HelpMe! in forum Proton Plus Compiler v3
    Replies: 4
    Last Post: 9th January 2009, 08:52
  3. [SOLVED !] PORTB.2 not working in INT handler
    By precision in forum Proton Plus Compiler v3
    Replies: 0
    Last Post: 17th August 2007, 13:43

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