PDA

View Full Version : Interrupt problem.



muddy0409
- 12th August 2005, 11:35
G'day all you smart people. Would someone be so kind as to help me out with an interrupt (and Timer1) problem. Sometimes we old blokes get caught up with all this new technology.
I have been playing with PICs for a few years, but this is the first time I have used interrupts or Timer1.
This is the reelvent code:


Blah, Blah, usual setup stuff here.


T1CON = %00111001 '1:8 prescaler

PRESET = 12000

'This should load the counter
'ELAPSED = 0
MAINLOOP:
T1CON.0 = 0 'stop the clock
TMR1H = PRESET.highbyte 'RELOAD THE COUNTER
TMR1L = PRESET.Lowbyte ' "
T1CON.0=1 'START THE CLOCK
PIR1.0=0
ON INTERRUPT GOTO TICKER
PIE1.0=1
INTCON.6=1
INTCON.7=1
LCDOUT $fe,1, elapsed 'this is only for seeing what happens - 'NOT required in final
TOGGLE PORTB.5 'nor this bit
ELAPSED = ELAPSED + 1

GOTO MAINLOOP

DISABLE
TICKER:
T1CON.0 = 0 'stop the clock
TMR1H = PRESET.highbyte
TMR1L = PRESET.Lowbyte
'PAUSE 1000
'toggle portb.5 'same as above note
T1CON.0=1
PIR1.0=0



RESUME
ENABLE

OK, when I look at the LCD and Portb.5 in the mainloop, the port line toggles OK, the LCD is too fast to read, but something is on the display, just can't see it.....So far so good.
When I disable the LCD and port in mainloop and enable it in the interrupt loop, the port line does not toggle, neither does the LCD show anything.
Quite obviously the thing is not jumping to the interrupt handler, or an interrupt is not being generated.
I have to ask someone for some help, as I ain't got any hair left to pull out. Been working on this now for 3 nights.........

Thank you, in advance,
Peter Moritz.

Bruce
- 12th August 2005, 17:24
Hi Peter,

Looks like you're reloading timer1 before it can over-flow (not sure without knowing the osc speed), but try something like this.

PRESET VAR WORD
ELAPSED VAR BYTE
PRESET = 12000

T1CON=%00110000 ' Set timer1 prescaler as 1:8
PIR1.0=0 ' Clear timer1 overflow flag
PIE1=%00000001 ' Enable interrupt on timer1 overflow
TMR1H=PRESET.highbyte ' Load timer1 high byte
TMR1L=PRESET.Lowbyte ' Load timer1 low byte
T1CON.0=1 ' Turm on timer1
INTCON=%11000000 ' Global & peripheral interrupts enabled

ON INTERRUPT goto TICKER

MAINLOOP:
TOGGLE PORTB.5
ELAPSED = ELAPSED + 1
GOTO MAINLOOP

DISABLE
TICKER:
TOGGLE PORTB.0 ' Toggle PORTB.0
TMR1H = PRESET.highbyte ' Load timer1 high byte
TMR1L = PRESET.Lowbyte ' Load timer1 low byte
PIR1.0=0 ' Clear TMR1 overflow flag
RESUME
ENABLE

END
HTH....;o}

muddy0409
- 13th August 2005, 06:40
Yeah, Thanks Bruce, that done it.
Isn't it amazing, once again my problem was so simple that I couldn't see it for trying. Makes me feel like a bloody idiot, (as is usual with my little errors) when that happens. The theory was right, just the placement wrong. Anyway, thanks a lot Bruce for your assistance.
Regards,
Peter Moritz.