An analog value is continuous, not discrete, as shown in Figure 15.1 Logical and Continuous Values. In the previous chapters, techniques were discussed for designing continuos control systems. In this chapter we will examine analog inputs and outputs so that we may design continuous control systems that use computers.
Figure 15.1 Logical and Continuous Values
Typical analog inputs and outputs for computers are listed below. Actuators and sensors that can be used with analog inputs and outputs will be discussed in later chapters.
Inputs:
· oven temperature
· fluid pressure
· fluid flow rate
Outputs:
· fluid valve position
· motor position
· motor velocity
A basic analog input is shown in Figure 15.2 Analog inputs. In this type of system a physical value is converted to a voltage, current or other value by a transducer. A signal conditioner converts the signal from the transducer to a voltage or current that is read by the analog input.
Figure 15.2 Analog inputs
Analog to digital and digital to analog conversion uses integers within the computer. Integers limit the resolution of the numbers to a discrete, or quantized range. The effect of using integers is shown in Figure 15.3 Quantization error where the desired or actual analog value is continuous, but the possible integer values are quantified with a 'staircase' set of values. Consider when a continuous analog voltage is being read, it must be quantized into an available integer value. Likewise, a desired analog output value is limited to available quantized values. In general the difference between the analog and quantized integer value is an error based upon the resolution of the analog I/O.
Figure 15.3 Quantization error
To input an analog voltage (into a computer) the continuous voltage value must be sampled and then converted to a numerical value by an A/D (Analog to Digital) converter (also known as ADC). Figure 15.4 Sampling an Analog Voltage shows a continuous voltage changing over time. There are three samples shown on the figure. The process of sampling the data is not instantaneous, so each sample has a start and stop time. The time required to acquire the sample is called the sampling time. A/D converters can only acquire a limited number of samples per second. The time between samples is called the sampling period T, and the inverse of the sampling period is the sampling frequency (also called sampling rate). The sampling time is often much smaller than the sampling period. The sampling frequency is specified when buying hardware, but a common sampling rate is 100KHz.
Figure 15.4 Sampling an Analog Voltage
A more realistic drawing of sampled data is shown in Figure 15.5 Parameters for an A/D Conversion. This data is noisier, and even between the start and end of the data sample there is a significant change in the voltage value. The data value sampled will be somewhere between the voltage at the start and end of the sample. The maximum (Vmax) and minimum (Vmin) voltages are a function of the control hardware. These are often specified when purchasing hardware, but reasonable ranges are;
0V to 5V
0V to 10V
-5V to 5V
-10V to 10V
The number of bits of the A/D converter is the number of bits in the result word. If the A/D converter is 8 bit then the result can read up to 256 different voltage levels. Most A/D converters have 12 bits, 16 bit converters are used for precision measurements.
Figure 15.5 Parameters for an A/D Conversion
The parameters defined in Figure 15.5 Parameters for an A/D Conversion can be used to calculate values for A/D converters. These equations are summarized in Figure 15.6 A/D Converter Equations. Equation 1 relates the number of bits of an A/D converter to the resolution. Equation 2 gives the error that can be expected with an A/D converter given the range between the minimum and maximum voltages, and the resolution (this is commonly called the quantization error). Equation 3 relates the voltage range and resolution to the voltage input to estimate the integer that the A/D converter will record. Finally, equation 4 allows a conversion between the integer value from the A/D converter, and a voltage in the computer.
Figure 15.6 A/D Converter Equations
Consider a simple example, a 10 bit A/D converter is set up to read voltages between -10V and 10V. This gives a resolution of 1024, where 0 is -10V and 1023 is +10V. Because there are only 1024 steps there is a maximum error of ±9.8mV. If a voltage of 4.564V is input, the A/D converter converts the voltage to an integer value of 746. When we convert this back to a voltage the result is 4.570V. The resulting quantization error is 4.570V-4.564V=+0.006V. This error can be reduced by selecting an A/D converter with more bits. Each bit halves the quantization error.
Figure 15.7 Sample Calculation of A/D Values
If the voltage being sampled is changing too fast we may get false readings, as shown in Figure 15.8 Low Sampling Frequencies Cause Aliasing. In the upper graph the waveform completes seven cycles, and 9 samples are taken. The bottom graph plots out the values read. The sampling frequency was too low, so the signal read appears to be different than it actually is, this is called aliasing.
Figure 15.8 Low Sampling Frequencies Cause Aliasing
Figure 15.9 Very Low Sampling Frequencies Produce Apparently Random
The Nyquist criterion specifies that sampling frequencies should be at least twice the frequency of the signal being measured, otherwise aliasing will occur. The example in Figure 15.8 Low Sampling Frequencies Cause Aliasing violated this principle, so the signal was aliased. If this happens in real applications the process will appear to operate erratically. In practice the sample frequency should be 4 or more times faster than the system frequency.
There are other practical details that should be considered when designing applications with analog inputs;
· Noise - Since the sampling window for a signal is short, noise will have added effect on the signal read. For example, a momentary voltage spike might result in a higher than normal reading. Shielded data cables are commonly used to reduce the noise levels.
· Delay - When the sample is requested, a short period of time passes before the final sample value is obtained.
· Multiplexing - Most analog input cards allow multiple inputs. These may share the A/D converter using a technique called multiplexing. If there are 4 channels using an A/D converter with a maximum sampling rate of 100Hz, the maximum sampling rate per channel is 25Hz.
· Signal Conditioners - Signal conditioners are used to amplify, or filter signals coming from transducers, before they are read by the A/D converter.
· Resistance - A/D converters normally have high input impedance (resistance), so they affect circuits they are measuring.
· Single Ended Inputs - Voltage inputs to the A/D converter can use a single common for multiple inputs, these types of inputs are called single ended inputs. These tend to be more prone to noise.
· Double Ended Inputs - Each double ended input has its own common. This reduces problems with electrical noise, but also tends to reduce the number of inputs by half.
· Sampling Rates - The maximum number of samples that can be read each second. If reading multiple channels with a multiplexer, this may be reduced.
· Quantization Error - Analog IO is limited by the binary resolution of the converter. This means that the output is at discrete levels, instead of continuous values.
· Triggers - often external digital signals are used to signal the start of data collection.
· Range - the typical voltages that the card can read. Typical voltage ranges are -10V to 10V, 0V to 10V, 0V to 5V, 1V to 5V, -5V to 5V, 4mA to 20mA.
· DMA - a method to write large blocks of memory directly to computer memory. This is normally used for high speed data captures.
· Filters - some A/D input cards will provide built in functions to filter the incoming data to remove high frequency noise components.
· Input impedance - most analog inputs have very high input resistances, in the range of Mohms.
Figure 15.10 A Successive Approximation A/D Converter
Analog outputs are much simpler than analog inputs. To set an analog output an integer is converted to a voltage. This process is very fast, and does not experience the timing problems with analog inputs. But, analog outputs are subject to quantization errors. Figure 15.11 Analog Output Relationships gives a summary of the important relationships. These relationships are almost identical to those of the A/D converter.
Figure 15.11 Analog Output Relationships
Assume we are using an 8 bit D/A converter that outputs values between 0V and 10V. We have a resolution of 256, where 0 results in an output of 0V and 255 results in 10V. The quantization error will be 20mV. If we want to output a voltage of 6.234V, we would specify an output integer of 160, this would result in an output voltage of 6.250V. The quantization error would be 6.250V-6.234V=0.016V.
The current output from a D/A converter is normally limited to a small value, typically less than 20mA. This is enough for instrumentation, but for high current loads, such as motors, a current amplifier is needed. This type of interface will be discussed later. If the current limit is exceeded for 5V output, the voltage will decrease (so don't exceed the rated voltage). If the current limit is exceeded for long periods of time the D/A output may be damaged.
Figure 15.12 A Digital-To-Analog Converter
Signals from sensors are often not in a form that can be directly input to a controller. In these cases it may be necessary to buy or build signal conditioners. Normally, a signal conditioner is an amplifier, but it may also include noise filters, and circuitry to convert from current to voltage. This section will discuss the electrical and electronic interfaces between sensors and controllers.
Analog signal are prone to electrical noise problems. This is often caused by electromagnetic fields on the factory floor inducing currents in exposed conductors. Some of the techniques for dealing with electrical noise include;
twisted pairs - the wires are twisted to reduce the noise induced by magnetic fields.
shielding - shielding is used to reduce the effects of electromagnetic interference.
single/double ended inputs - shared or isolated reference voltages (commons).
When a signal is transmitted through a wire, it must return along another path. If the wires have an area between them the magnetic flux enclosed in the loop can induce current flow and voltages. If the wires are twisted, a few times per inch, then the amount of noise induced is reduced. This technique is common in signal wires and network cables.
A shielded cable has a metal sheath, as shown in Figure 15.13 Cable Shielding. This sheath needs to be connected to the measuring device to allow induced currents to be passed to ground. This prevents electromagnetic waves to induce currents (and voltages) in the signal wires.
Figure 15.13 Cable Shielding
When connecting analog voltage sources to a controller the common, or 0V reference voltage, can be connected different ways, as shown in Figure 15.14 Single and Double Ended Inputs. The least expensive method uses one shared common for all analog signals, this is called single ended. The more accurate method is to use separate commons for each signal, this is called double ended. Most analog input cards allow a choice between one or the other. But, when double ended inputs are used the number of available inputs is halved. Most analog output cards are double ended.
Figure 15.14 Single and Double Ended Inputs
When a changing magnetic field cuts across a conductor, it will induce a current flow. The resistance in the circuits will convert this to a voltage. These unwanted voltages result in erroneous readings from sensors, and signal to outputs. Shielding will reduce the effects of the interference. When shielding and grounding are done properly, the effects of electrical noise will be negligible. Shielding is normally used for; all logical signals in noisy environments, high speed counters or high speed circuitry, and all analog signals.
There are two major approaches to reducing noise; shielding and twisted pairs. Shielding involves encasing conductors and electrical equipment with metal. As a result electrical equipment is normally housed in metal cases. Wires are normally put in cables with a metal sheath surrounding both wires. The metal sheath may be a thin film, or a woven metal mesh. Shielded wires are connected at one end to "drain" the unwanted signals into the cases of the instruments. Figure 15.15 Shielding for a Thermocouple shows a thermocouple connected with a thermocouple. The cross section of the wire contains two insulated conductors. Both of the wires are covered with a metal foil, and final covering of insulation finishes the cable. The wires are connected to the thermocouple as expected, but the shield is only connected on the amplifier end to the case. The case is then connected to the shielding ground, shown here as three diagonal lines.
Figure 15.15 Shielding for a Thermocouple
A twisted pair is shown in Figure 15.16 A Twisted Pair. The two wires are twisted at regular intervals, effectively forming small loops. In this case the small loops reverse every twist, so any induced currents are cancel out for every two twists.
Figure 15.16 A Twisted Pair
When designing shielding, the following design points will reduce the effects of electromagnetic interference.
· Avoid "noisy" equipment when possible.
· Choose a metal cabinet that will shield the control electronics.
· Use shielded cables and twisted pair wires.
· Separate high current, and AC/DC wires from each other when possible.
· Use current oriented methods such as sourcing and sinking for logical I/O.
· Use high frequency filters to eliminate high frequency noise.
· Use power line filters to eliminate noise from the power supply.
- ground voltages are based upon the natural voltage level in the physical ground (the earth under your feet). This will vary over a distance. Most buildings and electrical systems use a ground reference for the building. Between different points on the same building ground voltage levels may vary as much as a few hundred millivolts. This can lead to significant problems with voltage readings and system safety.
- A signal can be floating, or connected to a ground
- if floating a system normally has a self contained power source, or self reference such as a battery, strain gauge or thermocouple. These are usually read with double ended outputs. The potential for floating voltage levels can be minimized by connecting larger resistors (up to 100K) from the input to ground.
- a grounded system uses a single common (ground) for all signals. These are normally connected to a single ended inputs.
- the analog common can also be connected to the ground with a large resistor to drain off induced voltages.
- cable shields or grounds are normally only connected at one side to prevent ground loops.
- data smoothing by averaging inputs
- conversion back to an input voltage
- use it to calculate an output voltage for control.
· A/D conversion will convert a continuous value to an integer value.
· D/A conversion is easier and faster and will convert a digital value to an analog value.
· Resolution limits the accuracy of A/D and D/A converters.
· Sampling too slowly will alias the real signal.
· Analog inputs are sensitive to noise.
· Analog shielding should be used to improve the quality of electrical signals.
1. What is the difference between an A/D input and D/A output?
2. An analog voltage that has a range of -10V to 10V and is to be read to a precision of +/-0.05V. How is the minimum number of bits required for the A/D converter?
3. If given a 12 bit analog input with a range of -10V to 10V. If we put in 2.735V, what will the integer value be after the A/D conversion? What is the error? What voltage can we calculate?
4. Write a (complete) program for the ATmega32 that will read a potentiometer connected to PA0. The potentiometer is connected across a 2V voltage source. When the potentiometer is above the middle of the range (>1V) pin PB0 will be turned on.
1. An analog output needs to be between -4V and 8V, in 0.005V intervals. How many bits are required for the D/A converter?
2. Discuss methods for reducing electrical noise in analog inputs.
3. Write a C program for an ATMega 32 microcontroller to collect an analog data value every half a second and print it to the screen. The program should run for 10 seconds and then stop.
4. Write a C program for an ATMega 32 microcontroller to read a 10 bit analog input every 20ms and update an 8 bit PWM output. The relationship between input and output should be such that when the analog input is 0 the PWM output should be 0, and when the analog input is 1023 the PWM output should be 255.