View previous topic :: View next topic |
Author |
Message |
iw2nzm
Joined: 23 Feb 2007 Posts: 55
|
Why int_ccp1 doesn't fire? |
Posted: Sat Apr 14, 2007 9:26 am |
|
|
Hi,
this is my code:
Code: |
#int_CCP1
void CCP1_isr(void) {
output_toggle(PIN_A1)
}
void main() {
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_CLK_OUT);
setup_ccp1(CCP_COMPARE_RESET_TIMER);
CCP_1 = 32678;
for (;;) {}
}
|
On timer1 osc pins is connected a 32768 Hz xtal. If I catch the timer1 overflow interrupt it works fine (an int every 2 sec of course).
Why the ccp1 interrupt doesn't fire?
Thanks
Marco / iw2nzm |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Apr 14, 2007 11:44 am |
|
|
If you want an interrupt service routine to execute, you must enable
the INT_CCP1 interrupt, and also enable GLOBAL interrupts.
This can be done by adding two lines of code. |
|
|
iw2nzm
Joined: 23 Feb 2007 Posts: 55
|
|
Posted: Sat Apr 14, 2007 11:55 am |
|
|
PCM programmer wrote: | If you want an interrupt service routine to execute, you must enable
the INT_CCP1 interrupt, and also enable GLOBAL interrupts.
This can be done by adding two lines of code. |
You're right, obiouvsly.
I forgot to add them!
.
.
.
.
Added.
But the interrupt service routine is not still executed.
Thanks
Marco / iw2nzm |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Apr 14, 2007 12:19 pm |
|
|
I can test it tomorrow in hardware. If no one else helps you before
then, at least you'll get an answer tomorrow. |
|
|
Kenny
Joined: 07 Sep 2003 Posts: 173 Location: Australia
|
Re: Why int_ccp1 doesn't fire? |
Posted: Sat Apr 14, 2007 3:39 pm |
|
|
iw2nzm wrote: |
Code: |
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_CLK_OUT);
setup_ccp1(CCP_COMPARE_RESET_TIMER);
|
|
I can't test it today either but noticed the following:
Edited: T1_CLK_OUT enables the oscillator.
I think that for compare that the external clock input to timer 1
needs to be synchronised with the pic's internal clock.
So try
setup_timer_1(T1_EXTERNAL_SYNC|T1_DIV_BY_1|T1_CLK_OUT); |
|
|
iw2nzm
Joined: 23 Feb 2007 Posts: 55
|
Re: Why int_ccp1 doesn't fire? |
Posted: Sun Apr 15, 2007 5:01 am |
|
|
[quote="Kenny"] iw2nzm wrote: |
So try
setup_timer_1(T1_EXTERNAL_SYNC|T1_DIV_BY_1|T1_CLK_OUT); |
Yeah!
I thank you very much!
I'm using timer1 with ext clock and CCP1 as an RTC. I think it should be more accurate than using timer1 overflow interrupt and reload tmr1 value, should it?
However, I read somewhere that the external synchronization of tmr1 is less accurate than if the clock is not synchronized. Is it true?
Thanks again
Marco / iw2nzm |
|
|
Kenny
Joined: 07 Sep 2003 Posts: 173 Location: Australia
|
Re: Why int_ccp1 doesn't fire? |
Posted: Sun Apr 15, 2007 5:44 am |
|
|
Glad that you got it working.
[quote="iw2nzm"][quote="Kenny"] iw2nzm wrote: |
I'm using timer1 with ext clock and CCP1 as an RTC. I think it should be more accurate than using timer1 overflow interrupt and reload tmr1 value, should it?
However, I read somewhere that the external synchronization of tmr1 is less accurate than if the clock is not synchronized. Is it true?
|
Not sure about that, I'll leave that one to the 'big guns' on this board.
I would have thought that the latter was best.
What exactly do you want to achieve? An accurate low frequency square wave output?
Cheers
Ken |
|
|
iw2nzm
Joined: 23 Feb 2007 Posts: 55
|
Re: Why int_ccp1 doesn't fire? |
Posted: Sun Apr 15, 2007 6:37 am |
|
|
Kenny wrote: |
What exactly do you want to achieve? An accurate low frequency square wave output?
|
Yes, an accurate 1 Hz interrupt for a software RTC.
Bye
Marco / iw2nzm |
|
|
Kenny
Joined: 07 Sep 2003 Posts: 173 Location: Australia
|
|
Posted: Sun Apr 15, 2007 6:07 pm |
|
|
I think that the only advantage in using the timer 1 oscillator over the main one is that timer 1 can keep running in sleep mode (useful in data logging applications).
The down side is that the sync circuit needed for the compare mode is not in operation in sleep mode! Also the compare interrupt will not wake the pic. So would need to have timer 1 running asynchronously and have the overflow wake the pic.
If not needing sleep mode the main clock would be better. Neutone and ckielstra have posted neat code for a timer based RTC.
Last edited by Kenny on Thu Apr 19, 2007 7:39 pm; edited 1 time in total |
|
|
iw2nzm
Joined: 23 Feb 2007 Posts: 55
|
|
Posted: Mon Apr 16, 2007 3:04 am |
|
|
Kenny wrote: | If not needing sleep mode the internal clock would be better. Neutone and ckielstra have posted neat code for a timer based RTC. |
Well, I don't need sleep mode. I checked out their code and it's smart!
But in my system (timer1 with ext 32768 xtal and ccp1) I get just one interrupt per second.
In the other way there are a lot of interrupts per second and if the MCU is doing something other I guess it's not an advantage.
However, once the whole code is complete I may try both ways and report the behavior.
Bye
Marco/ iw2nzm |
|
|
|