Searching \ for '[PIC]: Mysterious INTCON troubles with PIC16F877' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/ints.htm?key=intcon
Search entire site for: 'Mysterious INTCON troubles with PIC16F877'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Mysterious INTCON troubles with PIC16F877'
2004\06\23@223418 by adastra

flavicon
face
Wise Ones:



I am a moderately experienced programmer, but I am completely puzzled by
the behavior of this code fragment.

I've been stuck on this all day. I'm obviously overlooking something.
Can anybody help?



This is inside an ISR and is intended to set a flag and clear a register
after counting down a number of TMR0 overflows.



 Inter

           (snip)



           decfsz   ir_cnt                ;counts down 8.9ms

            return                           ;return if not yet counted
down to 0

 irtst     nop                               ;test point for IR
countdown

           movlw   b'01110000'       ;clear any latent external
interrupt (from IR detector)

           movwf   INTCON            ;  and re-enable external
interrupt

           nop

           bsf        flags_5,1           ;set this flag denoting end
of 8.9ms period

           clrf        ir_dat

           return



========================================================



This is what happens, as seen by single-stepping in MPLAB IDE v5.61:



 irtst     nop                               ;test point for IR
countdown



When the program reaches this point, watch window shows INTCON =
b'01100110'



           movlw   b'01110000'       ;clear any latent external
interrupt (from IR detector)

           movwf   INTCON            ;  and re-enable external
interrupt



SURPRISINGLY after the movwf the watch-window shows INTCON = b'11110100'


How can b2 (TOIF) still be set ?



           nop



SURPRISINGLY after executing this NOP, the watch-window shows INTCON =
b'11110110'

Now b1, (INTF) is ALSO set, even if I (temporarily) physically strap the
RB0/INT pin HIGH

in order to be sure that no external interrupt can occur !



           clrf        ir_dat

           return



I just don't understand how this can be happening.



========================================================



Here are my INTCON and OPTION_REG setups:



INTCON setup



       movlw b'11110000'               ; GIE=on TOIE=on (peripheral AND
timer0 overflow

       movwf INTCON                    ;    AND ext-int set up)



            ;  x-------                       ; 7, GIE: Global Internet
Enable (1 = ints enabled)

            ;  -x------                       ; 6, PEIE: Peripheral
Interupt Enable (1 = p. ints enabled)

            ;  --x-----                       ; 5, TOIE: TMR0 Overflow
Interrupt Enable (1 enables interrupt)

            ;  ---x----                       ; 4, INTE: RB0/INT Ext.
int (1 enables ext ints)

            ;  ----x---                       ; 3, RBIE: RB Change
Interrupt Enable (1 enables port change int)

            ;  -----x--                       ; 2, TOIF: TMR0 Overflow
Interrupt Flag (1 = overflowed)

            ;  ------x-                       ; 1, INTF: RB0/INT
External Interrupt Flag (1=external int.)

            ;  -------x                       ; 0, RBIF: RB Port Change
Interrupt Flag (at least one of RB7:RB4

                                                           ;
has changed if this flag is set





OPTION_REG setup

       movlw        b'00001000'

       movwf OPTION_REG          ; load data into OPTION_REG

          ;

               ;  x-------                    ; 7, 0=enable, 1=disable,
portb pullups

               ;  -x------                    ; 6, 1=/, int edge select
bit 0=falling

               ;  --x-----                    ; 5, timer0 source,
0=internal clock, 1=ext pin.

               ;  ---x----                    ; 4, timer0 ext edge, 1=\

               ;  ----x---                    ; 3, prescaler assign,
1=wdt, 0=timer0

               ;  -----x--                    ; 2,1,0, timer0 prescaler
rate select

               ;  ------x-                    ;   000=2, 001=4, 010=8,
011=16, etc.

               ;  -------x                    ;

                                               ; Note! We set the
prescaler to the wdt, so timer0 overflows

                                               ; every 256 instructions
to make an interrupt every 102.4 uS

                                               ; (for 10 MHz clock)





TRISB is set for all outputs, except for RBO/INT which is used as an
external interrupt



===========================================================



Obviously I have to be able to clear the TOIF and INTF flags, but I
can't seem to do it.

I have tried different '877's on the off chance that the chip was bad,
but no joy.

Power Supply voltage looks good, with appropriate 0.1uF bypass at chip
pins

Interrupt context-saving is implemented



I would be so thankful if someone can tell me what I am missing here.



Thanks,



 Foster





                                                           ;


--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body

2004\06\23@225041 by adastra

flavicon
face
Wise Ones:



I am a moderately experienced programmer, but I am completely puzzled by
the behavior of this code fragment.

I've been stuck on this all day. I'm obviously overlooking something.
Can anybody help?



This is inside an ISR and is intended to set a flag and clear a register
after counting down a number of TMR0 overflows.



 Inter

           (snip)



           decfsz   ir_cnt     ;counts down 8.9ms

            return             ;return if not yet counted down to 0

 irtst     nop                 ;test point for IR countdown

           movlw   b'01110000' ;clear any latent external interrupt
(from IR detector)

           movwf   INTCON      ;  and re-enable external interrupt

           nop

           bsf        flags_5,1      ;set this flag denoting end of
8.9ms period

           clrf        ir_dat

           return



========================================================



This is what happens, as seen by single-stepping in MPLAB IDE v5.61:



 irtst     nop                 ;test point for IR countdown



When the program reaches this point, watch window shows INTCON =
b'01100110'



           movlw   b'01110000' ;clear any latent external interrupt
(from IR detector)

           movwf   INTCON      ;  and re-enable external interrupt



SURPRISINGLY after the movwf the watch-window shows INTCON = b'11110100'


How can b2 (TOIF) still be set ?



           nop



SURPRISINGLY after executing this NOP, the watch-window shows INTCON =
b'11110110'

Now b1, (INTF) is ALSO set, even if I (temporarily) physically strap the
RB0/INT pin HIGH

in order to be sure that no external interrupt can occur !



           clrf        ir_dat

           return



I just don't understand how this can be happening.



========================================================



Here are my INTCON and OPTION_REG setups:



INTCON setup

       movlw b'11110000'         ; GIE=on TOIE=on (peripheral AND
timer0 overflow

       movwf INTCON              ;    AND ext-int set up)



            ;  x-------          ; 7, GIE: Global Internet Enable (1 =
ints enabled)

            ;  -x------          ; 6, PEIE: Peripheral Interupt Enable
(1 = p. ints enabled)

            ;  --x-----          ; 5, TOIE: TMR0 Overflow Interrupt
Enable (1 enables interrupt)

            ;  ---x----          ; 4, INTE: RB0/INT Ext. int (1 enables
ext ints)

            ;  ----x---          ; 3, RBIE: RB Change Interrupt Enable
(1 enables port change int)

            ;  -----x--          ; 2, TOIF: TMR0 Overflow Interrupt
Flag (1 = overflowed)

            ;  ------x-          ; 1, INTF: RB0/INT External Interrupt
Flag (1=external int.)

            ;  -------x          ; 0, RBIF: RB Port Change Interrupt
Flag (at least one of RB7:RB4

                                 ;               has changed if this
flag is set



OPTION_REG setup

       movlw        b'00001000'

       movwf OPTION_REG          ; load data into OPTION_REG

          ;

               ;  x-------       ; 7, 0=enable, 1=disable, portb
pullups

               ;  -x------       ; 6, 1=/, int edge select bit
0=falling

               ;  --x-----       ; 5, timer0 source, 0=internal clock,
1=ext pin.

               ;  ---x----       ; 4, timer0 ext edge, 1=\

               ;  ----x---       ; 3, prescaler assign, 1=wdt, 0=timer0

               ;  -----x--       ; 2,1,0, timer0 prescaler rate select

               ;  ------x-       ;   000=2, 001=4, 010=8, 011=16, etc.

               ;  -------x       ;

                                 ; Note! We set the prescaler to the
wdt, so timer0 overflows

                                               ; every 256 instructions
to make an interrupt every 102.4 uS

                                               ; (for 10 MHz clock)



TRISB is set for all outputs, except for RBO/INT which is used as an
external interrupt



===========================================================



Obviously I have to be able to clear the TOIF and INTF flags, but I
can't seem to do it.

I have tried different '877's on the off chance that the chip was bad,
but no joy.

Power Supply voltage looks good, with appropriate 0.1uF bypass at chip
pins

Interrupt context-saving is implemented



I would be so thankful if someone can tell me what I am missing here.



Thanks,



 Foster




--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam@spam@mitvma.mit.edu with SET PICList DIGEST in the body

2004\06\23@225910 by Peter van Hoof

picon face
One thing I think I see here is return instead of retfie
might be misunderstanding because of the many snip's

Peter

{Original Message removed}

2004\06\23@231155 by Ken Pergola

flavicon
face
Hi Foster,

What is your reason for having RETURN instructions in your ISR (interrupt
service routine) as opposed to RETFIE instructions? Keep in mind that when
an interrupt occurs, global interrupts are disabled (GIE = 0). When you exit
an ISR with either a RETURN or RETLW instruction, you will definitely
return, but then global interrupts are left disabled. Is that what you
intended? The RETFIE instruction will re-enable global interrupts (GIE = 1).

Best regards,

Ken Pergola

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body

2004\06\24@002643 by Dwayne Reid

flavicon
face
At 08:33 PM 6/23/2004, adastra wrote:

>This is inside an ISR and is intended to set a flag and clear a register
>after counting down a number of TMR0 overflows.

I see 2 possible problems: you don't appear to clear the TMR0 interrupt
flag (T0IF), and you end the routine with <return> instead of <retfie>.

dwayne

--
Dwayne Reid   <.....dwaynerKILLspamspam.....planet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(780) 489-3199 voice          (780) 487-6397 fax

Celebrating 20 years of Engineering Innovation (1984 - 2004)
 .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-
    `-'   `-'   `-'   `-'   `-'   `-'   `-'   `-'   `-'
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.

--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestspam_OUTspamTakeThisOuTmitvma.mit.edu

2004\06\24@040400 by hael Rigby-Jones

picon face
>-----Original Message-----
>From: Dwayne Reid [dwaynerspamspam_OUTPLANET.EON.NET]
>Sent: 24 June 2004 05:24
>To: @spam@PICLISTKILLspamspamMITVMA.MIT.EDU
>Subject: Re: [PIC]: Mysterious INTCON troubles with PIC16F877
>
>
>At 08:33 PM 6/23/2004, adastra wrote:
>
>>This is inside an ISR and is intended to set a flag and clear a
>>register after counting down a number of TMR0 overflows.
>
>I see 2 possible problems: you don't appear to clear the TMR0
>interrupt flag (T0IF), and you end the routine with <return>
>instead of <retfie>.
>
>dwayne

The instructions:
           movlw   b'01110000'
           movwf   INTCON      ;  and re-enable external interrupt

should clear the T0IF flag.  However, it also enables the external interrupt
and peripheral interrupts are enabled.  The context save code is also not
shown, nor any handler for the other interrupts that may be enabled. The ISR
also "returns" (not setting GIE) with apparently no context restore code, is
the code snippet shown actually CALLed from the main ISR?

Regards

Mike





=======================================================================
This e-mail is intended for the person it is addressed to only. The
information contained in it may be confidential and/or protected by
law. If you are not the intended recipient of this message, you must
not make any use of this information, or copy or show it to any
person. Please contact us immediately to tell us that you have
received this e-mail, and return the original to us. Any use,
forwarding, printing or copying of this message is strictly prohibited.
No part of this message can be considered a request for goods or
services.
=======================================================================
Any questions about Bookham's E-Mail service should be directed to
KILLspampostmasterKILLspamspambookham.com.

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu

2004\06\24@100540 by adastra

flavicon
face
I should have included the context-saving code.  As Michael guessed, the
code snippet I posted earlier is CALLed from the actual interrupt
vector, and the RETURN shown in the snippet comes back to this
context-saving routine.  The RETFIE is at the end of it, so that isn't
the problem.



;**********************************************************************


       org     4             ; Interrupt Vector

;**********************************************************************

save  movwf      temp_w      ;save w contents

      swapf      STATUS,0    ;swap status, result in w

      movwf      temp_s      ;save status contents (swapped)



      call inter



intret swapf      temp_s,0    ;re-swap status, result in w

      movwf      STATUS      ;restore status

      swapf      temp_w,1    ;swap, back in file

      swapf      temp_w,0    ;re-swap, result in w

      retfie                 ;return with proper w contents

;**********************************************************************





>PREVIOUS POST:



Wise Ones:



I am a moderately experienced programmer, but I am completely puzzled by
the behavior of this code fragment.

I've been stuck on this all day. I'm obviously overlooking something.
Can anybody help?



This is inside an ISR and is intended to set a flag and clear a register
after counting down a number of TMR0 overflows.



 inter

           (snip)



           decfsz   ir_cnt     ;counts down 8.9ms

            return             ;return if not yet counted down to 0

 irtst     nop                 ;test point for IR countdown

           movlw   b'01110000' ;clear any latent external interrupt
(from IR detector)

           movwf   INTCON      ;  and re-enable external interrupt

           nop

           bsf        flags_5,1      ;set this flag denoting end of
8.9ms period

           clrf        ir_dat

           return



========================================================



This is what happens, as seen by single-stepping in MPLAB IDE v5.61:



 irtst     nop                 ;test point for IR countdown



When the program reaches this point, watch window shows INTCON =
b'01100110'



           movlw   b'01110000' ;clear any latent external interrupt
(from IR detector)

           movwf   INTCON      ;  and re-enable external interrupt



SURPRISINGLY after the movwf the watch-window shows INTCON = b'11110100'


How can b2 (TOIF) still be set ?



           nop



SURPRISINGLY after executing this NOP, the watch-window shows INTCON =
b'11110110'

Now b1, (INTF) is ALSO set, even if I (temporarily) physically strap the
RB0/INT pin HIGH

in order to be sure that no external interrupt can occur !



           clrf        ir_dat

           return



I just don't understand how this can be happening.



========================================================



Here are my INTCON and OPTION_REG setups:



INTCON setup

       movlw b'11110000'         ; GIE=on TOIE=on (peripheral AND
timer0 overflow

       movwf INTCON              ;    AND ext-int set up)



            ;  x-------          ; 7, GIE: Global Internet Enable (1 =
ints enabled)

            ;  -x------          ; 6, PEIE: Peripheral Interupt Enable
(1 = p. ints enabled)

            ;  --x-----          ; 5, TOIE: TMR0 Overflow Interrupt
Enable (1 enables interrupt)

            ;  ---x----          ; 4, INTE: RB0/INT Ext. int (1 enables
ext ints)

            ;  ----x---          ; 3, RBIE: RB Change Interrupt Enable
(1 enables port change int)

            ;  -----x--          ; 2, TOIF: TMR0 Overflow Interrupt
Flag (1 = overflowed)

            ;  ------x-          ; 1, INTF: RB0/INT External Interrupt
Flag (1=external int.)

            ;  -------x          ; 0, RBIF: RB Port Change Interrupt
Flag (at least one of RB7:RB4

                                 ;               has changed if this
flag is set



OPTION_REG setup

       movlw        b'00001000'

       movwf OPTION_REG          ; load data into OPTION_REG

          ;

               ;  x-------       ; 7, 0=enable, 1=disable, portb
pullups

               ;  -x------       ; 6, 1=/, int edge select bit
0=falling

               ;  --x-----       ; 5, timer0 source, 0=internal clock,
1=ext pin.

               ;  ---x----       ; 4, timer0 ext edge, 1=\

               ;  ----x---       ; 3, prescaler assign, 1=wdt, 0=timer0

               ;  -----x--       ; 2,1,0, timer0 prescaler rate select

               ;  ------x-       ;   000=2, 001=4, 010=8, 011=16, etc.

               ;  -------x       ;

                                 ; Note! We set the prescaler to the
wdt, so timer0 overflows

                                               ; every 256 instructions
to make an interrupt every 102.4 uS

                                               ; (for 10 MHz clock)



TRISB is set for all outputs, except for RBO/INT which is used as an
external interrupt



===========================================================



Obviously I have to be able to clear the TOIF and INTF flags, but I
can't seem to do it.

I have tried different '877's on the off chance that the chip was bad,
but no joy.

Power Supply voltage looks good, with appropriate 0.1uF bypass at chip
pins

Interrupt context-saving is implemented



I would be so thankful if someone can tell me what I am missing here.



Thanks,



 Foster






--
http://www.piclist.com hint: To leave the PICList
spamBeGonepiclist-unsubscribe-requestspamBeGonespammitvma.mit.edu

More... (looser matching)
- Last day of these posts
- In 2004 , 2005 only
- Today
- New search...