View previous topic :: View next topic |
Author |
Message |
deepakomanna
Joined: 06 Mar 2007 Posts: 92 Location: Pune,India
|
clear_ interrupt() query |
Posted: Thu Sep 27, 2007 10:34 pm |
|
|
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
|
Re: clear_ interrupt() query |
Posted: Fri Sep 28, 2007 1:49 am |
|
|
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
|
clear_ interrupt() query |
Posted: Fri Sep 28, 2007 5:14 am |
|
|
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
|
|
Posted: Fri Sep 28, 2007 6:21 am |
|
|
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
|
|
Posted: Fri Sep 28, 2007 11:02 am |
|
|
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. |
|
|
|