Products > Embedded Computing

Strange values while I'm measuring frequency with arduino

<< < (5/6) > >>

mikerj:
Your results suggest you are getting errors in the range of approximately +-50 to +-60 timer counts (assuming 16MHz AVR clock), a little worse at the lower frequencies and a little better at high frequencies.  This suggests a problem with noise on your zero crossing detection.

Another flaw in that code is that it measures the period of only a single cycle before calculating frequency and displaying the result.  This may be appropriate for low frequency signals, but as the signal frequency increases the resolution of your measurement decreases i.e. a few clock cycles error will give a much greater reported frequency error with a high frequency input signal than a low frequency one.  The solution is to average the result over a large number of cycles of the input signal which will reduce the effect of noise induced errors.

Peabody:
I don't see in Gammon's code where he disables the Timer0 millis interrupt.  Something like this:

  TIMSK0 &= ~bit(TOIE0);                   // disable overflow interrupt

If not disabled, that could mess things up about every millisecond.

mikerj:
Timer1 and it's overflow interrupt runs continuously, there is no need to disable them.

Peabody:

--- Quote from: mikerj on April 26, 2019, 02:06:53 pm ---Timer1 and it's overflow interrupt runs continuously, there is no need to disable them.

--- End quote ---

Yes, that's the timer he's using.  But I'm talking about timer0 and its overflow ISR, which is used to increment millis.  If that's still running, it seems it could interfere with getting good measurements from timer1.

dariodario:
Hi OM2220,
I tested the circuit you proposed with a TL081 and it doen't work. No signal AC signal at the output except a continue component to 4.2 Volt.
Note that I'm powering the circuit with a single voltage to +5V.

I'm not an expert but from what I read all "normal" OP AMP have a common mode voltage for the input so that the minimum voltage to work has to be > from lower side power supply and upper input < to upper side supply. So for example in my case, the TL081 has to have the input >4 volt if the lower supply is ground (see attached image from the datasheet (11volt with reference 15 volt dual)). The web site tone input is at 0.6 V RMS with value that passing from zero volt!
There are the "normal" op amp, the "single supply" and the so called "rail to rail".

If you lower the input in your simulation to 1 or 2 volt, the circuit have a different output than the square wave.

Regards.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

There was an error while thanking
Thanking...
Go to full version