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.

About PIC18F25K22 CCP function.

Status
Not open for further replies.

maniac84

Full Member level 6
Joined
Mar 4, 2012
Messages
337
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Activity points
3,661
Hi guys,

From the datasheet of the PIC18F25K22, we know that this mcu have the CCP function which we can capture and record the interval time between two signal from the same input.
I want to use the CCPR4 to record the time. May I know what is the maximum time interval I can get using this CCP function? I mean how long those it takes to run from value 0x0000 to 0xFFFF? This is because the interval time between my two input signal is more than 20 seconds. Is it suitable to use this CCP function?
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
20,800
Helped
4,496
Reputation
9,004
Reaction score
4,563
Trophy points
1,393
Activity points
137,345
Hi,

I'm not experienced with PICs, but it will be similar to other microcontrollers.

The capture function uses a timer/counter and captures it's value at the capture event.

So the resolution and the max time depends on the timer/counter setup. Especially the counter input clock frequency, prescaler and counter bit width.

Example: Input frequency 8MHz, prescaler 1024, 16 bit counter.
Max time = 2^16 * 1024 / 8MHz = about 8s.
If you need more than 20s you could increase prescaler value, decrease input frequency, increase bitwidth.
If this way 20V is not possible, then it is an easy interrupt task to count every counter overflow.

For every timer overflow just add 65536 to your timing value ( for a 16 bit counter).


Klaus
 

maniac84

Full Member level 6
Joined
Mar 4, 2012
Messages
337
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Activity points
3,661
Hi,

I'm not experienced with PICs, but it will be similar to other microcontrollers.

The capture function uses a timer/counter and captures it's value at the capture event.

So the resolution and the max time depends on the timer/counter setup. Especially the counter input clock frequency, prescaler and counter bit width.

Example: Input frequency 8MHz, prescaler 1024, 16 bit counter.
Max time = 2^16 * 1024 / 8MHz = about 8s.
If you need more than 20s you could increase prescaler value, decrease input frequency, increase bitwidth.
If this way 20V is not possible, then it is an easy interrupt task to count every counter overflow.

For every timer overflow just add 65536 to your timing value ( for a 16 bit counter).


Klaus

Thanks for the opinion sir.
Yup. I have configure my device timer so that it can work for the CCP.
But when I compare with the actual interval time I get from my stop watch, seems like the interval time I get from the PIC will be around 0.8 sec slower. How do we make the time from the PIC accurate?
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
20,800
Helped
4,496
Reputation
9,004
Reaction score
4,563
Trophy points
1,393
Activity points
137,345
Hi,

the time of the PIC is as precise as it´s clock source. Use a crystal, then you are on the safe side.

The capture feature is very preicise, it´s precision should be very close to +/- 0.5 counter clock ticks be.

If you encounter larger errors, then show us your code.

Klaus
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top