View previous topic :: View next topic |
Author |
Message |
marcus.couceiro
Joined: 04 Jan 2012 Posts: 12 Location: Brazil
|
Problem using CCP1 |
Posted: Mon Feb 20, 2012 7:55 pm |
|
|
Gentlemen,
I am trying to measure the period of a known frequency using the following code
Code: |
#include <16F873.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES PUT //Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
int1 interruption=0;
#int_CCP1
void CCP1_interruption()
{
interruption=1;
}
void main()
{
long timer_T1, timer_T2, period;
setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
set_timer1(0);
setup_ccp1(CCP_CAPTURE_RE);
setup_ccp2(CCP_OFF);
enable_interrupts(GLOBAL);
enable_interrupts(INT_CCP1);
clear_interrupt(INT_CCP1);
while(1)
{
if (interruption==1)
{
disable_interrupts(GLOBAL);
timer_T1 = CCP_1;
period = timer_T1-timer_T2;
timer_T2 = timer_T1;
clear_interrupt(INT_CCP1);
interruption=0;
enable_interrupts(GLOBAL);
}
putc(254);putc(1); delay_ms(10);
printf("period: %lu", period);
delay_ms(500);
}
}
|
So far my display gives only 0.0 as readings. Could anyone tell what am I doing wrong?
Thanks, _________________ Marcus Couceiro |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Stygian
Joined: 26 Apr 2011 Posts: 13
|
|
Posted: Mon Feb 27, 2012 8:56 am |
|
|
Hello All!
I don't want to open a new topic so I write here.
My question is simple. I'm using a PIC16F1938.
I want to use the CCP3 and the RS232 at the same time.
How can I disable the CCP3 on port C6 and enable on port B5 ?
Best regards,
Stygian |
|
|
|