Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 11 Data Acquisition and Manipulation The aims of this chapter are to introduce: the main features of a data acquisition system; the characteristics.

Similar presentations


Presentation on theme: "Chapter 11 Data Acquisition and Manipulation The aims of this chapter are to introduce: the main features of a data acquisition system; the characteristics."— Presentation transcript:

1 Chapter 11 Data Acquisition and Manipulation The aims of this chapter are to introduce: 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. Instructors using Designing Embedded Systems with PIC Microcontrollers are welcome to use or change these slides as they see fit. Feedback, to t.j.wilmshurst@derby.ac.uk, is welcomed.t.j.wilmshurst@derby.ac.uk The copyright to all diagrams is held by Microchip Technology, or T. Wilmshurst, unless otherwise stated Designing Embedded Systems with PIC Microcontrollers: Principles and Applications. 2 nd Edition. Tim Wilmshurst

2 A Data Acquisition System Transducer Generates signal Filter Removes unwanted signal components, usually foranti- aliasing purposes Amplify and Offset Amplifies signal and adds DC offset, to match ADC input range. Multiplexer Selects which input channel is connected to its output ADC Converts its AnalogInput to a Digital Output Sample & Hold Samples its input signal, and holds that voltage as a steady value at its output Voltage Reference Digital Output CPU Control Sample Input Select Start Conversion Output Result Conversion Complete When converting an analog signal to digital form, it is usually not enough just to find a suitable ADC (Analog to Digital Converter). Usually, more than one input is required and the signal needs processing before it can be converted. In most cases, therefore, it is necessary to build up a complete data acquisition system. The elements of such a system are shown below. This shows, in block diagram form, a system with multiple inputs, amplification, filtering, source selection, sample and hold, and finally the ADC itself. The different elements are outlined in the sections which follow.

3 The ADC accepts an input voltage that is infinitely variable, and converts this to one of a fixed number of output values. An example ADC conversion characteristic is shown, where the input voltage is represented on the horizontal axis, and digital output on the vertical. For an n-bit ADC, the maximum output value will be (2 n – 1). For example, for an 8-bit ADC, the maximum value will be (2 8 – 1), or (256 – 1), i.e. 255 decimal or 11111111 binary. The Analog to Digital Converter (ADC)...001 010 011 100 V max Digital Output Analogue Input 0 (2 - 1) n (2 - 2) n 0 Input Range

4 The Sample and Hold Circuit Because most ADCs work better converting a stationary voltage, a Sample and Hold circuit is commonly used. In this type of circuit a capacitor is charged from a source which inevitably has some resistance. Further resistance comes from internal resistance of the solid-state switch used in the S&H, and/or in the multiplexer. Therefore the capacitor takes finite time to charge, with a charging characteristic as shown. A Simple Form of Sample and Hold Circuit Charging Characteristic of Sample & Hold

5 Typical Timing Requirement of one A to D Conversion Configure & enable ADC SelectMultiplexer input Delay for signal acquisition Start Conversion Delay for conversion to complete Read Data “Sample” Input Signal “Hold” Input Signal These stages merge ifmultiplexerforms part of S&H

6 Integrating an ADC onto the Microcontroller It is now possible to integrate much of a data acquisition system onto a single chip, and/or into a microcontroller. But note - ADCs don’t easily integrate onto microcontrollers, mainly because there is the risk of massive digital interference, both radiated, and through shared earth and supply lines. A partial solution is to separate the ADC earth and supply from that of the microcontroller, and to minimise interference during conversion - by synchronising conversion to internal clock transitions, and minimising all other switching at this time. Ultimately, you will only find ADCs of limited resolution (generally 8- or 10-bit) integrated onto a microcontroller.

7 The 16F873A ADC The 16F873A has a versatile 10-bit ADC module, shown below. This provides a subset of the overall data acquisition system. The particular ADC design used incorporates the function of Sample and Hold. The input multiplexer, seen to the right, has 5 channels for the 16F873A. The inputs are shared with five of the six Port A bits. Port A bit four is not used, as it already shares with the Timer 0 input. Port bits can be allocated in a flexible way to analog or digital input. An external voltage reference can be used for applications requiring reasonable accuracy. Provision of the negative connection means that the reference does not have to be referred to system ground, or it can at least be connected to a “clean” ground. For lower cost, lower accuracy conversions, the power supply voltage can be used as reference. The input range is equal to whatever voltage reference is chosen.

8 The ADCON0 Register The ADC is controlled by two SFRs, ADCON0 and ADCON1. The result of the conversion is placed in two further SFRs, ADRESH and ADRESL. These four registers can all be seen in the SFR Memory Map. Any bits used for analog input must also be set as inputs in TRISA.

9 The ADCON1 Register

10 The ADC Clock Operation of the ADC is governed by the ADC clock, which has a period T AD. A full 10-bit conversion takes around 12 T AD cycles, depending slightly on which clock source is chosen. The user can select the clock frequency from a number of options. Although one generally wants a conversion to take place as quickly as possible, there is an upper limit to the clock frequency, specified as a period of 1.6  s. At the other extreme, if conversion is too slow, charge leaks from the storage capacitance, and the conversion becomes inaccurate. Best practice is therefore to set the ADC clock frequency such that it has a period equal to or just more than 1.6  s. Selection of the ADC clock source is controlled by bits ADCS2 in ADCON1, and ADCS1 and ADCS0 in ADCON0. The RC oscillator has a typical period of 4  s, but may range from 2 to 6  s. If the system clock is fast, 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.

11 Formatting the Result The 10-bit conversion result is stored in registers ADRESH and ADRESL. What are the advantages of the two possible result formats?

12 Analogue Input Model The acquisition time, i.e. the time for the hold capacitor to charge to acceptable final value, called tac, is given by: t ac = Amplifier Settling Time + Hold Capacitor Charging Time + Temperature Coefficient The Amplifier settling time is specified as 2  s. The Temperature Coefficient applies only when temperatures is above 25 o C, and is specified as: Temperature Coefficient = (Temperature - 25 o C)(0.05  s/ o C) It can be seen that this creates a time delay of only 0.5  s for every 10 o C above 25 o, so its impact in most cases is slight.

13 Example If a signal source has a resistance of 1k, the microcontroller is supplied from 5V, and 10-bit accuracy is required, what will the acquisition time be? If the main clock oscillator is 4MHz, propose a value for T AD, and hence for the relevant ADCONX bits. Estimate the overall time to convert one value.

14 bsfstatus,rp0 movlwB'00001011‘ ;set port A bits according to their function, movwftrisa ;ADC channels set as inputs movlwB'10000100' ;select port A bits 0,1,3 for analog input movwfadcon1 ;right justify result... bcfstatus,rp0 movlwB'01000001‘ ;set up ADC: clock Fosc/8, switch ADC on but not ;converting, movwfadcon0 ;input channel selection currently irrelevant... ;read and store ldrs main_loop movlw B'01000001' ;select channel 0 as input (left front ldr) movwfadcon0 call delay20u;acquisition time bsfadcon0,go;start conversion btfscadcon0,go_done ;wait for conversion to complete goto$-1 movfadresh,0;read and store ADC output data, high byte movwfldr_left_hi bsfstatus,rp0 movfadresl,0 ;read and store ADC output data, low byte bcfstatus,rp0 movwfldr_left_lo … Some Sample Code Configure & enable ADC Select MUX input Delay for signal acquisition Start Conversion Delay for conversion to complete Read Data

15 End of Lecture Note One of the simplest interfaces between the analog and digital world is the comparator. This acts like a 1-bit ADC. It is usually used to compare an input voltage with a reference. If the input is higher than the reference, the output goes high, if it is lower, the output goes low, as seen below. The 16F87XA has two comparators, which share inputs with the ADC inputs. Comparator 1 has inputs on AN0 and AN3, and comparator 2 on AN1 and AN2. They are controlled by the CMCON register. The Comparator Module


Download ppt "Chapter 11 Data Acquisition and Manipulation The aims of this chapter are to introduce: the main features of a data acquisition system; the characteristics."

Similar presentations


Ads by Google