Interrupts and stack


Closed Thread
Results 1 to 7 of 7

Hybrid View

  1. #1
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: Interrupts and stack

    You can read the Stack Pointer 'STKPTR' at any time and see what is going on.

    Before I put any code 'in the can', I print out the stack pointer value at the top of my main loop and try all sorts of
    things. If the value ever gets greater than zero, I know I'm in trouble.
    Charles Linquist

  2. #2
    Join Date
    Dec 2009
    Location
    Canada
    Posts
    68


    Did you find this post helpful? Yes | No

    Default Re: Interrupts and stack

    Thank you Gentlemen,

    Thank you,

    Reading the stack in the top of the Interrupt handler I learnt that it sometimes was above 150!

    Yes, I use RESUME for returning from the interrupt handler. I was thinking this was a stack problem because when I switch the fuse for ignoring the stack overrun/underrun it does not reset (but still does not work properly) The problem accurs when the code jumps into the interrupt and I found where my stupidity was. I used gosubs which jump from the interrupt handler into ENABLED area. DISABLEing that portion of code fixed the problem. In fact the interrupt handler was calling itself again and again while in the external subroutine with enabled interrupts.

    On this point of view if the stack is not rounded on these controllers I am not sure if I can use RESUME LABEL or not on tis particular controller - if I do not resume back into subroutine which was interrupted, I may have leakage of stack space again. Do you know how PICBASIC handles the RESUME LABEL? does it clear the stack from the previous broken calls?

    Thank you,

  3. #3
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: Interrupts and stack

    Can you post your code? You really should never gosub or goto out of an ISR. It just sets you up for bad hard to find problems. While I am not sure, I get the feeling you are using on interrupt. You can maybe get away with this in this case, but as you start using interrupts (DT_INT or ASM) this will cause you un known problems.

    As for the circular stack, that would just mask the problem. You code may appear to be working, but in fact may be doing lots of just looping willy-nilly until it finds the correct spot again.

    Remember even a broken clock is correct twice a day.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  4. #4
    Join Date
    Dec 2009
    Location
    Canada
    Posts
    68


    Did you find this post helpful? Yes | No

    Default Re: Interrupts and stack

    Hello Bert,

    Yes, you are right, I am using "ON INTERRUPT" and from the interrupt handler I accessed a subroutine placed outside. Putting "disable/enable" around that subroutine fixed the problem, but I will just copy that piece of code into the interrupt handler to avoid further problems. So far I am not ready to insert ASM code, so everything is in PICBasic.

    I like Charles idea to put stack value onto display in the beginning of the main loop to check if there is a problem. In my case I needed it in the interrupt handler (where I now have this value slightly above zero) but the test of the main loop for zero value is just great!

    Thanks, as usually you all are very helpful. Hope some day I will be able to help others too

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

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