problem using GOSUB under interrupt


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Apr 2009
    Posts
    6

    Default problem using GOSUB under interrupt

    Hello Guys,

    It is the first time I post a message here and I hope somebody could give me some suggestion.

    Here my problem:

    In my PBP program I'm using the ON INTERRUPT statement to activate interrupt.

    The interrupt routine is basiccally a decoding routine for a IR wireless communication which grab data from the IR signal and stores them into some variables.
    eahc time a correct value is received, it is stored into the variable and the interrupt calls, using GOSUB, a subroutine which reproduce a sound controlling an external chip.

    So the problem is here. The audio reproduction routine uses some delay cycles and is wrote under the DISABLE/ENABLE statement, in other words it could not be afected by the interrupts itself.
    It is something like this:

    ------------------------------------------------------
    DISABLE
    audio out:
    HIGH reset
    PAUSE 5
    LOW reset
    PAUSE 10
    HIGH data
    PAUSE 5
    LOW data
    data_count=8
    next_bit
    IF sound_code.0 = 0 then
    HIGH data
    PAUSEUS 200
    LOW data
    PAUSEUS 400
    ELSE
    HIGH data
    PAUSEUS 400
    LOW data
    PAUSEUS 200
    ENDIF
    sound_code=sound_code>>1
    data_count=data_count-1
    IF data_count > 0 THEN next_bit
    RETURN
    ENABLE

    ------------------------------------------------------

    As you can see it produces a timed signal to send to the audio device a serial command.

    The problem exactly is:

    If I call this sub from the interrupt routine like it is, it didn't make the pauses... if inside the audio_out routine I put a GOSUB which calls a sub which is outside the DISABLE/ENABLE statement, it works. So, to have the pauses working I must do something like this:

    ------------------------------------------------------

    DISABLE
    audio out:
    GOSUB do_nothing
    HIGH reset
    PAUSE 5
    LOW reset
    PAUSE 10
    HIGH data
    PAUSE 5
    LOW data
    data_count=8
    next_bit
    IF sound_code.0 = 0 then
    HIGH data
    PAUSEUS 200
    LOW data
    PAUSEUS 400
    ELSE
    HIGH data
    PAUSEUS 400
    LOW data
    PAUSEUS 200
    ENDIF
    sound_code=sound_code>>1
    data_count=data_count-1
    IF data_count > 0 THEN next_bit
    RETURN
    ENABLE

    do_nothing:
    RETURN

    ------------------------------------------------------

    In the reality the pauses are made by a ASM delay routine but the problem is present also if I use the PAUSEUS and PAUSE statement.

    Any idea?

    Thks in advance
    Last edited by fobya71; - 5th March 2010 at 08:52.

  2. #2
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    643


    Did you find this post helpful? Yes | No

    Default

    fobya71,

    It would be better if you post your code as it is, so we can spot where the problem is. I call sub-routines from the DISABLE-ENABLE Interrupt routine and never have any problems. Some people will tell you that it is not recommended but for me it works.

    Robert

  3. #3
    Join Date
    Apr 2009
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by rsocor01 View Post
    fobya71,

    It would be better if you post your code as it is, so we can spot where the problem is. I call sub-routines from the DISABLE-ENABLE Interrupt routine and never have any problems. Some people will tell you that it is not recommended but for me it works.

    Robert
    Yeah I know... usually the interrupt routine must be as shorter as possible and it should not call other subroutines... It is a modification of an existent project and so I have no time to change everything although I will do in future.


    As soon I will be at home I will write the exact code.

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


    Did you find this post helpful? Yes | No

    Default

    And while you are at it - take a look at Darrel Taylor's Instant Interrupts. They are almost as easy to use as ONINT-GOTO, and they have a lot of advantages -they can't be blocked, the code generated is smaller, the int latency is less...
    Charles Linquist

  5. #5
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    643


    Did you find this post helpful? Yes | No

    Default

    And while you are at it - take a look at Darrel Taylor's Instant Interrupts. They are almost as easy to use as ONINT-GOTO, and they have a lot of advantages -they can't be blocked, the code generated is smaller, the int latency is less...
    Charles,

    What do you mean by "they can't be blocked"? How much smaller is the code generated?

    Robert

  6. #6
    Join Date
    Apr 2009
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Charles Linquis View Post
    And while you are at it - take a look at Darrel Taylor's Instant Interrupts. They are almost as easy to use as ONINT-GOTO, and they have a lot of advantages -they can't be blocked, the code generated is smaller, the int latency is less...
    Yeah, I saw a bit... I will investigate more if they could be easily applied to my program.

  7. #7
    Join Date
    Apr 2009
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    tried Taylor's int managment. It doesn't work... gives those error on PicBasic Pro / MicroCodeStudio+:


  8. #8
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default

    Are you using MPASM as the assembler? You have to if you're going to use DT-INTS.

  9. #9
    Join Date
    Apr 2009
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    yes I use Mpasm

  10. #10
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default

    OK, did you also include ReEnterPBP-14.bas or ReEnterPBP-18.bas depending on what type of chip you're using? Which chip are you using by the way?

  11. #11
    Join Date
    Apr 2009
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    I'm using 18f2525 and yes, I also put the INCLUDE "ReEnterPBP-18.bas"...

    Which version of MPASMWIN is better?

Similar Threads

  1. Graphic LCD with PICbasic pro
    By amindzo in forum mel PIC BASIC Pro
    Replies: 41
    Last Post: - 25th November 2012, 11:45
  2. shifting problem
    By helmut in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 31st August 2007, 06:11
  3. Controlling an 240x128 LCD Touchpanel Display
    By Vincent in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 7th June 2006, 23:36
  4. Output PIC module
    By freelancebee in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th September 2005, 20:10
  5. ds1307 from f877 to f452 not work
    By microkam in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 7th July 2005, 00:02

Members who have read this thread : 1

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