View previous topic :: View next topic |
Author |
Message |
phabib
Joined: 11 Jan 2007 Posts: 2 Location: Mtn View CA
|
Event counting on PIC18F6722 |
Posted: Thu Jan 11, 2007 7:45 pm |
|
|
I need to measure a tach signal. I have it wired to C2, which is a ECCP input. I think I should be able to use that to get counts but I'm not sure how to do that.
I get the impression that I need to set up the ECCP to count mode, reset the timer, come back after a known period of time, and read the counter, then reset the timer and do it again.
Am I on the right track? Is there any demo code of either doing what I described or doing the right thing if I'm not on the right track?
Thanks. |
|
![](templates/subSilver/images/spacer.gif) |
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Fri Jan 12, 2007 8:47 am |
|
|
Just a thought, I'd try to use some binary up counters so that your not getting sooooo many interrupts from the count.
A couple cascaded will divide the count.
This reduces the granularity.
Do you know what this is used for or more specification that are required?
Last edited by treitmey on Fri Jan 12, 2007 8:50 am; edited 1 time in total |
|
![](templates/subSilver/images/spacer.gif) |
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Fri Jan 12, 2007 8:50 am |
|
|
Quote: |
Am I on the right track? Is there any demo code of either doing what I described or doing the right thing if I'm not on the right track?
|
Already you have a code -just to start-
See the EX_FREQC.C (in the Examples Folder) it uses Timer1 as counter in
External Clock Mode.
Humberto |
|
![](templates/subSilver/images/spacer.gif) |
phabib
Joined: 11 Jan 2007 Posts: 2 Location: Mtn View CA
|
|
Posted: Tue Jan 16, 2007 2:54 pm |
|
|
Thanks for the responses. The example show what I need, but I can't afford to just do nothing but run in a tight loop. I think I'll need to have some sort of interrupt routine instead.
I'm not sure about the best way to do this.
Do I set up an appropriately sized divider on my C2 pin resulting in an interrupt when I have that many cycles and then check the elapsed time since I started counting, or do I need to watch pin C2 and increment it at every one of my timer tick interrupts and see what the count is every regular amount of time?
I'm sure this type of thing is regularly done on PICs but I've never done it before.
My maximum number of ticks per second will be less than 200 and I have timer tick interrupt that happens 100 times per second right now. |
|
![](templates/subSilver/images/spacer.gif) |
|