PDA

View Full Version : Interrupt Problem



FrankM
- 19th June 2004, 14:09
Hello,

I use TMR1 to generate an interrupt.
All is working fine.

But when I call a procedure with GOSUB, e.g. GOSUB Pause1000, then the Interrupt doesn't work.
In this procedure is no interupt called, but when the program returns, the interrupt is working again.

So how can I make, that the interrupt works in procedures, too?

FrankM

Melanie
- 19th June 2004, 15:45
I assume you are using PBP's "On Interrupt..." rather than your own Assembler Interrupt.

In this case the interrupt is not serviced until AFTER the current Basic command has finished executing... this means that if you have a ONE SECOND delay in the form of...

Pause 1000

then the interrupt will not occur until AFTER the Pause 1000 has completed. That means at worst-case there could be a 1 Second delay before you jump into your ISR.

How can you improve on this? Simply break your pause up into smaller segments...

For ByteCounter=1 to 100
Pause 10
Next ByteCounter

Here the overall timing is still 1 Second, but the interrupt will be serviced after 10mS worst-case instead. You can use Pause 1 instead for an even faster Interrupt Service, however, when you get down to 1mS instructions, and if timing is critical to you, the extra processing for your Counter Code will start having an impact to your timing... example...

For WordCounter=1 to 1000
Pause 1
Next WordCounter

...here you may find that you have not got exactly 1 Second, but 1.05 Seconds or thereabouts (the actual figure depends on many factors). Then instead of using Pause 1, use PauseUS instead, and adjust the value to compensate to get as close to your overall ideal 1 Second as possible... eg...

For WordCounter=1 to 1000
PauseUS 995
Next WordCounter

Melanie

FrankM
- 19th June 2004, 22:34
Thanks for your answer, but that's not exactly my problem.

My Code looks like this:


Main:

ON INTERRUPT GOTO MyInt

GOTO Start

DISABLE
MyInt:

PIR1=0

'PINS
IF ReedPin=0 Then I2CTransfer
IF LadePin=0 THEN IsLoading

RESUME
ENABLE


Start:

T1CON=%00000101
INTCON=$C0
PIE1=%1

GOSUB SPKUp
PAUSE 100

GOTO ShutDown


SPKUp:
For SPKVAR1=10 to 60
FREQ=SPKVAR1*SPKVAR1
FREQOUT SpkPin, 10, FREQ
PAUSE 100
NEXT SPKVAR1
RETURN


My Problem is:
If I call SPKUp, the Interrupt Handler won't work. So it doesn't check the ReedPin oder LadePin.

And now my question:
What can I make, that this works?

I used the PBP's Interrupt handler, because I can no Assembler ;)

FrankM

Melanie
- 19th June 2004, 23:03
What PIC are you using?

FrankM
- 20th June 2004, 09:27
Pic 16F876 @ 20Mhz

Melanie
- 20th June 2004, 11:50
I disagree with you Frank... your posted code above CANNOT look like your code that doesn't work...

Your Subroutine MUST be positioned correctly...

(1) It must be located AFTER an ON INTERRUPT statement and...
(2) It must be located AFTER an ENABLE statement

I have tested all four examples below to double-check...

Example 1. This will Not work...

Jump to Start
Subroutine
ISR (Interrupt Service Routine with Disable/Enable)
Start:
On Interrupt Statement
Enable Statement
Main Program Loop

Example 2. This will not work

Jump to Start
Subroutine (with Enable)
ISR (with Disable/Enable)
Start:
On Interrupt Statement
Enable Statement
Main Program Loop

Example 3. This WILL work

Jump to Start
ISR (with Disable/Enable)
Start:
On Intterrupt Statement
Enable Statement
Main Program Loop
Subroutine

Example 4. This WILL work

On Interrupt Statement
Enable Statement
Jump to Start
Subroutine
ISR (with Disable/Enable)
Start:
Main Program Loop

Basically, the physical location of the Subroutine within your code MUST be AFTER the ON Interrupt Statement (which comes first) and after an ENABLE Statement (which comes second). Do not place the subroutine BEFORE an On Interrupt/Enable... it doesn't compile correctly.

Melanie

btw... forgot to say... Don't give up Music class... *smiles*

FrankM
- 20th June 2004, 14:15
OK, I agree, it was my fault :D

The subs are in seperate files, which are included at the beginning of my main file.

So I'll have to include these files at the end of my main prgramm.

I'll try it later and see if it works, but I hope that this was the mistake and I think, that this was the mistake.

thanks

Frank

FrankM
- 20th June 2004, 15:53
Thank you, it works!!!!

Frank