Analogue Interfacing What is a signal? • Signal: Function of one or more independent variable(s) such as space or time • Examples include images and speech Continuous vs. Discrete Time • Continuous time signals – Defined at all instances in time (or other I.V.s) – e.g. f(t) = sin(t) 1 • Discrete time signals – Defined only at a set of discrete (possibly infinite in number) times – Time sequence {x[n], n = 0,±1,±2, ….} – e.g. x[n] = sin(2πn/N), n integer – Not the same as digital which is discrete in the dependent variable as well • e.g. a sampled continuous time signal with analog digital converter • Signal level (voltage) represented by a binary number with limited precision (8, 10, 12, or 16bit fixed point number) – Often x[n] is a sampled version of x(t) at rate 1/TS (uniform spacing) x[n] = x(nTS), n = 0,±1,±2, … The world is analogue • One of the key functions of many embedded systems is to control and react to events in the real world • In digital systems we deal entirely with discrete signals • The real world is temporally continuous and analogue • Signals are not electronic: heat, pressure, light, …. 2 • Need to – Convert signals of interest into electrical form suitable for electronic processing (sensing and transduction) – Perform ‘signal conditioning’ to amplify, filter and otherwise transform analogue signals – Convert continuous-time, analogue signals to discrete-time sequence of binary numbers (or other digital form) – Process the discrete signals, need to retain the relationship with physical properties – Convert and digital outputs to analogue signals. May need to filter and condition. – Convert electrical signals to heat, light, motion, pressure … as appropriate (transduction, actuation) Physical Signal Sensing/ Transduction Signal Conditioning ADC Processing DAC Physical Signal Actuation/ Display Filtering/ Conditioning 3 Sensors and transduction Sensors • Many sensors exist to convert a wide range of analogue signals to electronic form – Temperature – Pressure – Speed or Displacement – Acceleration – Acidity – Many others Example: Optical Encoder From www.usdigital.com 4 Ex: Analog Devices ADXRS300 Gyroscopic Sensor From www.analogdevices.com Ex: Linear Variable Differential Transformer From www.analogdevices.com 5 Example: Thermocouple • Seebeck Effect: junction between two dissimilar metals creates temperature dependent voltage • Basis for thermocouple, a common temperature sensor widely used in process control http://www.picotech.com/applications/thermocouple.html • Typically convert signal of interest to analogue electrical signal – Voltage or current varies monotonically with physical signal of interest – Need to calibrate, amplify and filter … Signal Conditioning 6 Signal Conditioning • Amplification and level shifting – Convert the range and mean value (offset) of a signal to fit the range of the analogue to digital converter – Amplify – Attenuate – Level shift • Filtering – Remove unwanted frequency components in a signal (noise, interference …) – Shape signal to account for effects of signal transduction and transmission (equalisation) – Many filtering operations can be performed after conversion to digital form; some cannot (antialias filtering) 7 • Linearisation, calibration – Many sensors have nonlinear relationships between the physical signal and its electrical analogue – Can be calibrated before (analogue) or after (digital) analogue to digital conversion – Calibration before conversion allows faster processing; After is more precise, flexible and reconfigurable Inverting Non-Inverting Figures from Sedra and Smith Filter Differential Amplifier Buffer 8 Analogue to Digital Conversion Analogue-Digital Conversion • Convert voltage (analogue signal) to time series of digital numbers • Key considerations include resolution, dynamic range, sampling frequency and accuracy • 8, 10, 12, 16-bit ADCs are common, higher resolutions available • Acronyms ADC, A/D, ATD • Typically, analogue signal is sampled by analogue sample and hold circuit – Maintains a stable signal to convert • HCS12 has two built-in 8/10-bit analogue-digital converters – 8 channels can share each converter in time-multiplexed manner – Interrupt-based interface possible 9 Quantization Error • Representation as digital number – Digital signal can only change as fast as least significant bit – Changes are quantized to increments of the digital number. 12-bit ADC with linear mapping, each increment is 1/4096 of fullscale – Causes numerical error between the true value and the digital representation (error range 0-1 LSB or +/-0.5 LSB) Sampling Error • Sampling interval is a key consideration – Limits temporal resolution – Mean latency of 1/2 sample period from sampling alone • Irregular sampling can cause distortion of the sampled signal • Sampling rate should be controlled through timer circuitry 10 Effects of Irregular Sampling 12 10 8 6 4 2 0 0 2 4 6 8 10 12 12 10 8 6 True Analogue Delayed Analogue Irregular Digital 4 2 0 0 2 4 6 8 10 12 11 • Temporal resolution limited by sampling rate • Can up-sample to interpolate missing samples – Makes assumptions about signal From Catsoulis Aliasing • Periodicity – Periodic signals repeat regularly x(t ) = x(t + T ) for some T and all t, fundamental period is the smallest such T , – e.g. x(t ) = sin(t ) = sin(t + 2π ) = sin(t + 4π ) is periodic with period 2π • Fourier theory states that we can compose arbitrary signals by combining sinusoids – Periodic signals with Fourier Series – Aperiodic signals with Fourier Transform • But cannot represent all frequencies in an analogue signal in a sampled digital signal 12 if f 0 = 1 2 , period N = 2, ω 0 = 2πf 0 then if x[n] = cos(nω 0 ) x[0] = 1 x[1] = -1 x[2] = 1 Alternates sign every discrete interval, obviously fastest alternation possible 5 e.g. ω 0 = π , period N = 0.8 2 then if x[n] = cos(nω 0 ) x[0] = 1 x[1] = 0 x[2] = −1 x[3] = 0 x[4] = 1 • looks like ω0 = 2π/5 or N =5 • when one frequency is indistinguishable from another it is known as aliasing Nyquist Rate • To be able to reconstruct a signal from a sampled digital signal unambiguously – Need to sample at least twice the highest frequency in the signal – Or need to limit the highest frequency in the signal to less than one half the sampling rate (anti-aliasing filter) • Theoretical limitations, practically need to sample faster than Nyquist rate 13 • Anti-aliasing filtering needs to be done before sampling Flash Converters • In parallel, compare with voltage levels corresponding to all possible digital numbers • Priority encoder chooses largest digital number less than input • Very fast but expensive in circuitry (e.g. 1024 comparators for 10bit ADC) • Can implement nonlinear converters easily www.allaboutcircuits.com 14 Successive Approximation • Based on comparison with input – Successively count up or down ADC digital number – When digital number equals input, conversion is done from www.allaboutcircuits.com Successive Approximation • Special counter: count first by mostsignificant bit and work to leastsignificant bit. Faster than standard count Example 10-bit Successive Approximation Converter 15 • Successive approximation converters are typically slower than flash since they convert over multiple cycles • Can compromise and estimate several bits at each cycle (pipelined converter) http://www.analog.com/library/analogDialogue/archives/33-08/adc/index.html Sigma-Delta • A ‘1-bit’ DAC suitable for high resolution, low measurement rate applications http://www.analog.com/library/analogDialogue/archives/33-08/adc/index.html 16 Image acquisition • Analogue signals are not only 1-D, for example images acquired by a CCD array are analogue Representation of analogue signals Engineering Units and Fixed Point Representations • Physical signal expressed in standard unit: Watts, cd/m2, N, … • Converted to voltage which is represented by a digital number (e.g. 0255 for 8-bit converter) • Often more useful to work in ‘engineering units’ that represent physical units 17 • Could represent as a floating point number with floating point support – Slow in software – Additional circuitry for hardware support in custom processor – Hardware support may not be available or economical on chosen processor • One can consider the digital number as a fixed point representation – Can define the decimal point at any convenient bit position – After bit zero gives standard integer representation – Setting before most significant bit gives range 0 to 1 (actually one step less than one) Codecs • Stands for coder/decoder – Where paired coding and decoding of signals (eg ADC and DAC) occurs the device is called a codec – Many different ways of mapping the signal to the code • Linear • Logarithmic • Differential pulse coded 18 Digital to Analogue Conversion Digital to analogue conversion • One approach: Sum up contribution of each bit set in digital number • Weight each bit according to its place 1, 2, 4, 8 http://www.allaboutcircuits.com • This converts to analogue voltages but still need to handle time discretisation • Zero-order hold: output is staircase like, switching at each sample • Can filter to remove components above Nyquist rate and recover signal 19 PWM • Pulse width modulation (PWM) can support a form of analogue output interfacing • Control the duty cycle of a periodic binary signal • If signal has high frequency, filtering with external filter or by a ‘slow’ output device (e.g. an electric motor) can remove the high frequency switching • Leaves lower frequency signal – voltage is average over the cycle – Variations in filtered signal reflect variations in duty cycle From Heath, 2003 Actuators, Motors and Displays 20 Interfacing with Actuators and Switching Power • Switching large loads requires special interacing and protection circuitry • Many options exist for switching/ controlling devices requiring large amounts of power; choice depends on – Level and type of control desired – Type of load – Requirements for protection, isolation, EMC … H Bridge circuits From Heath, 2003 21