Connect with us

Reading in frequency of a modulated sine wave using A/D

Discussion in 'Electronic Design' started by Scott Ronald, Nov 4, 2007.

Scroll to continue with content
  1. Scott Ronald

    Scott Ronald Guest


    I need to calculate the frequency of a sine wave of varying frequency
    and amplitude to maximum of 50Hz. The signal will vary from its max to
    DC. I am using an 8 bit AVR with 10bit sampling. So far I have
    considered three approaches:
    -FFT (I'm not sure if this will be fast enough I would like to have a
    usable frequency reading every 100 A/D samples or so.)
    -zero crossing and time between each odd one
    -calculating the max slope and max amplitude and using their
    relationship to calculate frequency.

    Does anyone have experience they would like to share as to the best

  2. Guest

    I have experience in this particular case. This is what i do:

    I use a cross zero detector. A LM393 with 1Mohm resistor positive
    feedback, this is because when the sine wave cross zero have some
    crazy peaks and you have to create a little hysteresis of 10 mV above
    zero. If you dont do this you will see a pulse train and then your
    square signal. After you have a clean and perfect square signal from
    the comparator you just have to insert it to the microcontroller and
    calculate the time of the pulse, this gives you the frecuency (1/T).

    This works great and for 50 Hz the micro is going easy. Forget FFT,
    dont kill a fly with a magnum.

    If you need more help let me know.
  3. Jamie

    Jamie Guest

    if you do not have a complex signal and it's rather clean then use a
    zero crossing method. It's the cheapest on CPU time.
    Keep a running average on the Peak amplitude, You'll want to generate
    a Sin/Cos table for speed in the rom image to convert the PCM readings
    from the base line to obtain the fraction in a linear state.

    The only math you may need to do that maybe CPU taxing on an AVR is
    the scaling of the input signal to match the coefficients in the table.

    other than that, it's simple..

    If your signal is complex, then FFT is required and that can be
    taxing on the CPU.
    Some where around here, I have a simple PASCAL file that you can use
    to break down a FFT for 8 bit operations for the AVR if you need it.
  4. Jamie

    Jamie Guest

    good idea, I never thought of using a simple comparator which would
    make life easier on the coding side :)
    I use that years ago in the DOS days when for Slow scan tv via the
    serial port.
  5. John Larkin

    John Larkin Guest

    Interesting problem. What sample rate will you use? Is it constant?
    How accurate do you need the result to be? How fast can the input
    amplitude and frequency change? What might the input waveforms look

    We're working on a similar problem, but we'll do the math in an FPGA.
    We're considering phase-locking a DDS synthesizer to the incoming sine
    wave, among other things. That could be done in software, too.

  6. Why exactly can't you use the simple comparator and a period/frequency
    For the ultimate convenience, the AVR does have the comparator on the chip,
    and this comparator is already connected to the timer input capture.
    It depends.

    Vladimir Vassilevsky
    DSP and Mixed Signal Consultant
  7. I've done somthing similar (just not down to DC). I like to amplify the
    crap out of the signal to straighten up those rising and falling edges, and
    then feed that to a comparator.
  8. whit3rd

    whit3rd Guest

    Another use for a phase-locked loop? If you lock a 4046 type PLL chip
    to the signal, you can read the loop filter voltage through the
    and get about 1% linearity on the frequency. It only
    takes one ADC sample to get the frequency (average).
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day