Exact match. Not showing close matches.
PICList
Thread
'[PIC]: 16F876 Interrupts'
2001\06\18@121627
by
Malcolm Peill
|
Can anyone advise me on what I'm missing in getting interrupts to work using the timer1 overflow on the 16F876.
I have to admit to never having used interrupts before, so it may be obvious to those who have.....
My code includes the following:
ORG 0x000 ; processor reset vector
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector location
bank_low
CLRWDT
btfss PIR1,TMR1IF ;return if it wasn't a timer1 interrupt
retfie
movlw h'dc'
movwf TMR1L ;set timer1 to BDC, i.e. 3036 to give .5sec interval including prescaler
movlw h'0b'
movwf TMR1H
call letters
;rest of handler here
bcf PIR1,TMR1IF
retfie
;end of interrupt routine
;**********************************************************************
main ;
;other code here
movlw b'00110000' ;set prescaler to 1:8
movwf T1CON
movlw h'dc'
movwf TMR1L ;set timer1 to BDC, i.e. 3036 to give .5sec interval including prescaler
movlw h'0b'
movwf TMR1H
bcf PIR1,TMR1IF ;ensure interrupt flag is clear
movlw b'11000000' ;global interrupts, peripheral only
movwf INTCON
movlw b'00000001' ;Timer1 only
movwf PIE1
bsf T1CON,TMR1ON ;enable timer1
call initdisplay
I know the timer 1 overflow flag gets set, but never calls the interrupt vector.
Any help greatly appreciated.
Malcolm.
--
http://www.piclist.com hint: The PICList is archived three different
ways. See http://www.piclist.com/#archives for details.
2001\06\18@155911
by
David Cary
|
Dear Malcolm Peill,
Malcolm Peill <spam_OUTMalcolmTakeThisOuT
PEILL.ORG.UK> on 2001-06-18 11:04:51 AM admitted a lack
of knowledge when he said:
{Quote hidden}>I have to admit to never having used interrupts before, so it may be obvious
>to those who have.....
>
>My code includes the following:
>
> ORG 0x000 ; processor reset vector
> goto main ; go to beginning of program
> ORG 0x004 ; interrupt vector location
>
> bank_low
> CLRWDT
> btfss PIR1,TMR1IF ;return if it wasn't a timer1 interrupt
Yes, it's obvious. Interrupt routines need to save all kinds of stuff at the
beginning of the interrupt routine, then restore them at the end of the routine.
It's a little tricky, so everyone starts with the code in the
_PIC16F87X data sheet_ by Microchip Technology Inc.
http://www.microchip.com/0/lit/pline/picmicro/
p. 132: Example 12-1: Saving Status, W, and PCLatH Registers
.
Also be sure to use
piclist.org/techref/microchip/isrregs.htm
for a few improvements.
--
David Cary
--
http://www.piclist.com hint: The PICList is archived three different
ways. See http://www.piclist.com/#archives for details.
2001\06\18@172347
by
Mark Newland
|
David,
This is not always needed. You only have to "save all kinds of stuff" if it is
needed to be saved. I have MANY times had a simple little program where my code
went something like:
Main
btfss TMR_F
goto Main
bcf TMR_F
......
goto Main
All my interupt routine does is set TMR_F. I then waste time in the first two lines
of my code waiting for the timer to overflow. I don't care about saving anything
cause I start everything over again after the interrupt.
I will state AGAIN what his request was. His request was not how does he handle the
internals of the interupt routine. His request was how does he get the interupt
routine to execute. Or to put it in his own words, "...the timer 1 overflow flag
gets set, but never calls the interrupt vector."
David,
On the other side of the arguement, you are correct that he should at least be
aware that certain values MAY need to be saved. I know that when I first started,
this gave me headaches also.
Malcolm,
Assuming that your problem is not saving certain registers but is indeed as you
stated, "...the timer 1 overflow flag gets set, but never calls the interrupt
vector" all I can say is that I can't find anything wrong with it. Then again, I
can't see the nose on my face sometimes either.
David Cary wrote:
{Quote hidden}> Dear Malcolm Peill,
>
> Malcolm Peill <
.....MalcolmKILLspam
@spam@PEILL.ORG.UK> on 2001-06-18 11:04:51 AM admitted a lack
> of knowledge when he said:
> >I have to admit to never having used interrupts before, so it may be obvious
> >to those who have.....
> >
> >My code includes the following:
> >
> > ORG 0x000 ; processor reset vector
> > goto main ; go to beginning of program
> > ORG 0x004 ; interrupt vector location
> >
> > bank_low
> > CLRWDT
> > btfss PIR1,TMR1IF ;return if it wasn't a timer1 interrupt
>
> Yes, it's obvious. Interrupt routines need to save all kinds of stuff at the
> beginning of the interrupt routine, then restore them at the end of the routine.
> It's a little tricky, so everyone starts with the code in the
> _PIC16F87X data sheet_ by Microchip Technology Inc.
>
http://www.microchip.com/0/lit/pline/picmicro/
> p. 132: Example 12-1: Saving Status, W, and PCLatH Registers
> .
> Also be sure to use
> piclist.org/techref/microchip/isrregs.htm
> for a few improvements.
>
> --
> David Cary
>
> --
>
http://www.piclist.com hint: The PICList is archived three different
> ways. See
http://www.piclist.com/#archives for details.
--
http://www.piclist.com hint: The PICList is archived three different
ways. See http://www.piclist.com/#archives for details.
2001\06\19@035545
by
Malcolm Peill
Mark,
You've understood my problem. My code is all in bank 0 and I don't need to save pclath, W reg, Status etc. Thanks for the encouragement that the code seems to be ok. I'll have to keep trying.
David,
I will take a look at those links you suggest to see if something jumps out at me.........
{Original Message removed}
2001\06\19@104929
by
David Cary
|
Dear Malcolm Peill,
Malcolm Peill originally wrote:
> bsf T1CON,TMR1ON ;enable timer1
>
> call initdisplay
>
>I know the timer 1 overflow flag gets set, but never calls the interrupt =
>vector.
Malcolm Peill <Malcolm
KILLspamPEILL.ORG.UK> on 2001-06-19 02:53:13 AM
>My code is all in bank 0 and I don't need to save pclath, W reg, Status etc.
>Thanks for the encouragement that the code seems to be ok. I'll have to keep
trying.
Sorry. Kneejerk reaction. At first glance, it looked like a common newbie
mistake.
I find it hard to believe that you don't need to save W, but if you say so ...
The timer1 setup looks OK to me. Are you sure that the code that executes after
you enable the timer (which you didn't post) doesn't disable the timer or its
PIE interrupt enable bit or the INTCON interrupt enable bits ?
--
David Cary
--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspam
.....mitvma.mit.edu with SET PICList DIGEST in the body
2001\06\19@114647
by
Malcolm Peill
|
David,
This is a more detailed section of my code.
All code outside the interrupt routine finishes long before the next interrupt, and just hangs around a loop waiting, hence no need to store registers.
Running the code below works, just polling TMR1IF, and updates my display (shown in red)
If however I enable the code in blue (enabling interrupts) and comment out code in red, replacing it with a "loop goto loop" statement, my display is never updated (but should be if interrupts were being called)
ORG 0x000 ; processor reset vector
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector location
;**********************************************************************
;interrupt routine here
;**********************************************************************
bank_low
CLRWDT
btfss PIR1,TMR1IF ;return if it wasn't a timer1 interrupt
retfie
movlw h'dc'
movwf TMR1L ;set timer1 to BDC, i.e. 3036 to give .5sec interval including prescaler
movlw h'0b'
movwf TMR1H
call updatedisplay
bcf PIR1,TMR1IF ;ensure interrupt flag is cleared ready for next interrupt
retfie
;**********************************************************************
;end of interrupt routine
;**********************************************************************
main clrf numL
clrf numH
clrf hund
clrf tens
clrf ones
clrf tens_ones
clrf secunit
clrf sectens
clrf minunit
clrf mintens
clrf PORTA
clrf PORTB
clrf PORTC
bank_high
movlw H'3F'
movwf TRISA ;all inputs
clrf TRISB ;all outputs
clrf TRISC ;all outputs
movlw b'10001000'
movwf OPTION_REG ;no pullups on port B, prescaler to WDT
movlw b'10000000' ;analogue conversion right justified, all inputs analogue
movwf ADCON1
bank_low
movlw b'01100001' ;Fosc/8, AN4, A/D on
movwf ADCON0
movlw b'00110000' ;set prescaler to 1:8
movwf T1CON
movlw h'dc'
movwf TMR1L ;set timer1 to BDC, i.e. 3036 to give .5sec interval including prescaler
movlw h'0b'
movwf TMR1H
bcf PIR1,TMR1IF ;ensure interrupt flag is clear
;movlw b'11000000' ;global interrupts, peripheral only
;movwf INTCON
;movlw b'00000001' ;Timer1 only
;movwf PIE1
bsf T1CON,TMR1ON ;enable timer1
call initdisplay
call home0
call stringcharge
movlw H'07'
call moveto0
call stringtime
loop btfsc PIR1,TMR1IF
call updatedisplay
bcf PIR1,TMR1IF ;ensure interrupt flag is clear CLRWDT
goto loop
{Original Message removed}
2001\06\19@195845
by
Tony Nixon
|
Malcolm Peill wrote:
>
> David,
>
> This is a more detailed section of my code.
> All code outside the interrupt routine finishes long before the next interrupt, and just hangs around a loop waiting, hence no need to store registers.
>
> Running the code below works, just polling TMR1IF, and updates my display (shown in red)
>
> If however I enable the code in blue (enabling interrupts) and comment out code in red, replacing it with a "loop goto loop" statement, my display is never updated (but should be if interrupts were being called)
This does not clear the WDT...
Loop goto Loop
Loop clrwdt
goto Loop
You say that the TMR1 interval is 0.5S which may be causing WDT resets.
> i.e. 3036 to give .5sec interval including prescaler
As you say you don't need to save W etc in your ISR in this case, but
you do if you enable the other section of your main code because W and
STATUS may be changing....
> call updatedisplay
Does this subroutine take longer to execute than the WDT period?
--
Best regards
Tony
mICros
http://www.bubblesoftonline.com
EraseMEsalesspam_OUT
TakeThisOuTbubblesoftonline.com
--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listserv
spam_OUTmitvma.mit.edu with SET PICList DIGEST in the body
2001\06\20@045302
by
Malcolm Peill
Tony,
Thanks for the additional advice. I was trying to reduce the text in my e-mail and didn't mention the CLRWDT command.
The device is now working fine, thanks to all the help from this forum. The problem was not switching banks to the PIE1 register.
I can now move on to developing the next exciting section of code....!!!!
Malcolm
{Original Message removed}
More... (looser matching)
- Last day of these posts
- In 2001
, 2002 only
- Today
- New search...