PDA

View Full Version : problem using GOSUB under interrupt



fobya71
- 5th March 2010, 08:49
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 ;)

rsocor01
- 5th March 2010, 12:29
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. :D

Robert

fobya71
- 5th March 2010, 13:10
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. :D

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.

Charles Linquis
- 5th March 2010, 13:38
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...

rsocor01
- 5th March 2010, 13:59
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

fobya71
- 5th March 2010, 14:39
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.

fobya71
- 5th March 2010, 17:43
tried Taylor's int managment. It doesn't work... gives those error on PicBasic Pro / MicroCodeStudio+:

http://s3.postimage.org/aP7BS.jpg (http://www.postimage.org/image.php?v=PqaP7BS)

HenrikOlsson
- 5th March 2010, 17:59
Are you using MPASM as the assembler? You have to if you're going to use DT-INTS.

fobya71
- 5th March 2010, 18:34
yes I use Mpasm

HenrikOlsson
- 5th March 2010, 18:50
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?

fobya71
- 5th March 2010, 19:52
I'm using 18f2525 and yes, I also put the INCLUDE "ReEnterPBP-18.bas"...

Which version of MPASMWIN is better?