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.

Period calculation with PIC18 using C18

Status
Not open for further replies.

Anthony_87

Newbie level 4
Joined
Feb 25, 2010
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,330
Dear all,

I'm using a PICDEM USB mounted with PIC18F4550 and I'm using the C18 compiler. I
want to measure a certain period of time at one of the PIC's inputs, lets say between a falling edge and a rising edge. so what i need to do is to store the value of a "timer" at the falling edge moment and store it again at the rising edge moment and do the comparison, but how to write it in C18 with all timer configuration and stuff !??

Thanks in advance

Best Regards
 

May be you should use capture/compare module. It used to be available in PIC16 devices, not sure about PIC18.
 

with capture/compare module? sure,
something like this:
input = CCP1 pin on my 2550 it was RC2
Code:
#define input	PORTCbits.RC2
unsigned int getsize(){
	//configuracion previa
	T1CON=0b10110000;	//div 1:8 16 bits
	TMR1H=0;
	TMR1L=0;
	while(!input);//wait the 0...
	T1CONbits.TMR1ON=1;
		CCP1CON=0b0101;	//search rising
		PIR1bits.CCP1IF=0; //lost a us
		while(!PIR1bits.CCP1IF);// here!
		CCP1CON=0b0000;
		//read result
		return (CCPR1H*0x100)+ CCPR1L;
}

you could search the falling edge by setting CCP1CON to 0b0100 (as said on datasheet) but this is how i made it... change or set the Timer prescaler to a more suitable value (for your app)

hope it helps
 

    Anthony_87

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top