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
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 to ). 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 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:
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.
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 for both and and 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, 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 ( changes three bits).
# 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: with the responsivity in A/W (about to 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 converts the current into while holding the diode at . A small capacitor across 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 ) with . At the output reads and inv stays at about (a virtual ground). Slide the photocurrent: the output follows exactly .
Magnetic fields: Hall sensors
A current through a thin conductor of thickness in a perpendicular field deflects the carriers sideways until the Hall voltage
balances the magnetic force ( is the carrier density, the charge). Semiconductors with low give useful voltages; integrated Hall sensors add an amplifier, offset cancellation (spinning current) and temperature compensation, and output for example to (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 , and a photodiode with that receives up to , read by a ADC.
Find: the minimum number of encoder lines with x4 decoding, and for a full-scale output.
Solve:
Check: units: , . 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 per count. A photodiode at in room light (a few on a area) gives roughly : with , about .
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 ) to two scope channels and turn it: expect two square waves 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 with in parallel, powered from or a single supply with a mid-rail reference: expect the output to follow room light, show (or ) 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 to 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
- An LVDT has a sensitivity of at excitation. What does give at excitation?
- What is the Gray code of 5 (binary )?
Answer
- Sensitivity scales with excitation: , so (and a ratiometric reading would not care).
- .
Test yourself
Synchronous demodulation of an LVDT output
- measures only the amplitude
- recovers the signed displacement and rejects the quadrature null and out-of-band noise
- requires DC excitation
- doubles the output frequency
A 1000-line incremental encoder with x4 decoding has a resolution of
Why do absolute encoders use Gray code?
- it is shorter
- only one bit changes per step, so a read during a transition is off by at most one step
- it needs no light source
- it doubles the resolution
A photodiode with receives . With the transimpedance output magnitude is
- 0.06 V
- 0.6 V
- 6 V
- 60 mV per microwatt