Maker Pro
Maker Pro

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

S

Scott Ronald

Jan 1, 1970
0
Hi,

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
approach?

Scott
 
Hi,

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
approach?

Scott

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.
 
J

Jamie

Jan 1, 1970
0
Scott said:
Hi,

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
approach?

Scott
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.
 
J

Jamie

Jan 1, 1970
0
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.
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.
 
J

John Larkin

Jan 1, 1970
0
Hi,

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
approach?

Scott

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
like?

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.

John
 
V

Vladimir Vassilevsky

Jan 1, 1970
0
Scott Ronald said:
Hi,

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.

Why exactly can't you use the simple comparator and a period/frequency
counter?
For the ultimate convenience, the AVR does have the comparator on the chip,
and this comparator is already connected to the timer input capture.
Does anyone have experience they would like to share as to the best
approach?

It depends.


Vladimir Vassilevsky
DSP and Mixed Signal Consultant
www.abvolt.com
 
A

Anthony Fremont

Jan 1, 1970
0
Scott said:
Hi,

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
approach?

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.
 
W

whit3rd

Jan 1, 1970
0
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.

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
follower,
and get about 1% linearity on the frequency. It only
takes one ADC sample to get the frequency (average).
 
Top