Now I want to catch some edges with a PIC...

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Now I want to catch some edges with a PIC...

Post by zener »

I thought I would start a new thread since I hate those ones that go on and on and....

But this is really a continuation to my previous questions.

I am using the PIC18F27J13 and I want to catch some edges that are coming in at PIN 12/RC1/CCP8 which is a "Capture/Compare/PWM input/output".

I want to catch rising and falling edges and measure the time between each. So I am thinking that it will go something like this:

Set up a timer and get it running, like timer 1
Configure port C as an input for CCP8
Set for rising edge interrupt
When I get that interrupt save value of timer 1
change to falling edge
When I get that interrupt save value of timer 1
change to rising edge,
etc, etc

Then in my main loop do the math on the difference in the readings.

How does that sound?

I work with a guy who does Freescale code and he says the part he uses saves the timer value automatically so there is no interrupt latency. Can the PIC do this? I am guessing no but I don't know for sure.

Thanks

User avatar
opossum
 
Posts: 636
Joined: Fri Oct 26, 2007 12:42 am

Re: Now I want to catch some edges with a PIC...

Post by opossum »

In the ISR...
  • Calculate the difference between current capture and the previous - put in FIFO
  • Save the current capture for use next time
  • Change capture edge
  • Clear CCP interrupt flag
  • Return from ISR
That works. I have done it on 16F and 18F series parts.

The capture register holds the value of the timer when the edge occurred, so interrupt latency and jitter is much less important.

There is a method to do 24 bit capture if you need more range without resolution loss.

User avatar
zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: Now I want to catch some edges with a PIC...

Post by zener »

Ahhh, capture register. So that is the same as Freescale then. So that all makes sense, and I know what a FIFO is. But in terms of my program how do I best implement that? I am guessing make an array and use a pointer. And I finally found IPR4 for the CCP interrupt priority.

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”