PDA

View Full Version : Interrupt Yes or No - Difference



savnik
- 10th January 2007, 09:22
I have two codes which both of them works.
But i don't understand which is the difference with Interrupt and without Interrupt.
The operation both of them is the same

The first with Interrupt is :


' On Interrupt - Interrupts in BASIC
' Turn LED on-off. Interrupt on PORTB.0 (INTE) turns LED1 on
' Program waits 1 seconds and turns LED1 back off.


' 16F88

led var PORTA.2
led1 var PORTA.3

CMCON = 7
ANSEL = 0

On Interrupt goto myint ' Define interrupt handler

OPTION_REG = %00111111
INTCON = %10010000 ' Enable INTE interrupt

loop:

High LED
Pause 100
Low LED
Pause 100
Goto loop ' Do it forever

' Interrupt handler

Disable ' No interrupts past this point

myint:

High LED1 'If we get here, turn LED1 on
Pause 1000 ' Wait 1 seconds
Low LED1 ' If we get here, turn LED1 off
INTCON.1=0 ' Clear interrupt flag
Resume ' Return to main program
Enable

The second without Interrupt is :



' 16F88

led var PORTA.2
led1 var PORTA.3

CMCON = 7
ANSEL = 0
TRISB=%11111111

loop:

if PORTB.0=0 THEN GOSUB myint
High LED
Pause 100
Low LED
Pause 100
Goto loop 'Do it forever

myint:

High LED1 'If we get here, turn LED1 on
Pause 1000 'Wait 1 seconds
Low LED1 'If we get here, turn LED1 off

RETURN

HenrikOlsson
- 10th January 2007, 11:22
Hi,
In this particular case the difference is that in the example using interrupts the latency is max ~100mS and in the example not using interrupts the latency can be up to 200mS.

In the first example PBP check if there is an interrupt pending between each PBP statement. Basicly:


Loop:
Interrupt?
High LED
Interrupt?
Pause 100
Interrupt?
Low LED
Interrupt?
Pause 100
Interrupt?
Goto Loop


The second example checks the switch at the begining of each iteration thru the loop and since you have two Pause 100 in there it takes at least 200mS between each check. Depending on when you push the button the time it takes for program to respond will be between 0 and ~200mS.

/Henrik Olsson.