Category Archives: Electronics

Ad hoc metal detector using the VNWA

We are about to move to a house where most of the floors are making creaking noises when you walk over them. The floors are made of 22 mm thick wooden boards and below them there is an underfloor hydronic heating system with hot water pipes embedded in heat spreading sheets of aluminum as shown below.

Floor cross section with hydronic heating.
Floor cross section with hydronic heating.

One of the possible solutions to the creaking floor problem is to use screws to tie down the boards into the underlying wooden beams. There are few problems however. One is to locate the beams, but a more important issue is to make sure that we do not drill or screw into one of the water pipes. Doing so would obviously have catastrophic consequences. So how can one be sure to stay clear of the water pipes? We will borrow an IR camera and try to see how the pipes are routed, but I am not so sure this will clearly show all the pipes everywhere since the pipes might not be in good contact with the floor boards everywhere.

Another idea is to take advantage of the heat spreading sheets of aluminum placed between the beams. The pipes are sure to be straight and positioned a safe distance away from the beams everywhere where aluminum sheets are present. Close to the walls however the sheet metal will end to give the pipes space to curve around to reach the next pocket between the beams. It seems quite important to detect where the aluminum ends close to the walls so that we know where the danger zone is. Below is an example sketch of what the pipe layout might look like in a few rooms.

Example hot water pipe layout.
Example hot water pipe layout.

Hidden metal can be detected by a metal detector, but I do not have one of those. Buying one is obviously an alternative, but would it perhaps be possible to build one without too much effort?

I pondered this for a day or two. One principle to use would be to measure the inductance and/or loss of a coil. Probably there should be a noticeable change when metal interferes with the magnetic field. Another method would be to sense the coupling between two coils, which should also be affected by nearby metal. But could I quickly and easily build a circuit to do this? After all, a commercial metal detector might not be all that expensive.

A relatively simple and common way of detecting a change in inductance would be to build an oscillator where the coil forms part of the tank circuit of the oscillator and then detecting the frequency change somehow. This is certainly doable, but I came up with another idea that seemed quicker to implement with available hardware, namely to use my little vector network analyzer, the VNWA!

So I wound a wide and flat coil using two cut-off disposable plastic cups as the coil former. Then I put a 390 pF capacitor in series with the coil and placed the series LC-circuit as a shunt across the VNWA test board connected for a through (S21) measurement. Pictures of the coil and the connection to the test board are shown below.

Sensor coil with series capacitor.
Sensor coil with series capacitor.
VNWA test board with through connection (strip along the center) and shunting connection to the sense coil.
VNWA test board with through connection (strip along the center) and shunting connection to the sense coil.

Thus, at the frequency where the LC-tank is resonant, it will be quite successful at shunting the transmission line and thus reducing how much signal power gets through to the receiving port of the VNWA. I.e. the transmission parameter S21 will have a notch at the resonant frequency. When the coil comes close to metal, one can expect the inductance as well as the loss to change. A change in inductance will lead to a change in notch frequency while increased loss will show up as a less deep notch.

I did not know what parameter of the coil would be most sensitive to nearby metal, but using the VNWA it is easy to observe several parameters at once over a range of frequencies. I also did not know precisely at what frequency the tank circuit would be resonant, but it is very easy to find out using the VNWA. Another thing that is convenient with the setup is that performing a thru calibration does not require any tedious SMA connector screwing/unscrewing. Just unplug the cable to the sense coil and do the calibration. This is particularly nice when iteratively optimizing sweep parameters like start and stop frequencies, number of frequency points per sweep and dwell time at each frequency.

So did it work?

The resonance frequency without nearby metal turned out to be about 113 kHz, so since the capacitance is 390 pF, the inductance is apparently 5.1 mH. When the coil is 30 mm above a sheet of aluminum, the frequency changes to 115 kHz. If it is just 20 mm above aluminum, the frequency goes up further to 117.5 kHz. The notch in S21 is about 3 dB deep and 2 kHz wide, so it is very easy to detect the change in notch frequency. Below is a plot showing S21 when the coil is 30 mm above a 50 mm wide gap in the aluminum sheets (Mem1 with a notch frequency of 113.2 kHz) and another trace showing  S21 when the coil is 30 mm above an aluminum sheet (S21 with a notch at 115.3 kHz).

S21 curves showing a notch at 113.2 kHz when the coil is 30 mm above a 50 mm wide gap and 115.3 kHz when the coil is 30 mm above aluminum.
S21 curves showing a notch at 113.2 kHz when the coil is 30 mm above a 50 mm wide gap and 115.3 kHz when the coil is 30 mm above aluminum.

Below are some pictures of the test setup.

Coil placed 30 mm above a gap in the aluminum.
Coil placed 30 mm above a gap in the aluminum.
Coil placed 30 mm above a the aluminum.
Coil placed 30 mm above a the aluminum.

It turns out that the amount of frequency change (inductance change) is strongly dependent on the distance to the metal. If the distance is decreased to 20 mm, the frequency goes up to 117.6 kHz when over the metal, while it is almost unaffected when over the gap.

Frequency change when the coil is 20 mm above the aluminum sheets.
Frequency change when the coil is 20 mm above the aluminum sheets.

If the distance is increased to 46 mm, the frequency change is small, but still very much detectable, from 113.0 kHz to 113.8 kHz.

How small gaps can be detected?

Setup to test detection of small gaps.
Setup to test detection of small gaps.

I expect there to be about 10 cm or so of gap between the metal sheets, but it can be interesting to know if the setup also can detect much smaller gaps. So I tested this and found that a 10 mm gap at 30 mm distance from the coil results in a frequency of 114.1 kHz, which is well separated from the 115.3 kHz we see when the coil is directly over the metal. So even this small gap is easy to detect.

Detecting a 10 mm gap in the aluminum sheets at 30 mm distance.
Detecting a 10 mm gap in the aluminum sheets at 30 mm distance.

Since the notch is relatively strong and easy to detect using the VNWA, the sweep time can be short, which is good when quick feedback is desired while moving the detector coil across the floor. For all measurements shown above, I used a sweep of 101 points with a dwell time on each point of 3.33 ms, resulting in a sweep time of 0.34 s.

I wrote earlier about the different coil parameters that would potentially change with nearby metal. In the end it turned out that the frequency of the notch in S21 of the shunting tank circuit was the most convenient parameter to use, which means that it is the change in inductance of the coil that is primarily detected. I tried a couple of other parameters as well using the math capability of the VNWA, but nothing worked better than the S21 notch frequency. Below are plots of S21, the phase of S21, the magnitude of the shunting impedance and the real part of the shunting impedance for the cases where the coil is over a 50 mm slot and when it is directly over the metal.

Several parameters plotted when the coil is 30 mm above a 50 mm gap.
Several parameters plotted when the coil is 30 mm above a 50 mm gap.
Several parameters plotted when the coil is 30 mm above aluminum.
Several parameters plotted when the coil is 30 mm above aluminum.

As can be seen, the shunting impedance has a notch that is also easy to detect and the phase of S21 has a distinct transition at the notch. The location of all of these features along the frequency axis are directly determined by the coil inductance.

The real part of the shunting impedance (the ESR of the coil, the black curve above) is not affected very much at all and seems to be pretty useless in the detection of metal.

Some false starts and optimizations

It took an hour or two to build the first incarnation of this metal detector, but it was not quite as good as the version I have described above. Without thinking much I wound the first coil on a 50 mm diameter cardboard tube without taking any measures to make sure the winding was as close as possible to the end of the tube. Then I put a 1.5 nF capacitor in parallel across it and connected it as a shunt to the test board. Several things were suboptimal in this configuration.

Problem number 1: Using a parallel tank circuit means that the impedance is at maximum at the resonant frequency. This further means that the least amount of attenuation in S21 will occur at the resonant frequency, so S21 should have a peak here. However, with the component values selected, the attenuation around the peak will be pretty minimal and so the peak will be very small. Calculating the shunting impedance from S21 brings out the peak more clearly. This worked, but the peak was very noisy and I had to use a relatively slow sweep to detect it clearly. It would have been better to put the parallel tank in series with the VNWA signal instead of shunting it as a peak in impedance would then have resulted in a significant notch in S21 that would have been easier to see. The other option is to use a series LC tank and let that shunt the signal, which is obviously the solution I later selected.

Problem number 2: Reducing the distance between the coil and the metal strongly increases the sensitivity. So it is a good idea to try to keep the coil as close to the floor as possible. Having the coil spread out over maybe 15 mm of tube and with a distance of 5 mm from the end of the tube to the nearest coil windings is rather wasteful. A better coil design would have increased the sensitivity and this was addressed in the second design.

Problem number 3: A larger diameter of the coil gives longer range. The second coil design (depicted above) therefore has a diameter of 75 mm instead of 50 mm.

There is still room for improvement in the coil design, but it seems to already be more than good enough for my purposes, so I will probably leave it the way it is. After all, this was intended as a quick hack and not as a full on product development effort. In fact, building the first and second version of the coils and testing them took about two hours per night during two nights, while producing this blog post about it all took more time than that…

Decoupling Book as PDF

In 2010 I and Gunnar Karlström of BK Development published a book or rather booklet (36 pages) about decoupling on PCBs. It was based on measurements of decoupling impedance we had done using network analyzers and combined those findings with theory we had derived ourselves as well as decoupling theory from other sources.

The booklet was printed and handed out on a lecture we held in Linköping, Sweden, and the remaining copies were sold. We have now decided to make the PDF freely available for download, so if you are interested, you can download it using the link below. The book is written in Swedish, so lots of it will unfortunately be hard to understand unless you are able to read Swedish. Here is the link:

Avkoppla rätt

Four years after I finished writing the book, I have learned a bit more about decoupling and maybe some of the conclusions in the book would be slightly different if I were to rewrite it. The interesting concept of distributed matched bypassing (DMB) is not treated at all, and it seems like it has potential to in theory at least be a better alternative to the “big-V” decoupling strategy we advocate in the book.

For those of you who are really interested in the subject, I recommend reading the book “Frequency-Domain Characterization of Power Distribution Networks” of Istvan Novak and Jason Miller.

I have also published some more on decoupling parasitic inductance in the following recent blog posts (which are written in English):

Finding Components for the Lapse Pi

I have received a number of questions regarding some of the components of the Lapse Pi circuit I wrote about in a previous blog post. Here I will give some additional recommendations of what components to use and how to buy them.

Motor Drive NMOS Transistor

I used an NMOS transistor from the junk bin to drive the motor. The particular part I used is probably hard to find today, but fortunately, the requirements on this transistor are easily fulfilled by numerous modern parts.

So what are the requirements?

VGS(th): The transistor should be very well turned on when its gate-to-source voltage is whatever the Raspberry Pi can deliver. The GPIO outputs of the R Pi do not seem to have perfect documentation, but from what I have been able to piece together from various google searches, it seems like the outputs are pretty standard CMOS outputs and thus should deliver a voltage very close to the supply voltage when the output is high and no current flows out of the pin. Thus, we can count on the high output voltage to be pretty close to 3.3 V and thus we need to find a transistor whose threshold voltage (VGS(th)) is well below 3.3 V.

ID: The continuous drain current has to be a bit above the current that the motor consumes. Looking around for some suitable motors with gear boxes, it seems like one could expect a current around 50 mA to 300 mA. So a transistor that handles 1 A should be sufficient, although it is not too expensive to buy transistors that can handle significantly more current.

VDS: The supply voltage is nominally 12 V and we need a transistor that can withstand this voltage with some margin. It should have a drain-to-soruce voltage rating (VDS) of at least 20 V and preferably 30 V or more.

Depending on how you build the circuit (if you make your own PCB or build on stripboard like I did), you might prefer a surface mount or a through hole transistor. Most hobbyists who need the advice of this blog post probably prefer a through hole component.

Using the above criteria, it is quite easy to use the filtering functions of e.g. Digikey to find a bunch of suitable transistors. Here is how I would do it on Digikey:

  • Go to their front page and click on Product Index.
  • Under the heading “Discrete Semiconductor Products”, click on “FETs – single“.
  • Hold down the Ctrl key and click on Bulk, Cut Tape, Tray and Tube in the Packaging box. This eliminates some uninteresting (for us) packaging alternatives.
  • In the FET Type box, select “MOSFET N-Channel, Metal Oxide” and “MOSFET N-Channel, Schottky, Metal Oxide”.
  • In the Drain to Source Voltage box, click on 30V, hold down shift and click on 100V to select parts with this range of VDS. Parts outside this range is probably not of interest as they do either not fulfill our requirements or are highly overspecified and thus probably more expensive and/or worse in some other regard.
  • Tick the three boxes “In stock”, “Lead free” and “RoHS compliant.

The relevant part of the page should now look something like this:

Filtering of Digikey parts.
Filtering of Digikey parts.
  • Click “Apply filters”.
  • Still there are more than 3000 matches, so it would be nice to narrow the search further.
  • Select IDS between 1A and e.g. 30A (click on 1A, scroll to 30A, hold down shift and click on the 30A line)
  • Select VGS(th) between the minimum available and 2.5 V.
  • Select Through Hole in the Mounting Type box.

Now the selection should look like this:

Digikey-2

  • Click Apply Filters again.
  • Currently, this results in only 20 hits for me and now it is time to look through the alternatives.
  • I do this by sorting on price, lowest first, by clicking on the up-arrow in the Price column.

The first hit for me is a transistor called NTD5867 and looking at its datasheet it looks almost OK for this application. Below are some relevant plots. We can see that typically, a VGS of 2.8 V leads to a voltage drop of 0.5 V when the drain current is 2.5 A. For our currents which is about an order of magnitude smaller, the voltage drop should be negligible compared to the 12 V of the supply.

Some relevant plots from the datasheet of NTD5867.
Some relevant plots from the datasheet of NTD5867.

These are however typical plots and we are not guaranteed that the transistor will work like this. The VGS(th) specification in the “Electrical characteristics” table says that VGS(th) is typically 1.8 V (at 250 µA and 25 °C), but that it can be as high as 2.5 V. This difference of 0.7 V means that we might need 3.5 V to achieve  the behavior of the 2.8 V curve in the first plot above. And we do not have 3.5 V available to drive the transistor.

The second part in the Digikey results is NTD4906. Digikey says that this transistor has a VGS(th) of at most 2.2 V (compared to 2.5 V of the part above). Looking into the datasheet reveals a few other positive things, namely that that the difference between typical and maximum VGS(th) is 0.6 V and that it can conduct much more current at much less voltage drop at lower VGS than the previous part we looked at. Here are the plots for NTD4906:

Some relevant plots from the datasheet of NTD4906.
Some relevant plots from the datasheet of NTD4906.

At 2.4 V VGS it can typically conduct about 2 A with a voltage drop of 0.5 V, so if we add the 0.6 V difference between typical and maximum VGS(th), we get this performance at 3 V gate-source drive, which the R Pi can provide.

Based on the above, I would recommend NTD4906N as the transistor to use for this purpose, although there are of course many others that would fit the bill. If you are not shopping at Digikey, you can use the same criteria to try to find another suitable transistor that is available to you.

DC/DC PMOS Transistor

The process of finding a suitable PMOS transistor for the DC/DC converter is very similar to what I described above. Here the criteria are primarily: at least 2 A drain current, at least 30 V drain-source voltage and besides that we want good efficiency and thus prefer low gate charge/gate capacitance and an on-resistance that is low compared to the 0.27 Ω current sense resistor. Threshold voltage is not an issue here as we are driving the transistor with pretty much the full input voltage of nominally 12 V, but it is important that the transistor can tolerate this gate-source voltage.

After narrowing down the search criteria, the transistor FQU11P06 shows up and its datasheet shows no obvious drawbacks. It has an on-resistance of at most 0.185 Ω at 10 V gate-source voltage and a gate charge of 17 nC.

There are a few other and somewhat more expensive parts that have lower on-resistance and less gate charge, like STF10P6F6, but the minor efficiency improvement is probably not worth the higher price in this case. So FQU11P06 would be my recommendation in this case.

Shutter/Focus Transistor

Here we need a small-signal NMOS transistor with criteria very similar to the NMOS transistor for the motor drive, except that we do not need nearly as much current carrying capability. Oddly enough the selection of hole-mounted small-signal NMOS transistors turn out to be not that great. The part that I think looks best at Digikey is ZVNL110A.

The funny thing is that it is more expensive ($0.78) than the bigger NTD4906N ($0.57) we selected above, so if you do not mind the size, you could actually use NTD4906N here as well.

If you are OK with using a surface mount transistor, there are more options. BSS123 is widely available and seems to fit the bill, although there may be variations in the threshold voltage limits from different manufacturers, so check the datasheet for the part  you are about to buy.

DC/DC Inductor

The requirements on the inductor are primarily that the inductance shall be at least 220 µH and that the DC resistance shall be low to keep the efficiency high. And also that it shall be able to support enough peak current, which is probably around 1.5 A or so. The inductor I used has a resistance of 0.13 Ω, so this is a value to aim for to get the same or better efficiency.

Digikey does of course have a number of inductors that would do the job, but the one that seems to be least expensive is 2116-H-RC from Bourns. It is a toroid that has an inductance of 220 µH, a maximum current of 2.4 A and a maximum DC resistance of 0.12 Ω.

I hope the information in this blog post makes it easier to find suitable components for this project.