CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Problem with external interrupt

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Frank B.
Guest







Problem with external interrupt
PostPosted: Wed Nov 13, 2002 1:43 am     Reply with quote

Hi,

I'm using the external interrupt on RB0 for diffrent external devices. Because the interrupt-triggering is only on edges (in my case falling edges), my code looks like:

#int_ext
ext_isr()
{
do
{
...
}
while (!(PORTB & 0x01)); // do while INT-Pin is low
}

Now it seems that the PIC sometimes doesn't recognizes the falling edges. The result is, that the interrupt will then never occur again because the RB0 is steadily low.

The assembler code for the end of the int-function is:
.................... while (!(PORTB & 0x01)); // do while INT-Pin is low
0350: MOVF 06,W
0351: ANDLW 01
0352: XORLW 00
0353: BTFSC 03.2
0354: GOTO 20C
0355: BCF 0B.1
0356: BCF 0A.3
0357: BCF 0A.4
0358: GOTO 028
.................... }

If the next falling edge occur when the PIC is between line 350 and 355, the recognition of the edge (INTF) will be erased by the "BCF 0B.1" command. It is just a question of time.

I think the best would be to do the clear of the INTF before the "while" command.

Question:
how can I instruct the compiler not to generate this "BCF 0B.1" command at the end of the Ext-Interrupt-function?
Or other suggestions ?
___________________________
This message was ported from CCS's old forum
Original Post ID: 8831
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

Re: Problem with external interrupt
PostPosted: Wed Nov 13, 2002 8:26 am     Reply with quote

Why are you waiting for the level to go back high in the interrupt? Typically interrupts should be very short with no delays or conditional loops. But to answer your question, you can write your own interrupt handler (#int_global I believe) to allow more control over the process. Or you can do a couple of tricks that are easier but may require attention in the future. Here is the way I do it:

#define ISR_ADDRESS 0x28 // Note that you will have to find this value in the listing file change it and recompile

#int_ext
ext_isr()
{
INTCON.RBIF = 0;
do
{
...
}
while (!(PORTB & 0x01)); // do while INT-Pin is low
#asm
BCF 0x0A,3
BCF 0x0A,4
GOTO ISR_ADDRESS
#endasm
}

Basically the asm code causes the program to avoid the normal exit from the isr. The value of the goto in my code is the same as the one generated by the compiler. You are basically rewriting the code already there with the exception of the clearing of the flag. Alternatively, you could goto the start of the checking of the flag bits which could reduce interrupt latency caused from restoring the registers and then getting an intterrupt again only to have to store the registers again.

Regards,
Mark

:=Hi,
:=
:=I'm using the external interrupt on RB0 for diffrent external devices. Because the interrupt-triggering is only on edges (in my case falling edges), my code looks like:
:=
:=#int_ext
:=ext_isr()
:={
:=do
:= {
:= ...
:= }
:=while (!(PORTB & 0x01)); // do while INT-Pin is low
:=}
:=
:=Now it seems that the PIC sometimes doesn't recognizes the falling edges. The result is, that the interrupt will then never occur again because the RB0 is steadily low.
:=
:=The assembler code for the end of the int-function is:
:=.................... while (!(PORTB & 0x01)); // do while INT-Pin is low
:=0350: MOVF 06,W
:=0351: ANDLW 01
:=0352: XORLW 00
:=0353: BTFSC 03.2
:=0354: GOTO 20C
:=0355: BCF 0B.1
:=0356: BCF 0A.3
:=0357: BCF 0A.4
:=0358: GOTO 028
:=.................... }
:=
:=If the next falling edge occur when the PIC is between line 350 and 355, the recognition of the edge (INTF) will be erased by the "BCF 0B.1" command. It is just a question of time.
:=
:=I think the best would be to do the clear of the INTF before the "while" command.
:=
:=Question:
:=how can I instruct the compiler not to generate this "BCF 0B.1" command at the end of the Ext-Interrupt-function?
:=Or other suggestions ?
___________________________
This message was ported from CCS's old forum
Original Post ID: 8842
Frank B.
Guest







Re: Problem with external interrupt
PostPosted: Wed Nov 13, 2002 10:01 am     Reply with quote

Your suggestion to put

#asm
BCF 0x0A,3
BCF 0x0A,4
GOTO ISR_ADDRESS
#endasm

at the end of the interrupt-function works fine -> good idea

Thanks
Frank



:=Why are you waiting for the level to go back high in the interrupt? Typically interrupts should be very short with no delays or conditional loops. But to answer your question, you can write your own interrupt handler (#int_global I believe) to allow more control over the process. Or you can do a couple of tricks that are easier but may require attention in the future. Here is the way I do it:
:=
:=#define ISR_ADDRESS 0x28 // Note that you will have to find this value in the listing file change it and recompile
:=
:=#int_ext
:=ext_isr()
:={
:=INTCON.RBIF = 0;
:=do
:= {
:= ...
:= }
:=while (!(PORTB & 0x01)); // do while INT-Pin is low
:=}
:=
:=Basically the asm code causes the program to avoid the normal exit from the isr. The value of the goto in my code is the same as the one generated by the compiler. You are basically rewriting the code already there with the exception of the clearing of the flag. Alternatively, you could goto the start of the checking of the flag bits which could reduce interrupt latency caused from restoring the registers and then getting an intterrupt again only to have to store the registers again.
:=
:=Regards,
:=Mark
:=
:=:=Hi,
:=:=
:=:=I'm using the external interrupt on RB0 for diffrent external devices. Because the interrupt-triggering is only on edges (in my case falling edges), my code looks like:
:=:=
:=:=#int_ext
:=:=ext_isr()
:=:={
:=:=do
:=:= {
:=:= ...
:=:= }
:=:=while (!(PORTB & 0x01)); // do while INT-Pin is low
:=:=}
:=:=
:=:=Now it seems that the PIC sometimes doesn't recognizes the falling edges. The result is, that the interrupt will then never occur again because the RB0 is steadily low.
:=:=
:=:=The assembler code for the end of the int-function is:
:=:=.................... while (!(PORTB & 0x01)); // do while INT-Pin is low
:=:=0350: MOVF 06,W
:=:=0351: ANDLW 01
:=:=0352: XORLW 00
:=:=0353: BTFSC 03.2
:=:=0354: GOTO 20C
:=:=0355: BCF 0B.1
:=:=0356: BCF 0A.3
:=:=0357: BCF 0A.4
:=:=0358: GOTO 028
:=:=.................... }
:=:=
:=:=If the next falling edge occur when the PIC is between line 350 and 355, the recognition of the edge (INTF) will be erased by the "BCF 0B.1" command. It is just a question of time.
:=:=
:=:=I think the best would be to do the clear of the INTF before the "while" command.
:=:=
:=:=Question:
:=:=how can I instruct the compiler not to generate this "BCF 0B.1" command at the end of the Ext-Interrupt-function?
:=:=Or other suggestions ?
___________________________
This message was ported from CCS's old forum
Original Post ID: 8847
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group