Frequency Counter - Colpitts oscillator - Picaxe interface

Michael V

Senior Member
I was searching for tools to help me find and measure small quantities of iron in otherwise non magnetic samples. I found a piece of laboratory equipment that would do this. The principle is that the sample is inserted into a coil, and the amount of iron varies the inductance of the coil, and then the electronics determine from the change in inductance what (roughly) the iron content is. Trouble is this machine costs $15,000.

I thought - metal detctor circuit - plus some fancy electronics - a picaxe job for sure. I researched metal deteectors, the ones you use on the beach for finding coins. Seems the heart of these devices is a Colpitts oscillator - i have never heard of such a thing. (diagram attached) Seems that the coil and a pair of capacitors will naturally oscillate. If the inductance of the coil varies, so does the frequency of the oscillation and then you measure the change qualitatively to get the squealing noise you get from metal detectors. There is a formula with inverse of square root and pi and other stuff, that ties inductance , capacitance and frequency together. You probably learn that in electronics school, but it was news to me.

Well i built such an oscillator (was not so natural) and even learned how to use a borrowed oscilloscope. I put the output from the oscillator into a rail to rail op amp with high gain, so now i get some reasonably healthy looking 0-5V peaks with squareish tops and bottoms with 50% duty cycle. So far so good.

I bought a Jaycar QM 1544 pocket meter, capable of measuring frequency. My oscillator circuit oscillates at 54 kHz. The frequency does change ever so slightly when tiny quantities of iron are inserted in the coil. When a big lump of metal is inserted, the amplitude of the peaks falls and the wave form disappears completely, and you have to physically massage it to get it back.

My idea is to use the picaxe count function to count a lot of pulses, and then to measure a difference when a sample was inserted, and somehow make a measurement from the frequency change.

The manual says that at normal picaxe frequency, the highest frequency of pulses that can be counted is 25 kHz. But, with the magic of an external 8mHz resonator on a 28x2, the setfreq command, the speed can be increased to four times the normal. That should enable 56kHz to be measured.

Code:
#picaxe 28X2

setfreq em32

main:

pause 20
count 1, 1000, w1 ' count pulses in 1 seconds
'

sertxd("count ",#w1,13,10)

	
pause 10
goto main ' else loop back to start
But, it just doesn't work. I get a big fat zero.

I have measured with the mulimeter that the signal is getting to the picaxe pin OK, but no counts. When i connect/disconnect, sometimes numbers come up, some stray signals, but zero whenit is connected.

I don't know what to do next.

Any ideas?

I would ideally like to be at a higher frequency, i have read that metal detectors are usually at 100 - 200 kHz, but i'm finding my own way.

I thought that the frequency of pulses may still be too high despite what the book says, and learned that there is such a thing as a prescaler or cmos counter/divider. Would these be of any use? There seems to be so many options with these.

Any help appreciated.
Michael
 

Attachments

hippy

Ex-Staff (retired)
Staff member
count 1, 1000, w1

It's a 28X2, the pin should be specified as port.pin - Try that and let us know how you get on.
 

hippy

Ex-Staff (retired)
Staff member
Tried to sort out the duplicate posts but lost your scope trace in the process. Sorry.
 

Jaguarjoe

Senior Member
If you make it a beat frequency oscillator you'll get much more sensitivity. Build 2 identical oscillators of whatever type you like but make one slightly adjustable. Feed both of their signals into a mixer and measure the frequency of the output. With 2 perfectly equal oscillators the beat frequency will zero. With iron unbalancing one of the oscillators you will get a relatively low frequency signal output- much easier to work with and much more sensitive.
 

Michael V

Senior Member
Thanks Hippy, my cyber hero.

I changed

count 1, 1000, w1
to
count c.1 1000, w1

And I was getting numbers. But they were different to the frequency counter.
Then, the second trap for young players, the "1000" interval is actually now not 1 second, its one eighth of a second with the X2 and 8mZ external oscillator. so if i now

count c.1 8000, w1
or, if the counts are more than picaxe max 65,535 in a second
count c.1 800 w1,
and add a zero.

Then i get a number from the picaxe that is within 0.5% of the frequency than i get from the meter.

Thanks again Hippy - i'm back on track.
 

Attachments

Michael V

Senior Member
Beat Frequency

Hi Joe, Howyrrrrdoinn down south?

When i was researching the metal deterctor circuits i did find the beat frequency concept. I understood the idea, but the electronics scared me. It was actually the concept of beat frequencies that led me to use the picaxe. My idea was (and i'm open to ideas) that the picaxe itself has its own oscillator, or can be speeded up with an external oscillator, which would probably be more accurate and thermally and environmentally stable than any i could build. I would be comparing the external sensor oscillator with a more stable picaxe oscillator, and would then measure the differences in frequencies with lines of code.

What do you think?

Michael
 

Jaguarjoe

Senior Member
Down south? I'm up north on the Detroit river, near Lake Erie. Summers are nice but winters suck.

Well, you have 3 ways to go, internal Picaxe oscillator which is not the best, an external resonator which is better, or a crystal, which is the best.
 

Michael V

Senior Member
External crystal.

Hi Joe, sorry, thought MI was Mississppi, but of course its Michigan

So, crystal - how does that work? I thought crystals were in MHz, and i'm at less than 100 kHz.

Michael
 

Jaguarjoe

Senior Member
Crystals can be almost anything. Here is a 60kHz jobbie available for 0.76USD each from Mouser Electronics:

http://www.ecsxtal.com/store/pdf/ecs-31x.pdf

If you look for a 32.768 kHz watch crystal you can probably get it cheaper. They are very common.
If you are stuck on 58kHz for some reason, you get one cut to that frequency. It won't be 0.76USD though.
I'm thinking you should go way up in frequency, like 1MHz or so. I don't know how well the Picaxe will like that though.
 

Dippy

Moderator
Joe's solution is favourite.

BFO are the easiest and used in most low cost metal detectors (and many other places too).

Easiest way is to make 2 of your circuits but the second oscillator uses a fixed inductor.
And use an op amp as a mixer (Google it or even Yahoo it).

One advantage of using 'identical' oscillator designs is that they will 'drift' together. And they will drift with a non-compenstaed transistor circuit. And the 'cheaper' the components trhen the higher likelihood of instability.
 
Last edited:

Michael V

Senior Member
Oscillator

Yes Dippy,
you are right it would not be so much of a drama to wind another coil and make another oscillator, at least they will match. I already have a dual rail to rail op amp.

I guess then instead of looking to measure frequencies of 100 kHZ, i can try and make the oscillators run at a higher frequency (having trouble with that, it seems to either saturate or not start) and then the first op amp will mix the signals and create a beat frequency, and the second will amplify it to look more pulse like.

I'll let you know how i get on - but i have to get back to work now....
 
Top