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

Why int_ccp1 doesn't fire?

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



Joined: 23 Feb 2007
Posts: 55

View user's profile Send private message

Why int_ccp1 doesn't fire?
PostPosted: Sat Apr 14, 2007 9:26 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Apr 14, 2007 11:44 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Apr 14, 2007 11:55 am     Reply with quote

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.


Shocked
You're right, obiouvsly.
I forgot to add them!
.
.
.
.
Added.
But the interrupt service routine is not still executed. Confused

Thanks
Marco / iw2nzm
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Apr 14, 2007 12:19 pm     Reply with quote

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

View user's profile Send private message

Re: Why int_ccp1 doesn't fire?
PostPosted: Sat Apr 14, 2007 3:39 pm     Reply with quote

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

View user's profile Send private message

Re: Why int_ccp1 doesn't fire?
PostPosted: Sun Apr 15, 2007 5:01 am     Reply with quote

[quote="Kenny"]
iw2nzm wrote:

So try
setup_timer_1(T1_EXTERNAL_SYNC|T1_DIV_BY_1|T1_CLK_OUT);


Yeah! Very Happy

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

View user's profile Send private message

Re: Why int_ccp1 doesn't fire?
PostPosted: Sun Apr 15, 2007 5:44 am     Reply with quote

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

View user's profile Send private message

Re: Why int_ccp1 doesn't fire?
PostPosted: Sun Apr 15, 2007 6:37 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Apr 15, 2007 6:07 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Apr 16, 2007 3:04 am     Reply with quote

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
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