CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Frequency Measuring using IOC

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
marcusayoung



Joined: 03 Jun 2009
Posts: 28

View user's profile Send private message

Frequency Measuring using IOC
PostPosted: Wed Sep 23, 2009 7:08 am     Reply with quote

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: 126
Location: Bombay, India

View user's profile Send private message Visit poster's website

PostPosted: Wed Sep 23, 2009 7:36 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Sep 23, 2009 10:59 am     Reply with quote

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







PostPosted: Wed Sep 23, 2009 2:46 pm     Reply with quote

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








PostPosted: Wed Sep 23, 2009 7:20 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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