Microcontroller Basics and Applications | 10 Microcontroller A/D and D/A Conversion Interfaces

Click the blue text to follow us

Microcontroller Basics and Applications | 10 Microcontroller A/D and D/A Conversion Interfaces

1. Microcontroller Measurement and Control System and Analog Input Channel

1. Overview of Microcontroller Measurement and Control System

Measurement and control include two processes: “measurement” and “control”.

The so-called “measurement” is the real-time collection of physical parameters of the controlled object, such as temperature, pressure, flow rate, speed, and rotational speed. These parameters are usually analog quantities, i.e., continuously varying physical quantities.

The so-called “control” means that after processing the collected data through the microcontroller, conclusions are drawn to implement corrective control on the controlled object. However, the result obtained after microcontroller processing is a digital quantity.

The measurement and control system cannot do without the mutual conversion of analog and digital quantities; therefore, A/D (Analog to Digital) and D/A (Digital to Analog) conversion have become important components of the measurement and control system.

2. Analog Input Channel

The operation of the analog input channel starts with signal acquisition. Since the amplitude of the analog signals collected by sensors is usually very small, and continuously varying signals are easily disturbed, the raw signals collected by sensors must be amplified, sampled, held, filtered, etc., before being sent to the A/D converter. This series of processing steps constitutes the analog input channel, as shown in the figure below.

Microcontroller Basics and Applications | 10 Microcontroller A/D and D/A Conversion Interfaces

(1) Sensors

The main function of the sensor is to collect signals, and it also has a signal conversion function, that is, it converts the collected non-electric signals into electrical signals (voltage or current) for subsequent processing. There are many types of sensors, and commonly used sensors include the following:

① Temperature Sensor: Used to convert temperature into electrical signals.
② Photoelectric Sensor: Converts light signals into electrical signals using the photoelectric effect.
③ Humidity Sensor: Common humidity sensors include hair hygrometers, wet and dry bulb hygrometers, and metal oxide humidity sensitive components.
④ Flow Sensor: Used to measure the flow rate of liquids and gases. Common flow sensors include velocity-type flowmeters and volumetric flowmeters.
⑤ Pressure Sensor: Used for measuring atmospheric pressure (air pressure) and container wall pressure.
⑥ Mechanical Quantity Sensor: Common mechanical quantities include tension, pressure, displacement, speed, acceleration, torque, and load. Common mechanical quantity sensors include resistance strain gauges, force sensors, load sensors, displacement sensors, and rotational speed sensors.
⑦ Component Analysis Sensor: Used for automatic analysis of the components of mixed gases or mixtures.
⑧ pH Sensor: Used to measure the acidity and alkalinity of aqueous solutions.
(2) Amplifier

The voltage or current signals obtained from the sensors are often of small amplitude and difficult to perform A/D conversion directly, so amplifiers are needed to amplify the analog signals.

There are many types of amplifiers, but the type used in the analog input channel is a direct-coupled amplifier with high gain and deep negative feedback. Since it can perform various mathematical operations (such as proportional, addition, subtraction, integration, and differentiation) on the input signals, it is called an operational amplifier. Operational amplifiers have characteristics such as high input impedance, high gain, high reliability, low cost, and ease of use. There are now various specialized or general-purpose operational amplifiers available for selection.

(3) Sample/Hold Circuit

Sampling is to track the changes in the input signal, and its essence is to convert a continuously varying analog signal into a time-discrete sampled signal. The sampling frequency must be much higher than the highest frequency component in the analog signal (generally 2.5 times).

Holding is to maintain the sampled signal for a period of time, as the subsequent A/D conversion requires a time process. During the hold period, the signal must remain stable, and efforts should be made to keep the signal unchanged.

In the analog input channel, the sampling circuit and the hold circuit are combined, referred to as the sample/hold circuit. As shown in the figure below.

Microcontroller Basics and Applications | 10 Microcontroller A/D and D/A Conversion Interfaces

(4) Filter

Filtering can be divided into analog filtering and digital filtering.

Analog filtering is completed by filtering circuits built with electronic components, and analog filtering can be divided into passive and active types. Passive filtering uses passive components (inductors, capacitors, and resistors) to construct filtering circuits. Active filters use amplifiers along with capacitors and resistors to construct filtering circuits.

Digital filtering involves smoothing the sampled signals through programs to enhance useful signals and eliminate or suppress interference signals. There are various digital filtering programs, such as program judgment filtering, median filtering, arithmetic mean filtering, weighted average filtering, first-order lag filtering, and composite filtering.

Compared with analog filtering, digital filtering has many advantages, which is why digital filtering is widely used in modern measurement and control systems. Digital filtering not only does not require hardware devices but is also very convenient to use; it only requires adding a segment of filtering program before entering data processing or control algorithms.

(5) Multiplexing

Many measurement and control systems are multiplex systems to facilitate multi-parameter collection. In a multiplex system, as long as the speed allows, a scheme should be adopted where multiple channels share a single A/D converter to simplify the structure and reduce costs. A multiplexer needs to be set up in the analog input channel to switch channels, allowing each channel to be connected in turn and alternately.

2. A/D Converter Interface

1. 8-bit A/D Conversion Chip and 80C51 Interface

(1) ADC0809 Chip

ADC0809 adopts successive approximation A/D conversion principle and can achieve time-sharing collection of 8 analog signals. The chip has 8 analog switching gates and corresponding channel address latching and decoding circuits, with a conversion time of about 100 μs. The internal logic structure of ADC0809 is shown in the figure below.

Microcontroller Basics and Applications | 10 Microcontroller A/D and D/A Conversion Interfaces

The multiplexer in the figure can select 8 analog channels, allowing 8 analog quantities to be input in time-sharing, sharing a single A/D conversion chip for conversion. The address latching and decoding circuit completes the latching and decoding of the three address bits A, B, and C, and its decoding output is used for channel selection. The 8-bit A/D converter is of the successive approximation type, consisting of control and timing circuits, a successive approximation register, a tree switch, and a 256R resistor ladder network. The output latch is used to store and output the digital quantity obtained from the conversion.
The functions of each pin of ADC0809 are as follows:

Microcontroller Basics and Applications | 10 Microcontroller A/D and D/A Conversion Interfaces

IN7~IN0: Analog quantity input channels.
A, B, C: Address lines, selection signals for analog channels. A is the low address, and C is the high address. It can select 8 channels.
ALE: Address latch enable signal. Corresponding to the rising edge of ALE, the address state of A, B, and C is sent to the address latch.
START: Conversion start signal. When the START rises, all internal registers are cleared to 0; when the START falls, A/D conversion begins; during A/D conversion, START should remain low.
D7~D0: Data output lines.
OE: Output enable signal. Used to control the tri-state output latch to output the data obtained from the conversion to the microcontroller. When OE=0, the output data lines are in high impedance; when OE=1, the converted data is output.
CLK: External clock signal input.
EOC: End of conversion signal. EOC=0 indicates that conversion is in progress; EOC=1 indicates that conversion is complete. VCC: +5 V power supply.
VREF: Reference power supply.
(2) ADC0809 and 80C51 Interface
The following figure shows the connection of ADC0809 to 80C51. The selection signals A, B, and C for the 8 analog channels are connected to the lowest three address A0, A1, A2 (i.e., P0.0, P0.1, P0.2), while the address latch enable signal ALE is controlled by P2.0, making the address for the 8 analog channels FEF8H~FEFFH.

Microcontroller Basics and Applications | 10 Microcontroller A/D and D/A Conversion Interfaces

2. 12-bit A/D Conversion Chip and 80C51 Interface
For A/D conversion chips with more than 8 bits, the interface must consider the time-sharing reading of the conversion results. Taking the 12-bit A/D conversion chip AD574A as an example, the signal line connection part of AD574A to 80C51 is shown in the figure below.

Microcontroller Basics and Applications | 10 Microcontroller A/D and D/A Conversion Interfaces

AD574A has two analog input terminals, where the voltage range of 10VIN is 0~10 V and that of 20VIN is 0~20 V. In the 80C51 system, when using the AD574A chip, its conversion data should be read in two stages, with the high 8 bits and low 4 bits read separately. The reading is controlled by A0, which is generally connected to the least significant address line A0. When A0=0, the high 8 bits are read; when A0=1, the low 4 bits are read.
  • R/C: Read/start conversion signal. When R/C=0, it is the start conversion signal; when R/C=1, it is the read signal.
  • STS: Conversion end signal. It is high during the conversion, and goes low when the conversion is complete.
  • 12/8: Output bit selection signal. When 12/8=1, it is a 12-bit output; when 12/8=0, it is an 8-bit output.
  • CE: Enable signal, active high. It participates in controlling the start of conversion and reading data.
3. A/D Conversion Chip Application Description
(1) Chip Types Classified by Principle
  • Integrating A/D Converter: Also known as dual-slope or multi-slope A/D converters. It is widely used and has advantages such as high accuracy and strong anti-interference ability.
  • Successive Approximation A/D Converter: Simple principle, easy to implement, and does not have time delay problems.
  • Flash A/D Converter: Its main feature is high speed, but it has high power consumption and complex circuits, so the chip size is also larger.
  • ΣΔ A/D Converter: Also known as oversampling A/D converters. Although it appeared later, it has advantages such as high resolution, low cost, and strong anti-interference ability.
(2) Input Voltage Signal Forms
  • Unipolar voltage signals, all A/D conversion chips have this input form. The generally allowed voltage range is 0~+5 V, 0~+10 V, and 0~+20 V, etc.
  • Bipolar voltage signals can be both positive and negative. Although they are still input through one lead, the chip needs a pair of power supplies with opposite polarities to work together.
  • Differential signals are voltage signals that are not grounded together. Two polarities of differential signals require two signal lines to be input, represented on the chip as VIN+ and VIN-. Differential voltage signals can start from non-zero volts, with ranges such as ±2 V, ±4 V, ±5 V, and ±10 V.
(3) Output Binary Code Forms
  • The binary code A/D conversion chip outputs binary codes, with bit numbers ranging from 8 bits, 10 bits, 12 bits, 14 bits, 16 bits, 20 bits to 24 bits, etc.
  • BCD code A/D conversion chips output multi-digit BCD codes. This type of conversion chip is typically used in digital voltmeters, where the output BCD code can be directly sent to LED or LCD for display. Common BCD code A/D conversion chips have bit numbers of 3.5 bits, 4.5 bits, and 5.5 bits, etc.
(4) A/D Converter Resolution

The A/D converter converts voltage, so its resolution is the ability to distinguish changes in the input voltage signal. The more bits the A/D converter has, the smaller the resolution value, and the stronger the resolution capability, meaning the converter’s sensitivity to changes in input quantity is higher. Therefore, when selecting an A/D converter, the number of bits should be given importance.

(5) Control Signals of A/D Converters

There are some control signals in A/D conversion chips, including clock signals, conversion start signals, and conversion end signals, etc. These signals need to be processed during interface connections.

1) Clock Signal
A/D conversion requires clock signals. Some A/D conversion chips (such as AD571, etc.) have internal clock circuits. Other A/D conversion chips (such as ADC0808/0809, etc.) do not have internal clock circuits, and the required clock signals are provided externally.
2) Conversion Start Signal
The conversion start signal should be provided by the CPU. Different models of A/D conversion chips have different requirements for the conversion start signal. Some require pulse signals to start, such as ADC0804, ADC0809, etc., while others require level signals, such as AD570, AD571, and AD574.
(6) Conversion End and Data Reading

The digital quantity data obtained after A/D conversion should be transmitted to the microcontroller for processing in a timely manner, and reading should be done after data conversion is complete.

1) Timed Waiting Method
For an A/D conversion chip, the conversion time is a known and fixed technical specification, and the timed waiting method can be used to wait for conversion to complete.
2) Polling Method
A/D conversion chips provide status signals indicating conversion completion, which can be used in the polling method to check whether the conversion is complete.
3) Interrupt Method
The status signals indicating conversion completion (EOC for ADC0809) can be used as interrupt request signals, allowing the use of the interrupt method for transmitting conversion data.

3. D/A Converter Interface

1. D/A Conversion Chip

There are many D/A conversion chips; here we take DAC0832 as an example.

DAC0832 is an 8-bit D/A conversion chip powered by a single +5 V supply, with a reference voltage range of ±10 V, a current settling time of 1 μs, using CMOS technology, low power consumption (20 mW), and a 20-pin dual in-line package. The pin arrangement is shown in the figure below.

Microcontroller Basics and Applications | 10 Microcontroller A/D and D/A Conversion Interfaces

  • DI7~DI0: Data input for conversion.

  • CS: Chip select signal (input), active low.

  • ILE: Data latch enable signal (input), active high.

  • WR1: First write signal (input), active low.

  • XFER: Data transfer control signal (input), active low.

  • WR2: Second write signal (input), active low.

  • IOUT1: Current output 1. When the data is all 1s, the output current is maximum; when all 0s, the output current is minimum.

  • IOUT2: Current output 2.

  • RFB: Feedback resistor terminal, which is the feedback resistor terminal of the operational amplifier, and the resistor (15 kΩ) is fixed in the chip. DAC0832 is a current output type D/A converter; to obtain voltage conversion output, operational amplifiers need to be connected to the two current output terminals, with RFB being the feedback resistor of the operational amplifier.

  • VREF: Reference voltage, an external high-precision voltage source connected to the internal resistor network of the chip. This voltage can be positive or negative, with a range of -10 to +10 V. The reference voltage determines the output voltage range of the D/A converter; for example, if VREF is connected to +10 V, the output voltage range is 0 to -10 V.

  • DGND: Digital ground.

  • AGND: Analog ground.

The internal structural block diagram of DAC0832 is shown in the figure below, where the resistor decoding network is included in the 8-bit D/A converter shown in the diagram. The input channel consists of an input register and DAC register, forming two levels of data input latching, controlled by three “AND” gate circuits to produce LE1 and LE2 signals, which control the two input registers.

Microcontroller Basics and Applications | 10 Microcontroller A/D and D/A Conversion Interfaces

2. Single Buffer Connection Mode for DAC0832

The so-called single buffer connection mode means that one of the two input registers of DAC0832 (usually the DAC register) is in a direct pass-through state, while the other is in a controlled latching state. In practical applications, if there is only one analog output, or if there are multiple analog outputs but synchronization is not required, the single buffer mode should be used. Its connection is shown in the figure below.

Microcontroller Basics and Applications | 10 Microcontroller A/D and D/A Conversion Interfaces

3. Dual Buffer Connection Mode for DAC0832

The so-called dual buffer connection mode means that both the input register and DAC register of DAC0832 are connected in a controlled latching mode. In multi-channel D/A conversion, if synchronous output is required, the dual buffer connection mode should be used. The dual buffer connection mode for DAC0832 is shown in the figure below.

Microcontroller Basics and Applications | 10 Microcontroller A/D and D/A Conversion Interfaces

4. Serial Interface of A/D and D/A Converter Chips

1. Serial Interface via I2C Bus

For A/D or D/A conversion chips with I2C bus interfaces, the interface can be realized through the I2C bus. Here, we take the mixed chip PCF8591 as an example.

PCF8591, produced by Philips, is a typical mixed A/D and D/A conversion chip with I2C bus interface, using CMOS semiconductor technology. The analog input channel of the A/D conversion part has 4 channels, with a conversion result of 8 bits, adopting a successive approximation conversion method with a sample/hold circuit. The D/A conversion part has 1 analog output. The pin arrangement of the dual in-line chip is shown in the figure below.

Microcontroller Basics and Applications | 10 Microcontroller A/D and D/A Conversion Interfaces

The functions of each pin are as follows:
  • AIN3~AIN0: Analog signal input.
  • A3~A0: Pin addresses.
  • SCL, SDA: I2C bus interface signals.
  • OSC: External clock input, internal clock output.
  • EXT: Internal/external clock selection, EXT=0 selects internal clock, EXT=1 selects external clock.
  • Aout: D/A conversion analog output.
  • VDD, VSS: Chip power supply.
  • VREF: Reference power supply.
  • AGND: Analog ground.
  • PCF8591’s device address is 1001, and the pin address is set by A2, A1, and A0. A system can expand up to 8 PCF8591 chips.
  • PCF8591 has a control register inside, and the microcontroller controls A/D and D/A conversion by writing control words to this register. Therefore, before conversion, it is necessary to transmit the control word.
  • The main content of the control word written during D/A conversion in the PCF8591 chip is to set the analog output enable bit to 1. Subsequently, each time a data byte is written, the conversion result is output at the AOUT terminal.
2. Serial Interface Simulated by Software

For microcontroller chips without a serial interface, a software simulation method can be used to achieve a serial interface. Taking MAX187 as an example. MAX187 is a 12-bit single analog channel A/D conversion chip with an SPI bus, which has a sample/hold circuit and adopts a successive approximation conversion method with a conversion time of 10 μs. The pin arrangement is shown in the figure below.

Microcontroller Basics and Applications | 10 Microcontroller A/D and D/A Conversion Interfaces

The functions of each pin are as follows:
  • AIN: Analog signal input, effective voltage range is 0 V~VREF.
  • DOUT: Serial output of conversion results.
  • SCLK: Clock signal input.
  • CS: Chip select signal.
  • SHDN: Control signal. This pin is connected to low level, and the chip is in low power mode; this pin is connected to high level, and the chip uses the internal reference power supply; this pin is left floating, and the chip uses the external reference power supply.
  • VREF: Reference power supply.
  • VDD: Chip power supply.
  • GND: Digital ground and analog ground.

The connection of the software simulated serial interface is very simple; just connect three port lines of the 80C51 to the CS, SCLK, and DOUT signal pins of MAX187, as shown in the figure below.

Microcontroller Basics and Applications | 10 Microcontroller A/D and D/A Conversion Interfaces

Microcontroller Basics and Applications | 10 Microcontroller A/D and D/A Conversion Interfaces

Long press the image to follow

Discover more exciting content

WeChat ID: Mechanical-knowledge

Leave a Comment