Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Now I want to catch some edges with a PIC...
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

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

by zener on Fri Sep 17, 2010 1:57 pm

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

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

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

by oPossum on Fri Sep 17, 2010 2:04 pm

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.
I am the Possum, and I approve of this message. Sent from MacBook Wheel Sorry for my bad German.
oPossum
 
Posts: 636
Joined: Fri Oct 26, 2007 12:42 am
Location: Michigan, USA

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

by zener on Fri Sep 17, 2010 2:17 pm

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.

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

Please be positive and constructive with your questions and comments.