Analog - Atomic Rhubarb Analog.pdf · When analog sensors are involved the interfacing becomes more...

Preview:

Citation preview

An

alo

g

Real Time Embedded Systems

www.atomicrhubarb.com/embeddedLecture 1 – January 17, 2012

Topic

Section Topic

• Where in the books– Catsoulis chapter/page– Simon chapter/page– Zilog UM197 (ZNEO Z16F Series Flash Microcontroller Contest Kit User Manual)

– Zilog UM171 (ZiLOG Developer Studio II—ZNEO User Manual)

– Zilog PS220 (ZNEO Z16F Series Product Specification)

– Zilog UM188 (ZNEO CPU Core User Manual)

– Assorted datasheets

Signals

Analog

DigitalReferencevoltage

Digital-Analog Connecting a sensor to digital circuitry is

simple if the sensor provides digital output.

We have seen that switches, and logic encoders are easily interfaced with gate circuits due to the nature of their signals.

When analog sensors are involved the interfacing becomes more complex.

We need a way to electronically translate analog signals into digital quantities, and visa-versa.

Analog Signals

How do we input and output analog signals?

Signal Converters

Analog to Digital signal converter on the inputs

Digital to Analog signal converter on the outputs

Digital -> Analog

A Digital to Analog converter is an electronic circuit which accepts a digital number at its input and produces a corresponding analog signal (usually a voltage) at the output

Digital -> Analog

DAC Several Types

PWM output + low pass filter Binary Weighted DAC R2R Ladder Kelvin Divider

DAC

Kelvin Divider

DAC

R-2R ladder network is a simple Digital-Analog converter.

Only two resistance values are used anywhere in the entire circuit.

Modern DACs use the ‘R-2R ladder’

But ...

We don't have a Digital to Analog converter on the ZNEO (or any of the Zilog microcontrollers).

Fortunately we know how to add that capability if we need

it Add a DAC chip I2C, SPI, 1-wire, … Or parallel digital input 1000's to choose from (really!)

Like this one!

Analog -> Digital

An Analog to Digital converter is an electronic circuit which accepts an analog input signal (usually a voltage) and produces a corresponding digital number at the output

ADC

Analog-to-Digital Conversion The workhorse of the test and

measurement world. Providing a means for a micro-

controller to measure analog signals.

ADC Several Types (ways to convert analog

to digital) Digital Ramp Successive Approximation Subranging Tracking Slope Integration Flash Sigma Delta

Flash ADC

Start with a voltage comparator Determines of a signal is greater than a

reference signal (a 1-bit analog to digital converter).

Vref

Vin

VoutVref

Vin

Vout

+

Flash ADC

n-bit resolutionrequires2n-1 comparators

8-bit means255 comparators

10-bit means1023 comparators

Digital Ramp A binary counter counts up

from 0. The output of the counter to feed into a digital to analog converter.

The generated analog signal is compared to the input signal.

When the generated signal is greater than the input signal the counter stops and the binary value is the digital value for this signal

Sigma Delta ADC

High resolution and Low cost The Z16 uses Sigma-Delta ADC One of the more advanced ADC

technologies

Why so many different ways?

Resolution vs Speed

ADC Signal Sampling

Sampling can cause errors (aliasing)

Nyquist rate = 2x highest frequency of interest

Practically: always sample at least 5x, or higher

What kinds of things can you measure with an ADC?

Sensors

Sensors with analog output Temperature Pressure Light intensity Position Velocity, RPM ...

Analog Input

Don't like the ADC on your microcontroller?

Add an external one. Many to choose from Parallel data out I2C, SPI, 1-wire, ....

MAX19588

100 Million samples per second 16 bit

MAX1072 1.8 Million samples per second 10-bit data 1 micro amp in shutdown

Why so many different ADC?

Why

Speed (samples/second) Low Power for battery/portable

applications Resolution (8,10,12,14,18 bits) Number of channels Interface Range of analog input (3v, 12v, +/- 12v,

...)

Z16 ADC

One ADC 12 Switched inputs 10-bit resolution Internal voltage reference generator Ability to supply external reference

voltage.

Z16 ADC

The Pins

ANA0..11 AVDD, AVSS VREF

ADC

10 bit conversion (needs 2 bytes for result)

12 analog input sources are multiplexed with general-purpose I/O ports

Interrupt upon conversion complete Internal voltage reference generator

ADC

• Each ADC measurement consists of three phases:

1. Input sampling (programmable, minimum of 1.0 μs).

2. Sample-and-hold amplifier settling (programmable, minimum of 0.5 μs).

3. Conversion is 12 ADCLK cycles.

Z16 ADC Registers

ADC0CTL – Control Register ADC0DH, ADC0DL – ADC data ADCSST – Sample Settling Time ADCST – Sample Time ADCCP – Clock Prescaler ADC0MAX – Max Chanel Register ADCTCAP_H,L – Timer0 Capture

Register

Z16 ADC Registers

Don't forget GPIO alternate functionand interrupt control registers

ADC0CTL

ADC0D_H,L

Interrupt?

Why do I want to generate an interrupt on conversion?

Single ShotADC

Single ADC

1. Enable the alternate function of the GPIO pins that you want to use for analog inputs (PORT B & H)2. Write to ADC0CTL to configure which input source (one

source can be active at a time)3. Set ADCCTL START0 to enable conversion.4. Watch STAT0 bit until conversion is complete. 5. Read value from ADC0D_H, ADC0D_L

Example Example

Analog_Photodiode

Photodiode

Like a diode (allows current to flow in one direction and not the reverse)

BUT, light changes that and allows current to flow in the reverse direction also.

Dark = little current flow More light = more current flow

5v_| Photo| diode LED 100+---|<----+--->|--------/\/\/\----+

| || v GND+--> ANA0

LED for visualindicator

Photodiodeis blocked, LED not on

Photodiodeis blocked, LED not on

Photodiodeis illuminated, LED is on

Photodiodeis illuminated, LED is on

Why would we want an External Reference Voltage?

External Reference

This circuit gives us access to supply our own reference voltage (on J7) or

Use a MAX6160 voltage reference (and potentiometer) to provide a variable VREF

VREF

Internal VREF=3.3v 3FF 10 bits 3.3v 0FF 8 bits 0.82v 00F 4 bits 0.05v 001 1 bit

0.003v

With external VREF=1v 3FF 10 bits 1.0v 0FF 8 bits 0.25v 00F 4 bits 0.0156v 001 1 bit 0.001v

Recommended