CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

CCP question

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
oxxyfx



Joined: 24 May 2007
Posts: 97

View user's profile Send private message

CCP question
PostPosted: Fri May 20, 2011 2:08 pm     Reply with quote

Hello,

I am working with a PIC16F886 and trying to capture a set of pulses. I am looking at the help on the CCP and I see this:

Code:

Example Code:
 
 
#int_ccp1
 
 
void isr()
 
 
{
 
 
     rise = CCP_1;
 //CCP_1 is the time the pulse went high
 
     fall = CCP_2;
 //CCP_2 is the time the pulse went low
 
     pulse_width = fall - rise;
 //pulse width
 
}
 
 
..
 
 
setup_ccp1(CCP_CAPTURE_RE);
 // Configure CCP1 to capture rise
 
setup_ccp2(CCP_CAPTURE_FE);
 // Configure CCP2 to capture fall
 


Now, where I am confused is that the 16F886 has 2 CCP modules, 1 and 2.

If I do the above code in my testing, will the "fall" capture the falling edge from the CCP1 or from the CCP2 module?

I have the incoming pulse connected to CCP1 only.

Thank you,
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri May 20, 2011 2:24 pm     Reply with quote

You need the input signal to be connected to both pins:
Quote:
/////////////////////////////////////////////////////////////////////////
//// EX_CCPMP.C ////
//// ////
//// This program will show how to use the built in CCP to ////
//// measure a pulse width. ////
//// ////
//// Configure the CCS prototype card as follows: ////
//// Connect a pulse generator to pin C2 and pin C1 ////
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Fri May 20, 2011 2:28 pm     Reply with quote

The example you have uses both CCP's, with the signal connected to both. One is set to capture the rising edge (CCP1), and the other the falling edge (CCP2). On the rising edge you get an interrupt (INT_CCP1), so you can then calculate the pulse _width_ from the difference between the two captured values.
The example won't work without the signal connected to both inputs.

Questions for you are:
What frequency is your signal?.
What do you actually want to measure (pulse width, repetition rate etc..).

If you only want the rate, you can use either CCP module.
You can do width with just one module, but _only_ if the minimum width is fairly long (long enough to get into an interrupt on one edge, store the value, reprogram the module for the other edge, and get out again).
For widths smaller than this, the 'two CCP' solution is easier.

Best Wishes
oxxyfx



Joined: 24 May 2007
Posts: 97

View user's profile Send private message

PostPosted: Fri May 20, 2011 6:58 pm     Reply with quote

Hello,

Thank you, that's what I thought, but that was not clarified in the CCS C Compiler Help file. Indeed the program example clears it - but the help file is confusing.

The Pulse I am measuring is a composite PPM signal coming out from the trainer port of an RC receiver. It has all the 8 RC channel signals on one pin something like on the scope capture on this link:

http://www.radrotary.com/OMMrxconverter/OMMrxconverter.html

I will need to count how many channels are there, convert each pulse length value in a serial data and send it out as a serial string before the next cycle begins. This is an on/off project of mine - I always come back with questions about it when I have time to work on this.

The serial data will be sent over to a receiver wireless, it will be decoded on the other side to drive the servos. Technically the same as an RC link - just resolved with some pic processors and not on the RC frequency but as serial data.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group