View previous topic :: View next topic |
Author |
Message |
Juan Pablo Guest
|
MEASURE THE PERIOD OF A SIGNAL |
Posted: Wed Oct 27, 2004 6:25 am |
|
|
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
|
|
Posted: Wed Oct 27, 2004 6:48 am |
|
|
I know something that happened: your CAPS LOCK was inadvertently activated during the typing of the topic title... |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Oct 27, 2004 6:57 am |
|
|
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 |
Posted: Thu Oct 28, 2004 5:27 am |
|
|
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!!!! |
|
|
|