Need advice: Metal detector with stm32f103

What are you developing?
asen0v
Posts: 31
Joined: Wed Sep 21, 2016 4:51 pm
Location: Bulgaria

Need advice: Metal detector with stm32f103

Post by asen0v » Sat Nov 05, 2016 6:37 pm

Hello guys,
Recently I'm trying to design a Pulse induction metal detector using maple mini. I already built two detectors using arduino and they work pretty well. Arduino generated only the timings, but the signal was processed by integrators.
Now I want to built DSP detector. You can see the scheme I drew. Unfortunately electronics and programming is only my hobby and there are much things I don't know. Such detectors have been already built using atmega328p and atmega8. They all use 10 bits of adc. With faster sampling and better resolution maple mini should have even better performance.
Thanks to the O-Scope project I managed to run the ADC in the fastest mode of 0.58uS per sample. You are great guys ;)
I need to process only the positive portion of the pre amp output signal and this is why I will use the rectifier on the scheme. This will protect the ADC from negative voltage. Now my main concern is - what resistor should I put between the pre amp output and the ADC input? I have no an idea what value to put here. Or maybe just leave it as it is now? I will be happy to hear your opinion. Thank you in advance!
Scheme

User avatar
RogerClark
Posts: 6877
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Need advice: Metal detector with stm32f103

Post by RogerClark » Sat Nov 05, 2016 7:40 pm

I think the input impedance to the ADC is at least 50k, so as long as your OpAmp is running from 3.3v I dont think you need a resistor.

If the OpAmp is running on a higher voltage e.g. 5v, you need to use a voltage divider ( resistors) in which case you need to look at what current the OpAmp can produce, e.g. can it for example drive 5mA, and if so, perhaps get it to drive 1mA through a resistor divider

User avatar
Pito
Posts: 1522
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Need advice: Metal detector with stm32f103

Post by Pito » Sat Nov 05, 2016 9:11 pm

The impedance at ADC input should be held as low as possible for higher speeds. You have got there the zener D6 3V3 so it should be ok, I would add an 1k in series with MM's ADC input, just for case. The max negative voltage at the MM's ADC input would be someting like -0.65V with the zener (moreover there are clamping diodes inside the MM's pins).

The timing constant of the RV1 (mid position) and C10 is something like 0.5us - do you think that that OPAMP used is fast enough for such speeds?

Mind the D6 zener has a "knee" around 3.3V, so you may not get full 3.3V at the ADC input.

I would also change R1 and R2 to 1k to speedup the edges, add 1k from base to emitter of Q6.
And also do not power MapleMini with 12V, plz.. ;)
Pukao Hats Cleaning Services Ltd.

User avatar
RogerClark
Posts: 6877
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Need advice: Metal detector with stm32f103

Post by RogerClark » Sat Nov 05, 2016 9:37 pm

I didnt notice the link to the schematic when I looked on my iPad :-(

I'm not sure why you'd use a zener, it introduces artefacts you may not want.
Also, what does the 1N4148 do, (well apart from stopping the voltage going below zero to the STM32 if you run a dual rail supply

Both those diodes will impact on your readings

It looks like it runs off a single 12V supply. If so, it doesnt look like the output from the OpAmp is going to go below GND.

I'd probably opt for using a resistor divider on the output of the OpAmp.

asen0v
Posts: 31
Joined: Wed Sep 21, 2016 4:51 pm
Location: Bulgaria

Re: Need advice: Metal detector with stm32f103

Post by asen0v » Sat Nov 05, 2016 10:03 pm

Guys, I knew you will give me valuable advice. You are great here.
Pito, I will add resistor between Q6 gate and emiter. Also will change the R1 and R2 as you suggest and will put 1k in series with the ADC input. Thank you!
The timing constant of the RV1 (mid position) and C10 is something like 0.5us - do you think that that OPAMP used is fast enough for such speeds?
I use RV1 to shrink or strech the signal in order to use the whole 0 to 3.3 range of the ADC input. The C10 is here just for filtering. I have no an idea how to calculate its value, but just saw other people put it there and I did the same :lol:
I'm not sure why you'd use a zener, it introduces artefacts you may not want.
Also, what does the 1N4148 do, (well apart from stopping the voltage going below zero to the STM32 if you run a dual rail supply

Both those diodes will impact on your readings

It looks like it runs off a single 12V supply. If so, it doesnt look like the output from the OpAmp is going to go below GND.
Roger, 1N4148 and RV1 together are acting as half wave rectifier. I saw the half wave rectifier in internet and just replicated it there :)
The amplifier runs from -12 and +12, this is why i need to "cut" the negative part of the signal somehow. The zener is here just to protect the ADC from voltages higher than 3.6V. I may remove it, because I can control the signal range by adjusting RV1.
And also do not power MapleMini with 12V, plz.. ;)
Why is that? It is a maple mini from baite and there is a lable on it which states "vin max 15v". Or it is not really true?

User avatar
ahull
Posts: 1596
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: Need advice: Metal detector with stm32f103

Post by ahull » Sun Nov 06, 2016 12:00 am

You might find these links beneficial. They go over the general theory of operation of this kind of detector.

http://forum.arduino.cc/index.php?topic=65712.0
https://www.lammertbies.nl/electronics/ ... ector.html


I've been thinking about building one for a while, but other commitments keep getting in the way. I'll be very keen to know how you get on. :D
Why is that? It is a maple mini from baite and there is a lable on it which states "vin max 15v". Or it is not really true?
That depends on which voltage regulator was cheap at the Shenzhen market that day. Some of these boards have a fairly robust regulator, others I wouldn't trust with more than about 6V input. If in doubt, add another regulator, but I would avoid any kind of buck regulator unless you are willing to do a bit of additional filtering on your supply lines, as it may add high frequency noise in to the signal you are trying to measure.
- Andy Hull -

asen0v
Posts: 31
Joined: Wed Sep 21, 2016 4:51 pm
Location: Bulgaria

Re: Need advice: Metal detector with stm32f103

Post by asen0v » Sun Nov 06, 2016 12:57 am

Hi ahull,
I will listen to you and pito, and will feed the maple mini with 5V.

I have built 4 pulse induction detectors and I know how they work in details. My main problem now is how to interface the pre amp with the ADC. There is a simple way of cutting the negative part of the signal which have been used in other DSP detectors:
Image

Unfortunately, using the above method, some part of the negative signal still remains uncut. It is usually about -0.7V. I will not going to sample the signal at the portion when it is negative, because there is no valuable information in this portion, but my main concern is if this negative voltage will damage the maple. I don't know what is the absolute minimum voltage STM32F103CBT6 ADC can handle. I searched the refference manual and all the documents I have found, but there is no answer. Does anyone here knows? If it can handle -0.7V I will use the method from the above picture.

User avatar
ahull
Posts: 1596
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: Need advice: Metal detector with stm32f103

Post by ahull » Sun Nov 06, 2016 1:23 am

http://www.st.com/content/ccc/resource/ ... 161566.pdf
Page 38 - 5.3.1 General operating conditions. I/O characteristics suggests the pins wont be happy with a negative input in excess of -03V so you are going to have to clamp your -0.7V or level shift it somehow.
- Andy Hull -

User avatar
Pito
Posts: 1522
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Need advice: Metal detector with stm32f103

Post by Pito » Sun Nov 06, 2016 1:27 am

The OPAMP is powered by +12 and -12V (minus is weak as it is created by simple charge pump converter). The zener D6 at the opamp output is OK there, otherwise the voltage may overshoot to +/-12V and destroy the ADC.
The RV1 for amplitude regulation is wrong. You have to use an voltage divider for that (but you do not need as the voltage is limited by zener D6).
The RV1 there is just a part of the timing constant RV1C10. Unless you set RV1 so low that the OPAMP will not be able to feed enough current to the RV1.
Mind the output currents of the Opapm could be 20mA max, so double check.
The D3=1n4148 diode at the opamp output works as a simple peak detector with time constant ~RV1C10.
Based on the first schematics, the max peaks ampl at ADC input will be -0.6 to 3V, with time constant of 0.5usecs (1/2piRV1C10). So the pulse will disappear with aprox this time when the opamp output goes to zero. Not sure you would be fast enough to sample such short pulses properly.
Now - what you want actually want to measure??, as it seems to me you are not clear about that..
If you want to sample the "shape" of the pulses you need an ADC with sample rate at least 10x the 1/(pulse_duration).
If you want to detect the peak amplitude of each pulse you need a longer time constant - similar to the 1/frequency of your pulses into the coil and a good timing between shooting the pulse into the coil and sampling that pulse at the output.
If you want to measure the average amplitude of a train of pulses then you may use large timing constant (ie 10-100ms) and measure the average voltage with the ADC without any need for fast adc.
So what you actually want to do? Mind the electronics is about good understanding of the circuitry and using MATH :)

PS: I see the frequency of your pulses is 650Hz, 70us/1400us.
So the RV1 shall be for example ~10kohm and C10=10-22nF. That gives you aprox 500-1400us time constant and together with the diode D3 it will work as a simple "peak detector". You would have about 0.1 x timeconstant to sample the peak till the voltage drops significantly at the ADC input (so something like 50-100us). The precise timing depends on the shape of the pulse, however. So an oscilloscope may help.
Again - you have to specify WHAT you want to measure at the output of opamp to decide on proper signal processing approach..

PS: adding the 1k in series with front of the ADC input will limit the clamp current to the lower clamp diode inside the chip to aprox I = -0.6V/1kohm, the clamp diodes are usually rated for I<<5mA.
Pukao Hats Cleaning Services Ltd.

asen0v
Posts: 31
Joined: Wed Sep 21, 2016 4:51 pm
Location: Bulgaria

Re: Need advice: Metal detector with stm32f103

Post by asen0v » Sun Nov 06, 2016 2:26 am

http://www.st.com/content/ccc/resource/ ... 161566.pdf
Page 38 - 5.3.1 General operating conditions. I/O characteristics suggests the pins wont be happy with a negative input in excess of -03V so you are going to have to clamp your -0.7V or level shift it somehow.
ahull, Thank you!

Pito,
The scheme is based on THIS detector. I have done it with arduino instead of PIC and it works really good. Even better from my Whites SurfMaster detector. Now I want to sample directly from the op amp output instead of using integrators to process the signal.
What i changed on the scheme:
-I removed the 78l05. I use -/+12V for the opamp.
-I use the op amp in inverting mode, because it will be easier to process the signal.
-I tried to cut the negative part of the signal.

This is how the signal usually looks:
Image

We send a pulse to the ground 1000 times per second. This pulses width is 50uS. Immediately after we stop the pulse, the eddy currents are generating another pulse in the opposite direction. As you can see in the picture this pulse decays slowly for abaout 15uS. This decay forms a curve. If there is no target present, the curve stays the same(there are some small ripples usually). In the picture, 1 is the curve without target and 2 is the curve with some metal target in front of the coil.
What I need to measure is portion of about 15 to 20 uSeconds. The measure should start at the end of the curve. Just before it reaches 0 volts.
How will I measure it: I will "record" about 32 points with convertion speed of 0.58us(Thanks to O-scope project!). Then I will average this 32 points by dividing by 8. In this way I will try to gain 2 extra bits out from the ADC. Then I will average the result with the last 16 results.
All the numbers may be slightly different. I used them just for explanation.

The op amp should have gain of 1000.
NE5534 is exactly 10Mhz and it has a good specs at all. It have been used in many commercial pulse induction detectors.

Post Reply