View previous topic :: View next topic |
Author |
Message |
oxxyfx
Joined: 24 May 2007 Posts: 97
|
CCP question |
Posted: Fri May 20, 2011 2:08 pm |
|
|
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
|
|
Posted: Fri May 20, 2011 2:24 pm |
|
|
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: 19549
|
|
Posted: Fri May 20, 2011 2:28 pm |
|
|
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
|
|
Posted: Fri May 20, 2011 6:58 pm |
|
|
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. |
|
|
|