PDA

View Full Version : Interrupt question



ultiblade
- 26th November 2009, 07:02
Hi !

I have a small question. If i use the following code:


;==== Dec's for OSC
DEFINE OSC 8 'Int OSC @ 8 MHz, for PBP
OSCCON = %01110001 'Int OSC @ 8 MHz

'==== Interrupt handler
on interrupt goto intHANDLER

'==== Set defines
OPTION_REG = %10000000 'Set Weak pull-ups
WPU = %00000000 'Weak pull-ups disabled
INTCON = %11000000 'Enable unmasked perhipal interrupts
PIE1 = %00000001 'Set TMR1 overflow interrupt
PIR1 = %00000000 '
PCON = %00000000
IOC = %00000000 'Interrupt On Change disabled
PCON = %00000000 'Ultra lowpower + BOR disabled
ANSEL = %00000000 'GPIO 0 Analog
TRISIO = %00101000 'GPIO 0,3 inputs
GPIO = %00000001 'All I/O low
CMCON0 = %00000111 'Comparator off
CMCON1 = %00000000 'Output is synced with TMR1
VRCON = %00000000 'Voltage ref. disabled
ADCON0 = %00000000 'ADC off
T2CON = %00000100 'TMR2 = ON, prescaler = 1:1
T1CON = %10000111 'Timer1 counts 100Hz
CCP1CON = %00000000 'CCP engine is off


'==== Dec's for variables
countLOOP var word
synclong var word

'==== Initialise variables
countLOOP = 0

'==== Set timer1 3000 from overflow
synclong = 65535-3000
TMR1H = synclong.highbyte
TMR1L = synclong.lowbyte

'==== Main program
start:
GPIO.0 =1 'pulse 1 on
pauseus 800 'Pause 800 us
GPIO.0 = 0 'pulse 1 off
pauseus 800 'pause 800 us
goto start

'==== The End ================================================== =====================
theend: 'Endless loop
goto theend

'==== Interrupt handler
DISABLE
intHANDLER: 'Disable interrupts
intdelay = 1 'Set interrupt has occured bit
PIR1.0 = 0 'Clear interrupt
TMR1H = synclong.highbyte 'Set Tmr1 3000 from overflow again
TMR1L = synclong.lowbyte
resume
enable


Tmr1 is setup as a counter. If it overflows within one of the the 800us delays, will the interrupt be fired directly, or will it first finish the 800us and then fire ?

Should i be using the DT instant interrupts ? I've noticed that the DT interrupts can't resume to a specific label, am i right ?

Thanks
UB

HenrikOlsson
- 26th November 2009, 11:13
Hi,
The interrupt flag will be set as soon as TMR1 overflows but PBP won't "see" it until the PauseUs statement is completed. Hence, the ISR won't be executed until after the pause.

Using DTInts won't give you that problem.

ultiblade
- 26th November 2009, 12:08
OK ! I will give the Dtint a try ...

Thanks for the fast reply !

Best regards,
UB

ultiblade
- 26th November 2009, 12:32
Just wondering. With the pbp ON INTERRUPT STATEMENT i could do a RESUME to a specific label.

This is not possible with the DT int, right ?

Charles Linquis
- 26th November 2009, 20:12
DT interrupts can't return to a specific label - but you can set a flag inside the ISR and test for that in your main program loop. If set, you can jump to wherever you want.

Although it isn't quite "instant", that method can usually accomplish what you need.