EE Embedded Systems Fall 2015

Slides:



Advertisements
Similar presentations
Introductory Circuit Analysis Robert L. Boylestad
Advertisements

Interfacing to the Analog World
Analog to Digital Conversion (ADC)
Analog-to-Digital Converter (ADC) And
Lecture 17: Analog to Digital Converters Lecturers: Professor John Devlin Mr Robert Ross.
Data Acquisition ET 228 Chapter
Digital to Analogue Conversion Chapter 13. Why is conversion needed? Most signals in the world are analogue. Microprocessors and most computers computers.
Digital to Analog and Analog to Digital Conversion
Announcements Assignment 8 posted –Due Friday Dec 2 nd. A bit longer than others. Project progress? Dates –Thursday 12/1 review lecture –Tuesday 12/6 project.
Data Acquisition Concepts Data Translation, Inc. Basics of Data Acquisition.
COMP3221: Microprocessors and Embedded Systems
5/4/2006BAE Analog to Digital (A/D) Conversion An overview of A/D techniques.
Lecture 9: D/A and A/D Converters
Analogue to Digital Conversion
Interfacing Analog and Digital Circuits
5-1 Analogue Input/Output Many sensors/transducers produce voltages representing physical data.  To process transducer data in a computer requires conversion.
Data acquisition and manipulation
Explain the introduction to ADC, ADC characteristics, Programming ADC using PIC18, Introduction to DAC and DAC interfacing with PIC18.
Storey: Electrical & Electronic Systems © Pearson Education Limited 2004 OHT 26.1 Data Acquisition and Conversion  Introduction  Sampling  Signal Reconstruction.
EET260: A/D and D/A converters
H. Huang Transparency No.11-1 The 68HC11 Microcontroller Chapter 11: 68HC11 Analog to Digital Converter The 68HC11 Microcontroller Han-Way Huang Minnesota.
Analogue Input/Output
PH4705/ET4305: A/D: Analogue to Digital Conversion
Electronic Devices Ninth Edition Floyd Chapter 13.
Data Converters ELEC 330 Digital Systems Engineering Dr. Ron Hayne
1 Sensors and Measurements Penderia & Pengukuran ENT 164 Signal Processing Elements Hema C.R. School of Mechatronics Engineering Northern Malaysia University.
DATA ACQUISITION Today’s Topics Define DAQ and DAQ systems Signals (digital and analogue types) Transducers Signal Conditioning - Importance of grounding.
ACOE2551 Microprocessors Data Converters Analog to Digital Converters (ADC) –Convert an analog quantity (voltage, current) into a digital code Digital.
Digital to Analogue Converter
One of the most important feature of the microcontroller is a number of input/output pins used for connection with peripherals. In the case of PIC 167CX,
Data Acquisition ET 228 Chapter 15 Subjects Covered Analog to Digital Converter Characteristics Integrating ADCs Successive Approximation ADCs Flash ADCs.
Chapter 2 Introducing the PIC Mid-Range Family and the 16F84A The aims of this chapter are to introduce: The PIC mid-range family, in overview The overall.
Analog Capture- Port E. Digital to Analog and Analog to Digital Conversion D/A or DAC and A/D or ADC.
Analog/Digital Conversion
Chapter 11 Data Acquisition and Manipulation The aims of this chapter are to introduce: the main features of a data acquisition system; the characteristics.
Digital to Analog Converter (DAC)
ECE 2799 Electrical and Computer Engineering Design ANALOG to DIGITAL CONVERSION Prof. Bitar Last Update:
Analog to Digital Converter (ADC)
Chapter 3 Parallel Ports, Power Supply and the Clock Oscillator The aims of this chapter are to introduce: Why we need parallel input/output; How simple.
Digital-to-Analog Analog-to-Digital Week 10. Data Handling Systems  Both data about the physical world and control signals sent to interact with the.
Lecture Notes / PPT UNIT III
Analog-Digital Conversion. Analog outputs from sensors and analog front- ends (analog signal conditioning) have to be converted into digital signals.
CEng3361 CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT Spring 2011 Recitation 06.
Digital to analog converter [DAC]
MECH 373 Instrumentation and Measurements
Microprocessors Data Converters Analog to Digital Converters (ADC)
Digital-to-Analog Analog-to-Digital
Digital Control CSE 421.
Chapter 12: Analog-to-Digital Converter
SAR ADC Input Types TIPL 4003 TI Precision Labs – ADCs
Electronic Devices Ninth Edition Floyd Chapter 13.
Analog-Digital Conversion
EI205 Lecture 13 Dianguang Ma Fall 2008.
Digital-to-Analog Analog-to-Digital
Analog to Digital Converters Electronics Unit – Lecture 7
Digital Acquisition of Analog Signals – A Practical Guide
EE Embedded Systems Fall 2015
EE Embedded Systems Fall 2015
ECE 354 Computer Systems Lab II
Lesson 8: Analog Signal Conversion
CSCI1600: Embedded and Real Time Software
Introducing the PIC Mid-Range Family and the 16F84A
Conversation between Analogue and Digital System
ADC and DAC Data Converter
Digital Fundamentals Floyd Chapter 1 Tenth Edition
MSP432™ MCUs Training Part 6: Analog Peripherals
Chapter 7 Converters.
CSCI1600: Embedded and Real Time Software
ADC and DAC Data Converter
PIC Microcontroller ADC interfacing Prof. Ashvini Kulkarni
Presentation transcript:

EE 22442 - Embedded Systems Fall 2015 Chapter Eleven: Data acquisition and manipulation EE 22442 - Embedded Systems Fall 2015 Belal H. Sababha, Ph.D. Assistant Professor of Electrical & Computer Engineering Computer Engineering Department King Abdullah II Faculty of Engineering Princess Sumaya University for Technology Amman, 11941, Jordan Phone: +962-6-535-9949 ext. 222 Email: b.sababha@psut.edu.jo Web: http://www.psut.edu.jo/sites/bsababha

Introduction In the chapter we will learn about: The main features of a data acquisition system. The characteristics of an analog-to-digital converter. The characteristics of the 16F873A analog-to-digital converter. How the 16F873A analog-to-digital converter can be applied. Some simple data manipulation techniques. The use of comparators and the 16F873A comparator capability.

The main idea – analog and digital quantities, their acquisition and use

The data acquisition system

The analog-to-digital converter An ADC determines a digital output number that is equivalent of an input voltage. The design of such circuits is a non-trivial task. Many very different ADC circuits have been developed, targeted towards different applications. Some, like the dual ramp ADC, are slow but with very high accuracy, and useful for precision measurements such as digital voltmeters. Others, like the Flash converter (not to be confused with Flash memory technology), are fast but of lesser accuracy, and are used to convert high-speed signals such as video or radar. Others, like the successive approximation ADC, are of medium speed and medium accuracy, and useful for general-purpose industrial applications. This is the type most commonly found in embedded systems. Descriptions of how this type of ADC circuit works can be found in most electronics textbooks [see Ref. 1.1].

ADC Characteristics An ADC is characterized principally by the following features: Conversion characteristics Conversion speed  Digital interface

Conversion characteristics Input Range and Voltage reference Output Range and n-bit ADC Step Size Resolution

Conversion characteristics …cnt’d Input voltage infinitely variable. Fixed Number of Output values. Min and Max Values: Input (Analog) : e.g. 0 - 5V Output (Digital): e.g. 0x00 – 0xFF For an n-bit ADC, the maximum output value will be ((2^n) – 1 The input range (0-5V or -5V – 5V) usually relates in a direct way to the value of the voltage reference, which forms part of the ADC. The higher the number of output bits, the higher will be the number of output steps and the finer is the conversion. Step Size, Resolution: This is the amount by which the input has to change to go from one output value up to the next. In the diagram, the resolution is the width of one step in the conversion characteristic.

Conversion speed The time it takes an ADC to do its work is called the conversion time. A slow ADC, with a high conversion time, will only be able to convert low-frequency signals - Nyquist’s criterion must always be satisfied. The conversion time of an ADC defines which type of signal it can be used to convert. High-accuracy ADCs generally take longer to complete a conversion.

Digital interface The digital interface is made up of the control signals and the data output. A signal to the ADC that causes a conversion to start. When the conversion is complete, the ADC signals that completion with an output signal. A further signal causes the ADC to output its data. Depending on the type of interface required, the ADC has a parallel or serial data interface. An ADC always works in conjunction with a ‘voltage reference’. This is a device or circuit that maintains a very precise and stable voltage, and is based around a zener diode or a band-gap reference. The ADC effectively uses the voltage reference as the ruler with which it measures the incoming voltage. An ADC is only as good as its voltage reference. For accurate A-to-D conversion, a good ADC must be used with a good reference.

Signal conditioning – amplification and filtering The input voltage should traverse as much of its input range as possible, without exceeding it. Most signal sources, say a microphone or thermocouple, produce very small voltages. Therefore, in many cases amplification is needed to exploit the range to best effect. Voltage level shifting may also be required, for example if the signal source is bipolar while the ADC input is unipolar (voltage is positive only). If the signal being converted is periodic, then a fundamental requirement of conversion is that the conversion rate must be at least twice the highest signal frequency. (Nyquist sampling criterion). Anti-aliasing filtering may therefore be required to ensure that the Nyquist criterion is satisfied.

Optimal Voltage Range for A/D Conversion Needs a low reference voltage (VRL) and a high reference voltage (VRH) in performing A/D conversion. VRL is often set to ground level. VRH is often set to VDD. Most A/D converter are ratiometric, i.e., A 0 V (or VRL) analog input is converted to the digital code of 0. A VDD (or VRH) analog input is converted to the digital code of 2n – 1. A k-V input will be converted to the digital code of k  (2n – 1)  VDD. The A/D conversion result will be the most accurate if the value of analog signal covers the whole voltage range from VRL to VRH. The A/D conversion result k can be translated back to an analog voltage VK by the following equation: VK = VRL + (range  k)  (2n – 1)

Example: Example: Suppose that there is a 10-bit A/D converter with VRL = 1 V and VRH = 4V. Find the corresponding voltage values for the A/D conversion results of 25, 80, 240, 500, 720, 800, and 900. Solution: range = VRH – VRL = 4V – 1V = 3V V(25) = 1 V + (3  25)  (210 – 1) = 1.07 V V(80) = 1 V + (3  80)  (210 – 1) = 1.23 V V(240) = 1 V + (3  240)  (210 – 1) = 1.70 V V(500) = 1 V + (3  500)  (210 – 1) = 2.47 V V(720) = 1 V + (3  720)  (210 – 1) = 3.11 V V(800) = 1 V + (3  800)  (210 – 1) = 3.35 V V(900) = 1 V + (3  900)  (210 – 1) = 3.64 V

Scaling Circuit Some transducer has the an output voltage in the range of 0 ~ VZ, where VZ < VDD. VZ can be much smaller than VDD. When VZ is much smaller than VDD, the A/D conversion result cannot be accurate. The solution to this problem is to use an scaling circuit to amplify the transducer output to cover the whole range of 0 V to VDD. AV = VOUT  VIN = (R1 + R2)  R1 = 1 + R2/R1 Example 12.2 Choose appropriate values of R1 and R2 in Figure 12.6 to scale a voltage in the range of 0~200mV to 0~5V. Solution: AV = 1 + R2/R1 = 5V / 200mV = 25 R2/R1 = 24 Choose R1 = 10 K ohm and R2 = 240 K ohm to achieve the desired ratio.

Voltage Translation Circuit Some transducer has output voltage in the range from V1 to V2 (V2 > V1). The accuracy of the A/D conversion will be more accurate if this voltage can be scaled and shifted to 0 ~ VDD. The circuit shown below can shift and scale the voltage from V1 to V2 to the range of 0~VDD.

Example Example: Choose appropriate resistor values and the adjusting voltage so that the circuit shown in previous slide can shift the voltage from the range of –1.2 V ~ 3.0 V to the range of 0V ~ 5V. Solution: Applying the Equation on the lower and higher ends of the range: 𝑉 𝑂𝑈𝑇 = 𝑅 𝑓 𝑅 1 𝑉 𝐼𝑁 − 𝑅 𝑓 𝑅 2 𝑉 1 0 = -1.2  (Rf/R1) – (Rf/R2)  V1 5 = 3.0  (Rf/R1) – (Rf/R2)  V1 By choosing R0 = R1 = 10 KΩ, R2 = 50 K Ω, Rf = 12 K Ω, and V1 = -5V, one can translate and scale the voltage to the desired range.

The analog multiplexer In case of multiple inputs, an analog multiplexer is used. Having multiple ADCs, is costly and space-consuming. The multiplexer acts as a selector switch, choosing which input out of several is connected to the ADC at any one instant. The multiplexer is built around a set of semiconductor switches. The semiconductor switch is an imperfect device. When switched ‘on’, it has internal series resistance, which can range from tens to thousands of ohms. This can impact on the data acquisition process, as we shall see.

Sample and Hold Because most ADCs are unable to accurately convert a changing voltage, a ‘Sample and Hold’ (S&H) circuit is often found. This takes a sample of the voltage, like a snapshot, and holds it steady for the duration of the conversion. A circuit of a simple but practical S&H is shown in Figure 11.3. At its heart are just a semiconductor switch and a capacitor. When the switch is closed, the capacitor charges up to the input voltage VS. At this moment, ideally Vo = Vc = Vs

Acquisition time Problem with the shown circuit: There is a series resistance in the signal path. This is represented by the resistor in the circuit. When the switch closes, therefore, the capacitor voltage Vc does not take on the signal voltage immediately, but rises towards it exponentially. The voltage rise is given by: Vc = Vs {1- exp(t/RC)} Our interest from a data acquisition point of view is to ensure that the voltage has risen sufficiently close to its final value with the switch closed, before the switch is opened (the signal is then ‘held’) and a conversion allowed to start. The time that Vc (and hence Vo) takes to reach a value deemed to be acceptable is called the ‘acquisition time’.

Timing and microprocessor control

Data acquisition in the microcontroller environment Embedded systems need ADCs, so it is natural to expect to find an ADC integrated onto a microcontroller as one of its peripherals. ADCs and microcontrollers do not make happy bedfellows. To operate to a good level of accuracy, an ADC needs a quiet life (electronically speaking), with excellent and clean power supply and ground, and freedom from electromagnetic interference. A microcontroller, being a digital device, tends to corrupt its power supply and ground with a voltage spike on every switching edge. As a consequence, with all its intensive internal digital activity, it radiates a smog of local interference. Therefore, to integrate an ADC onto a microcontroller is at best a compromise and high accuracy is not usually possible. ADCs are widely available in the microcontroller environment, with many microcontrollers having an on-chip ADC. These are mostly 8- or 10-bit.

The PIC 16F87XA ADC module The input multiplexer, seen to the right of the diagram, has five channels for the 16F873A and ’F876A, and eight for the 16F874A and ’F877A.

Controlling the ADC The ADC is controlled by two SFRs, ADCON0 (Figure 11.7) and ADCON1 (Figure 11.8). The result of the conversion is placed in two further SFRs, ADRESH and ADRESL. Other SFRs also have an important impact on the ADC. These include TRISA and (for the 40-pin devices) TRISE. Any bits used for analog input must be set as inputs in these. Registers PIR1 and PIE1, which contain the ADC interrupt flag and interrupt enable bits respectively, are also used.

Control sequence Switching on Setting the conversion speed Configuring the input channels and selecting the voltage reference Starting a conversion and flagging its end Formatting the result

Switching on The ADC is switched on and off by the ADON bit of ADCON0. Switching it off when not needed offers a slight power-saving advantage.

Setting the conversion speed Operation of the 16F87XA ADC is governed by the ADC clock, which has a period TAD. A full 10-bit conversion takes around 12 TAD cycles, depending slightly on which clock source is chosen. The user can select the clock frequency from a number of options. There is an upper limit to the clock frequency. For the 16F87XA the minimum clock period for correct operation is 1.6 us (Electrical Characteristics), or a frequency of 625 kHz. This implies a fastest conversion time of 19.2 us. If conversion is too slow, charge leaks from the storage capacitance and the conversion becomes inaccurate. Best practice is to set the ADC clock frequency such that it has a period equal to or just more than 1.6 us. Selection of the ADC clock source is controlled by bits ADCS2 in ADCON1, and ADCS1 and ADCS0 in ADCON0. Various divisions of the main clock frequency are possible. There is also a dedicated RC oscillator which can be chosen. This has a typical period of 4 us, but may range from 2 to 6 us. If the system clock is fast (> 500 KHz), it is usually appropriate to use it to derive the clock source. If the system clock is slow, however, it is better to use the RC oscillator.

Configuring the input channels and selecting the voltage reference The way the input port bits are used is defined by the setting of bits PCFG3 to PCFG0 of ADCON1. Any port pin that is to be used as an analog input must be set as an input in its TRIS register. Selecting the input channel: CHS2 to CHS0 in ADCON0

Starting a conversion and flagging its end A conversion is initiated by setting bit GO/DONE in register ADCON0. When the conversion is complete the bit is returned to zero by the hardware. Completion of conversion is also signaled by an ADC interrupt flag ADIF. Completion of conversion may therefore be detected by testing either of the bits: GO/DONE or ADIF, or by enabling the interrupt and responding to it in an ISR.

Formatting the result The result of the conversion is placed in registers ADRESH and ADRESL. The result can be left justified, in which case the eight most significant bits appear in ADRESH. This is useful if only an 8-bit result is required, as the contents of ADRESL can then be ignored. In most other cases a right justified result will be the more useful. The formatting is controlled by bit ADFM in ADCON1.

Formatting the result … cnt’d

Repeated conversions When a conversion is complete, the converter waits for a period of 2 × TAD before it is available to start a new conversion cycle. Once this time is up, either the same input channel may be converted again, or a new one (which may already have been selected) may be converted. A best possible conversion time of 28.5 us was calculated in Section 11.3.4. If a period of 2 × TAD is added to this, i.e. 3.2 us for fastest possible, then the complete conversion cycle time becomes 31.7 us. If successive conversions are intended, this implies a maximum sampling rate of around 30 kHz. Note, however, that this figure takes no account of software overheads, which would tend to slow the conversion rate.

Trading off conversion speed and resolution The conversion times deduced above are not particularly fast by today’s standards and there will be occasions when a faster conversion time is needed. One option is to use an external ADC. Another is to consider whether the full 10-bit resolution is needed. If it is not, then the conversion time can be reduced.

Some simple data manipulation techniques Fixed- and floating-point arithmetic Binary to Binary Coded Decimal conversion

Live Demo Example and Live Demo void ATDinit(void); unsigned int ATDread(void); void main() { unsigned int k; TRISD = 0; // PORTD is output TRISB = 0; // PORTB is output ATDinit(); // initialize the ATD module while(1){ k = ATDread(); PORTD= k; PORTB= k>>8; } void ATDinit(void){ ADCON1 = 0xF0; // right justified, all channels are analog TRISA= 0xFF; // Port A is input ADCON0 = 0x59; //prescale 16, channel3, dont start conversion, power on ATD unsigned int ATDread(void){ ADCON0 = ADCON0 | 0x04; // set the GO bit, start the conversion while(!(ADCON0 & 0x04)); // wait until the GO/DONE bit is reset, the ATD reading is ready return ((ADRESH<<8)|(ADRESL)); Live Demo Example and Live Demo