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 CCS Technical Support

clear_ interrupt() query

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
deepakomanna



Joined: 06 Mar 2007
Posts: 92
Location: Pune,India

View user's profile Send private message AIM Address Yahoo Messenger

clear_ interrupt() query
PostPosted: Thu Sep 27, 2007 10:34 pm     Reply with quote

Dear Sir,
here i am using 16f684, MPLAB 7.5 Ver. & CCS PCM C Compiler, Version 3.249, 34534.
it is necessary to define these statements,
Quote:

CLEAR_INTERRUPT(INT_TIMER0);
CLEAR_INTERRUPT(INT_TIMER1);

in the ISR?
but i checked .lst file in this i saw the statements which will clear interrupt flag while returning,
Quote:

#INT_TIMER0
.................... void Timer0_isr()
.................... {

}
0166: BCF 0B.2
0167: BCF 0A.3
0168: GOTO 02B

#INT_TIMER1
....................void Timer1_isr()
...................{

}
016B: BCF 0C.0
016C: BCF 0A.3
016D: GOTO 02B


Then also it is necessary to define clear_ interrupt().... ?
Also at the POR i defined set_timer0(240);....2ms overflow for timer0
then in the timer0 ISR it is necessary to define again set_timer0(240);
_________________
Thank You,
With Best Regards,
Deepak.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

Re: clear_ interrupt() query
PostPosted: Fri Sep 28, 2007 1:49 am     Reply with quote

deepakomanna wrote:
it is necessary to define these statements,
Quote:

CLEAR_INTERRUPT(INT_TIMER0);
CLEAR_INTERRUPT(INT_TIMER1);

in the ISR?
From the CCS manual
Quote:
#int_xxx This directive specifies that the following function should be called whenever the xxx interrupt is triggered. If the compiler generated interrupt dispatcher is used, the compiler will take care of clearing the interrupt flag bits.
Using the CCS interrupt handler it will clear the interrupts for you.

Quote:
Also at the POR i defined set_timer0(240);....2ms overflow for timer0
then in the timer0 ISR it is necessary to define again set_timer0(240);
With set_timer0() you are modifying the actual counter value, this value will increase at every next counter tick. Timer0 has no special hardware to 'remember' your value, so yes, you will have to set the value again everytime in the interrupt service routine. Better: use timer2 which has an additional period register designed for your purpose and will 'remember' your setting. The period value is set using the setup_timer_2() function.
deepakomanna



Joined: 06 Mar 2007
Posts: 92
Location: Pune,India

View user's profile Send private message AIM Address Yahoo Messenger

clear_ interrupt() query
PostPosted: Fri Sep 28, 2007 5:14 am     Reply with quote

Thanks sir,
But i am not understand the meaning of,
Quote:
If the compiler generated interrupt dispatcher is used

plz tell me in detail about "compiler generated interrupt dispatcher "
_________________
Thank You,
With Best Regards,
Deepak.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Sep 28, 2007 6:21 am     Reply with quote

In the PIC processor all interrupts are jumping to the same hardware address 0x0008 (or 0x0008 and 0x0018 if you are using high priority interrupts). An interrupt dispatcher is a software routine that checks all interrupt flags to discover which interrupt caused the interrupt and then calls the corresponding Interrupt Service Routine (ISR), i.e. your interrupt function.

In many compilers like the C18 you have to write the interrupt dispatcher yourself but in CCS if you use the #int_xxx keywords the compiler will generate the dispatcher for you. The CCS dispatcher does a few extra things like saving all processor registers before the ISR is called, clearing the interrupt and restoring the processor registers on interrupt exit.

Sometimes it is desired to write your own interrupt dispatcher, for example because you don't want all the register saving overhead of the CCS dispatcher. In those rare cases you can use #int_global which has no dispatcher. Be careful though, writing your own handler is not easy because it is easy to overlook a variable that is not saved/restored.
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Fri Sep 28, 2007 11:02 am     Reply with quote

If the issue is why is there the need for a clear interrupt function when the compiler generates one anyway upon calling the interrupt service routine (ISR) the answer is for timers you often want to time between events. The hardware timer could have already triggered an interrupt before you want to begin timing in which case the ISR is called immediately instead of after the expected time has elapsed. It is necessary to clear the interrupt before enabling the timer and resetting the counter that way the first interrupt occurs with the same elapsed time as every subsequent interrupt.
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