# MEASURE INPUT SINE WAVE SIGNAL USING PIC'S OP-AMP

Discussion in 'Embedded' started by electro, Apr 7, 2006.

1. ### electroGuest

hello..
this is in continuation of ADC option..
cant i just have a form of freqeucny measurement
by determining the time interval between the zero crossings
of my input signal which is at zero dc offset.

any reaction?suggestion?

thanks

electro, Apr 7, 2006

2. ### Peter DickersonGuest

Yes, in principle, but in practice doing the math(s) shows the problem. Your
input signal is 480kHz so the cycle time is 2.083333­ µs. If you want to
detect a 10 Hz shift i.e. 480.01kHz then the cycle time is now 2.083290 µs.
To measure the difference cycle-by-cycle you'd need to be able to detect the
0.000043 µs change. Of course you don't need the result updated 480000 times
per second, so you could time how long 100000 cycles take (say) and now need
a resolution of 4.3 µs - much more reasonable. Whether you time how long a
fixed number of cycles take or count how many cycles in a fixed time is
mostly a matter of which is most convenient on the hardware available.

Now if you were measuring 50 or 60 Hz and want to se 1 Hz shifts the
measuring the cycle time is entirely feasable...

Peter

Peter Dickerson, Apr 7, 2006

3. ### Noway2Guest

The more I think about your application and what you are describing (in
multiple news groups), the more it seems like your application is like
an FM demodulator.

You have a base frequency of, 480KHz I think it was, and you are
varying this frequency in relation to the presence of metal or not. I
really think you should look at applications of using a PLL to
demodulate an FM signal as this may give you a way to strip out the
480KHz and leave you with the low frequency result.

Noway2, Apr 7, 2006
4. ### CBFalconerGuest

That's what a beat frequency oscillator does in one swell foop.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the

CBFalconer, Apr 7, 2006
5. ### Mat NieuwenhovenGuest

The resolution of a frequency measurement can be increased in two ways:
- use standard PIC frequency measurement code and take a longer measurement
time (1 second will give you 1 Hz resolution), There's lots of this around
for the 16F series, don't know about other models.
- Divide the signal externally down to a low frequency (say in the order of 5
Hz if you want 5 readings per second, 200 milliseconds), and use reciproke
frequency measurement. In 200 milliseconds and a 50 Mhz clock, you can get
10^7 counts, thus 7-digit resulution. If you're only interested in the
difference from a standard you can just compute the difference by subtracting
the standard value. But with this reciprocal measurement technique you need
external hardware.

Mat Nieuwenhoven

Mat Nieuwenhoven, Apr 8, 2006
6. ### electroGuest

i only plan to detect the first two zero crossings which is 1/2 of the
total period...and then i will store this to a register...
after starting the metal detection process, i will do the same process
of getting the difference in the zero crossing and then compare it to
my ambient period...

also i scaled down my frequecny to 240 khz and used a 20mhz oscillator
to give adequate cycles or resolution..

electro, Apr 10, 2006
7. ### Peter DickersonGuest

But what is the frequency variation you expect on detection? What is the
smalles change in frequency that you hope to detect? And the largest?

BTW khz -> kHz and mhz -> MHz.

Peter

Peter Dickerson, Apr 10, 2006
8. ### PeterGuest

In simple words, the more cycles that you count, the more accurate your
frequency measurement will be.

You need to reread the other postings like Mat's and do some mathematics
yourself. Your timer runs a twelfth of the 20MHz processor clock. Over the
solitary half a wave that you want to measure I make that about 3 timer
ticks. That resolves the frequency to the nearest 80kHz which would be
disappointly coarse.

Peter

Peter, Apr 10, 2006
9. ### electroGuest

im using the internal clock of pic16lf876a: fosc/4 = 5mhz =
200ns/instrcution cycle [my unit timer resolution]
my 240khz approx = 4us but only need half of it so 2us...
now divide 2us/200ns...about 10 cycles.........not 3

also,do you have any idea on how to implement this using simple
circuits like multivibrator and 555timer?

electro, Apr 11, 2006