Analogue Signals and Op-Amps

Basic Electronics

Course 1 · Chapter 7 · Analogue Signals and Op-Amps

The real world is analogue. Temperature, light, force, current and sound all vary smoothly, and a sensor turns them into a voltage that can be any value in a range. A microcontroller, on the other hand, only understands numbers. The bridge between the two has two halves: signal conditioning (making the sensor's voltage the right size and shape) and the analogue-to-digital converter (ADC), which turns that voltage into a number. The star of the conditioning half is the operational amplifier, or op-amp, a small chip with two inputs and one output that can buffer, amplify, subtract, add or compare voltages. The chapter uses the divider rules of Basic Electronics 3, the RC filter of Basic Electronics 4 and the idea of a switch that is fully on or off from Basic Electronics 6 (in this chapter we meet the opposite, a circuit that works at every voltage in between).

1. Analogue and digital signals

Analogue signalDigital signal
Values it can takeAny voltage in a range (0 to 3.3 V, say), continuouslyTwo levels only: LOW and HIGH (a few volts apart)
CarriesA measurement: the voltage is the informationA bit; many bits in sequence make a number
WeaknessAny added noise is part of the signal and cannot be told apart from itNoise below the switching threshold is ignored completely
ExamplesThermistor divider, light sensor, microphone, strain gauge, battery voltageButton, encoder pulses, I2C and UART data, a PWM output

The ADC: sampling and quantisation

An ADC does two things. Sampling measures the voltage at regular instants, fs times a second. Quantisation rounds each measurement to one of 2N levels, where N is the number of bits. The step between levels is the least significant bit (LSB):

LSB = Vref / 2^N code = floor( Vin / LSB ) (the number the program reads) Each code covers a step of one LSB, so a reading is only right to within one LSB (about half an LSB if the converter rounds). That rounding error behaves like random noise of rms quantisation noise = LSB / sqrt(12) = 0.29 LSB and an ideal converter fed a full-scale sine wave has a signal-to-noise ratio of SNR = 6.02 x N + 1.76 dB (each extra bit buys 6 dB, a factor of 2 in voltage) Worked example (12 bits, Vref = 3.3 V): LSB = 3.3 / 4096 = 0.806 mV Vin = 1.000 V: 1.000 / 0.000806 = 1241.2 so the code is 1241 (1241 x 0.806 mV = 0.9999 V) rms quantisation noise = 0.806 / 3.46 = 0.23 mV; ideal SNR = 6.02 x 12 + 1.76 = 74 dB
ConverterBitsFull scaleLSBNotes
Arduino Uno / Nano (built in)105 V (default)4.88 mV1024 codes; 6 inputs; never exceed 5 V on a pin
Raspberry Pi Pico (built in)123.3 V0.806 mV3 usable inputs; the real accuracy is about 9 effective bits, so the bottom 3 bits are noise
ESP32 (built in)12about 0 to 3.1 V (attenuation setting)0.8 mVMany inputs, but noisy and non-linear near 0 V and 3.3 V; keep signals between about 0.15 and 3.0 V; the Wi-Fi radio blocks one of its two converters
ADS1115 (external, over I2C)16±4.096 V (gain setting)125 µVThe upgrade for a precision measurement, and the way to add analogue inputs to a Raspberry Pi, which has none

These figures are typical; the datasheet of your board is the authority. The bit count says how finely a converter can read, not how accurately it does: noise, gain error and a poorly decoupled reference can ruin the bottom bits of a 12-bit converter.

Why the sampling rate matters: aliasing

A converter sampling at fs can only see frequencies up to fs/2 (the Nyquist limit). Anything faster is not just lost: it is folded back down and appears as a false, slower signal.

alias frequency = | f - k x fs | where k is the whole number that gives the answer nearest 0 fs = 1000 samples/s (Nyquist limit 500 Hz). A noise tone at 1100 Hz appears at |1100 - 1000| = 100 Hz. The program cannot tell it from a real 100 Hz signal. The cure has to come BEFORE the ADC: a low-pass filter (an RC network, Basic Electronics 4) that removes everything above fs/2. Section 7 designs one.

2. The ideal op-amp

An op-amp is a differential amplifier with a very high gain: it amplifies the difference between its two inputs.

Vout = A x ( V+ - V- ) A = open-loop gain: 100,000 or more (100 dB) at DC for a typical chip The symbol (the sign is printed beside each input: read the SIGN, not the position on the page): +----------+ IN- ----| - | | U1 |---- OUT IN+ ----| + | +----------+ (with power pins V+ at the top and V- at the bottom, usually left out of the drawing) Real chip, DIP-8, a dual op-amp (two amplifiers in one package: LM358, MCP6002): notch at the left, pins numbered anticlockwise from pin 1 at the bottom-left, as seen from above pin 8 V+ (positive supply) pin 7 OUT B pin 6 IN- B pin 5 IN+ B (top row, left to right) pin 1 OUT A pin 2 IN- A pin 3 IN+ A pin 4 V- (0 V on a single supply) (bottom row) Pin 8 is directly across from pin 1, and pin 5 across from pin 4. Check the datasheet of your chip: single and quad op-amps have different pin orders.

Why you never use it open-loop as an amplifier

With A = 100,000, an input difference of 30 µV already drives the output through 3 V, and the gain varies wildly between chips, with temperature and with frequency. You make it useful by feeding part of the output back to the inverting input, called negative feedback. The feedback makes the circuit's gain depend only on the resistors, not on A.

Take the non-inverting circuit of section 3, with feedback fraction b = Rg / (Rf + Rg) fed back to V-: V+ = Vin V- = b x Vout Vout = A x (Vin - b x Vout) Vout x (1 + A x b) = A x Vin so Gain = Vout / Vin = A / (1 + A x b) = (1 / b) x ( A b / (1 + A b) ) When A x b is much bigger than 1 the last bracket is almost exactly 1, so Gain = 1 / b = 1 + Rf / Rg. Example, Rf = 10 k, Rg = 1 k: b = 1/11, ideal gain 11, A = 100,000: Gain = 100,000 / (1 + 100,000 / 11) = 10.9988 (only 0.011 % below 11: the resistors set the gain) And the voltage between the inputs is V+ - V- = Vout / A: for Vout = 3 V that is 30 microvolts.
The two golden rules (for an op-amp with negative feedback)
Rule 1 (the virtual short): the output does whatever is needed to make V+ equal to V-. If you know one input's voltage, you know the other's. Rule 2: the inputs draw no current (a bipolar chip needs tens of nanoamps, a CMOS chip picoamps; both are negligible next to the currents in 1 kΩ to 100 kΩ resistors). Every circuit in section 3 follows from these two rules and Ohm's law. The rules apply only when feedback takes the output back to the inverting input; a circuit with no feedback, or with feedback to the non-inverting input (the comparator of section 4), follows different rules.

3. Building blocks with negative feedback

The voltage follower (buffer)

+----------+ Vin o----------| + | | U1 |-----+------o Vout +-----| - | | | +----------+ | | | +----------------------+ Rule 1: V- = V+ = Vin, and V- is wired straight to Vout, so Vout = Vin gain = 1 It copies the voltage but changes the impedance: the input draws almost nothing, the output can supply milliamps. Use it to stop a high-impedance source being loaded. Example: a divider of 10 k over 10 k gives 1.65 V from 3.3 V. An ADC that needs to draw 20 microamps from it through 5 k of divider resistance would pull the node down by 0.1 V (6 %); a follower between the divider and the ADC removes that error. Basic Electronics 3 showed the loading problem; this is the cure.

The non-inverting amplifier

+----------+ Vin o----------| + | | U1 |-----+------o Vout +-----| - | | | +----------+ | +--------[ Rf ]--------+ | [ Rg ] | 0 V o----+ Rule 1: V- = V+ = Vin. Rule 2: no current enters the - input, so the current through Rg and Rf is the same: current through Rg = (Vin - 0) / Rg = Vin / Rg Vout = Vin + (current) x Rf = Vin + Vin x Rf / Rg Gain = Vout / Vin = 1 + Rf / Rg always 1 or more; the output has the SAME sign as the input Example: Rf = 39 k, Rg = 1 k: gain 40. A sensor output of 0 to 80 mV becomes 0 to 3.2 V. Input impedance: huge (the + input draws nothing). Rf = 0 (a wire) and Rg open gives the follower: gain 1.

The inverting amplifier

+-------[ Rf ]-------+ | | | +----------+ | Vin o--[ Rin ]-----+-----| - | | | U1 |---+----o Vout 0 V o--------------------| + | +----------+ Rule 1: V+ = 0 V, so V- = 0 V: the - node is a "virtual ground" (at 0 V, but not connected to it). Rule 2: no current enters the - input, so the whole input current flows through Rf: input current = (Vin - 0) / Rin = Vin / Rin Vout = 0 - (input current) x Rf Gain = Vout / Vin = - Rf / Rin the minus sign: the output is upside-down Example: Rin = 2 k, Rf = 10 k: gain -5. Vin = +0.5 V gives Vout = -2.5 V (a negative voltage: needs a negative supply) Input impedance = Rin (the signal source sees Rin to a virtual ground), unlike the non-inverting amplifier. Unlike the non-inverting amplifier, the gain can be anything: 0.1 (attenuator) as well as 100.

The summing amplifier

+-------[ Rf ]-------+ | | V1 o--[ R1 ]-------+ | V2 o--[ R2 ]-------+ +----------+ | V3 o--[ R3 ]-------+-----| - | | | U1 |---+----o Vout 0 V o--------------------| + | +----------+ Every input pushes its own current into the virtual ground (the three currents simply add: Kirchhoff, Basic Electronics 2): Vout = - Rf x ( V1/R1 + V2/R2 + V3/R3 ) With R1 = R2 = R3 = 30 k and Rf = 10 k: Vout = - (V1 + V2 + V3) / 3 minus the average of the three With unequal resistors each input gets its own weight (a mixer, a digital-to-analogue converter built from R-2R ladders). Check: V1 = 1.0 V, V2 = 0.5 V, V3 = 2.0 V, R1 = 10 k, R2 = 20 k, R3 = 10 k, Rf = 10 k: Vout = - 10 k x (0.1 mA + 0.025 mA + 0.2 mA) = - 3.25 V

The difference (subtracting) amplifier

V1 o--[ R1 ]----+--------[ R2 ]-------------+ | | | +----------+ | +-----| - | | | U1 |----------+----o Vout V2 o--[ R3 ]----+-----| + | | +----------+ [ R4 ] | 0 V o-----------+ Choose R3 = R1 and R4 = R2. Derive with the golden rules: + input: a divider: V+ = V2 x R4 / (R3 + R4) = V2 x R2 / (R1 + R2) - input: V- = V+ , and no current enters the input, so the current through R1 flows on through R2: (V1 - V-) / R1 = (V- - Vout) / R2 Vout = V- x (1 + R2/R1) - V1 x R2/R1 = V2 x ( R2 / (R1 + R2) ) x ( (R1 + R2) / R1 ) - V1 x R2/R1 Vout = (R2 / R1) x ( V2 - V1 ) Use: it amplifies the DIFFERENCE and rejects what the two inputs have in common (the "common-mode" voltage, such as a shared offset or interference picked up by both wires). How well it rejects it depends on how closely the resistors match: worst-case CMRR is about (1 + R2/R1) / (4 x t) for resistors of tolerance t unity gain, t = 1 %: CMRR = 2 / 0.04 = 50 (34 dB) hardly better than no rejection at all t = 0.1 %: CMRR = 2 / 0.004 = 500 (54 dB) The instrument amplifier of section 6 solves the weakness with matched resistors inside the chip. Input impedance is only R1 + R2 (on the V1 side R1) and the two inputs see DIFFERENT impedances: another reason for the buffers in section 6.
CircuitGainInput impedanceUse
Follower1Very highIsolate a high-impedance source; drive a load or an ADC
Non-inverting1 + Rf/RgVery highScale a sensor signal up to the ADC range
Inverting−Rf/RinRinAttenuate or amplify with a sign change; the base of the summer
Summing−Rf/Ri per inputRi per inputMix signals; add an offset to a signal
DifferenceR2/R1R1 and R1+R2 (unequal)Subtract two voltages; remove an offset; bridge sensors

4. The comparator: a decision, not an amplifier

With no feedback an op-amp is a comparator. The huge gain pushes the output hard against one supply rail or the other, depending only on which input is higher:

V+ higher than V-: output goes to the HIGH rail (V+ supply) V+ lower than V-: output goes to the LOW rail (0 V on a single supply) It turns an analogue voltage into a digital decision: "is the light above this level?", "is the battery below 3.3 V?". Weakness: when the input hovers near the threshold, any noise makes the output chatter: 1, 0, 1, 1, 0, 1, 0, 0 ... A sensor with 20 mV of noise sitting within 20 mV of the threshold gives a burst of false pulses, a menace to a counter or a relay.

Hysteresis: the Schmitt trigger

The cure is positive feedback: a little of the output is fed back to the non-inverting input, so that the threshold itself moves each time the output switches. Once it has switched, the input must go back past the original threshold before it switches again. The two thresholds are VH (rising input) and VL (falling input), and the gap between them is the hysteresis.

+----------+ Vref o-------------| - | | U1 |----+----------o OUT +-----| + | | | +----------+ | Vin o-[ R1 ]-+ | | | +-------[ Rf ]--------+ R1 carries the input to the + node, Rf feeds the output back to it. No current enters the input, so the node voltage is a weighted average (superposition): V+ = ( Vin x Rf + Vout x R1 ) / ( R1 + Rf ) The output switches when V+ equals Vref. Solve that for Vin: Vin(switch) = Vref x ( 1 + R1/Rf ) - Vout x ( R1/Rf ) Two possible values of Vout, two thresholds (Vh and Vl are the output's HIGH and LOW voltages; for a rail-to-rail chip, Vcc and 0 V): Output HIGH (Vout = Vh): falling threshold VL = Vref x (1 + R1/Rf) - Vh x R1/Rf Output LOW (Vout = Vl): rising threshold VH = Vref x (1 + R1/Rf) - Vl x R1/Rf Hysteresis = VH - VL = (Vh - Vl) x R1 / Rf Design (Vl = 0, Vh = Vcc): choose R1/Rf = hysteresis / Vcc; then VH = Vref x (1 + R1/Rf). Worked example: Vcc = 3.3 V, Vref = 1.65 V, R1 = 10 k, Rf = 100 k: R1/Rf = 0.1 VH = 1.65 x 1.1 = 1.815 V VL = 1.815 - 3.3 x 0.1 = 1.485 V hysteresis = 0.33 V Output LOW, Vin rising: the output goes HIGH at 1.815 V. Output HIGH, Vin falling: it goes LOW at 1.485 V. A noise level of up to 0.33 V peak-to-peak can no longer cause a false switch. Source impedance: the circuit above assumes Vin comes from a low-impedance source. A source of resistance Rs simply adds to R1: use (R1 + Rs) in the formulas, or put a follower in front, as the build does.

An op-amp or a comparator chip?

A comparator chip (LM393, LM339, TLV3201) is built for the job: it switches fast (tens to hundreds of nanoseconds), recovers at once from being driven hard, and an LM393 has an open-collector output that needs a pull-up resistor to whatever voltage the next circuit uses (the same pull-up idea as Basic Electronics 3). A general op-amp as a comparator is slower (microseconds) and slow to recover from saturation, but it is fine for light levels, temperatures and battery voltages that change over seconds. Do not use a comparator chip in the linear circuits of section 3: it has no internal compensation, and feedback to its inverting input makes it oscillate.

5. Real op-amps

Gain-bandwidth product and slew rate

Open-loop gain falls with frequency. Above a few hertz, A x f is a constant, the gain-bandwidth product (GBW): A(f) = GBW / f MCP6002 and LM358: about 1 MHz. A = 1 at 1 MHz (the "unity-gain frequency"). So a closed-loop amplifier of gain G has the bandwidth (the -3 dB frequency) f(-3 dB) = GBW / G G = 11: 1 MHz / 11 = 91 kHz G = 40: 1 MHz / 40 = 25 kHz G = 1000: 1 MHz / 1000 = 1 kHz Rule of thumb: you cannot have both high gain and high bandwidth from a cheap op-amp. For gain 1000 at 20 kHz you would need 20 MHz of GBW, or two amplifier stages of gain 32 each (1 MHz / 32 = 31 kHz each). Example: gain 40 at 10 kHz: the gain is down by a factor of 1 / sqrt(1 + (10/25)^2) = 0.93, so 40 becomes 37.1. Slew rate (SR): the fastest the output can change, in volts per microsecond, set by an internal capacitor charged by a fixed current. A sine wave of peak voltage Vp and frequency f has a steepest slope of 2 x pi x f x Vp, so it is distorted into a triangle wave once 2 x pi x f x Vp is larger than SR so the full-power bandwidth is f(max) = SR / (2 x pi x Vp) MCP6002 (SR 0.6 V/us), 1.65 V peak (a full 3.3 V swing): f(max) = 0.6e6 / (2 x pi x 1.65) = 58 kHz LM358 (SR 0.3 V/us), same swing: f(max) = 0.3e6 / 10.37 = 29 kHz For small signals the bandwidth limit is what you hit; for large signals the slew rate limit is.

Offset, bias current and single supply

  • Input offset voltage (VOS): a real op-amp behaves as if a small voltage (tens of microvolts to a few millivolts) sat in series with one input. It is amplified along with the signal: VOS = 2 mV in a gain of 40 gives 80 mV at the output, 99 ADC counts at 3.3 V, 12 bits. Use a precision amplifier, or measure the offset and subtract it in software.
  • Input bias current (IB): 20 nA for a bipolar LM358, 1 pA for a CMOS MCP6002. Flowing through a source resistance Rs it drops IB × Rs: 20 nA × 1 MΩ = 20 mV. With a high-impedance sensor (a pH probe, a photodiode) use a CMOS or JFET input.
  • Single supply. A text-book op-amp has ±15 V supplies and swings both ways around 0 V. A robot has one battery, so the amplifier gets one supply, V+ and 0 V, and the signals must sit between 0 V and V+. Two limits then matter: the input common-mode range (how close to the rails the inputs may go) and the output swing (how close the output can get to each rail).
  • Rail-to-rail chips (MCP6002, MCP6004, LMV358, OPA2340) have inputs and output that can go to within millivolts of both rails. A classic LM358 can take its inputs down to 0 V and its output swings down to a few millivolts, but its output only goes up to about V+ minus 1.5 V: on a 3.3 V supply it tops out at 1.8 V, and it is out of spec below 3 V. That is the reason the builds use an MCP6002.
  • Inverting stages on a single supply need the + input biased at a reference voltage (normally V+/2) instead of 0 V, and the signal is then amplified about that reference. The same trick, a reference node held by a follower, is used in stage B of the build to shift the sensor's voltage down.
PartSupplySwingGBWSlew rateUse here
LM358 / LM324 (dual / quad)3 to 32 VInputs to 0 V; output 0 V to V+ − 1.5 Vabout 1 MHz0.3 V/µs5 V and 12 V builds where the output needs not reach V+; cheap, tough, everywhere
MCP6002 / MCP6004 (dual / quad)1.8 to 6 VRail-to-rail in and out1 MHz0.6 V/µs3.3 V boards (Pico, ESP32): the output reaches both rails
LM393 (dual comparator)2 to 36 VOpen-collector output(not an amplifier)(fast, about 1 µs)Threshold detection with a pull-up to any logic level
TL072 (dual JFET)±5 to ±18 VWithin 1.5 V of the rails3 MHz13 V/µsAudio, from a split supply; not a 3.3 V part
INA333 (instrumentation amp)1.8 to 5.5 VRail-to-rail output(gain set by one resistor)—Strain-gauge and other bridge sensors (section 6)

All figures are typical; read the datasheet of the exact part. The pinouts of the dual versions are the same as the diagram in section 2.

6. Sensor conditioning

A sensor rarely gives a voltage between 0 and 3.3 V. Conditioning converts what it gives (a resistance change, a few millivolts, a small current) into a voltage that fills as much of the ADC's range as possible, without ever leaving it.

The thermistor

An NTC thermistor is a resistor whose resistance falls as it warms, steeply and not in a straight line. The usual model is the B-parameter equation, with R0 the resistance at T0 = 25 °C (298.15 K) and B (about 3950 K for a common 10 kΩ disc, quoted between 25 and 85 °C):

R(T) = R0 x exp( B x ( 1/T - 1/T0 ) ) T in KELVIN (K = degrees C + 273.15) Solve for the temperature (this is the formula the program uses): T = 1 / ( 1/T0 + ln( R / R0 ) / B ) 10 k, B = 3950: R(0 C) = 10 k x exp(3950 x (1/273.15 - 1/298.15)) = 10 k x exp(1.2126) = 33.6 k R(50 C) = 10 k x exp(3950 x (1/323.15 - 1/298.15)) = 10 k x exp(-1.0250) = 3.59 k Sensitivity: differentiate: dR/dT = - B x R / T^2 at 25 C: dR/dT = - 3950 x 10000 / 298.15^2 = - 444 ohm per kelvin (that is - 4.4 % per kelvin: huge compared with a metal wire) The curve is not straight; the equation is good to about 1 degree between 0 and 50 C and drifts at the ends. For better accuracy use the Steinhart-Hart equation (three fitted constants) or a look-up table from the datasheet.

A resistance is measured by turning it into a voltage with a divider (Basic Electronics 3). With the thermistor on the top and a fixed resistor Rb at the bottom, the voltage rises as it gets warmer:

+3.3 V o------+ | [ NTC 10k ] | +--------o Vs | [ Rb 10 k ] | 0 V o--------+ Vs = 3.3 x Rb / ( Rt + Rb ) choose Rb = Rt at the middle of the range (10 k at 25 C) so Vs = 1.65 V mid-scale there T (C) Rt Vs 0 33.6 k 0.757 V 10 20.2 k 1.094 V 25 10.0 k 1.650 V 35 6.51 k 1.999 V 40 5.30 k 2.157 V 50 3.59 k 2.429 V Sensitivity at 25 C: dVs/dT = 3.3 x Rb x (-dR/dT) / (Rt + Rb)^2 = 3.3 x 10000 x 444 / 20000^2 = 36.6 mV per kelvin Over 0 to 50 C Vs spans only 1.67 V, about half of the ADC range and not centred: amplifying it uses all of it (stage B). Self-heating: the current through the thermistor warms it, so the reading errs high. P = I^2 x Rt: at 25 C: I = 3.3 / 20 k = 0.165 mA, P = 0.165e-3^2 x 10000 = 0.27 mW (about 0.2 mW over the range) Typical dissipation constant in still air = about 2 mW per C so the error is 0.27 / 2 = 0.14 C (small)

The photoresistor (LDR)

A light-dependent resistor (cadmium-sulphide cell, such as the GL5528) falls from megohms in the dark to a few hundred ohms in bright light. Its resistance follows a power law, a straight line on log axes:

R(L) = R10 x ( L / 10 lux ) ^ ( - gamma ) R10 = the resistance at 10 lux (given on the datasheet), gamma about 0.6 to 0.9 Illustration, R10 = 15 k, gamma = 0.7, in a divider with the LDR on TOP and a 10 k resistor at the bottom (so Vs rises with light): 1 lux (a dim room): R = 15 k x 10^0.7 = 75 k Vs = 3.3 x 10 / (75 + 10) = 0.39 V 10 lux: R = 15 k Vs = 3.3 x 10 / 25 = 1.32 V 100 lux (an indoor desk): R = 15 k x 10^-0.7 = 3.0 k Vs = 3.3 x 10 / 13 = 2.54 V 1000 lux (a bright window): R = 0.6 k Vs = 3.3 x 10 / 10.6 = 3.11 V Four decades of light become 0.4 to 3.1 V: the divider does the job unaided, and the log-like response suits eyes. The R10 value and gamma vary by 2:1 between samples, so calibrate each unit, or use it only to compare with a threshold. An LDR is slow (10 to 100 ms) and its cadmium is restricted in some regions; a phototransistor or a TEMT6000 module (voltage out, much faster) is a good substitute.

The strain gauge and the Wheatstone bridge

A strain gauge is a thin metal foil pattern bonded to a part: stretch it and its resistance rises a tiny amount. The gauge factor GF (about 2) is the ratio of the fractional change in resistance to the strain ε (the fractional change in length):

dR / R = GF x strain 350 ohm gauge, GF = 2, strain 2000 microstrain (0.002): dR = 350 x 2 x 0.002 = 1.4 ohm A change of 0.4 % cannot be seen by a divider at the volt level. A bridge measures only the CHANGE, as a small DIFFERENCE between two nodes: +3.3 V (excitation) +-------+--------+ | | [ R1 350 ] [ R3 350 ] | | +----- Va +----- Vb | | [ R2 350 ] [ Rg 350 (1 + x) ] Rg = the active gauge, x = dR/R | | +-------+--------+ 0 V Balanced (x = 0): Va = Vb = 1.65 V and the difference is exactly 0, whatever the supply. Vdiff = Vb - Va = Vex x ( Rg/(R3+Rg) - 1/2 ) = Vex x x / ( 2 x (2 + x) ) about Vex x x / 4 for small x x = 0.004 (2000 microstrain): Vdiff = 3.3 x 0.004 / (2 x 2.004) = 3.293 mV (the quick formula gives 3.300 mV) A few millivolts, sitting on 1.65 V that both nodes share: a plain amplifier cannot separate them (the 1.65 V would be amplified too), and a difference amplifier from resistors needs matching to 0.01 % or better. This is the job of the instrumentation amplifier.

The instrumentation amplifier

An instrumentation amplifier (in-amp) is three op-amps in a standard arrangement, with laser-trimmed matched resistors, in one chip: two input buffers (which give each input a very high impedance, fixing the weakness in the difference amplifier of section 3) followed by a difference amplifier. One external resistor RG sets the gain, for the INA333:

Inside: two buffer amplifiers, each with a resistor R to its output, sharing RG between their inverting inputs. By rule 1 the voltage across RG equals the differential input Vd, so the current through RG, and through each R, is Vd / RG: voltage across the whole chain (R + RG + R) = Vd x ( 1 + 2R / RG ) The output stage subtracts the two buffer outputs with gain 1, so Gain = 1 + 2R / RG INA333: 2R = 100 k: G = 1 + 100 k / RG (RG open: gain 1; RG = 100 ohm: gain 1001) Strain gauge, gain chosen so that 2000 microstrain gives a 1.5 V change: Vout = REF + G x Vdiff REF pin tied to a 1.65 V node (the output can then move up AND down about 1.65 V for stretch and compression) G = 1.5 / 3.293 mV = 455.5 RG = 100 k / (G - 1) = 220 ohm (a standard value, G = 455.5, 1.5003 V at full strain) 600 microstrain: Vdiff = 0.989 mV, Vout = 1.65 + 455.5 x 0.989 mV = 2.10 V

For a complete weighing scale, a ready-made module such as the HX711 combines the in-amp and a 24-bit ADC and talks to any board with two pins; the principles above are what is inside it.

Current sensing

To measure a current, put a small known shunt resistor in its path and measure the voltage across it: V = I × Rs (Ohm's law, Basic Electronics 1). The amplifier makes the small voltage readable.

+V o-------[ LOAD ]--------+---- to the + input of a non-inverting amplifier (Vsense = I x Rs) | [ Rs 0.05 ] | 0 V o--------------------+ Choose Rs so the loss is small, but the voltage large enough to read: Rs = 0.05 ohm, I = 3 A: Vsense = 0.15 V power in Rs = 3^2 x 0.05 = 0.45 W (use a 1 W part) Non-inverting amplifier Rf = 20 k, Rg = 1 k: gain 21, Vout = 3.15 V at 3 A (1.05 V per amp) Disadvantage of the "low-side" shunt drawn here: the load's return is lifted 0.15 V above the board's 0 V at 3 A, so the grounds of anything else connected to the load differ by that amount. A "high-side" shunt (between +V and the load) avoids this but needs a difference amplifier or a dedicated current-sense chip (INA219, INA180, ACS712 modules, which sense the current and report it digitally). Offset error: an op-amp V(OS) of 2 mV gives 2 x 21 = 42 mV at the output, equal to 42 mV / (1.05 V/A) = 40 mA of false current.

7. Noise, decoupling, grounding and filtering

An analogue signal's enemy is noise. The small signals that sensors produce (millivolts) are easily swamped, and the converter's LSB is only 0.8 mV on a 3.3 V, 12-bit ADC.

SourceWhere it comes fromSize (example)Cure
Thermal (Johnson) noiseRandom motion of charge in every resistorvn = √(4 k T R Δf): 10 kΩ, 10 kHz: 1.29 µV rms; 1 MΩ: 12.9 µVLower resistances, narrower bandwidth (filter)
Mains pickupCapacitance between your wire and the 230 V, 50 Hz wiring1 pF coupling: i = 2πfCV = 2π × 50 × 1 pF × 230 V = 72 nA; into 100 kΩ = 7.2 mV; into 1 kΩ = 72 µVLow-impedance nodes, short wires, shielding, averaging over 20 ms
Supply noise and spikesMotors, relays, a microcontroller's switching, a USB supply's rippleTens of millivolts at switching edgesDecoupling capacitors, separate analogue supply or filter
Ground shiftsLarge currents flowing in wires that are also the signal's return1 A through 20 mΩ of wire = 20 mV = 25 LSB of a 12-bit, 3.3 V ADCStar grounding, separate return wire

Decoupling the op-amp

Every op-amp and ADC needs a 100 nF ceramic capacitor right at its supply pins (the leads as short as possible), plus a 10 µF capacitor somewhere on the board for slower changes. The capacitor supplies the brief bursts of current the chip draws when its output changes, so that the burst does not travel along the supply wires and appear as a voltage ripple on everything else (the decoupling idea of Basic Electronics 4). Without it an op-amp may oscillate at megahertz, giving strange, unstable readings.

Grounding

  • Separate the paths. A motor's current should never share a wire with a sensor's return. Join the motor ground and the signal ground at one point only, near the supply (a star ground).
  • Reference the sensor to the ADC's own ground, not to a ground at the other end of a noisy wire. A ratiometric sensor (the divider and bridge circuits above, whose output is a fraction of the supply) powered from the same 3.3 V as the ADC's reference also cancels supply variations: if the supply drops 2 %, the output and the converter's full scale both drop 2 % and the code is unchanged.
  • Keep analogue and switching signals apart on the board; cross at right angles if they must cross.

Shielding and cabling

  • Run a sensor's two wires twisted together so both pick up the same interference, which a difference amplifier or in-amp then cancels (common-mode rejection again).
  • For a long run, use shielded cable with the shield connected to ground at one end only (the amplifier end), so that no current can flow along the shield.
  • High-impedance nodes (the + input of an op-amp, an ADC pin with a large source resistance) are the most sensitive; keep their wires very short, or drive them from a follower.

The anti-alias filter

The cure for aliasing is a low-pass filter ahead of the ADC, a simple RC (Basic Electronics 4: fc = 1/(2πRC)), with its corner well below fs/2 and above the highest frequency you want to measure.

op-amp OUT o----[ R 1.5 k ]----+----o to the ADC pin | [ C 1 uF ] | 0 V o-----------------------+ fc = 1 / (2 x pi x R x C) = 1 / (2 x pi x 1500 x 1e-6) = 106 Hz Attenuation at frequency f: |H| = 1 / sqrt( 1 + (f / fc)^2 ) 50 Hz: 1 / sqrt(1 + 0.222) = 0.905 (-0.9 dB) hum at 50 Hz passes almost untouched: filter or average it, below 10 kHz: 1 / sqrt(1 + 8900) = 0.0106 (-39.5 dB) fast noise is reduced almost 100 times This suits a temperature sensor read 10 to 100 times a second (the thermistor changes over seconds: 106 Hz is still a very generous cut-off). Choose R no larger than the ADC allows: an Uno's input wants a source resistance of 10 k or less. R also isolates the op-amp output from the capacitor, which could otherwise make a cheap op-amp unstable. Digital helpers: Averaging N readings cuts random noise by sqrt(N): 16 readings = 4 times less noise, equivalent to 2 more bits ("oversampling": 4^n readings add n bits, if there is enough noise to dither the signal). Mains hum: average over a whole number of mains cycles, 20 ms for 50 Hz (16.7 ms for 60 Hz), and the hum averages to zero.

8. Which board for analogue work?

JobBest boardWhy
A single thermistor or light sensor, easy to wire, 5 V signalsArduino Uno or Nano10-bit ADC, 5 V reference, rugged pins, a one-line analogRead(); the stage B output (0.15 to 3.0 V) simply uses 60 % of its range
Several sensors on a small robot, 3.3 V logic, low costRaspberry Pi Pico12-bit ADC and a clean 3.3 V reference pin (ADC_VREF); a pair of 3.3 V rails that match the op-amp stage of this chapter
Sensors plus Wi-Fi in one boardESP32Many analogue pins and a radio; use the middle of the range (0.15 to 3.0 V), average readings, and do not use the second converter while Wi-Fi is on
Precise bridge or gauge measurement (weighing, strain)Any board with an external ADS1115 or HX711The board's own converter is too coarse and too noisy for microvolt signals
A full Raspberry Pi computerRaspberry Pi with an external ADCIt has no analogue inputs at all: add an ADS1115 (I2C) or an MCP3008 (SPI) and power it from the Pi's 3.3 V

Basic Electronics 10 reads these voltages in code and Basic Electronics 11 compares the boards in full.

9. Build it: a light trigger and a conditioned temperature sensor

Two stages on a 3.3 V supply. A is a light-triggered comparator with hysteresis, whose output lights an LED (it could equally drive a pin, a relay stage from Basic Electronics 6, or a robot's decision to turn on a lamp). B is a thermistor conditioned so that 0 to 50 °C gives about 0.15 to 3.0 V, ready for an ADC. Both use the MCP6002, which swings its output to both rails.

Power and static
The MCP6002 runs from 1.8 to 6 V and is damaged above about 7 V: use a 3.3 V supply (a breadboard power module set to 3.3 V, or the 3V3 pin of a Pico or ESP32 board) and check it with the meter before you connect the chip. Fit the 100 nF capacitor across the supply rails next to each chip. Connect the power last. A 5 V supply also works (all the voltages scale; the comparator thresholds are ratios of the supply), but then the stage B output reaches 4.5 V, above what a 3.3 V board's pin can take.

Parts list

PartValueUsed in
U1, U2MCP6002 dual rail-to-rail op-amp, DIP-8 (two chips; or an LMV358 / MCP6002 breakout)A (U1), B (U2)
LDRPhotoresistor, GL5528 type (about 10 to 20 kΩ at 10 lux)A
NTC10 kΩ at 25 °C NTC thermistor, B = 3950B
R1, R2, R5, R6, R8, R9, R10, Rg10 kΩ, 1/4 W (brown-black-orange)A (R1, R2, R5, R6), B (R8, R9, R10, Rg)
Rf (stage A)100 kΩ (brown-black-yellow)A
R71 kΩ (brown-black-red)A
Rf (stage B)6.8 kΩ (blue-grey-red)B
Raa1.5 kΩ (brown-green-red)B (anti-alias, optional)
Caa1 µF ceramic or electrolytic (+ to the op-amp side)B (optional)
C1, C2100 nF ceramicdecoupling, one per chip
LEDRed, 5 mmA
Supply3.3 V (breadboard module or the 3V3 pin of a board)A, B
Breadboard, jumpers, multimeterA cup of ice water and a mug of warm water for the temperature testA, B

Stage A: the light-triggered comparator

The signal path: the LDR divider gives Vs; a follower (U1A) buffers it so that its source resistance cannot disturb the hysteresis resistors; U1B is the comparator with hysteresis of section 4; the LED shows the output.

+3.3 V o------+--------------------+ | | [ LDR ] [ R5 10 k ] | | +--------o Vs +--------o Vref (1.65 V) | | [ R2 10 k ] [ R6 10 k ] | | 0 V o--------+--------------------+ U1A: a follower. Vs to pin 3 (IN+ A); pin 2 (IN- A) wired to pin 1 (OUT A). Pin 1 is then Vbuf = Vs. U1B: comparator with hysteresis: +----------+ Vref o-------------| - (6) | | U1B |----+------+---o OUT (pin 7) +-----| + (5) | | | | +----------+ | [ R7 1 k ] Vbuf o[ R1 ]-+ | | 10 k | | [ LED ] | | | +-----[ Rf 100 k ]----+ | 0 V o Check the dividers' effect on the thresholds: R1 = 10 k, Rf = 100 k, Vref = 1.65 V, Vcc = 3.3 V: VH = 1.65 x (1 + 0.1) = 1.815 V VL = 1.815 - 3.3 x 0.1 = 1.485 V hysteresis 0.33 V In terms of the LDR (LDR on top, 10 k below): Vs = 3.3 x 10 k / (R(LDR) + 10 k) Vs rising to 1.815 V: R(LDR) = 10 k x (3.3 / 1.815 - 1) = 8.18 k the LED comes ON when the LDR falls below 8.2 k Vs falling to 1.485 V: R(LDR) = 10 k x (3.3 / 1.485 - 1) = 12.2 k the LED goes OFF when the LDR rises above 12.2 k In between (8.2 k to 12.2 k) the LED keeps whatever state it already had: no flicker. LED current = (3.3 - 2.0) / 1 k = 1.3 mA (dim but clear; use 470 ohm for 2.8 mA). Pin 5 voltage when the output switches: it jumps by Vcc x R1/(R1+Rf) = 3.3 x 0.0909 = 0.30 V: the positive feedback at work. The comparator makes a "light is on" decision with the dead band built in. For a night-light (on in the DARK) swap the signals: Vbuf to the - input and Vref (with R1 and Rf) to the + input, or put the LDR at the bottom of the divider.
Breadboard layout. Top rails: + rail = 3.3 V, - rail = 0 V. C1 (100 nF) sits across the top rails right next to the chip. U1 straddles the centre gap with the notch towards column 1. Pins 1 to 4 in row e, columns 10 to 13; pins 8 to 5 in row f directly opposite (pin 8 across from pin 1 in column 10, pin 5 across from pin 4 in column 13). Columns have rows a-e joined and rows f-j joined. U1 pin 1 = column 10 row e pin 2 = column 11 row e pin 3 = column 12 row e pin 4 = column 13 row e U1 pin 8 = column 10 row f pin 7 = column 11 row f pin 6 = column 12 row f pin 5 = column 13 row f (if your board has the rows lettered the other way round, turn the chip so pin 8 is still opposite pin 1 and the notch is at the left) Power: jumper column 10 row g -> top + rail (pin 8, V+) jumper column 13 row a -> top - rail (pin 4, V-) Follower U1A: jumper column 10 row a -> column 11 row a (OUT A to IN- A) Sensor divider: LDR: column 20 row a -> column 21 row a; jumper column 21 row b -> top + rail R2 (10 k): column 20 row b -> column 22 row b; jumper column 22 row c -> top - rail jumper column 20 row c -> column 12 row b (Vs to IN+ A, pin 3) Buffered signal: jumper column 10 row b -> column 16 row g (Vbuf) Comparator U1B: R1 (10 k): column 16 row h -> column 13 row h (Vbuf to IN+ B, pin 5) Rf (100 k): column 11 row h -> column 13 row i (OUT B, pin 7, back to IN+ B) Reference: R5 (10 k): column 18 row g -> column 20 row g; jumper column 20 row h -> top + rail R6 (10 k): column 18 row i -> column 21 row i; jumper column 21 row j -> top - rail jumper column 18 row j -> column 12 row g (Vref to IN- B, pin 6) Indicator: R7 (1 k): column 11 row j -> column 25 row j; LED anode column 25 row i, cathode column 26 row i; jumper column 26 row h -> top - rail Connect the power LAST. Measure: Vs = red probe column 12 row a; Vref = red column 12 row h; pin 5 = red column 13 row j; OUT = red column 11 row i (black probe on the - rail for all)
  1. Cover the LDR with your hand: Vs falls to a few hundred millivolts, the LED is off and OUT is about 0 V. Pin 6 (Vref) reads 1.65 V.
  2. Bring the LDR slowly towards a lamp, watching Vs: the LED should switch on when Vs reaches about 1.8 V; at the same instant pin 5 jumps by 0.3 V.
  3. Take the lamp away slowly: the LED stays lit until Vs drops below about 1.5 V, then goes off. That is the hysteresis (0.33 V).
  4. Test it without light: swap the LDR for a 20 kΩ potentiometer wired as a variable resistor and turn it slowly, reading Vs and the LED. Then remove Rf (100 kΩ) from the breadboard: the circuit loses its hysteresis, and with the pot held near the threshold the LED may flicker or switch at a single level.
  5. Change Rf to 47 kΩ and find the new thresholds by calculation (challenge 2) and by test.

Stage B: the conditioned temperature sensor

The thermistor divider gives Vs from 0.757 V (0 °C) to 2.429 V (50 °C), about 1.67 V of span. U2A scales and shifts it so it fills the ADC, using the reference Vo of 1.65 V (buffered by U2B):

+3.3 V o------+---------------------+ | | [ NTC 10k ] [ R9 10 k ] | | +-------o Vs +-------o to U2B pin 5 (IN+ B) | | [ R8 10 k ] [ R10 10 k ] | | 0 V o--------+---------------------+ U2B: a follower. Pin 5 (IN+ B) = the 1.65 V node; pin 6 (IN- B) wired to pin 7 (OUT B). Pin 7 = Vo = 1.65 V, at low impedance. U2A: the non-inverting amplifier of section 3, but the bottom of Rg is connected to Vo instead of 0 V: +----------+ Vs o---------------| + (3) | | U2A |-----+----------o Vout (to the ADC, through the optional 1.5 k + 1 uF filter) +-----| - (2) | | | +----------+ | +------[ Rf 6.8 k ]----+ | [ Rg 10 k ] | Vo o---------+ (pin 7 of U2B) Derive with superposition (the amplifier is linear): Vs enters the + input, so it is amplified as non-inverting: (1 + Rf/Rg) x Vs. Vo is on the bottom of Rg, so the circuit treats it as an inverting input: - (Rf/Rg) x Vo. Together: Vout = (1 + Rf/Rg) x Vs - (Rf/Rg) x Vo Rf/Rg = 0.68 Vo = 1.65 V = 1.68 x Vs - 1.122 V 0 C: Vs = 0.757 V: Vout = 1.68 x 0.757 - 1.122 = 0.149 V 25 C: Vs = 1.650 V: Vout = 1.68 x 1.650 - 1.122 = 1.650 V (Vs = Vo: no offset, a built-in check) 50 C: Vs = 2.429 V: Vout = 1.68 x 2.429 - 1.122 = 2.958 V The span is now 2.81 V, and nothing is outside 0.15 to 3.0 V, comfortably inside every 3.3 V ADC (the ESP32 included). Gain at the ADC: dVout/dT = 1.68 x 36.6 mV/K = 61.6 mV per kelvin at 25 C. 12-bit, 3.3 V (LSB 0.806 mV): 0.806 / 61.6 = 0.013 K per count far finer than the thermistor's own accuracy (1 % of 10 k: 0.23 K) 10-bit, 5 V (LSB 4.88 mV; Vout scales to 0.22 to 4.5 V if the whole circuit runs on 5 V): about 0.05 K per count In the program: from a reading (12-bit, 3.3 V reference), e.g. code 1000: Vout = 1000 x 3.3 / 4095 = 0.806 V Vs = (Vout + 1.122) / 1.68 = 1.1475 V Rt = 10 k x (3.3 / Vs - 1) = 10 k x (2.876 - 1) = 18.76 k T = 1 / (1/298.15 + ln(18.76/10)/3950) = 284.6 K = 11.5 C
Breadboard layout (the same breadboard, further along; the pin positions work as in stage A, columns 40 to 43). U2 pin 1 = column 40 row e pin 2 = column 41 row e pin 3 = column 42 row e pin 4 = column 43 row e U2 pin 8 = column 40 row f pin 7 = column 41 row f pin 6 = column 42 row f pin 5 = column 43 row f C2 (100 nF) across the top rails next to U2. Power: jumper column 40 row g -> top + rail (pin 8) jumper column 43 row a -> top - rail (pin 4) Thermistor divider: NTC: column 50 row a -> column 51 row a; jumper column 51 row b -> top + rail R8 (10 k): column 50 row b -> column 52 row b; jumper column 52 row c -> top - rail jumper column 50 row c -> column 42 row b (Vs to IN+ A, pin 3) Reference: R9 (10 k): column 55 row a -> column 56 row a; jumper column 56 row b -> top + rail R10 (10 k): column 55 row b -> column 57 row b; jumper column 57 row c -> top - rail jumper column 55 row c -> column 43 row g (1.65 V to IN+ B, pin 5) Follower U2B: jumper column 41 row g -> column 42 row g (OUT B pin 7 to IN- B pin 6) Gain network U2A: Rf (6.8 k): column 40 row b -> column 44 row b; jumper column 44 row c -> column 41 row d (OUT A pin 1 through Rf to IN- A pin 2) Rg (10 k): column 41 row h -> column 46 row h; jumper column 46 row i -> column 41 row b (Vo from OUT B pin 7 through Rg to IN- A pin 2) Output: column 40 row d is Vout. Optional anti-alias filter: Raa (1.5 k): column 40 row a -> column 47 row a; Caa (1 uF): column 47 row b -> column 48 row b; jumper column 48 row c -> top - rail (electrolytic: + leg in column 47); the ADC wire goes to column 47 row c. Connect the power LAST. Measure: Vs = red probe column 50 row d; Vo = red column 55 row d; Vout = red column 40 row d (black probe on the - rail for all)
  1. With the thermistor at room temperature (about 20 °C): Vo reads 1.65 V; Vs about 1.47 V; Vout about 1.34 V (compare the table below, and measure the room temperature with a thermometer).
  2. Warm the thermistor between your fingers (about 30 to 33 °C at its surface): Vout rises smoothly by about 60 mV for each kelvin; it climbs over seconds because the thermistor has thermal mass.
  3. Put it into a bag in ice water (0 °C) and then warm (about 45 °C) water, checking the table. Keep the leads and joints dry: the water's conductivity would short the divider.
  4. Connect Vout to an ADC pin (with the 1.5 kΩ and 1 µF filter) of a Pico or ESP32, apply the conversion at the end of the stage's schematic in code, and compare with the thermometer: agreement within about 1 °C is typical (the thermistor tolerance is the limit).

Simulators

Falstad Circuit Simulator (falstad.com/circuit): from the Draw menu take the op-amp (Active Components), resistors and a voltage source (Inputs and Sources). Falstad's op-amp is a very high-gain ideal amplifier with a default output limit of ±15 V: right-click the op-amp, choose Edit and set Max Output to 3.3 and Min Output to 0 to model the single-supply chip. Use a 3.3 V source and a slider-controlled resistor (a Potentiometer, or a resistor with its value editable) in place of the LDR, then watch the output switch at the thresholds, and view the hysteresis loop by adding a scope trace of Vs and OUT. The thermistor can be modelled with a potentiometer (or the thermistor element if your version has one) set to the values in the table. Falstad's op-amp has no offset or noise, so it shows the calculated numbers exactly.

Tinkercad Circuits (tinkercad.com): the component list includes an Op Amp, a Photoresistor, a Potentiometer, a multimeter, an Arduino Uno and a power supply that can be set to 3.3 V. Tinkercad's op-amp model need not swing all the way to the rails, so measure the output while overdriven and compare with the table: any difference tells you about the model, not the circuit. The Photoresistor part is convenient: Tinkercad lets you change the light level in the simulation with a slider. Feed the stage B output to the Uno's A0 pin and print the reading with analogRead (the Uno's 5 V full scale; 3.3 V corresponds to a code of about 675).

Expected readings

MeasurementCalculatedReal (typical)Simulator
A: Vref (pin 6)1.650 V1.63 to 1.67 V (1 % resistors)1.650 V
A: LDR covered, Vs / OUTbelow 0.3 V / 0 V0.05 to 0.3 V / 0.00 V(set the resistor to 100 kΩ) 0.3 V / 0 V
A: rising threshold (LED on)Vs = 1.815 V (LDR 8.18 kΩ)1.78 to 1.85 V1.815 V
A: falling threshold (LED off)Vs = 1.485 V (LDR 12.2 kΩ)1.45 to 1.52 V1.485 V
A: hysteresis0.330 V0.32 to 0.34 V0.330 V
A: OUT high / low3.3 V / 0 V3.27 to 3.30 V / 0.00 to 0.03 V3.3 V / 0 V
A: pin 5 just after switching on1.95 V1.93 to 1.97 V1.95 V
A: LED current1.3 mA1.2 to 1.4 mA1.3 mA
B: Vo (pin 7 of U2B)1.650 V1.63 to 1.67 V1.650 V
B at 0 °C: Rt / Vs / Vout33.6 kΩ / 0.757 V / 0.149 VVout 0.10 to 0.25 V0.149 V
B at 10 °C: Rt / Vs / Vout20.2 kΩ / 1.094 V / 0.715 V0.65 to 0.78 V0.715 V
B at 25 °C: Rt / Vs / Vout10.0 kΩ / 1.650 V / 1.650 V1.60 to 1.70 V1.650 V
B at 35 °C: Rt / Vs / Vout6.51 kΩ / 1.999 V / 2.237 V2.18 to 2.30 V2.237 V
B at 40 °C: Rt / Vs / Vout5.30 kΩ / 2.157 V / 2.501 V2.44 to 2.56 V2.501 V
B at 50 °C: Rt / Vs / Vout3.59 kΩ / 2.429 V / 2.958 V2.90 to 3.02 V2.958 V
B: 12-bit ADC codes (3.3 V) at 0, 25, 50 °C184, 2048, 3671within about ±60 counts(from Vout)
B: Vout change per kelvin at 25 °C61.6 mV/Kabout 55 to 68 mV/K61.6 mV/K

Real readings spread because resistors are 1 % parts, the thermistor has a 1 % tolerance on R0 and 1 % on B (about 0.5 °C of error away from 25 °C), the LDR varies by 2:1 from sample to sample, and the chip has a small offset. What does not vary is the structure: the comparator has two distinct thresholds 0.33 V apart; U2B's output equals the 1.65 V reference; Vout equals Vo when Vs equals Vo (25 °C); and Vout rises steadily with temperature, always inside 0 to 3.3 V.

10. Challenges

Challenge 1: Quantisation and amplifier gain
(a) Find the LSB of a 10-bit converter on a 5 V reference, a 12-bit on 3.3 V, and a 16-bit on 3.3 V. For the 12-bit converter find the code for 1.000 V, the voltage that code stands for, the rms quantisation noise and the ideal SNR. (b) A bridge sensor gives 0 to 80 mV. Using Rg = 1 kΩ choose Rf from the E12 series so that the non-inverting amplifier gives the largest gain that keeps the output under 3.3 V, find the full-scale output, the sensor-side resolution (LSB divided by the gain) with the 12-bit converter, the exact closed-loop gain if the op-amp's open-loop gain is 100,000, and the closed-loop bandwidth and gain at 10 kHz for GBW = 1 MHz. (c) A summing amplifier with Rf = 10 kΩ has inputs V1 = 1.0 V (10 kΩ), V2 = 0.5 V (20 kΩ), V3 = 2.0 V (10 kΩ): find Vout. Then choose equal input resistors so that it gives minus the average of the three inputs.
View solution
Challenge 2: Comparators and hysteresis
(a) A rail-to-rail comparator on 5 V has Vref = 2.5 V, R1 = 10 kΩ and Rf = 220 kΩ. Find VH, VL and the hysteresis. (b) Design a fan switch with the stage B thermistor divider (NTC 10 kΩ, B = 3950, on top of 10 kΩ, 3.3 V) that turns the fan ON at 40 °C and OFF at 35 °C: find the thermistor resistances and the divider voltages at the two temperatures, the ratio R1/Rf and E12 values (R1 = 10 kΩ), the required Vref and a divider of two resistors from 3.3 V that makes it, and the actual switching temperatures you end up with. (c) In stage A change Rf from 100 kΩ to 47 kΩ: find the new VH, VL, hysteresis and the LDR resistances at which the LED switches, and say whether a 50 mV peak-to-peak flicker from a mains-powered lamp could still cause false switching with each choice.
View solution
Challenge 3: Sensors and the signal chain
(a) A 350 Ω strain gauge (GF = 2.0) in a quarter bridge with 3.3 V excitation sees 2000 microstrain: find the resistance change and the bridge's output voltage (exact and approximate). For an INA333 (G = 1 + 100 kΩ/RG) with its REF pin at 1.65 V, find the gain and E12 value of RG that give +1.5 V at 2000 microstrain, then the output at 600 microstrain. (b) A low-side current sensor uses Rs = 0.05 Ω for currents up to 3 A: find the shunt voltage and power, choose a non-inverting amplifier (Rg = 1 kΩ, Rf to be chosen from the E24 series) that keeps 3 A below 3.3 V, and find the offset error for VOS = 2 mV in amps. (c) A signal is sampled at 2 kHz. Design an RC anti-alias filter (R = 1 kΩ, find C) with a corner at about 160 Hz; find the alias frequency and attenuation of a 1.7 kHz noise tone of 100 mV peak-to-peak and its size in ADC counts (12-bit, 3.3 V). Then find the highest frequency at which an MCP6002 (SR 0.6 V/µs) can reproduce a 3 V peak-to-peak sine, and the lower limit for a gain-40 stage.
View solution

Quick reference

  • ADC: LSB = Vref/2N; code = floor(Vin/LSB); rms quantisation noise = LSB/√12; SNR = 6.02N + 1.76 dB; sample at least twice the highest frequency, and filter before the converter (alias = |f − k fs|)
  • Op-amp rules (with negative feedback): V+ = V− and no input current; open-loop A is large and the closed-loop gain = A/(1+Aβ), about 1/β
  • Follower: gain 1; non-inverting: 1 + Rf/Rg; inverting: −Rf/Rin (virtual ground); summing: −Rf Σ(Vi/Ri); difference: (R2/R1)(V2 − V1), CMRR about (1 + G)/(4 t)
  • Comparator with hysteresis: VH = Vref(1 + R1/Rf) − Vl R1/Rf, VL = Vref(1 + R1/Rf) − Vh R1/Rf; hysteresis = (Vh − Vl)R1/Rf
  • Speed: bandwidth = GBW/G; full-power bandwidth = SR/(2πVp); single supply needs a rail-to-rail chip if the output must reach V+ (an LM358 stops 1.5 V short)
  • Thermistor: T = 1/(1/T0 + ln(R/R0)/B) in kelvin; dR/dT = −BR/T2; divider with Rb = R at the middle temperature; watch self-heating
  • Bridge and in-amp: Vdiff = Vex x/(2(2 + x)) ≈ Vex x/4; in-amp gain = 1 + 2R/RG (INA333: 1 + 100 kΩ/RG)
  • Shunt: V = I Rs, power I2 Rs, amplify with gain 1 + Rf/Rg; offset error = VOS/(Rs × G) in amps
  • Noise: 100 nF at every supply pin plus 10 µF per board; star ground; twisted pair and a one-ended shield; RC anti-alias filter fc = 1/(2πRC); average N readings for √N less noise; average over 20 ms for 50 Hz hum

Next, Basic Electronics 8 moves from the smooth world of analogue voltages to the two-level world of digital logic: logic levels, gates, latches and counters, and the 555 timer.