frequency counter

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

 hi frnds

   

i am using two counters for measuring freuency, one counter for 1 sec generation, another counter for counting pulses,

   

after every one sec interrupt generate.

   

now the problem is after 1 sec it does not give exact value

   

eg.  if i take 10--->10,for 100-->98,for1000--->992,for 10000--->99960

   

why it come like this,plz help?

0 Likes
10 Replies
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

A number of issues involved -

   

 

   

1) Don't use ISR from timer to read counter, it is not a synchronous process.

   

 

   

2) Set timer for 2 sec, 50% duty cycle, and route compare output to the counter

   

enable. When gate is low, for 1 sec, read counter, then update counter

   

to its max value. When gate is high, for 1 sec, counter will be counting. Repeat

   

this cycle in code. You can use Timer compare out and route it to a pin, and set

   

pin to ISR on - edge (of the compare output), to indicate when to read and reload

   

counter.

   

 

   

3) There are row in routes, timer and counter routes, that have synch settings.

   

I have found if I want max count frequency to turn these off. But I suggest ex-

   

periment with these settings.

   

 

   

Regards, Dana.

0 Likes
lock attach
Attachments are accessible only for community members.
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Note, when you read counter you have to subtract it from max count val,

   

to get counts, or Freq, example if a 16 bit counter subtract it from 65535,

   

eg. 2n - 1.

   

 

   

Additionally, if you care about absolute accuracy, use an external clock

   

for PSOC with target accuracy you want to achieve. That controls gate

   

time accuracy, hence precision. PSOC clock is accurate to only 2.5%.

   

 

   

Some ap notes that may be useful, attached.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

i take vc1=12;vc2=13;vc3=153; so frequency come =1006;

   

so, one counter period =1006,another counter period =65535;

   

any changes occur in aboveselecting parameters

   

plz attach eg.code

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Project, ap note, and code -

   

 

   

www.cypress.com/

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

 i dont understand an2283 

   

plz post another example

0 Likes
lock attach
Attachments are accessible only for community members.
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Here is a basic project you can work from. Test F measured is 1.2 Khz, you can change

   

that by changing period and compare value of TestFreq16 in properties window.

   

 

   

Its run on a PSOCeval1, 29466.

   

 

   

Regards Dana.

0 Likes
Anonymous
Not applicable

 thank you very much dana

   

i want to count 1sec pulses, so tell me period value and vc1,vc2,vc3 for test frequ16

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

If the frequency you are measuring is 100 Hz or less you want to consider reciprocal

   

counting technique. If you are referring to counting pulses for 1 sec, in other words

   

a one second gate time, then the project settings for VC1/2/3 already take care of that.

   

 

   

You can use the project for measuring < 100 Hz, and measurement times will be

   

very long. For example if you needed to measure .001 Hertz, then min measuring gate

   

time would be 1000 seconds. Bigger consideration is accuracy. Thats why reciprocal

   

method more appropriate for very low freq signals.

   

 

   

So what is the freq range you are trying to measure, what measurement resolution do

   

you want, and what accuracy ? 3 crucial design questions to answer.

   

 

   

Lastly VC1/2/3 are project dependent. If the reason for these clocks is for gate only, then the

   

product of all the divisors must meet N = Fcpu / Fgate =  VC1 x VC2 x VC3 x Gate timer divisor.

   

So if Fcpu = 24 Mhz, Gate = .5 Hz (1 sec gate), then N = 24000000 / .5 = 48000000. But if you

   

have other project needs you may choose to set VC1/2/3 to other values, and adjust total N

   

with Gate timer divisor.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

 ok tell me about reciprocal type

0 Likes
lock attach
Attachments are accessible only for community members.
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Here is the technique, attached.

   

 

   

Regards, Dana.

0 Likes