op-amps – Neil's Log Book https://nrqm.ca What could possibly go wrong? Sun, 12 Feb 2017 07:32:14 +0000 en-US hourly 1 https://wordpress.org/?v=5.4.1 Un-improving range on the infrared channel https://nrqm.ca/2011/10/un-improving-range-on-the-infrared-channel/ Tue, 04 Oct 2011 03:51:46 +0000 https://nrqm.ca/?p=668 It turned out doing software UART was a terrible idea.  The processor is way too slow to support a reasonable baud rate.  I did figure out how to use a comparator though: the key phrase I was missing was “rail-to-rail.”  That means that inputs can be in the full voltage range from ground to Vcc.  Another handy phrase is “push-pull,” which means that the comparator can output 0 and 1; in contrast, an “open collector” comparator can only output 0, and needs an external resistor to pull the output to 1.

I bought a rail-to-rail push-pull comparator, the MCP6541, and tried it with the receiver circuit, and sure enough it increased the maximum range significantly.  Unfortunately it also increased the minimum range significantly.

Here’s the circuit diagram for the modified receiver circuit:

Infrared receiver with comparator for amplification.

Infrared receiver with comparator for amplification.

The 1 kΩ and 10 kΩ resistors are in a voltage divider configuration to generate a 3.0 V reference against which the input is compared.  If the input is higher than 3.0 V, the comparator outputs 3.3 V, and otherwise the comparator outputs 0 V.

I guess there are a bunch of transistors inside the comparator, and putting them in a chain with the pair of external transistors messes things up.  I don’t know why, but it might be a gain-bandwidth thing (too much gain, lowers the maximum frequency the circuit can operate at).  This is what the output looks like at about 6.5 cm:

'U' character sent over infrared with infrared amplifier.

'U' character sent at 19200 bps over infrared with comparator amplifier.

The jagged bits aren’t there without the comparator.  I used the U character to test because its binary pattern is 01010101.  As you can see, the pattern is there but it’s kind of messed up and it’s dangerously close to 3.0 V.  (Now that I look at this again I see maybe reducing the 3.0 V threshold would improve the minimum range.)

I figured I could put an OPA2134 op-amp voltage follower in between the external transistors and the comparator.  This would de-couple the two sets of transistors, so the weird transistor chaining effect would disappear.  This worked perfectly, once, for no apparent reason at all.  Eventually, after spending a day trying to reproduce my success, I read the op-amp’s datasheet more closely and discovered that it’s not rail-to-rail and should never have worked (it can’t output the full 3.3 V signal, so the comparator’s input was never reaching 3.0 V).

I switched to a JFET op-amp that had rail-to-rail output, and it was able to transmit the ‘U’ character at a good set of ranges, both small and large.  Unfortunately this is the signal it was outputting, at 7.5 cm and at 2 cm:

'U' sent at 19200 bps over infrared with JFET voltage follower at 7.5 cm.

'U' sent at 19200 bps over infrared with JFET voltage follower at 7.5 cm.

'U' sent over infraret with JFET voltage follower at 2 cm.

'U' sent at 19200 bps over infrared with JFET voltage follower at 2 cm.

The observant among you, my imaginary audience, will notice two strange things from this screenshot:

  1. The signal is peaking at almost 4 V.
  2. It’s sending 9 bits at 7.5 cm and 19 bits at 2 cm.

Hoo boy, it didn’t work at all, and it was pure luck that the ‘U’ transmitted correctly at short range (followed, presumably, by a framing error that my system silently ignored).  No other character worked.

I found out that you can use an op-amp as a comparator, so I tried that with my OPA2134:

'U' sent at 19200 bps over infrared with op-amp comparator.

'U' sent at 19200 bps over infrared with op-amp comparator.

Okay!  You can see what it means that the amplifier is not rail-to-rail, it’s only going up to 2.6 V (and that only briefly), but if I remember correctly it received.  Unfortunately the high bits got narrower for some reason as the range decreased, so it didn’t actually do anything to solve the range problem.

I tried using the JFET amp as a comparator, but it didn’t output anything at all so I gave up and ignored the project for a few weeks.  My current solution is to pretend there isn’t a problem, and if I run into the  minimum range issue then I can just bend the receiver askew so that the signal is damped enough to receive.  In the meantime, the transmitter now has a wider field of view, which ought to make it easier to place several receivers in range of the control unit.

]]>
Improving range on the infrared channel https://nrqm.ca/2011/09/improving-range-on-the-infrared-channel/ Sat, 03 Sep 2011 19:15:55 +0000 https://nrqm.ca/?p=663 The range on the infrared channel, which I discussed in the last entry, is probably enough; but I’d like to increase it a bit.  With more range I can space modules farther apart if needed, and hopefully be able to have a wider angle between the transmitter and receiver.

Fortunately the signal output by the Darlington transistor pair on the receiver is a pretty clean digital signal.  At full power it ranges from (a little above) 0 V to (a little below) 3.3 V.  As the transmitter gets farther away the digital signal remains but the low voltage increases beyond the UART receiver’s ability to read a 0.  For example, at a large distance the UART signal might range from 2.5 V (logical 0) to 3.3 V (logical 1).

There are several options I’ve considered:

The handy old Schmitt trigger is the most straightforward, but it’s touchy to design and it will add a bunch of parts (an op-amp and a bundle of resistors).  I tried using a comparator chip, which is like the Schmitt trigger but simpler, but I found that it had a big limitation.  It worked, but the inputs can’t exceed Vcc – 1.5 V (the “common mode input voltage range” on the datasheet).  It can’t read a digital signal ranging between 1.8 (or more) and 3.3 V, so it would provide some amplification but not a lot.  I’m targeting 90% of Vcc as my threshold, so it should read anything below 3.0 V as low.  I also considered using another PNP transistor to amplify the difference between Vcc and the input voltage, but: that much amplification is risky noisewise, an extra transistor reduces the bandwidth too much, and the PNP transistor will produce a logically inverted signal.

Another option is to amplify the signal using crazy op-amp magic, but aaaaaaah no.

So I tried thinking like I’m supposed to for once, and I’m going to try a software solution.  AVR processors include an analog comparator, which I can (hopefully) use to amplify the digital signal coming from the infrared optotransistor.  The downside to doing it this way is that it bypasses the UART module, which means that the application needs to receive data manually (I can still use UART to transmit the signal).  Receiving data will tie up the processor, but as long as there’s enough time to run the receiver code it should be okay, I don’t foresee much data traffic.  Here’s a potential flow chart for the receive procedure:

Software receiver flow chart.

Software receiver flow chart.

Some notes:

  • The wait process is a euphemism for “disable the timer, store the data, blah blah blah, then go back to the program until the next start bit.”  This process takes place during the stop bit, so if there’s another byte incoming then it should finish in time to receive the next start bit.
  • Kevin Rosenberg’s awesome tool AVRCalc calculates that the 8-bit timer running at 8 MHz can be used to generate a 57554 Hz interrupt rate using an OCR value of 0x8A.
  • I might need to mess around with the timing so that the AC reads the right bit, but probably not.  There should be plenty of interrupt overhead delay, and the sampling rate is a little slow and will drift toward the end of the bit.
  • I’m not sure how long the analog comparator takes to produce a result but I’m guessing it’s pretty fast because it doesn’t have to do much.  The AVR datasheet doesn’t have much information on it.  I also don’t know if the comparator has a large common mode input range.

Failing that, I can look for an external comparator with a large common mode input range, or just suck it up and use an op-amp.

]]>
Acoustic modem circuit diagrams https://nrqm.ca/2011/01/content-is-king-acoustic-modem-circuit-diagrams/ Thu, 13 Jan 2011 23:18:46 +0000 https://nrqm.ca/?p=464 Here are some circuit diagrams (leaving the power source abstract):

Acoustic transmitter circuit

Acoustic transmitter circuit diagram (click for full size).

Acoustic receiver circuit

Acoustic receiver circuit diagram (click for full size).

Acoustic modem microcontroller circuit

Acoustic modem microcontroller circuit diagram (click for full size)

]]>
Low-rent acoustic receiver https://nrqm.ca/2011/01/low-rent-acoustic-receiver/ Wed, 05 Jan 2011 07:07:08 +0000 https://nrqm.ca/?p=357
Receiver Circuit

Transmitter (top) and receiver (bottom) circuits.

I’ve previously described the power supply and transmitter for my acoustic modem.

The receiver circuit completes the modem’s hardware design.  It is simply a two-stage amplifier that gives a total gain of about 2000, in series with a band-pass filter.

The acoustic transducer produces a beautiful sine wave with nearly no noise.  I found that I could apply a huge gain to its output and the amplifier’s output would still be clean: the raw (unfiltered) output has a 5 V offset, and the signal fits into the 5 V above the offset.  In other words, the output is at -5 V when idle and peaks at around 0 V when the receiver receives a signal.

The goal is for the receiver to output a signal that is around -10 V when idle and peaks at -5 V when it receives a signal.  These voltages correspond respectively to logic low and high on the microcontroller.

The band-pass filter serves two functions: a blocking capacitor (the simplest kind of high-pass filter) removes the 5 V DC component, and a low-pass filter removes the 40 kHz carrier wave.  The filter also has a side-effect of attenuating the signal, so that the filter’s output peaks at 1 V instead of 5 V (this is bad).  The attenuation problem can probably be avoided, either by tuning the filter better (I’m not sure how), or by replacing the DC blocking capacitor with a diode or something that drops 5 V, or by subtracting 5 V from the output with a difference amplifier.  From now on I discuss the output of the filter, not the raw unfiltered amplifier output.

Acoustic Receiver Output

The receiver's output (0.5 V/div vertical and 500 μs/div horizontal)

You can see the receiver’s output in the photo above.  Unfortunately my screen capture technology is unsophisticated.  The output peaks at just over 1 V (due to the filter attenuation), and lasts for about 3 ms (recall that the 40 kHz carrier signal is filtered out, so it’s just one big chunk of signal).  The waveform corresponds to a very strong input into the receiver: I held a piece of paper about a foot above the modem and transmitted an acoustic ping with the transmitter.  The waveform looks somewhat different when the received signal is weaker:

Weaker received acoustic signal

The receiver output for a somewhat weaker signal (0.5 V/div vertical and 500 μs/div horizontal).

This corresponds to the piece of paper being held a metre or so away from the transmitter.  There is a dip in the middle of the signal, and a lone tertiary peak a little more than 0.5 ms after the original wave ends.  As the acoustic signal gets weaker, this dip gets more pronounced.  This is caused by ringing in the receiver transducer’s piezoelectric sensor.

As I mentioned in my post on the transmitter component, the transmitter encodes a 1 bit of data as eight acoustic pulses at 40 kHz (a 0 bit is simply encoded as no signal).  The total duration of the acoustic signal is 200 μs; clearly this is much less than the 3 ms output observed at the receiver.  What happens is that when the acoustic signal is received, the receiver starts to resonate, like a guitar string.

It takes 8 pulses for the receiver’s piezoelectric crystal to reach full resonance.  Once the acoustic signal stops, the crystal continues to resonate, until after 3 ms the energy finally dissipates and the crystal goes quiet.  I’m not totally sure what’s going on, but I think the dips are caused when the resonance somehow interferes with itself; you can observe this phenomenon in many resonance effects.  Eventually the resonance gets back into phase with itself (or whatever) and reinforces itself for a while.

Anyway, the good news is that even at large distances (>10 metres) the acoustic receiver can pick up the transmitted signal effectively, and the receiver’s output includes a strong peak that fits reliably in a 3 ms window.  This means that for data transmission, one bit can be sent every 3 ms, for a total bit rate of 333 bits per second.  This is a low data rate, but not so much lower than that of commercial modems.  I’ll write more about data transmission later.

]]>
Low-rent acoustic transmitter https://nrqm.ca/2010/12/low-rent-acoustic-transmitter/ Sun, 12 Dec 2010 22:44:02 +0000 https://nrqm.ca/?p=324 Acoustic transmitter circuit

Acoustic transmitter circuit.

Above you can see the transmitter part of my acoustic modem.  From left to right, the components are: the power supply, the acoustic transducer, the amplifier, and the microcontroller.

The problem: I need to send a 40 kHz, 20 V peak-to-peak square wave to the transducer.  The circuit has two outputs, + and -, that are connected to the two transducer pins.  In other words, each output needs to switch from +10 V to -10 V  and back once every 25 microseconds.

As always, there are a few decent solutions, and as always I didn’t implement the best one.

Solution: Transformer

I think the best solution, or at least the awesomest, is to use a step-up transformer.  I don’t need a transformer because the transducer I’m using is pretty low-voltage, so I can use it with a reasonable power supply.  A higher voltage transducer such as the Meas-Spec US40KT-01 [PDF], which operates at up to 300 V peak-to-peak, would definitely need a transformer.  The main downside of using a transformer is that I don’t know very much about using transformers, and also I suspect the circuitry will be more expensive (I do have room in my budget).  The upside is that it will produce a  high voltage signal and should be a simpler circuit once I figure it out.

Solution: Amplifier

I have a little microcontroller generating a 0 V to 5 V square wave at 40 kHz.  Originally I had some kind of vague notion that I would use an amplifer to bump the micro’s output up to 0 V to 20 V.

My stumbling block is that the microcontroller is grounded to the -10 V rail, so according to the op-amp, the micro’s outputs are actually from -10 V to -5 V.  How do you amplify that to a signal that goes from -10 V to +10 V?  I’m sure there’s a slick way of doing it by mucking around with virtual ground, but I gave up pretty quickly.

Solution: Schmitt Trigger

Suddenly it’s clear why I wrote a log entry about the Schmitt trigger!  Another reason: I was too busy to make a long log entry about something more complicated.

Originally I learned about the Schmitt trigger trying to figure out how to turn the receiver’s analog output into a digital signal.  It transforms a signal of arbitrary amplitude into a digital signal flipping back and forth between the op-amp’s two power rails.  I was going to turn the ±10 V output into a 0-5 V output by adding a diode to block the -10 V signal and a voltage divider to turn the +10 V signal into +5 V.

Anyway, the Schmitt trigger produces a ±10 V signal and hey, that’s exactly what I want, so I just made a Schmitt trigger with threshold levels between -10 V and -5 V (that being, again, the microcontroller’s output from the op-amp’s perspective).

It works okay.  The ±10 V waveform is more trapezoidal than square.  Square waves are always are kind of trapezoidal, but this one is really trapezoidal.  But it’s square enough and the acoustic signal it produces is fine.  The raw output of a receiver module receiving my signal is indistinguishable from that of the SRF04 I’m trying to copy, except my signal is marginally more powerful (since I’m sending the transducer a slightly higher voltage).

So that’s what I’m using as a transmitter for now.  The plan is to upgrade the transducer and switch to a transformer amplifier at some point down the line.  This transmitter functions as a proof-of-concept that works well in air (how to get it working underwater is TBD).

Output

Acoustic modem output waveform

Visualization of the output waveform.

The modem encodes data in acoustic pulses, as shown above.  The image is a representation of a single 1 bit, encoded as eight consecutive pulses at 40 kHz.  I will discuss this more later.

]]>
The Schmitt trigger https://nrqm.ca/2010/12/the-schmitt-trigger/ Fri, 03 Dec 2010 05:06:11 +0000 https://nrqm.ca/?p=327 Schmitt trigger example

Simulation of a Schmitt trigger. The yellow sine wave is the input, the purple square wave is the output.

I was looking for a way to convert an analogue signal into a digital signal, and came across the Schmitt trigger.  This is a great little circuit that you can build with a couple transistors or with an operational amplifier.  I tried to build a transistor-based simulation in Simulink, but it didn’t work right away.  My op-amp simulation did work, so I stuck with that.

The principle is simple: if the trigger input rises above a certain threshold, then the output saturates to the op-amp’s positive power supply voltage.  When the input falls below another threshold, the output saturates to the op-amp’s negative power supply voltage.  If the input lies between the thresholds then the output doesn’t change from whatever it was before.

This is incredibly useful.  To the left you can see a 0.3 V sine wave being converted into a 5 V binary signal (actually a 4.5 V signal, since I added a diode in series with the output to keep it from going down to -5 V).  It also effectively filters out any input jitter that doesn’t cross the threshold needed to change the output state.  Microcontrollers have Schmitt triggers on their digital inputs.  For example, an AVR microcontroller being powered by 5 V typically considers a 0 logic level to be under 1.5 V and a 1 logic level to be over 3 V.  If the input sits between 1.5 V and 3 V then the digital state remains whatever it was before the input entered that region.

Alas, it’s not a perfect circuit.  I used an online calculator to figure out what resistances I needed for my project.  Configurations that worked in the calculator and in simulation didn’t work in reality, either producing no output or something more like a sawtooth wave than the square wave I expected.  It’s probably a limitation in my op-amp—maybe the signal is too high-frequency, I didn’t investigate very deeply.

]]>