Frequency counter

Go To Last Post
13 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

Is it there some type of measure where measuring is not based on waiting of 1 sec and then display value from counter (timer)? Now I use two timers.

I ask becouse I have counter wich work nice from 1 HZ to 5 Mhz but I need to measure more accurate on low frequency for example now is 1,2 .. HZ, but I need 1.1Hz, 1.2Hz,...1,9Hz,2Hz.., becouse I need measure RPM (Hz*sec )and there is to big hole between two measuring of RPM 1Hz=60Hz, 2Hz=120RPM! Minimum step of 5 RPM is what will be ok on low RPM or even 10Hz.

With my system I will must wait 10 sec. for 0.1 Hz step but, 10 sec. is to long for measure RPM of el. motor becouse in 10 sec. RPM can go from 100RPM to 6000RPM!

Any ideas how to make it?

Thanks in advance,

gpugelni

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You could measure period of signal and then
compute its reciprocal (=frequency).

Usually one measures the time for some periods or
averages over several measurements.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

Do you mean on the duration time of complete period like sine from 0 to 360 ?

regards

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I use the input capture feature to measure period - the time between each event. since you get a value each revolution, you need to 'smooth' the value to get a stable reading. There's been a bit of discussion about this on the forum previously.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Instead of counting for a constant length of time, you can count a fixed number of edges.

Or, you may try multiplying the frequency of the input signal, as I'm doing in my current project.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for replies,

Kartman,for input capture feature to measure period I must use ICP1 port (PD.4 on Atmega 128) only, or I need to use more inputs? I ask becouse if I must free some ports if it is needed.

Thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi.

You should create an int variable, that on each overflow of your timer the variable will be incremeted, so in the end of your period measurement, you multiple this variable for the seconds that each timer overflow is, in seconds (probilby an constant float). So for the multiplication result's, you will need an float variable, and in the end you get an frequency with a precision of a float variable.

Bruno

Regards,

Bruno Muswieck

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman, wich post that talk about reading the frequency and smooth the value?

Thanks.

Regards,

Bruno Muswieck

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

So for the multiplication result's, you will need an float variable,

Why? In the end, we are measuring in discrete increments, AVR timer ticks or slower. We are (directly or indirectly) counting these distinct integer values. Even if fractions of something are the final result, it can be implied decimal point. Of course the float has a wider range which may be important in some apps. But if the range is knowin a 32-bit int has more precision than the 22/23 bit float mantissa.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok ,

I have free PD.4(OCP1) and PD.6(INT1) ports on Atmega128, which of it (OCP1 or INT1) I should use for faster measure 1.6 HZ (fast = 0,5-1 sec.) , and which procedure I should use for it? :?

a) OCP
or
b) INT

Thanks in advance,

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Of course the float has a wider range which may be important in some apps.

His case, he needs to measure 1.6 Hz, so he could do by using a float variable or use some multiplications to use integer.

Quote:

a) OCP
or
b) INT

My advise is to use INT. But you can always use differents ways to get the same result.

Bruno

Regards,

Bruno Muswieck

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My advice is none of the above. Use Tn for timer-as-couter, and tie the signal to ICPn. Depending on the rate, shift the processing from one signal to the other.

If ICP pin is used, some AVR models can trigger from analog comparator.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

We have two techinques:

1/measure pulses per unit time (int and a timer)
or
2/ reciprocal method - using the input capture.

Both methods have their strengths and weaknesses - the first method trades response time for resolution, the second gives you plenty of samples.I use the second method as I do fuel injection and need to estimate timing related to angle.

As to which technique to choose depends on what you're trying to achieve.

As for searching for previous posts - I have trouble with the search engine of this site - maybe someone else can offer some guidance on how to search?

Floating point calcs should not be required.