PDA

View Full Version : Instant Interrupts and Capture



Andy Wood
- 1st February 2008, 05:31
Hello,

I am currently working on a project and using Darrell's Instant Interrupts with the CCP1 module in capture mode. I am measuring the period (frequency) of signals in the range 25 to 4000Hz.

Everything is working nearly as it should however I am having a minor issue which i can't get my brain around at present. At low input frequencies the system is very responsive. As the input frequency increases, the program loop time (and hence system responsiveness) slows down because of the extra time needed to service the extra interrupts generated by the CCP module - this makes sense. What I am trying to achieve is to only take, say, one or two samples per loop. This should make my program loop time the same regardless of input frequency.

I thought I could achieve one sample per loop by adding the line:

@ INT_DISABLE CCP1_INT

as the last line in my interrupt handler and then enabling the interrupt again at the start of the loop by adding:

@ INT_ENABLE CCP1_INT

(This assumes, of course, the loop time is longer than the longest period to be measured.) This idea didn't work - the captured values are not consistent. I feel there is something I am missing here.

I really only need to sample the input signal once (or maybe twice) per program loop however it must be interrupt driven as there are many calculations and other operations to be done at the same time. I tried other methods (Pulsin, using CCP with a loop to test the flag bit etc.) but they are too slow.

I think I am going about this all the wrong way and would appreciate any input.

Thanks,

Andy

Darrel Taylor
- 1st February 2008, 06:36
It's really hard to say without more info ...

Does it look anything like Bruce's capture example, here ?
http://www.picbasic.co.uk/forum/showthread.php?p=23401#post23401

The second example in that post.
<br>