# Gas station without pumps

## 2021 June 21

### Controlling current

Filed under: Circuits course — gasstationwithoutpumps @ 11:06
Tags: , , ,

In the electrode lab this year, students had even more trouble than usual in understanding that the the goal was to provide a constant current to the silver-wire electrodes for a measured time period, in order to produce a known amount of AgCl on the anode.  I will have to rewrite that section of the book for greater clarity.  I also plan to add a circuit that does the constant-current control for them, so that they don’t have to adjust the voltage to get the desired current (a concept that seems to have eluded many of them).

Here is a possible circuit:

This circuit provides a current from Ip to Im of Vri/Rsense, as long as the voltage and current limitations of the op amp are not exceeded.

The negative-feedback loop tries to bring the $I_m$ output to the voltage of the $V_{\rm ri}$ input, which is only possible if the current through the sense resistor is $I=V_{\rm ri}/R_{\rm sense}$.  Let’s say that we want 1mA from Ip to Im—then we would set $V_{\rm ri}= (1\,mA) R_{\rm sense} = (1\,mA)(100\Omega) = 100\,mV$.  If $V_{\rm rail}$ is 5V and the op amp is a rail-to-rail op amp, then we could get the desired 1ma of output as long as the load resistance from Ip to Im is less than 4900Ω (well, 4650Ω really, because of the internal resistance of the op amp).  With a higher load resistance, the voltage at Ip would hit the top rail and still not provide the desired current.  There is no lower limit to the load resistance—even with a short circuit the current would be the desired 1mA.

I chose 100Ω for the sense resistor, so that the control voltages do not get too close to the bottom rail, while leaving enough voltage range for fairly large load resistances.  By using 100Ω, it is possible to specify currents up to 50mA, which is beyond the capability of the op amp to supply.  Since the MCP6004 op amps have a short-circuit current of about 20mA with a 5V supply, about the most we can deliver is 14mA for a short-circuit load, because of the internal resistance of the op amp.

Using a 1kΩ resistor might also be reasonable, since the input voltage in volts would then specify the current in mA, but a 1mA output current would limit the voltage across the output ports to $V_{\rm rail} -1\,V$ (which is probably still fine for the electrode lab). With a 1kΩ resistor and a 5V supply, the maximum specifiable current would be 5mA, and the maximum obtainable is about 4mA.  If you needed 2V across the load, then you could not specify more than 2.4mA (still plenty for the electrode lab).

For the electrode lab, the currents required are low enough that this circuit is adequate, but what if we needed more current?  Here are a couple of circuits that can provide that:

By using a pFET, we can have the voltage output of the op amp control the current. No current is needed from the op amp, and we just need that Vrail is large enough that the pFET can be fully turned on.

If we use a PNP transistor, then we need to turn the voltage output of the op amp into a current for the base.  That current is about 1/50th or 1/100th of the collector current being controlled (depending on the transistor).

Both these designs have the positive and negative inputs of the op amp reversed from the low-current design, because the pFET or PNP transistor provides a negation—the voltage at Im rises as the voltage at the output of the op amp falls.  I reduced to the sense resistor to 10Ω, to allow specifying higher currents (up to 500mA for a 5V supply).  The main limitations on this design are the thermal limitations of the transistor and the resistor—there may be both a large voltage drop and a large current.  The worst case for the transistor is when the load is a short circuit and the voltage at Im is half the power-supply voltage—then the power dissipated in the transistor (and in the sense resistor) is $(V_{\rm rail}/2)^2/10\Omega$.  For a 400mW limitation on the transistor, we would want to limit $V_{\rm rail}$ to 4V.  For a ¼W resistor, we would want to limit $V_{\rm ri}$ to 1.58V (specifying 158mA), or up the resistor to 100Ω for a 5V limit (but then we could only specify up to 50mA).  We really need a 2.5W resistor if we want to have 10Ω and a 5V supply and use the full range.

For the book, I think I’ll just present the low-current version of the current control—we don’t need the high-current version, and students are likely to request too much current for the electroplating if they have it available (errors in computing the area of the electrodes that are off by a factor of 100 are pretty common—mixing up $({\rm mm})^2$ and $({\rm cm})^2$, for example).

## 2021 May 4

### Resonance with nonlinear impedances

Filed under: Circuits course — gasstationwithoutpumps @ 08:24
Tags: , ,

My book uses nonlinear impedance $Z=(j\omega\;1\,s)^\alpha M$ for modelling loudspeakers and electrodes.  The loudspeaker models include an inductor-like component with $\alpha>0$ and the electrode models include a capacitor-like component with $\alpha<0$. Standard linear components are special cases of the nonlinear impedance: inductors have $\alpha=1$, resistors have $\alpha=0$, and capacitors have $\alpha=-1$.

This past week I was thinking about the resonance that I see in some loudspeakers around 4MHz, which can be modeled with a capacitor in parallel with the main nonlinear impedance.  How can I estimate the capacitance to get initial values for model fitting?  In general, when do I get resonance with two nonlinear impedances?

Although I initially looked at the capacitor case, I realized that the general case of two nonlinear impedances in series gives me simple math that I can easily generalize to special cases and to parallel connections, so let’s look at $Z=(j\omega\;1\,s)^\alpha M + (j\omega\;1s)^\beta N$.  The first thing to do is to replace $j$ by the polar form $e^{j\pi/2}$, getting $Z=e^{j \alpha\pi/2}(\omega\;1\,s)^\alpha M + e^{j \beta\pi/2}(\omega\;1s)^\beta N$.  The we can apply Euler’s formula to get the real and imaginary parts:

$\Re(Z) = \cos(\alpha\pi/2)(\omega\;1\,s)^\alpha M + \cos(\beta\pi/2)(\omega\;1s)^\beta N$.

$\Im(Z) = \sin(\alpha\pi/2)(\omega\;1\,s)^\alpha M +\sin(\beta\pi/2)(\omega\;1s)^\beta N$.

We will get resonance whenever the imaginary part goes to zero:

$0= (\omega\;1\,s)^{\alpha-\beta} M\sin(\alpha\pi/2) +N \sin(\beta\pi/2)$, or

$\omega = \left(\frac{ -N \sin(\beta\pi/2)}{M\sin(\alpha\pi/2)} \right)^{1/(\alpha-\beta)} s^{-1}$.

The special case of an inductor and a capacitor sets $\alpha=1$, $M = L / 1\,s$, $\beta = -1$, and $N= 1\,s/C$,  yielding $\omega= \left(\frac{N}{M}\right)^{1/2} s^{-1} = \sqrt{\frac{1}{LC}}$, which is the standard result.

We get a resonance whenever $\alpha$ and $\beta$ have opposite signs.

We can deal with parallel rather than series impedances by looking at the sum of admittances instead of the sum of impedances.  To get the admittances, the exponents $\alpha$ and $\beta$ get negated and the coefficients $M$ and $N$ inverted, giving us

$\omega = \left(\frac{ -M \sin(\beta\pi/2)}{N\sin(\alpha\pi/2)}\right)^{1/(\beta-\alpha)} s^{-1}$.

Note: this post is a much simpler analysis than last year’s in Resonance for non-linear impedance, because here I am just looking for where the phase goes to zero, rather than where the magnitude of impedance is minimized.

Update 2021 May 4: The two definitions of resonance I’ve used (minimum $|Z|$ and $\Im(Z)=0$) are not the same—I tried doing a parametric plot of the magnitude vs. the phase for one asymmetric example ($\alpha=0.6$ and $\beta=-0.2$) and saw that the minimum magnitude did not occur at 0°.  So I’ll need to think some more about what I want “resonance” to mean for nonlinear impedances.

## 2021 January 9

### One week into new quarter

We’re one week into the new quarter (10% of the way through!) and the course is going ok. Most of the students have finished the first-week lab, which consists of installing a lot of software and soldering headers onto a Teensy LC board.

The software they had to install was

Of course, each piece of software has its own installation idiosyncracies, different on Windows, macos, and Linux.  Some people even bumped into some problems because of running old versions of macos or Python (which were luckily cleared by upgrading to slightly newer versions).

The soldering was a bigger problem, because many students plugged in their cheap irons and left them on for a long time without tinning the tips.  The result was a sufficient build-up of corrosion that that they could not then tin the tips—even using a copper ChoreBoy scrubber to clean the tips didn’t help in some cases. In the in-person labs, I often spent most of the first week labs cleaning soldering iron tips that students had managed to mess up, but I can’t do that online.  This was not such a problem last quarter, as most of the students knew how to care for soldering irons from the first half of the course, but it may be a bigger problem this quarter, as most of the students have never touched a soldering iron before.  Some of the ones who are living here in town may be contacting the lab staff to see if they can get access to tip tinner or get some help cleaning their irons.  Those further away may be buying tip tinner on their own—I had not included it in kits, because I nad not expected so many to need it and it costs \$8 apiece.

Grading is going fairly well.  My grading team and I have had two Zoom meetings so far (for Homeworks 1 and 2) and I graded Quiz 1 by myself, so we are keeping up with the grading.  He have Homework 3 and Prelab 2a (there is no Prelab 1) both due Monday morning, and we’ll try getting them graded Monday night.  We’re having to do most of our grading in the evening, because one of the graders is living in China, 15 time zones away, and none of us in California is an early morning person.

In other news, I’ve finally finished clearing the blackberries and ivy from behind the garage (a project I started about 2 years ago).  I’ll probably find some more when I cut back the kiwi vine (an annual winter project, in addition to frequent minor pruning during the summer).  I think I either need to get some female kiwi vines and an arbor for them or uproot the male kiwi.  There is really not much point to having just a male kiwi intent on taking over a big chunk of the yard.

There are still a lot of blackberry roots out there that will sprout new vines.  I’ll try uprooting them where I have access (not where they are coming through the cracks in the concrete), but I’ll probably have to do a monthly sweep of the yard to remove blackberries for the rest of my life in this house.

## 2020 October 28

### Analog Discovery 2 power-supply noise

Filed under: Circuits course — gasstationwithoutpumps @ 11:38
Tags: , , ,

Last night and this morning I spent some time investigating the noise on the power supplies of the Analog Discovery 2, because some students were having trouble with power-supply noise on their audio amplifiers (an inherent problem with biasing the microphone with just a bias resistor to the power supply).

I looked at the positive supply set to +3.3V using oscilloscope Channel 1, and saw a fluctuation in voltage that was not too surprising for a switching power supply (though the switching frequency seemed ridiculously low).  The power supply is specified to stay within 10mV of the desired voltage, and the voltage seemed to be doing that.

I know that some switching power supplies shut themselves off under low-load conditions, to retain efficiency at the cost of adding low-frequency ripple to the output, so I tried running the power supply with different load resistors.  I did the sampling at 400kHz and took FFTs of the signal (exponential averaging of RMS with weight 100, Blackman-Harris window).

Here are the signals:

The signals show quite a bit of oscillation without a load, but decreasing with increasing load.

Here are the spectra from the Fourier transform (removing the DC spike):

The spike around 57.2kHz is present with all loads and remains at the same frequency even if I change the sampling rate, so is probably the underlying frequency of the switching power supply.

The rather large fluctuations in the audio range are probably the result of the power supply shutting itself off when there is low current draw.  Drawing 10 mA is not quite enough to prevent this shutdown, but 27.5mA seems to be enough.

So there seem to be at least three solutions for students having problems with power-supply noise:

• Taking enough current from the power supply that the power supply doesn’t shut itself down.  This is a rather fragile technique, as other sources of power-supply noise (such as noise injected by the power-amplifier stage in a later lab) will not be eliminated.
• Using a transimpedance amplifier instead of a bias resistor to bias the mic.  The bias-voltage input to the transimpedance amplifier can have a low-pass filter to keep it clean.
• Putting a low-pass filter (with a small resistor and large capacitor) between the power supply and the bias resistor.  The resistance of the filter adds to the resistance for the DC bias calculation, but not to the resistance for the i-to-v conversion.

## 2020 October 5

### First Zoom lab

Filed under: Circuits course,Uncategorized — gasstationwithoutpumps @ 20:25
Tags: ,

I had my first remote lab session today, using Zoom to supervise pairs of students working from home.  It went more smoothly than I expected, but not perfectly.

I had pre-assigned lab partners to groups using a CSV file, following the instructions at https://support.zoom.us/hc/en-us/articles/360032752671-Pre-assigning-participants-to-breakout-rooms.  A couple minutes into the lab time, when most of the students had shown up, I opened the breakout rooms, and everyone managed to get into their rooms.

Except those students who showed up late—they had to be manually assigned to their rooms, and of course they did not remember what group number they were in, so I had look for them in my list of email addresses (which was not easy, because the name they were showing on the screen might have no more than 1 letter in common with their email address).  I wish that Zoom could remember the pre-assignment even for those who are late!

Once I finally got everyone into their breakout rooms, I started going from room to room, looking over the shoulders of the students and asking if they had any questions.  On the second or third room, the students couldn’t get screen sharing to work (though others had in other rooms).  I tried setting all the screen sharing options, but nothing seemed to work.

I left that group to answer a question in another room, which also turned out to be about screen sharing, but reactivating it for them worked!  So I went back to the room that first had trouble, and reactivated screen sharing for them, and this time it worked.

After that I mostly answered questions for a group until some other group asked for help, then I moved over and answered questions there.  It was very similar to the experience I had with the live labs, except that it was hard to see their breadboards.  Most of the questions were about setting up Waveforms on the Analog Discovery 2 to collect the data or about gnuplot scripts to plot and model the data.

A couple of times students had to quit Zoom and re-enter, and I had to reassign them to their breakout rooms.  It turns out that this can be done while in a breakout room, so I did not have to go back to the main room. Again, I wish Zoom could remember their assignments!

There were a few times when I was free to float between breakout rooms, and I think I managed to touch base with each group at least once, but I’m not 100% sure of that.

I was pretty burned out after 2 hours of being constantly “on”, but that is not so different from a usual lab session.  I did not, however, feel like recording another video tonight.

Next Page »