Gas station without pumps

2014 February 8

More on loudness circuits

Filed under: Circuits course — gasstationwithoutpumps @ 21:07
Tags: , , , ,

My son got interested in a loudness circuit again, and we tried coming up with one that that would take few components. We decided on having a 3-stage system: a preamp to get voltage up, a peak (or trough) detector with low-pass filter to extract the envelope, and a log amplifier to convert to a dB scale. We were planning to use a Schottky diode, rather than a precision rectifier for the peak detector.

Block diagram for loudness sensor using peak detector.

Block diagram for loudness sensor using peak detector.

The gain of the first stage was set by looking at the sensitivity of the SPU0410HR5H‐PB silicon microphone and the maximum loudness that the system should be able to record. The mic has -42±3dB sensitivity referenced to 1V/Pa.  That means it has 7.94mV/Pa.  The loudest sound for the mic should be the sound level at a rock concert, approximately 120dB referenced to 20µPa—that is 20Pa.  So the microphone should have an AC output of about 160mV.  Because he is planning to work with a 3.3V power supply, a gain of 10 should just keep the signal within the rails.

    Here is the loudness circuit, before the component values have been determined.

Here is the loudness circuit, before the component values have been determined.

To get a gain of 10 (actually –10), we need R2=10*R1.  The R1 C1 time constant determines the cutoff for the high-pass DC-blocking filter.  A reasonable cutoff frequency is 10–20Hz, giving an RC time constant of  8–16msec.  Picking a cheap value for C1 (0.1µF),  gives us R1≈100kΩ and R2≈1MΩ.

The peak finder is just a Schottky diode charging C2 through R3, with R4 slowly discharging it.  Because the signal does not spend a long time at the peak, we want R3≪R4, so that we can catch the peaks. We also want a moderately rapid attack (to catch percussive sounds quickly) and a fairly slow decay, so that low-pitched sounds do not appear as fluctuating loudness.  We also want R4 to be sized so that the log amplifier has a good dynamic range.  We probably want to keep the currents through Q1 to between 0.2µA and 2mA, which suggests R4≈1kΩ, and R3≈47Ω.  To make the R4*C2 time constant around 0.1 sec, C2 would have to be 100µF, which costs about 50¢, so it may be cheaper to put in another op amp to separate the peak detector from the log amplifier, using a smaller C and larger R for the peak detector, followed by an op amp, then the low resistance for the log amplifier.

Modified loudness circuit with unity-gain buffer to separate peak detector from log amplifier.

Modified loudness circuit with unity-gain buffer to separate peak detector from log amplifier.

Now we can make C2 be a reasonable size (say 0.1µF) and scale R3 and R4 to match (say 100kΩ for R4, to get a discharge time constant 0f 10msec, and 1kΩ for R3, to get a charge time constant of 100µsec).  This also limits the current drawn from U1 to 1.65mA (well less than the 15mA short-circuit current).

R5 can now be made fairly small (say 470Ω) to give us a large dynamic range on the amplifier.  If Q1 is an NPN transistor with characteristics like the S9013 transistor that I tested when I was playing with log amplifiers, then the output should range from Vref-0.65v up to almost Vref, which at 3mV/dB gives a range of over 200dB (which we certainly won’t get—the log amp may be good to 80 or 90dB.  If the ADC has 10-bit resolution on a full-scale range of Vref, then the steps are about 0.55dB (a 12-bit ADC would have steps of about 0.14dB).

Note that the log amplifier provides V_{BE} = V_{T} \ln \left ( 1+ \frac{I_{C}}{I_{SO}}\right), where IC is the collector current, ISO is the saturation current of the base-emitter diode, and VT is the thermal voltage V_{T} = \frac{k_{B} T}{q} \approx 26 mV at 300º K.  I should be able to estimate VT and ISO from the log amplifier measurements I made earlier. (I get VT =25.6mV and ISO=7.9E-15A for S9013.)

Along the way, I realized that I had never plotted a voltage-versus-current curve for the Schottky diodes, to confirm the theoretical formula V = V_{T} \ln \left ( 1+ \frac{I_{C}}{I_{S}}\right), where IS is the saturation current of the diode.

I did those measurements this morning, using a 1N5817 Schottky diode, a series resistor, a series potentiometer, and an Arduino (Leonardo) board.  I measured the voltage across the resistor (to get current) and across the diode.

The voltage does fit nicely to the log of current, with IS=1.32µA and VT=27.1 mV. Given the quantization noise in the voltage measurement, these seem like a pretty good fit to theory.

The voltage does fit nicely to the log of current, with IS=1.32µA and VT=27.1 mV. Given the quantization noise in the voltage measurement, these seem like a pretty good fit to theory. (click to embiggen)

When my son gets the Data Logger working with the KL25Z boards, I’ll probably want to redo these measurements with higher precision. Note that both VT and IS depend on temperature, and I did not measure the temperature (probably around 18ºC). IS normally doubles for every 10ºC temperature rise, so any measuring device relying on these characteristics would need to have temperature compensation or calibration to correct for temperature.  In any event the IS values for the Schottky diodes are much larger than for the base-emitter junctions, so voltage drop across the diode is much smaller for a given current—which is why we use Schottky diodes!

2014 January 31

Wire loop vs. twisted pair try 1

Filed under: Circuits course — gasstationwithoutpumps @ 21:54
Tags: , , , ,

I was thinking about things we might do in the first lab day for the Applied Circuits course next quarter, now that I have 2 lab sessions a week.  The first, obvious thing is to unpack the lab kits and identify the different components, labeling the capacitor zip locks with values of the contained capacitors, and learning to use the wire strippers, the power supplies, and the voltmeters.

I’m thinking that I should have the students make a 3′ red-black twisted pair and pack it with their parts, so that they don’t try getting new power wires every week.

One experiment I was considering having them do is to look at the AC signal from a large loop of wire and from twisted pair, to see the difference in noise pickup.  I tried doing this at home today, with rather disappointing results.  The large loop did not pick up more 60Hz noise than the twisted pair when viewed on either my Kikusui oscilloscope or by Bitscope USB oscilloscope.  In fact I couldn’t see any noise with either one.

I tried adding my 1500-gain EKG amplifier as a front end, and then I could see about 60μV noise, but that did not change whether I used a long loop, a twisted pair, or a very short loop between the instrumentation amp inputs.

I first tried looking at how much noise there was from the Bitscope with the DP01 active probe using AC coupling:

Looking at shorted inputs  for the AC-coupled DP01 active probe in its high gain mode.  This is 2mV/division, 100µs/division, "macro" mode.  The noise is a couple of mV.

Looking at shorted inputs for the AC-coupled DP01 active probe in its high gain mode. This is 2mV/division, 100µs/division, “macro” mode. The noise is a couple of mV, about the same as the noise level without the DP01, but the resolution is much better with the DP01.  The high-speed trace here is to show the component of the noise that is around 30.8kHz, which is about as big as the 60Hz component.  The 30.8kHz noise is most likely from the USB power supply into the Bitscope.  The Bitscope does not appear to have as good power-supply noise rejection as one might want.

I then hooked up the EKG amplifier board (which should have a gain around 1508) using a separate power supply, and looked at the noise on the Vref signal (which is just buffered from a voltage divider on the power supply).

At 2mV per division and 10ms per division, we can see a little 60Hz noise added to the high-frequency noise of the Bitscope, but the noise is still only 2–3mV, which would be an input-referenced noise of about 2µV given the amplifier gain around 1500.

At 2mV per division and 10ms per division, we can see a little 60Hz noise added to the high-frequency noise of the Bitscope, but the noise is still only 2–3mV, which would be an input-referenced noise of about 2µV given the amplifier gain around 1500.

The noise on Vref is not much more than noise inherent to the Bitscope and is very similar to the noise I see looking just at the output of the power supply without the EKG attached.
Next I looked at the output of the EKG, with both inputs shorted to Vref.

This is now 40mv/division and 10ms/division looking at the output of the EKG amplifer with both inputs shorted to Vref.  The output noise is around 90mV, so the input-referenced noise is around 60µV.

This is now 40mv/division and 10ms/division looking at the output of the EKG amplifer with both inputs shorted to Vref. The output noise is around 90mV, so the input-referenced noise is around 60µV.

Now we see a signal that is not just Bitscope or power supply noise, and have a noise floor for looking at signals at the input of the EKG amplifier.

Unfortunately, replacing the short with a large loop of wire does not appreciably change the signal, but if I connect the two EKG inputs to Vref via separate 2.2MΩ resistors, I get a large output:

200mV/division, 10msec/division.  Inputs of EKG amplifier separately connected to Vref via 2.2MΩ resistors.  This signal is about 1.04V peak-to-peak (so the input is about 690µV.

200mV/division, 10msec/division. Inputs of EKG amplifier separately connected to Vref via 2.2MΩ resistors. This signal is about 1.04V peak-to-peak (so the input is about 690µV).

The output can be changed substantially by putting my hand near the resistors—the 60Hz noise appears to be capacitively coupled into the amplifier. I can reduce the peak-to-peak voltage to about 500mV  (that is around 300µV at the input) and make it have a larger 120Hz that is almost 10dB larger than the 60Hz component, , just by moving my finger around near the resistors. I can also raise the signal until the EKG amplifier is swinging rail-to-rail (at least 3mV at the input).

So I don’t have a demonstration circuit for electromagnetic pickup here, but I do have one for capacitive coupling.  To detect currents induced in a loop, I probably need a transimpedance amplifier to detect small currents, rather than an instrumentation amplifier to detect small voltages .  I’ll leave that for a separate post.

2013 July 21

Virtual ground circuits

Filed under: Circuits course — gasstationwithoutpumps @ 15:55
Tags:

To use single-supply op amps properly, one usually needs to create a “virtual ground” or “bias voltage” between the two power-supply rails.  I have used 3 different circuits for these virtual grounds:

Three different virtual ground circuits I've used.

Three different virtual ground circuits I’ve used.

The circuit on the upper left is the one that I’ve been teaching in the Applied Circuits course, because it uses some of the thematic elements of the course: the voltage divider and the unity-gain buffer. The output is half the power supply voltage and tracks it well. It works well for most of the circuits they do, but has one major problem: any noise on the power-supply line is coupled into the virtual ground. Given that they could be powering their circuits off an Arduino powered from a USB port on a computer, the “5v” power can be very noisy indeed. (See, for example, the glitches observed in capacitor charging).  The unity-gain buffer limits the current from the virtual ground to about ±20mA.

The circuit on the upper right again uses a unity-gain buffer, but uses a TL431ILP  “adjustable shunt regulator” (drawn here as an adjustable zener diode).  This circuit provides a 2.5v output, as long as the power-supply voltage is high enough. The TL431ILP needs 1mA of current to get good regulation, hence the 2.5kΩ pullup resistor.  A somewhat smaller resistor would be safer, as the regulator would then have sufficient current even if the power supply voltage dropped a lot.  I usually use about a 1kΩ resistor, wasting a couple of mA to get good 2.5v output even when the input drops to 3.5v.  Without the unity-gain buffer, the shunt regulator should be able to sink about –100mA, but its source capability would limited (maybe 1.5mA with a 1kΩ pullup). We could get a balanced ±50mA capability with a 51Ω pullup, but there would be a 49mA current through the shunt regulator with no output current, resulting in 123mW of wasted power.

The bottom circuit uses a low-drop-out linear voltage regulator that can source +100mA.  This circuit is limited to sinking about –2.6mA, though, as the only path to ground is through the pair of feedback resistors, and the LDO feedback would cease to provide proper regulation once the output is pulled above the desired output voltage.  Smaller feedback resistors could be used to sink more current, at the cost of having a large current through the feedback resistors.  For example, we could get a balanced ±50mA supply by reducing the resistors to 27Ω each, but there would be a 50mA current through the feedback resistors with no output current (wasting about 116mW of power).

I don’t know of any off-the-shelf chip that provides a good voltage reference that can both source and sink significant current without wasting power in resistors.

Either the LDO or the shunt regulator costs about 40¢ (single-part costs for through-hole parts), so they are expensive parts to add to a design if not needed, but either will provide good noise immunity.

2013 July 18

Improved rectifier with Schottky diodes

Filed under: Circuits course,Data acquisition — gasstationwithoutpumps @ 22:32
Tags: , , , ,

In the Improved rectifier post, I gave the following circuit for an inverting rectifier and showed traces of its performance using diode-connected S9018 NPN transistors as diodes:

Only one of D1 and D2 can be conducting.

Only one of D1 and D2 can be conducting.

With a constant amplitude triangle wave input (about 2.6v peak-to-peak),  the circuit had some pretty serious glitches:

frequency positive glitch negative glitch
3kHz 40mV 40mv
10kHz 80mV 80mv
20kHz 120mV 100mv
30kHz 160mV 140mv
40kHz 200mV 180mv
50kHz 220mV 210mv
60kHz 250mV 260mv
70kHz 260mV 300mv

I claimed that I could reduce the glitches  by replacing the NPN transistors with 1N5817 Schottky diodes.  The diodes arrived today, and I tried them out with the same 10kΩ resistors and 30kHz triangle wave as before:

With the 1N5817 Schottky diodes, the glitches at 30kHz are much reduced—only about 68mV of overshoot.

(click to embiggen) With the 1N5817 Schottky diodes, the glitches at 30kHz are much reduced—only about 68mV of overshoot when turning off, which is half of the glitch with the S9018 NPN transistors as diodes.

I noticed that there was a bit of phase shift for the 30kHz signal, as well as the small overshoot. I tried adding capacitors in parallel with the resistors to improve the performance at 30 kHz (both to correct the phase shift and to keep the gain at -1).

This circuit works well up to 30kHz, and is still somewhat functional at 100kHz, though the "corners" have gotten soft enough that the clipping to the threshold voltage is no longer very precise at 80kHz.

This circuit works well up to 30kHz, and is still somewhat functional at 100kHz

C2 seems to adjust the overshoot, and C1 then needs to be set to fix the phase and gain.  I had the best results at 30kHz with C1=330pF and C2=220pF:

With capacitors in parallel with the feedback resistors, the phase shift is mostly corrected and there is less than 20mV of overshoot—the turn-on and turn-off corners are softened somewhat.

(click to embiggen) With capacitors in parallel with the feedback resistors, the phase shift is mostly corrected and there is less than 20mV of overshoot—the turn-on and turn-off corners are softened somewhat.

Unfortunately, there is no easy way in the BitScope software to set the offset of the traces precisely. You can do a lot of range changing and clicking the left or right sides of buttons (and start all over if you accidentally hit the middle of the button), but the offset is only displayed to 2 decimal points, but can be adjusted somewhat finer, making it hard to guess exactly what it is set to. As result, I’ve not been able to measure the overshoot or undershoot when it is less than 10mV—I’m never sure exactly what I’m measuring with respect to, and visually similar settings result in ±10mV in the estimate. In any event, the errors in this version of the improved rectifier are at least 5× better than in the version with the S9018 diode-connected transistors.

The circuit works well throughout the audio range, and can be pushed to 100kHz, though the “corners” have gotten soft enough that clipping to the threshold voltage is no longer very precise at (about 60mV off @ 80kHz—undershoot, not overshoot). At 100kHz, the output signal is still pretty good, but there is about an 85mV error in the threshold, and the corners are so rounded that the output almost looks like a sine wave:

Waveform at 100kHZ (sine wave input), showing the soft corners at that frequency.  The output doe snot get down to the threshold voltage, but only to about 85mV above threshold.

(click to embiggen) Waveform at 100kHZ (sine wave input), showing the soft corners at that frequency. The output does not get down to the threshold voltage, but only to about 85mV above threshold.

I can get better performance at 100kHz with smaller capacitors (100pF and 220pF, instead of 220pF and 330pF), but at the cost of some overshoot at 20kHz and 30kHz.  I suspect that the right values for the capacitors depend heavily on what op amp is used (especially its slew rate), but since I only have MCP6002 (and the equivalent MCP6004) op amps, I’ve not tested this suspicion.

2013 July 17

Improved rectifier

Filed under: Circuits course,Data acquisition — gasstationwithoutpumps @ 00:54
Tags: , , ,

In the Precision rectifier post, I gave the simplest circuit for making a precision rectifier:

This circuit is both a log amplifier and a precision rectifier.  If Vb is set to a constant voltage, then Vout1-Vb varies as log(Vb-a).  Vout2 is max(Va,Vb).

This circuit is both a log amplifier and a precision rectifier. If Vb is set to a constant voltage, then Vout1 varies as log(Vb–Va). Vout2 is max(Va,Vb). 
The diode can be connected in the opposite direction, to get Vout2=min(Va,Vb) and Vout1 varying with log(Va–Vb).

And I showed the problem with this circuit at “high” frequency, as the slew rate limitations of the op amp limit the turn-on time (to about 8 µs):

The S9018 NPN transistor with a 10kΩ resistor and a 15kHz input signal.  The overshoot as the rectifier turns off is about 50mV, and the turn-on delay is about 8µsec.  The turn-on delay does not vary much with the input resistance, unlike the turn-off overshoot.

(click to embiggen) The S9018 NPN transistor with a 10kΩ resistor and a 15kHz input signal. The overshoot as the rectifier turns off is about 50mV, and the turn-on delay is about 8µsec. The turn-on delay does not vary much with the input resistance, unlike the turn-off overshoot.

I also promised, “There are standard solutions that limit the voltage swing, but I think I’ll leave that for a later blog post.”  This is that post.

The textbook standard solution is to add another diode and resistor, and to configure the rectifier as an inverting amplifier (rather than a unity-gain one) when it is following the input:

Only one of D1 and D2 can be conducting.

Only one of D1 and D2 can be conducting.

This circuit has an input impedance of R1 (not the very high input impedance of the previous circuit). In this circuit, if Vin is more than Vthreshold, the output of the op amp goes low until diode D1 conducts and the negative input of the op amp is held at Vthreshold, as is Vout (with an output impdeance of R2).  If Vin is less than Vthreshold, the output of the op amp rises until D2 conducts, and the feedback circuit makes an inverting amplifier with V_{out} -V_{threshold} = \frac{-R_{2}}{R_{1}}(V_{in} - V_{threshold}).  The output impedance is very low.  Note that the difference in the output impedance for the two states is similar to the situation for the simpler circuit, and can cause problems if the output of the rectifier is fed directly to an RC filter, unless the R value for the RC filter is much larger than R2.  For the loudness circuit, we want a very large RC time constant to smooth out the ripples of the rectifier, so a large R value is not a problem.

We expect this circuit to have problems when neither D1 nor D2 is conducting—that is, as the circuit makes transitions between the rectifier being on or off.  The simple rectifier circuit only had problems with turning on (as the op amp had to slew from a rail to a diode-drop past Vthreshold), but this improved circuit has to swing two diode drops when turning on or when turning off.  The two-diode-drop swing is smaller than the

Here is an example of the output with a 30kHz clock, using S9018 transistors as diodes and R1 and R2 both at 10kΩ:

    (click to embiggen) Output (yellow) for the improved rectifier with a 30kHz triangle wave as input (green). The glitches are about 300mV and last for about 4 µsec.

(click to embiggen) Output (yellow) for the improved rectifier with a 30kHz triangle wave as input (green). The glitches are about 140mV–160mV and last for about 4 µsec.

The duration of the glitches is always about 4µs, but the magnitude of the glitches depend very much on frequency.  With a 2kHz triangle wave signal, I can’t see the glitches with the BitScope USB oscilloscope (so less than about 20mV).  The magnitude of the glitch seems to be proportional to the input magnitude. Using a constant amplitude triangle wave input (about 2.6v peak-to-peak),  I measured the glitches for some higher frequencies:

frequency positive glitch negative glitch
3kHz 40mV 40mv
10kHz 80mV 80mv
20kHz 120mV 100mv
30kHz 160mV 140mv
40kHz 200mV 180mv
50kHz 220mV 210mv
60kHz 250mV 260mv
70kHz 260mV 300mv

To understand where the glitches come from, it helps to look at the op-amp output and the negative feedback input:

The output of the op amp (green) is either a diode drop above or a diode drop below the output of the rectifier circuit.  The transitions between these states are limited by the op amp slew rate.  I measured about 600 mV/µsec, which is what the MCP6002 op amp I'm using is specified to have as a slew rate (I measured before looking it up, to keep from being biased by the correct answer).

(click to embiggen) The output of the op amp (green) is either a diode drop above or a diode drop below the output of the rectifier circuit (yellow) depending which diode is conducting.  The transitions between these states are limited by the op amp slew rate.  I measured about 600 mV/µsec, which is what the MCP6002 op amp I’m using is specified to have as a slew rate (I measured before looking it up, to keep from being biased by the “correct” answer).

 The negative input of the op amp, which the feedback circuit is trying to keep at Vthreshold, has glitches when the op amp output is ramping between its two states.

(clcik to embiggen) The negative input of the op amp (green), which the feedback circuit is trying to keep at Vthreshold, has glitches when the op amp output (yellow) is ramping between its two states.

The glitches in the improved circuit are smaller than for the simpler circuit, and can be further reduced by using Schottky diodes (to reduce the size of the diode drop, and hence how far the op amp must swing to change states) or a faster op amp (to reduce how long the op amp takes to slew the two diode drops).  I expect that with the Schottky diodes, the glitches should be reduced to 2(450mV)/(600 mV/µs)=1.5µs.  Since the glitches are basically triangular pulses, reducing the duration by a factor of 2–3 should reduce the amplitude by as much, and the total energy by 8–27.

To test the rectifier circuit with better diodes, I’ve ordered some 1N5817 Schottky diodes from Digi-key. I like dealing with that company, as they have a lot of components I need, are always very fast in processing orders, and have not yet messed up an order.  They were once out of stock on something that I had ordered, and called me up to apologize profusely for the mistake in their inventory database (normally they notify you before you order if something is out of stock).  For today’s order, they sent me notice that they had shipped the order less than an hour and a half after I had placed the order.  Because they offer first-class US mail as a shipping option, their shipping charges tend to be much less than most of the places I deal with.  (UPS ground is cheaper for big things, but no one is beating the Post Office prices on small lightweight objects.)

Disclaimer: neither Digi-key nor the Post Office has offered me anything for my endorsement—I’m just feeling pleased with them right now.

Next Page »

The Rubric Theme Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 250 other followers

%d bloggers like this: