PDA

View Full Version : TMR0 interrupt and HSERIN



boban
- 1st September 2008, 12:51
Hello,
I have a question about the interrupts. I have a simple program which uses the TMR0 interrupt. Then I have a task which is using HSERIN / HSEROUT and this task is executed each minute. But looks like, that this task cause, that the TMR0 interrupt is not correctly managed, I am loosing seconds when the task is running. I am trying to findout why, because for the waiting operation I am using e.g. this routine, which should not block the OnInterrupt:

pauseWithInterrupt:
for k=0 TO 1200
PAUSE 1
NEXT k
return

My question is what will happen, if I have e.g. the command:

HSERIN 100, retMail2, [wait ($0D, $0A, $0D, $0A), STR COMMAND\96\$0D]

And the TMR0 interrupt will arrive, when the HSERIN is waiting. Based on the manual, I expect, that the program will jump to On Interrupt after the HSERIN command will finish. Is it true? It cannot happen, that the interrupt is lost?

Becuase I have in On Interrupt:
On Interrupt Goto intManagement

disable
intManagement:
if (INTCON.2 == 1) then
ticks = ticks + 1 ' Count pieces of seconds
If ticks < 61 Then tiexit
toggle ACTIVITY_LED
ticks = 0 'One second elasped - update time
if (skipSecIncr <> 1) then second = second + 1
skipSecIncr = 0
tiexit:
INTCON.2 = 0
endif
INTCON.7 = 1
resume

Because I was thinking, if the TMR0 interrupt is fired and I will not perform the INTCON.2 = 0 and INTCON.7 = 1 then the TMR0 is not increased - not counted. So I should not do any operation, which will take more than 16 ms. Is it true?

I am using this setting:

'interrupt for timer
T0CON = $C5
RCON.7 = 0
INTCON = $a0 'enable TMR0 interrupts and global interrupt


I think, the possible solution, how to prolong this 16 ms period is to use prescaller for TMR0.
But my general question is if TMR0 interrupt is running all the time, even if the INTCON.2 = 1
and INTCON.7 = 0

I am using the PIC 18F2520
Thanks Robert

Charles Linquis
- 1st September 2008, 15:28
I think a better solution would be to use Darrel Taylor's Instant Interrupts. The "on interrupt go to" structure in PBP is not a "true" interrupt, in that it doesn't go to the ISR at the end of the present instruction cycle.

boban
- 2nd September 2008, 11:48
I think, that the question is, if the interrupt is called, when I am using long operations like e.g.
HSERIN 100, retMail2, [wait ($0D, $0A, $0D, $0A), STR COMMAND\96\$0D]

Becuase I have realized, that the HSERIN command is not probably terminated by the interrupt and it is waiting till the end.
So the only solution is to use e.g. longer TMR0 interrupt - like to switch the TMR0 to 16 bit, then the interrupt is called each half second and in that case it is always managed.

Are my assuptions correct?