TExcelTAD
Home › Electrical & Electronic Measurements › Displacement, Position, Light and Magnetic Field Sensors

Displacement, Position, Light and Magnetic Field Sensors

A machine tool needs to know where its spindle is to a micrometre, a motor controller needs the rotor angle a thousand times per revolution, a medical oximeter needs the light passing through a finger, and a current sensor needs the magnetic field in a core gap. Each of these is a transducer with its own trick for turning the quantity into a clean electrical signal: AC excitation and synchronous demodulation for the LVDT, counting for the encoder, current-to-voltage conversion for the photodiode, and a Hall voltage for the field. This lesson covers the four, with the measurement idea each one teaches.

The LVDT: displacement with AC excitation

S1 primary S2 2.5 kHz excitation joined in series opposition vo = v1 - v2 core moves by x multiply by ref low-pass: signed DC

A linear variable differential transformer has one primary and two secondaries wound on a tube, with a movable ferromagnetic core. The primary is excited with a sine (typically 11 to 10 kHz10\ \text{kHz}). With the core centred, the two secondaries pick up equal voltages; they are connected in series opposition, so the output is zero (apart from a small null voltage in quadrature). Moving the core increases one coupling and decreases the other: the output amplitude is proportional to displacement, and its phase flips by 180∘180^\circ as the core passes the centre.

An AC voltmeter reads the amplitude but loses the sign. Synchronous (phase-sensitive) demodulation multiplies the output by the excitation reference and low-pass filters the product:

vo(t) sin⁡ωt‾=Kxsin⁡2ωt‾=Kx2\overline{v_o(t)\,\sin\omega t} = \overline{K x \sin^2 \omega t} = \frac{K x}{2}

which keeps the sign, rejects the quadrature null voltage (its product with the reference averages to zero) and rejects noise outside a narrow band around the excitation frequency. This lock-in principle is one of the most powerful ideas in measurement: it recovers signals buried far below the noise when you control the excitation. LVDTs are frictionless and robust (no contact, so practically unlimited life), with resolutions of fractions of a micrometre; RVDTs and resolvers apply the same idea to angles.

python · try it yourself
import numpy as np

# LVDT: 2.5 kHz excitation, output amplitude 80 mV/mm with phase 0 (core above centre) or 180 deg (below),
# plus 2 mV of quadrature null voltage and noise. Synchronous (phase-sensitive) demodulation.
fs, f_ex, T = 200e3, 2.5e3, 0.02
t = np.arange(int(fs * T)) / fs
ref = np.sin(2 * np.pi * f_ex * t)
rng = np.random.default_rng(4)
for x_mm in (+0.50, -0.50, +0.05, 0.0):
    sig = 0.080 * x_mm * ref + 0.002 * np.cos(2 * np.pi * f_ex * t) + 0.005 * rng.standard_normal(len(t))
    rms = np.sqrt(np.mean(sig**2))                     # what an AC voltmeter would show
    demod = 2 * np.mean(sig * ref)                     # multiply by the reference and average (low-pass)
    print(f"x = {x_mm:+.2f} mm: AC rms {1e3 * rms:6.2f} mV (no sign), demodulated {1e3 * demod:+7.2f} mV "
          f"-> {demod / 0.080:+.3f} mm")
x = +0.50 mm: AC rms  28.89 mV (no sign), demodulated  +40.21 mV -> +0.503 mm
x = -0.50 mm: AC rms  28.87 mV (no sign), demodulated  -40.18 mV -> -0.502 mm
x = +0.05 mm: AC rms   5.93 mV (no sign), demodulated   +3.91 mV -> +0.049 mm
x = +0.00 mm: AC rms   5.24 mV (no sign), demodulated   -0.15 mV -> -0.002 mm

The AC voltmeter shows 28.9 mV28.9\ \text{mV} for both +0.5+0.5 and −0.5 mm-0.5\ \text{mm} and 5 mV5\ \text{mV} of noise and null at zero; the demodulator returns the signed displacement within a few micrometres.

Encoders: position by counting

An incremental encoder has a disk (optical or magnetic) that produces two square waves, A and B, 90∘90^\circ apart (quadrature), and often an index pulse once per revolution. Counting every edge of both channels (x4 decoding) gives four counts per line, and the order of the edges gives the direction. A decoder that misses a state cannot tell the direction: sample faster than the edges arrive, or use a hardware counter (most microcontrollers have one). Incremental encoders know only relative position; after power-up they need a homing move.

An absolute encoder reads a coded track and knows its position at power-up. The code is Gray code, where one bit changes per step, so a reading taken while the disk moves between two positions is off by at most one step, never by a large jump as a binary code could be (011→100011 \to 100 changes three bits).

python · try it yourself
# Quadrature decoding (x4): the state (A, B) steps 00 -> 01 -> 11 -> 10 for one direction
STEP = {(0, 0): 0, (0, 1): 1, (1, 1): 2, (1, 0): 3}
def decode(samples):
    pos, prev = 0, STEP[samples[0]]
    for ab in samples[1:]:
        s = STEP[ab]
        d = (s - prev) % 4
        if d == 1: pos += 1
        elif d == 3: pos -= 1
        elif d == 2: raise ValueError("missed a state: sampling too slow")
        prev = s
    return pos

forward = [(0, 0), (0, 1), (1, 1), (1, 0)] * 3 + [(0, 0)]
back = [(0, 0), (1, 0), (1, 1), (0, 1)] * 2 + [(0, 0)]
print("3 cycles forward:", decode(forward), "counts;  2 cycles back:", decode(back), "counts")
lines = 500
print(f"{lines}-line encoder, x4 decoding: {4 * lines} counts/rev = {360 / (4 * lines):.3f} deg per count")

# Absolute encoders use Gray code: one bit changes per step
for n in range(8):
    g = n ^ (n >> 1)
    print(f"{n}: binary {n:03b}  Gray {g:03b}")
3 cycles forward: 12 counts;  2 cycles back: -8 counts
500-line encoder, x4 decoding: 2000 counts/rev = 0.180 deg per count
0: binary 000  Gray 000
1: binary 001  Gray 001
2: binary 010  Gray 011
3: binary 011  Gray 010
4: binary 100  Gray 110
5: binary 101  Gray 111
6: binary 110  Gray 101
7: binary 111  Gray 100

Light: photodiodes and the transimpedance amplifier

A photodiode produces a current proportional to the optical power: I=RPI = \mathcal{R} P with the responsivity R\mathcal{R} in A/W (about 0.40.4 to 0.6 A/W0.6\ \text{A/W} for silicon in the near infrared, less in the blue). Two operating modes:

  • Photovoltaic (zero bias): no dark current, lowest noise, slower (large junction capacitance). For precise low-light measurements.
  • Photoconductive (reverse bias): lower capacitance, faster, but with a temperature-dependent dark current.

The standard interface is a transimpedance amplifier: the photodiode drives the inverting input of an op-amp whose feedback resistor RfR_f converts the current into Vo=−IRfV_o = -I R_f while holding the diode at 0 V0\ \text{V}. A small capacitor across RfR_f keeps the loop stable with the diode's capacitance and sets the bandwidth. Light-dependent resistors (LDRs) are cheap and slow; phototransistors add gain but are less linear. Light level in lux is a photometric unit weighted by the eye's response; a photodiode measures radiometric power, so converting to lux needs a filter matched to the eye's curve.

Simulation. The photocurrent I1 flows into the inverting node inv of an op-amp (E1, gain 10610^6) with Rf=100 kΩR_f = 100\ \text{k}\Omega. At 5 μA5\ \mu\text{A} the output reads −0.500 V-0.500\ \text{V} and inv stays at about +0.5 μV+0.5\ \mu\text{V} (a virtual ground). Slide the photocurrent: the output follows exactly −IRf-I R_f.

node voltages (to ground 0)inv500.0 nVout-500.0 mVnetlistI1 0 inv DC 5uRf inv out 100kE1 out 0 0 inv 1megRl out 0 10kelement currents (node 1 to node 2 through it)I10>inv5.00 uARfinv>out5.00 uAE1out>055.0 uARlout>0-50.0 uA

Magnetic fields: Hall sensors

A current II through a thin conductor of thickness tt in a perpendicular field BB deflects the carriers sideways until the Hall voltage

VH=IBnqtV_H = \frac{I B}{n q t}

balances the magnetic force (nn is the carrier density, qq the charge). Semiconductors with low nn give useful voltages; integrated Hall sensors add an amplifier, offset cancellation (spinning current) and temperature compensation, and output for example 11 to 50 mV/mT50\ \text{mV/mT} (linear sensors) or a digital switch (latches, switches for position and speed). They sense DC fields, so they detect position (a magnet on a moving part), speed (a toothed wheel), and current (Current Measurement). Fluxgates and magnetoresistive (AMR, GMR, TMR) sensors reach much lower fields (compasses, nanotesla-level magnetometers).

Worked example: choosing an encoder and a feedback resistor

Given: a motor shaft that must be positioned to 0.2∘0.2^\circ, and a photodiode with R=0.5 A/W\mathcal{R} = 0.5\ \text{A/W} that receives up to 40 μW40\ \mu\text{W}, read by a 3.3 V3.3\ \text{V} ADC.

Find: the minimum number of encoder lines with x4 decoding, and RfR_f for a 3.0 V3.0\ \text{V} full-scale output.

Solve:

counts/rev≥360∘0.2∘=1800⟹lines≥18004=450(choose 500:0.18∘)Imax=0.5 A/W×40 μW=20 μA,Rf=3.0 V20 μA=150 kΩ\begin{aligned} \text{counts/rev} &\ge \frac{360^\circ}{0.2^\circ} = 1800 \quad\Longrightarrow\quad \text{lines} \ge \frac{1800}{4} = 450 \quad (\text{choose } 500: 0.18^\circ) \\ I_\text{max} &= 0.5\ \text{A/W} \times 40\ \mu\text{W} = 20\ \mu\text{A}, \qquad R_f = \frac{3.0\ \text{V}}{20\ \mu\text{A}} = 150\ \text{k}\Omega \end{aligned}

Check: units: A/W×W=A\text{A/W} \times \text{W} = \text{A}, V/A=Ω\text{V}/\text{A} = \Omega. The output of a transimpedance amplifier is negative for a photodiode connected as in the lab; reverse the diode (current out of the inverting node) or use a negative reference to get a positive voltage.

Guided lab: quadrature and light

Hand calculation. A 20-detent rotary encoder (a common hobby part) with x4 decoding gives 80 counts per revolution, or 4.5∘4.5^\circ per count. A photodiode at 0.5 A/W0.5\ \text{A/W} in room light (a few μW\mu\text{W} on a 7 mm27\ \text{mm}^2 area) gives roughly 1 μA1\ \mu\text{A}: with Rf=1 MΩR_f = 1\ \text{M}\Omega, about 1 V1\ \text{V}.

Simulation. The decoder program (feed it your own A/B sequences) and the transimpedance lab.

What you would measure. Connect a mechanical encoder's A and B outputs (with pull-ups to 3.3 V3.3\ \text{V}) to two scope channels and turn it: expect two square waves 90∘90^\circ apart whose order reverses with direction, and contact bounce of a millisecond or so on each edge (which a decoder must filter). Build the transimpedance amplifier with a low-bias-current op-amp, a BPW34-class photodiode and Rf=1 MΩR_f = 1\ \text{M}\Omega with 10 pF10\ \text{pF} in parallel, powered from ±5 V\pm 5\ \text{V} or a single supply with a mid-rail reference: expect the output to follow room light, show 100 Hz100\ \text{Hz} (or 120 Hz120\ \text{Hz}) flicker under mains-powered lamps, and fall to a few millivolts when covered.

Hazards and safe setup. Low-voltage supplies only. Do not point lasers at the photodiode (or anyone's eyes); room light and LEDs are enough. LVDTs need a 11 to 10 kHz10\ \text{kHz} excitation from a signal generator, never from mains.

Pitfalls

  • Reading an LVDT with an AC voltmeter and losing the sign (and the null voltage).
  • Polling encoder signals too slowly in software.
  • Using binary code for an absolute encoder track.
  • A transimpedance amplifier without feedback capacitance: the photodiode's capacitance makes it oscillate.

Practice

  1. An LVDT has a sensitivity of 120 mV/mm120\ \text{mV/mm} at 5 V5\ \text{V} excitation. What does 0.25 mm0.25\ \text{mm} give at 3 V3\ \text{V} excitation?
  2. What is the Gray code of 5 (binary 101101)?
Answer
  1. Sensitivity scales with excitation: 120×3/5=72 mV/mm120 \times 3/5 = 72\ \text{mV/mm}, so 18 mV18\ \text{mV} (and a ratiometric reading would not care).
  2. 101⊕010=111101 \oplus 010 = 111.

Test yourself

Synchronous demodulation of an LVDT output

  1. measures only the amplitude
  2. recovers the signed displacement and rejects the quadrature null and out-of-band noise
  3. requires DC excitation
  4. doubles the output frequency

A 1000-line incremental encoder with x4 decoding has a resolution of

  1. 0.36∘0.36^\circ
  2. 0.09∘0.09^\circ
  3. 1∘1^\circ
  4. 0.009∘0.009^\circ

Why do absolute encoders use Gray code?

  1. it is shorter
  2. only one bit changes per step, so a read during a transition is off by at most one step
  3. it needs no light source
  4. it doubles the resolution

A photodiode with R=0.6 A/W\mathcal{R} = 0.6\ \text{A/W} receives 10 μW10\ \mu\text{W}. With Rf=100 kΩR_f = 100\ \text{k}\Omega the transimpedance output magnitude is

  1. 0.06 V
  2. 0.6 V
  3. 6 V
  4. 60 mV per microwatt