Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

CCP module pic18f2550 +CCS

Status
Not open for further replies.

nicko-391

Member level 2
Joined
Dec 8, 2010
Messages
42
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Sri Lanka
Activity points
1,542
I want to measure pulse width of a signal.I wrote this.but It always gives constant pulse width whether frequency is changed.What is the wrong with this?


#include <18f2550.h>
#include <math.h>
#use delay(clock=8000000)
#fuses HSPLL,NOWDT,NOPROTECT,BROWNOUT, PUT, NOLVP,NODEBUG,USBDIV,CPUDIV1,VREGEN
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,errors)
static unsigned int8 x,y,ex;
static float duration;
static char vt[5];
static int1 got_RE,got_P,display;

#INT_CCP1
void detect(){
disable_interrupts(global);

if(got_RE){

x=ccp_1;
setup_CCP1(CCP_CAPTURE_FE);
got_RE=FALSE;
printf("\r%d\n",x);

}

else{
y=ccp_1;
duration=frexp(ccp_1,&ex);
duration=duration+y;

setup_CCP1(CCP_CAPTURE_RE);
got_RE=TRUE;
printf("\r%d\n",(y-x));
got_P=TRUE;

}

clear_interrupt(INT_CCP1);
enable_interrupts(INT_CCP1);
enable_interrupts(GLOBAL);

}

void main()
{

setup_ccp1(CCP_CAPTURE_RE);
setup_timer_1(T1_EXTERNAL | T1_DIV_BY_2);
enable_interrupts(INT_CCP1);
enable_interrupts(global);
x=0;
y=0;
got_RE=TRUE;
got_P=FALSE;
ccp_1=0;


while(1){

if(got_P){

ccp_1=0;

}

}

}
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top