34
INTERFACING TO THE ANALOG WORLD Prepared by: Islam Samir

Interfacing to the analog world

Embed Size (px)

Citation preview

Page 1: Interfacing to the analog world

INTERFACING TO THE ANALOG WORLD

Prepared by:

Islam Samir

Page 2: Interfacing to the analog world

AGENDA

The importance of signals. Why do we process signals? Continuous VS Discrete. Analog signals VS digital signals. How to convert an analog signal into digital? S/H, Quantization, Encoding.

Page 3: Interfacing to the analog world

WHAT ARE SIGNALS?

Signals are mathematical functions that represents an electrical quantity (voltage, current ..etc).

These quantity carries information in one of its parameters [amplitude, frequency ..etc].

Page 4: Interfacing to the analog world

WHY DO WE PROCESS SIGNALS?

We’ve to process these signals in an appropriate way to:

1. Extract the information that they carry.

2. To get them in a better form (filtering).

Page 5: Interfacing to the analog world

CONTINUOUS VS DISCRETE Continuous Signals:- Signals that are defined for

all time instants.

Discrete signals:- Signals that are defined only

for certain time instants: T, 2T, 3T, ….etc.

- (T) is the sampling time of the original continuous signal.

Page 6: Interfacing to the analog world

ANALOG SIGNALS For analog signals, the voltage - or current - can take

any value and the system is supposed to respond to this value.

Information is represented by changing the signal’s voltage, current, frequency, or total charge.

The amplitude of an analog signal can take any value.

Page 7: Interfacing to the analog world

THE RULE OF TRANSDUCERS (SENSORS) Information is converted from some other physical

form (sound, light, temperature ..etc) to an electrical signal by a transducer.

The processing system (analog or digital) can then take the right decision based on the electrical quantity that it monitors, which represents the corresponding physical quantity.

Page 8: Interfacing to the analog world

DIGITAL SIGNALS Digital signals are discretized in time, and quantized

in amplitude. The time interval between each number and the next

is Ts.

Page 9: Interfacing to the analog world

Signal Conditionin

gSensor ADC

Analog Continuous-time signal

Digital signal

Digital signals are the only type of signals that can be processed by digital systems.

We use the (signal conditioning circuitry + ADC) to convert an analog continous-time signal into a digital signal.

Page 10: Interfacing to the analog world

DIGITAL SIGNALS A digital computer can only deal with binary values,

these values change in a limited range due to the limited word length.

Ex. For an 8-bit register

It can hold one of 256 ( ) values only.

So, digital signals can take one of certain values only (Quantized).

82

Page 11: Interfacing to the analog world

DIGITAL SIGNALS- The hardware that converts an analog signal to

digital needs time to quantize this signal and encode it. Also we need time for the required processing.

- We use a (Sample & Hold) circuit that takes samples of the original continuous signal every time interval (Ts), where:

Ts> hardware delay + processing delay

So, digital signals are discretized in time.

Digital signals are discretized in both time and amplitude.

Page 12: Interfacing to the analog world

ANALOG VS DIGITAL

Analog signals Digital signals

The signal’s amplitude can take any value.

The signal’s amplitude is limited to a certain range of values. (Quantized)

Can be discrete or continuous in time.

Always discrete in time.

Page 13: Interfacing to the analog world

HOW TO CONVERT ANALOG SIGNALS TO DIGITAL?

Page 14: Interfacing to the analog world

HOW TO CONVERT ANALOG SIGNALS TO DIGITAL?

LPF: Low pass filter

S/H: Sample and hold circuit.

X(t): Analog signal to be converted.

X(kTs): Sampled signal.

Xq(kTs): Quantized signal.

Page 15: Interfacing to the analog world

HOW TO CONVERT ANALOG SIGNALS TO DIGITAL?

1. LPF: The signal is filtered and band limited to 0.5 Fs, in order to avoid aliasing. (Review sampling theorem)

Fs≥2Fm [Nyquist rate]

Fm: the max. signal frequency.

- If the sampled signal is not band limited, aliasing will occur. This will result:

1. The digital signal produced is not representing the original analog signal.

2. If we tried to reproduce the analog signal it’ll be distorted.

Page 16: Interfacing to the analog world

HOW TO CONVERT ANALOG SIGNALS TO DIGITAL?

1. (S/H): - To convert the continuous signal to a discrete

signal.- This is done for two reasons:

a) A time is required for the ADC to quantize and encode the coming sample.

b) A time is required to do the required processing on this sample.

Page 17: Interfacing to the analog world

HOW TO CONVERT ANALOG SIGNALS TO DIGITAL?

3. Quantizer:- Due to the limited word length of any digital

computer , the sample’s value must be within a certain range according to the number of bits used to represent the sample.

Ex. If we used an 8 – bit ADC

The sample can take one of 256 values.

The quantizer has to approximate every sample to the nearest level.

Page 18: Interfacing to the analog world

HOW TO CONVERT ANALOG SIGNALS TO DIGITAL?

4. Encoder:- After quantization, the quantized sample must be

encoded to the corresponding binary value by an encoder.

- Usually, the quantizer and the encoder are implemented by the same hardware.

- The use of quantization introduces an error between the input signal and the signal at the quantizer output.

quantization error or (e)

, where: e = X(t) – Xq(kTs)

Page 19: Interfacing to the analog world

Example.

Discrete & analog signalDiscrete & quantized signal(Digital signal)

Page 20: Interfacing to the analog world

ANALOG-TO-DIGITAL CONVERTER The ADC converts an analog sample into the

corresponding digital value according to:

1. The (Full-scale) voltage. (called also Vref).

2. The number of bits.

- The conversion can be: unipolar (0 +Vfs)

or bipolar (-Vfs (+Vfs-1LSB)).

or (Vref-) (Vref +).

Page 21: Interfacing to the analog world

ANALOG-TO-DIGITAL CONVERTER In an A/D converter, Q = 1 LSB.

Q determines the resolution of the system, that is, the lowest change in voltage that will produce a code change.

Dynamic range:

- It’s the minimum number of voltage levels needed to represent a certain voltage signal, according to the range of this signal and the required resolution.

Page 22: Interfacing to the analog world

Ex. 4-bit ADC , Vref=10v (Unipolar)

note that the analog value represented by the all-ones code is not full-scale (FS), but (FS – 1 LSB).

Page 23: Interfacing to the analog world

Transfer function of a 3-bit ADC (Unipolar)

- There is a range of analog input voltage over which the ADC will produce a given output code; this range is the quantization uncertainty and is equal to 1 LSB.

Page 24: Interfacing to the analog world

Ex. 4-bit ADC (Bipolar)

- In order to maintain perfect symmetry about midscale, the all-zeros code (0000) representing negative full-scale (–FS) is not normally used in computation.

Page 25: Interfacing to the analog world

Transfer function of a 3-bit ADC (Bipolar)

- Most ADC ICs are unipolar. To monitor both positive and negative voltage values, use a level shifter circuit before the ADC.

Page 26: Interfacing to the analog world

SIGNAL CONDITIONING Typical sensors yield low-amplitude analog signals that

need to be amplified and then digitized by means of an (A/D) converter.

To adapt the analog signal to the range of expected amplitude at the input of the A/D converter, a signal conditioner is used.

Ex. If the analog signal in the range: [-20mv 20mv]

and the ADC is [0v 5v]- The number of values that represent this analog range is

small, so that the quantization noise will be large.- If we amplified the signal by (*100) , it’ll be in the range: [-

2v 2v]

and the quantization noise is reduced.𝐺=𝑀𝑎𝑥 .𝐴𝐷𝐶𝑉𝑜𝑢𝑡

𝑀𝑎𝑥 .𝑚𝑒𝑎𝑠𝑢𝑟𝑒𝑑𝑠𝑖𝑔𝑛𝑎𝑙 𝑎𝑚𝑝𝑙𝑖𝑡𝑢𝑑𝑒

Page 27: Interfacing to the analog world

SIGNAL CONDITIONING- If the analog signal can be +ve or –ve, use a shift up circuit

(adder) to make it in the range [0v Vref v].

Page 28: Interfacing to the analog world

Ex.

- We wish to measure a temperature between (–40°C, 60°C) with a

resolution of (0.5°C). How many bits does the A/D converter need?

If we use a sensor with a sensitivity of (1 mV/°C) and an A/D

converter with an input range between (0 V, 5 V), how much gain is

necessary?

1- DR= (60-(-40))/0.5 = 200

We need 200 level at least to represent the output (8-bits).

2- G = 5v/100mv = 50

Or, G= (5v - 0v)/ (60mv – (-40mv)) = 50

We need to shift up the analog voltage 40mv before converting it

by the ADC.

Page 29: Interfacing to the analog world

THE PIC’S ADC- It’s a 10-bit, SAR ADC, with eight multiplexed inputs.

- It can sample and process signals as fast as 25 kHz or so accurately.

- The analog input charges a sample and hold capacitor. The output of the sample and hold capacitor is the input into the converter.

- The A/D module has high and low voltage reference input that is software selectable to some combination of VDD, VSS, RA2, or RA3.

Page 30: Interfacing to the analog world

THE PIC’S ADC

Page 31: Interfacing to the analog world

THE PIC’S ADC Acquisition time: After the analog input channel is selected

(changed), you have to wait for this time before the conversion can be started.

Conversion time: The A/D conversion requires a minimum 12TAD per 10-bit conversion. (Tad min.=16µs)

How can we get (Tad)? The four possible options for TAD are: 2Tosc, 8Tosc,

32Tosc, Internal A/D module RC oscillator. If you use Tosc to get Tad, ensure that Tad is greater than

16µs.

Page 32: Interfacing to the analog world

Registers and bits: A/D Result High Register (ADRESH) A/D Result Low Register (ADRESL) The ADRESH:ADRESL registers contain the 10-bit result of

the A/D conversion. A/D Control Register0 (ADCON0): controls the operation of

the A/D module. A/D Control Register1 (ADCON1): configures the functions

of the port pins. The port pins can be configured as analog inputs (RA3 can also be the voltage reference), or as digital I/O.

(GO/DONE~) bit (ADCON0<2>): cleared when the conversion is done.

ADIF: set when the conversion is done.

Page 33: Interfacing to the analog world

These steps should be followed for doing an A/D Conversion:

1. Configure the A/D module:

• Configure analog pins/voltage reference and digital I/O (ADCON1)

• Select A/D input channel (ADCON0)

• Select A/D conversion clock (ADCON0)

• Turn on A/D module (ADCON0)

Select the format of the result to be right-justified or left justified.

If you’ll take only

the most significant

8-bits, choose

left justified.

Page 34: Interfacing to the analog world

2. Configure A/D interrupt (if desired):

• Clear ADIF bit

• Set ADIE bit

• Set PEIE bit

• Set GIE bit

3. Wait the required acquisition time. (at least 20µs)

4. Start conversion:

• Set GO/DONE bit (ADCON0)

5. Wait for A/D conversion to complete, by either:

• Polling for the GO/DONE bit to be cleared

OR

• Waiting for the A/D interrupt

6. Read A/D result register pair

(ADRESH: ADRESL), clear bit ADIF if required.

7. for the next conversion, go to step 1 or step 2, as required.