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

MEASURE THE PERIOD OF A SIGNAL

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







MEASURE THE PERIOD OF A SIGNAL
PostPosted: Wed Oct 27, 2004 6:25 am     Reply with quote

I am working with a PIC16F877 and a oscilator of 20 MHz.

I need to measure the period of a square wave every 0.5 seconds, so I try to use the RTCC (76 interruptions per second, which I have to use in the programme) and enable the CCP1 interruption every 0.5 seconds, disabling it when the period is obtained:

...
set_rtcc(0);
setup_counters(RTCC_INTERNAL, RTCC_DIV_256);
enable_interrupts(INT_RTCC);
setup_ccp1(CCP_CAPTURE_RE);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);
enable_interrupts(GLOBAL);
...
#int_ccp1 void velocidad() {
long peraux;
disable_interrupts(GLOBAL);
if(!segundo){
//first rising edge
subida1 = CCP_1;
segundo=1;
}
else{
//second rising edge
subida2 = CCP_1;
peraux = subida2 - subida1;
segundo=0;
//Global int variables
auxi=peraux;
valor=peraux>>8;
}
disable_interrupts(INT_CCP1);
enable_interrupts(GLOBAL);
}

The period is obtained correctly but the PIC resets itself in 5 or 6 minutes time.

I didnīt use Watchdog, the stack used 4 of its 8 positions, RAM is used at 72 % (worst case) and ROM at 23 %.

Does anybody know why it happens? I can say that if I donīt enable CCP1 the PIC works properly.

Any better idea to implement this application?

Thanks in advance.
Guest








PostPosted: Wed Oct 27, 2004 6:48 am     Reply with quote

I know something that happened: your CAPS LOCK was inadvertently activated during the typing of the topic title... Wink
Mark



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

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

PostPosted: Wed Oct 27, 2004 6:57 am     Reply with quote

Don't monkey around with the interrupt enable inside of the int. Ints are automatically enabled/disabled. You are enabling the int during and int. If another int occurs, you are going to trash the temp storage.
Juan Pablo
Guest







Measuring the frequency of a signal
PostPosted: Thu Oct 28, 2004 5:27 am     Reply with quote

I have placed the next code in main function:

...
if(activar){
enable_interrupts(INT_CCP1);
activar=0;
}
else{
if(convertir){
disable_interrupts(INT_CCP1);
convertir=0;
}
}
...

And it seems that the problem has disappeared.

Thanks for your help!!!!
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