Gas station without pumps

2020 June 5

Compensation in impedance analyzer

Filed under: Circuits course — gasstationwithoutpumps @ 00:18
Tags: , ,

The Analog Discovery 2 has an impedance analyzer that includes short-circuit and open-circuit compensation to correct for the impedances of the test fixture, and I’ve been thinking about how that might be computed internally.  The open-circuit and short-circuit compensation can be applied independently or together, but each requires making and recording an impedance at each frequency for which impedance analysis is done.

Since there are three impedances that are measured (open-circuit, short-circuit, and device-under-test), I came up with two circuits that could model the test setup:

The measurement is made at the two ports, and Z_DUT is the device being measured—the other two impedances are parasitic ones of the test fixture that we are trying to eliminate.

Let’s look at the short-circuit compensation first.  For the first model, if we replace Z_DUT with a short circuit, we measure an impedance of Z_{sc} = Z_{s1}, while for the second circuit we measure Z_{sc} = Z_{p2} || Z_{s2}.   In the first model, we can do short-circuit compensation as Z_{DUT} = Z_{m} - Z_{sc}, where Z_{m} is the measured impedance with the DUT in place.  For the second circuit, we would need to measure another value to determine the appropriate correction to get Z_{DUT}.

For open-circuit compensation, in the first model we get Z_{oc} = Z_{s1} + Z_{p1} and in the second model we get Z_{oc} = Z_{p2}.  So for the first model we would need another measurement to get Z_{DUT}, but for the second model Z_m=Z_{oc} || Z_{DUT}, so Z_{DUT} = \frac{1}{1/Z_m - 1/Z_{oc}} = \frac{Z_m Z_{oc}}{Z_{oc}-Z_m}.

If we do both compensations, we can use either model, but the corrections we end up with are slightly different.

For the first model, we have Z_m = Z_{s1} + (Z_{p1} || Z_{DUT}) = Z_{sc} + ((Z_{oc}-Z_{sc}) || Z_{DUT}). We can rearrange this to Z_m -  Z_{sc} = (Z_{oc}-Z_{sc}) || Z_{DUT}, or \frac{1}{Z_m -  Z_{sc}} = \frac{1}{Z_{oc}-Z_{sc}} + \frac{1}{Z_{DUT}}.

We can simplify that to Z_{DUT}=\frac{1}{1/(Z_m-Z_{sc}) - 1/(Z_{oc}-Z_{sc})} = \frac{(Z_m-Z_{sc})(Z_{oc}-Z_{sc})}{Z_{oc}-Z_m}.  If Z_{sc}=0, this simplifies to our open-compensation formula, and if Z_{oc}\rightarrow\infty, this approaches our formula for short-circuit compensation.

For the second model, the algebra is a little messier. We have Z_m = Z_{oc} || (Z_{s2} + Z_{DUT}), which can be rewritten as \frac{1}{Z_m} - \frac{1}{Z_{oc}} = \frac{1}{Z_{s2} + Z_{DUT}}, or Z_{s2}+Z_{DUT} = \frac{1}{1/Z_m - 1/Z_{oc}} = \frac{Z_m Z_{oc}}{Z_{oc} - Z_m}.

We also have 1/Z_{sc} = 1/Z_{p2} + 1/Z_{s2}, so Z_{s2} = \frac{1}{1/Z_{sc} - 1/Z_{oc}}=\frac{Z_{sc}Z_{oc}}{Z_{oc} - Z_{sc}}, and so

Z_{DUT} = \frac{Z_m Z_{oc}}{Z_{oc} - Z_m} - \frac{Z_{sc}Z_{oc}}{Z_{oc} - Z_{sc}}

Z_{DUT} = Z_{oc} \left( \frac{Z_m}{Z_{oc}-Z_m} - \frac{Z_{sc}}{Z_{oc}-Z_{sc}}\right)

Z_{DUT} = Z_{oc} \left( \frac{Z_mZ_{oc} - Z_{sc}Z_{oc}}{({Z_{oc}-Z_m})(Z_{oc}-Z_{sc})}\right)

Z_{DUT} = \frac{Z_{oc}^2(Z_m - Z_{sc})}{({Z_{oc}-Z_m})(Z_{oc}-Z_{sc})}

Once again, when Z_{sc}=0, this formula simplifies to our formula for just open-circuit compensation, and when Z_{oc}\rightarrow\infty, this approaches out formula for short-circuit compensation.

We can make the two formulas look more similar, by using the same denominator for both, making the formula for the first model

Z_{DUT} = \frac{(Z_{oc}-Z_{sc})^2(Z_m - Z_{sc})}{({Z_{oc}-Z_m})(Z_{oc}-Z_{sc})}

That is, the only difference is whether we scale by Z_{oc}^2 or correct the open-circuit measurement to use (Z_{oc}-Z_{sc})^2.  At low frequencies (with any decent test jig) the open-circuit impedance is several orders of magnitude larger than the short-circuit impedance, so which correction is used hardly matters, but at 10MHz, changing the compensation formula can make a big difference.

For example, for the following compensation measurements using the flywires, a breadboard, and some short leads with alligator clips to make the test fixture

the choice of compensation formula would make a 3% difference is the reported impedance at 10MHz.  Notice that Z_{oc} is approximately a small capacitor and Z_{sc} is approximately a small resistor in series with a small inductor.  Shorter wires and no breadboard can make these parasitic values much smaller, so that the compensation is not so crucial.  For example, here are measurements of the impedance analyzer board:

Because the open-circuit impedance here is much higher than the input impedance of the measuring oscilloscope channel, I believe that corrections have already been made for known characteristics of the oscilloscope channels.

The exact values of the Z_{oc} measurements are often limited by the noise in measuring the current through the sense resistor, at least at lower frequencies, where the impedance of the parasitic capacitance is very high.

2019 December 19

Macos 10.15 Catalina vs PteroDAQ

I had a serious scare today.

First, I found out that the software for my Analog Discovery 2 was crashing on the MacBook Air that I will be using for lectures and lab next quarter.  It behaved normally at first and then crashed for no discernible reason after a couple of minutes.  I figured that the problem was probably related to the macos “upgrades” I had done recently, so I checked the Digilent website, and they had just posted a new version of the software last week, addressing the changes that Apple had made to their USB stack (which broke almost all 3rd-party software and a fair amount of Apple’s own software).  I downloaded the new version of Waveforms from the Digilent site and everything worked again.

But any changes to the USB stack are likely to break the code that PteroDAQ uses for finding what devices are connected, so I checked PteroDAQ with my usual setup.  The GUI for PteroDAQ did not list the Teensy board as it used to do, and PteroDAQ couldn’t run!  I spent a long time with ioreg trying to figure out how to modify to find the device again.  The Teensy board was visible as an AppleUSBDevice and AppleUSBInterface, but not as an IOSerialBSDClient as it used to be.  I could not figure out how to open it as a serial port!

Now my usual setup involves going through a USB 2.0 hub (in the Cerebrus cable), so I dug around in my drawer of parts until I found a plain USB-micro data cable.  Hooking up the Teensy board directly with that cable did show an IOSerialBSDClient interface, and PteroDAQ worked fine.  So the problem is just that connections through the USB 2.0 hub are not made the same way they used to be—the serial connection no longer is visible the way it used to be.

I’ll enter an issue for this on the PteroDAQ GitHub, but I won’t try to fix it unless it turns out that modern USB C-USB 3 docks exhibit the same problem.

2019 August 14

Beginning design of a cat drinking fountain

Filed under: Uncategorized — gasstationwithoutpumps @ 22:11
Tags: , , ,

One of our cats likes to drinking from running water (a bathroom sink on a trickle setting), so my wife challenged me to make a drinking fountain for the cat that recirculates water in a water dish.  This project will be mainly physical design (3D printing, gluing things together) with a little electronics to control the pump.

I started by buying a very cheap pump from American Science and Surplus: an ET 23 series pump that they are getting rid of for only $2.50.  Somewhat surprisingly, there is a data sheet available for this pump from the manufacturer:, but (not so surprisingly) the specs are different from what American Science and Surplus claims. The manufacturer says that the pump is submersible and can be run at 5V to 12V, while American Science and Surplus says it is not submersible and runs on 4V to 6V.  Because the pump electronics are fully potted, I tend to believe the manufacturer on this one.

The pump uses a brushless motor with two sets of windings (and only 2 transistors to power them) and seems to start pumping at about 4V.  To characterize the pump, I used my Analog Discovery 2 to sweep the power-supply voltage from 0V to 10V, measuring the current through a 0.5Ω resistor.  The results were interesting:

At low voltage, the current seems to be exponential with voltage, as would be expected from having a diode in the circuit—the nonideality of 5.6 is consistent with about 3 silicon diode drops. Above 4V, the motor behaves about like a 26Ω resistor, though with a lot of noise. The turn-on and turn-off behavior between 2V and 4V is interesting—the pump takes a lot of power at these voltages. All these measurements were taken with the pump running dry—it likely behaves differently when pumping water.

The “noise” in the I-vs-V curve is not random noise—it is fluctuation in the amount of current taken as the circuitry for the brushless motor switches between the two sets of coils. If we set the power supply to a constant 5V across the motor in series with the 0.5Ω resistor, we can observe the voltage and the current for the motor:

The two coils seem to take slightly different peak currents when the switch for them is turned on, but both spikes are about 2.8 times the average current. The frequency is around 643 Hz, which implies a speed of around 19300RPM.

I tried controlling the pump with one of the PWM LED controllers that I made for the desk lamps. With a 6V power supply, I need about 60% duty cycle to start the motor, but then can turn it down to about 15–20% duty cycle.  With an 8V power supply, I need about 40% to start and with a 10V supply about 30% to start. All these were crude measurements by turning a potentiometer until the motor started, but they are consistent with about a 3.3V average starting voltage and ability to keep running down to almost 1V.  If the pump stalls at low voltage, one has to bring it up to about 3.5V to turn it back on.

The motor runs even with fairly slow, low-duty cycle PWM. The current spikes at the beginning of each cycle are large.

The PWM control seems to work even with a PWM frequency as low as 270Hz, which is somewhat surprising.  There does not seem to be much in the way of voltage spiking, even with no capacitor or flyback diode added.  There is a short-lived initial current spike of about 3.5A (staying above 2A for about 4µs), which probably comes from charging capacitor C3 in the motor, which is across the power lines after the diode D1 (which seems to be there to prevent reversed power supply).  The 11µC spike is consistent with C3 being about a 1 µF capacitor (or maybe 2.2µF), which seems plausible.  I’m not sure why the current drops to 0 before the motor voltage drops more than about a volt.

I bought some cheap plastic bowls from a thrift store, and my next task is going to be to design a 3D-printed base to hold the pump and the electronics under the bowl and a clip to hold a ¼” ID vinyl tube over the bowl.  The pump is not self-priming, so I need to drill a hole in the bottom of the bowl and glue on the pump to make a gravity feed to do the priming.

2019 January 6

OpenScope MZ review: Bode plot

Filed under: Circuits course,Data acquisition — gasstationwithoutpumps @ 14:47
Tags: , , ,

Continuing the review in OpenScope MZ review, I investigated using the OpenScope MZ for impedance analysis (used in both the loudspeaker lab and the electrode lab).

Waveforms Live does not have the nice Impedance Analyzer instrument that Waveforms 3 has, so impedance analysis is more complicated on the OpenScope MZ than on the Analog Discovery 2.  It can be done well enough for the labs of my course, but only with a fair amount of extra trouble.

There is a “Bode Plot” button in Waveforms Live, which performs something similar to the “Network Analyzer” in Waveforms, but it uses only a single oscilloscope channel, so the setup is a little different. I think I know why the Bode plot option uses only one channel, rather than two channels—the microcontroller gets 6.25Msamples/s total throughput, which would only be 3.125Msamples/s per channel if two channels were used. In contrast, the AD2 gets a full 100Msamples/s on each channel, whether one or two is used, so is effectively 32 times faster than the OpenScope MZ.

We still make a voltage divider with the device under test (DUT) and a known reference resistor, and connect the waveform generator across the whole series chain.  Because there is only one oscilloscope channel, we have to do two sweeps: first one with the oscilloscope measuring the input to the series chain (using the “calibrate” button on the Bode panel), then another sweep measuring just across the DUT.  The sweeps are rather slow, taking about a second per data point, so one would probably want to collect fewer data points than with the AD2.  Also there is no short or open compensation for the test fixture, and the frequency range is more limited (max 625kHz).

The resulting data only contains magnitude information, not phase, and can only be downloaded in CSV format with a dB scale.  It is possible to fit a model of the voltage divider to the data, but the gnuplot script is more awkward than fitting the data from the impedance analyzer:

load '../definitions.gnuplot'
set datafile separator comma


undb(db) = 10**(db*0.05)
model(f,R,C) = Zpar(R, Zc(f,C))
div(f,R,C) = divider(Rref, model(f,R,C))

R= 1e3
C= 1e-9
fit log(abs(div(x,R,C))) '1kohm-Ax-Bode.csv' skip 1 u 1:(log(undb($2))) via R,C

set xrange [100:1e6]
set ylabel 'Voltage divider ratio'
plot '1kohm-Ax-Bode.csv' skip 1 u 1:(undb($2)) title 'data', \
      abs(div(x,R,C)) title sprintf("R=%.2fkohm, C=%.2fnF", R*1e-3, C*1e9)

The fitting here results in essentially the same results as the fitting done with the Analog Discovery 2.

Although the Bode plot option makes the OpenScope MZ usable for the course, it is rather awkward and limited—the Analog Discovery 2 is still a much better deal.

2019 January 5

OpenScope MZ review

During the CyberWeek sales I bought myself an OpenScope MZ USB scope from Digilent, to see how it compared with the Analog Discovery 2, which I use frequently.  I particularly wanted to see whether I could recommend it as a low-cost alternative ($89 list) for the AD2 ($279 list, but $179 with academic discount).

I’ve not had a chance to do much testing yet, but the short answer is that I would recommend saving up for the Analog Discovery 2—the OpenScope MZ is nowhere near being a professional instrument, but the AD2 is close.

The first thing I tested was the function generator.  The OpenScope MZ does not have a real DAC, but uses digital output pins and a resistor ladder to generate analog voltages.  The result is a “DAC” that is non-monotonic.  The non-monotonicity can be observed by generating a sawtooth waveform and observing the result with an Analog Discovery 2.

The non-monotonicity is worst when the DAC switches from 0x1ff to 0x200 (from 511 to 512 out of 1024 steps). This was a 3Vpp sawtooth at 10Hz. The OpenScope MZ also has a much larger offset than the AD2.

To get clean measurements, I set the AD2 to average 100 traces.  I also did 16-fold oversampling, so that I could get good time resolution while recording the whole period.

The steps are not of uniform duration, but don’t seem to be a simple pattern of single or double clock pulses:

The step durations vary here from 64µs to 136µs in this small sample, but with 1024 steps in 0.1s, I would expect 97.66µs.

The step heights are not completely consistent either, but seem to average to roughly the right value:

The step size should be 3V/1024=2.93mV, but in this range the average step size is a little high. (but the first step at the bottom left is too small).  The variable duration of the steps is also very visible here.

The speed limitations of the amplifier for the OpenScope’s function generator are also quite clear:

There seems to be a 12V/µs slew rate limitation, and the large step at the end of the sawtooth has a 258ns fall time. By way of contrast, the AD2 has about a 40ns fall time for the same 10Hz ramp up and a slew rate of about 120V/µs.

I found the Analog Discovery 2 falling edge rather interesting—the stepwise descent may be an artifact of recording the waveform with the same instrument used for generating it (so that the oversampling does not work correctly), but it might also indicate that the ramp edge is digitally pre-filtered to keep it from overshooting.

Next Page »

%d bloggers like this: