|
|
View previous topic :: View next topic |
Author |
Message |
marcusayoung
Joined: 03 Jun 2009 Posts: 28
|
Frequency Measuring using IOC |
Posted: Wed Sep 23, 2009 7:08 am |
|
|
Hi Folks,
I'm interested in measuring square wave frequency with a 12F683. I've seen other posts about this using capture on a CCP module, but is there another way with, say, IOC (i'm just thinking out loud here, as my CCP would be doing something else, and i need to find another way to measure frequency)?
I'm thinking along the lines of sampling an edge using IOC, and while servicing the initial request, start a timer. Then, service the second request and stop the timer, using the generated constant to define the frequency. Conceivable, or a waste of time? |
|
|
Jerson
Joined: 31 Jul 2009 Posts: 125 Location: Bombay, India
|
|
Posted: Wed Sep 23, 2009 7:36 am |
|
|
I would say it is practical, but it will not be as fast as when you use the CCP module to do this. Think of the overhead in code that is needed to take the interrupt, save registers, check the state of the pin and then count. It may not be obvious when you code in C, but take a look at the LST file. Definitely a lot slower than the hardware method. _________________ Regards
Jerson Fernandes |
|
|
marcusayoung
Joined: 03 Jun 2009 Posts: 28
|
|
Posted: Wed Sep 23, 2009 10:59 am |
|
|
More info: range of frequencies i am interested in measuring are 8kHz-100kHz.
The constant that gets generated will be used to flash an LED and gets stored in memory each time the frequency changes.
Still good to go on this?? Its hard for me to tell if 100kHz is too fast for the overhead involved here. |
|
|
Ttelmah Guest
|
|
Posted: Wed Sep 23, 2009 2:46 pm |
|
|
Much too fast....
Remember multiple things though:
1) You can use an interrupt _flag_, without using an interrupt handler. Reduces overhead to a handful of instructions.
2) A pulse train at 100KHz, 'best case' (50% duty cycle), only has 5uSec between successive edges, if using IOC. At the maximum clock rate for the chip (20MHz - 5MIPS), implies just 25 instruction times between changes. The typical interrupt 'overhead', to just get into, and out of the handler, is in the order of 60 instructions in total....
3) You can reduce this overhead, by only saving the registers really needed etc., coding as 'INT_GLOBAL'. Probably drop it to below 20 instructions in total.
4) The IOC handler, will involve extra instructions to record the count, and read the port.
Doing everything very carefully, by polling the flag, and not calling a handler, it is 'achievable', but borderline.
Best Wishes |
|
|
Guest
|
|
Posted: Wed Sep 23, 2009 7:20 pm |
|
|
You need external counter chips - then detect overflow and calc based on that - reset external and count again.
You'll never get great resolution though. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|