PDA

View Full Version : DT interrupts and Pause



Luckyborg
- 18th February 2009, 21:18
Hey guys, I've had great success in my latest project thanks a lot to the info in these forums. I came across an odd problem while using Darrel Taylors interrupts around a Pause command I like to give my power supply time to level out so I usually put a pause 1000 or whatever near the beginning of the code before I do anything that will start to draw power. When I enable the RX_Int before the pause 1000 everything works like I want, however if I place the enable immediately after the Pause 1000, the interrupt does not work. I have already made a type of pause command that acts as a debounce while refreshing my LEDs, which I can use if needed and just refresh with blanks, but found the problem a little curious. If anyone has any knowledge on why or how to clear up whatever I'm doing I would appreciate it.


'*********From Mister_E's calculator**********

RCSTA = $90 'enable serial port and cont rx
TXSTA = $24 'enable TX, BRGH = 1
SPBRG = 17 '9600 baud @ -0.03%
SPBRGH = 4
BAUDCON.3 = 1 'enable 16 bit baudrate
'************************************************* **


;****************Using Darrel Taylor Interrupts****************************
;----[High Priority Interrupts]--------------------------------------------
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler RX_INT, _GetData, PBP, no
INT_Handler TMR0_INT, _IntCounter, PBP, yes
endm
INT_CREATE ;Creates the High Priority interrupt processor
ENDASM

T0CON = %11010010 'T0 = 8 bit, Prescaler 8

'@ INT_ENABLE RX_INT ; enable RX_INT interrupts
Pause 1000
@ INT_ENABLE RX_INT ; enable RX_INT interrupts

mainloop:

'...

goto mainloop

'---[USART RX - interrupt handler]---------------------------[High Priority]---
GetData:

HSERIN 1000,No232,[inbyte]
hserout [inbyte]
red = 1 'turn off red LED
stream[counter] = inbyte
counter = counter + 1
if inbyte = 13 then
counter = 0
update = 1
endif

No232:
@ INT_RETURN

IntCounter:

ticks0 = 6 'preload to get 200 us
count200us = count200us + 1

@ INT_RETURN


I've included the parts I think are relevant as everything works fine or not fine based on which enable line is commented out.

Thanks
David

Darrel Taylor
- 18th February 2009, 22:23
By the time it finishes the PAUSE 1000, the USART buffer has probably overflowed.

Check the OERR bit (RCSTA.1).
If it's set, you have to toggle the CREN bit (RCSTA.4) to reset the USART.

Since you are using HSERIN, you can set ....
DEFINE HSER_CLROERR 1
But that way, your program will never know when the overflows happen.

Or, you could just wait to set-up/enable the USART until after the PAUSE.
<br>

Luckyborg
- 18th February 2009, 22:37
So once the interrupt is setup, is the USART running in the background even when not enabled and that would cause the overflow? I assumed if I disabled the interrupt the USART was basically sitting there inactive. I would have expected the problem to show up when the interrupt was enabled and there was a long pause, but that seems to execute just fine. I'll play with clearing CREN shortly

Luckyborg
- 18th February 2009, 22:47
Both solutions worked, it is good to know that everything is running in the background and that the problem is that I'm just not servicing the interrupt to keep the flags clear. I'll have to keep that in mind for next time.

Thanks, David