PDA

View Full Version : Enable and Disable in Interrupts



stevecrunch
- 29th October 2007, 01:43
Hello interrupt experts,

I need some clarifications on Interrupts. I am reading a GREAT book on PicBasic called PicBasic Projecs by Dogan Ibrahim. He does explain the ENABLE and DISABLE commands but something doesn't make sense. Please look at the code below.

'Main Program
ON INTERRUPT GOTO XYZ
**********
*MAIN *
*PROGRAM *
*CODE *
*HERE *
**********

DISABLE ' DISABLE INTERRUPTS
XYZ:
**********
*INTERRUPT*
*CODE *
*HERE *
**********
RESUME 'RETURN TO CODE WHERE INTERRUPT OCCURRED
ENABLE ' ALLOW INTERRUPTS TO HAPPEN


This means that when an interrupt occurs (say a timer overflow) our program jumps to XYZ. Right?

I understand why we do this. We don't want an interrupt, during an interrupt.

My question is, shouldn't the DISABLE command go after the XYZ: label and the ENABLE COMMAND go before the RESUME command?

The way it is written in my sample, when the program jumps to XYZ: the DISABLE is not executed. Also, When we exit the interrupt code with RESUME, the program doesn't execute the ENABLE. Kinda defeats the purpose. No?


Thanx in advance.

Jumper
- 29th October 2007, 03:02
Hi,

You should really consider DT Instant interupt routines. They are easy to use and works instantly. The oldfashioned PBP way will not execute the interupt until after the command it is currently in is finished and that can be a long time if you just have entered a Pause_more_or_less_forever command.

Search the forum and you will find all about it.

/me

Melanie
- 29th October 2007, 06:55
ENABLE and DISABLE are really compiler directives and NOT run-time program executable commands.

What this means is that during COMPILE, additional code for checking and jumping to your PICBASIC interrupt will not be inserted between your code statements between the DISABLE and ENABLE pair. So the example you show is valid.

The use of PICBASIC interrupts makes your program very code hungry (and slows it down) because of the way additional statements are inserted between your code, so the best way is only to have them enabled ONLY when you really want them. And because they don't get executed immediately (as can be now seen they're only jumped to BETWEEN your PICBASIC statements, this means that your PICBASIC commands will complete in the normal way BEFORE any interrupt jump is encountered... but if you understand what's going on inside your PIC you can handle this. Go search the forum for OLYMPIC TIMER for an example of PICBASIC interrupt usage.

stevecrunch
- 30th October 2007, 01:10
Melanie,

You you hit the nail on th head. That's what I wanted. It makes sense now. I just want to know and understand every line in my projects.

Is there a list of these "compiler" directives anywhere?

Thanks for the tip Jumper. I will look into it.


Thanks for the en lighting answer.