Digital or Analog 1 1/8 1/16 1/32 1/64 1/128 or analog? - - PowerPoint PPT Presentation

digital or analog
SMART_READER_LITE
LIVE PREVIEW

Digital or Analog 1 1/8 1/16 1/32 1/64 1/128 or analog? - - PowerPoint PPT Presentation

Digital or Analog 1 1/8 1/16 1/32 1/64 1/128 or analog? binary coded funnels q digitally: q 0 255 q 7 q 6 q 5 q 4 q 3 q 2 q 1 q 0 Volume flow [l/min] Digi gita tal s sty tyle Old sc d school William


slide-1
SLIDE 1

Digital or Analog

William Sandqvist william@kth.se

  • digitally:

q 0 … 255 q7q6q5q4q3q2q1q0

  • or analog?

1 ½ ¼ 1/8 1/16 1/32 1/64 1/128

q

  • Old sc

d school

  • Digi

gita tal s sty tyle

binary coded funnels

Volume flow [l/min]

slide-2
SLIDE 2

Digital→Analog converter?

William Sandqvist william@kth.se

b7b6b5b4b3b2b1b0

1 ½ ¼ 1/8 1/16 1/32 1/64 1/128 ×100 kΩ

The current I is the sum of the currents from the ”binary coded” resistors.

  • Binary coded resistor values

      + + + + ⋅ =         + + + = = 781 ... 25000 50000 100000 5 1 ... 1 1 1

7 2 1 2 1

b b b b R R R U R U I

n

DA converter

slide-3
SLIDE 3

Digital→Analog converter?

William Sandqvist william@kth.se

b7b6b5b4b3b2b1b0

      + + + + + + + ⋅ = = 781 1563 3125 6250 12500 25000 50000 100000 5

7 6 5 4 3 2 1

b b b b b b b b R U I A 128 781 1 1563 1 3125 1 6250 1 12500 1 25000 1 50000 1 100000 1 5

max

µ =       + + + + + + + ⋅ = I

256 steps 0,5 µA/step

DA converter

slide-4
SLIDE 4

Problems with tolerances

William Sandqvist william@kth.se

Binary coded resistors for 8 bit. Biggest resistor exactly 100000 Ω and smallest resistor exactly 781 Ω (preferably 781,25 )? It is difficult to manufacture such various resistors with tight tolerances.

  • There is a better solution!

R2R- method.

slide-5
SLIDE 5

R-2R-ladder

William Sandqvist william@kth.se

b4b3b2b1b0

Just one resistance value needs to be manufactured, R, and then R+R =2R. One must be able to produce many "equal" resistors - the exact value is no longer important.

b4 b3 b2 b1 b0

slide-6
SLIDE 6

Two-terminal equivalent RI

William Sandqvist william@kth.se

The R2R-ladder is not that easy to understand … Repeated use of two-terminal equivalents and the superposition rule is what is required.

slide-7
SLIDE 7

R-2R b0=0 RI =?

William Sandqvist william@kth.se

b0 ? =

I

R Ω = + ⋅ = k 1 2 2 2 2

I

R

slide-8
SLIDE 8

R-2R b0=1 RI =?

William Sandqvist william@kth.se

b0 ? =

I

R Ω = + ⋅ = k 1 2 2 2 2

I

R b0 1 or 0, same internal resistance!

slide-9
SLIDE 9

R-2R b0 RI =?

William Sandqvist william@kth.se

b0 Ω = + = k 2 1 1

I

R The total resistance of one stage becomes 2 kΩ.

slide-10
SLIDE 10

R-2R b1=0 RI =?

William Sandqvist william@kth.se

b1 ? =

I

R Ω = + ⋅ = k 1 2 2 2 2

I

R =2 kΩ

slide-11
SLIDE 11

R-2R b1=1 RI =?

William Sandqvist william@kth.se

b1 ? =

I

R Ω = + ⋅ = k 1 2 2 2 2

I

R =2 kΩ b1 1 or 0, same internal resistance!

slide-12
SLIDE 12

R-2R b1 RI =?

William Sandqvist william@kth.se

b0 Ω = + = k 2 1 1

I

R b1 Regardless 1’s or 0’s is the total input resistance from the previous stages always 2 kΩ =2 kΩ

  • Conclusion:
slide-13
SLIDE 13

Two-terminal equivalent E0

William Sandqvist william@kth.se

slide-14
SLIDE 14

R-2R b4=1 E0=?

William Sandqvist william@kth.se

b4 b3 b2 b1 b0 =2 kΩ − + E

slide-15
SLIDE 15

R-2R b4=1 E0=?

William Sandqvist william@kth.se

2 2 2 2 E E E = + = b4 =2 kΩ − + E Volage divider:

slide-16
SLIDE 16

R-2R b3=1 E0=?

William Sandqvist william@kth.se

b4 b3 b2 b1 b0 =2 kΩ − + E

slide-17
SLIDE 17

R-2R b3=1 E0=?

William Sandqvist william@kth.se

b3 2 kΩ − + E

2 2 2 2 E E = + Ω = + ⋅ k 1 2 2 2 2

− + E

2 E − = + 4 E E

slide-18
SLIDE 18

R-2R conclusion E0 …

William Sandqvist william@kth.se

b4 b3 b2 b1 b0 ... 8 1 4 1 2 1

2 3 4

E b E b E b ⇒ = ⇒ = ⇒ = − + E

  • Reasonable guess – is it not?
slide-19
SLIDE 19

R-2R superposition

William Sandqvist william@kth.se

b4 b3 b2 b1 b0       + + + + ⋅ = 32 16 8 4 2

1 2 3 4

b b b b b E E − + E

  • According to the superposition principle, the contributions of

b4 b3 b2 … b0 can be added individually: b4b3b2b1b0 We have a DA-converter!

slide-20
SLIDE 20

R-2R simulation

William Sandqvist william@kth.se

Guess value of voltage OUT?

b3 b2 b1 b0 b3b2b1b0=1010

slide-21
SLIDE 21

William Sandqvist william@kth.se

slide-22
SLIDE 22

AD-converter?

William Sandqvist william@kth.se

slide-23
SLIDE 23

William Sandqvist william@kth.se

Successive approximations

AD conversion according to the method of successive approximations is comparable to weigh an unknown mass with binary weights on a balance. We try step by step to adding binary ”weight” if ”<” or remove ” weight” if ”>”. AD-converter contains a DA- converter, and an analog voltage comparator.

”Comparator”

Analog Guess! Digitally

slide-24
SLIDE 24

William Sandqvist william@kth.se

AD conversion takes

  • time. For each bit

higher resolution a comparison one step further is required.

Binary weights 8 4 2 1 …

8 8+4 8+2 8+2+1

slide-25
SLIDE 25

An AD-converter, 14 channels

William Sandqvist william@kth.se

Channel selection multiplexor.

AD converter occupies a large area on the chip - so it is economic to use the same converter to alternately measure up to 14 different sources, channels.

The PIC- processor has a 10-bits AD- converter

slide-26
SLIDE 26

Supply voltage as reference

William Sandqvist william@kth.se

It is easiest to use the supply voltage as ADC comparison value – reference. The drawback is that it is not particularly accurate.

slide-27
SLIDE 27

Internal or external reference?

William Sandqvist william@kth.se

Why external reference?

slide-28
SLIDE 28

Stabilized reference 4,096 V

MCP1541

William Sandqvist william@kth.se

If you buy a stabilized reference circuit you can perhaps choose the value 4,096 V ( 4096=212 ) which gives a 10-bit AD- converter exact 4 mV-steps, without the need to scale the measured result with multiplications and divisions.

slide-29
SLIDE 29

Ratiometric connection

William Sandqvist william@kth.se

If a sensor measurement value depends on it’s supply voltage, you can either have stabilized supply (expensive) –

  • r easier, use so-called ratiometric connection. If the sensor

supply voltage and AD converter reference voltage are the same, then changes in this voltage will be the same for both, and the AD converted measured value will remain intact! sensor

Same voltage!

slide-30
SLIDE 30

Adapt measuring range

William Sandqvist william@kth.se

An NTC thermistor has a high sensitivity but a non-linear temperature relationship. One linearize with a resistor – and then get the measuring range 0 …3,5 V. If the reference is 3,5 V instead of 5 V then one utilizes the entire ADC range for the measurement.

slide-31
SLIDE 31

William Sandqvist william@kth.se

10 bits 1024 steps 5 mV/step resolution ≈ 0,1%

b9b8b7b6b5b4b3b2b1b0

AD converter is 10 bits. What does a sensor cost that has 10-bit resolution? 100 $ ? More common is that you can afford an 8-bit

  • sensor. ( PIC processor itself costs 2 $ ).

Are 10-bit resolution required?

The picture shows a resistive position sensor that can take advantage of 10-bit resolution.

slide-32
SLIDE 32

William Sandqvist william@kth.se

8 bit 256 steps 20 mV/step resolution ≈1%

b9b8b7b6b5b4b3b2 b1b0

If one need only 8 bit resolution one can ignore the two least significant bits and handle the result as a byte.

8-bit program

slide-33
SLIDE 33

William Sandqvist william@kth.se

8-bit program

ADFM=0; char value; value = ADRESH; /* 8-bit measurement */ One can care only about the 8 most significant bits!

slide-34
SLIDE 34

William Sandqvist william@kth.se

8 effective bits, 256 effective steps with 5 mV/step resolution ≈1%

1 0 b7b6b5b4b3b2 b1b0

If one only need 8 bit resolution one can still use the 10-bit resolution to avoid the need to amplify the sensor signal, the two most significant bits becomes

  • constant. One can therefore ignore to read them.

Avoid amplifier

A fever thermometer only need a small temperature range 34°…43° (right?) 34° 43°

slide-35
SLIDE 35

William Sandqvist william@kth.se

8-bit program (10 bit)

ADFM=0; char value; value = ADRESL; /* 8-bit measurement */ One can care only about the 8 least significant bits that change!

1 1

slide-36
SLIDE 36

William Sandqvist william@kth.se

16-bit program

ADFM=1; unsigned long value; value = ADRESH * 256; value += ADRESL; /* 10-bit measurement */ When you really need 10 bits in a 16-bit variable.

10-bits 1024 steps 5 mV/step resolution ≈ 0,1% 1 1

slide-37
SLIDE 37

William Sandqvist william@kth.se

slide-38
SLIDE 38

William Sandqvist william@kth.se

What happens if the signal changes during conversion?

AD converter can not "undo" a previously determined bit!

The result is a value that has occurred during the conversion, but at an unspecified time!

slide-39
SLIDE 39

William Sandqvist william@kth.se

The problem The time for the sampling is indeterminate!

slide-40
SLIDE 40

William Sandqvist william@kth.se

Sample & Hold - circuit

The solution is that the analog signal is "frozen" during the conversion. At the AD conversion start a switch is taking a "sample" of the signal and stores it in a capacitor. The course PIC processor, the sampling capacitor has capacitance ≈10pF.

slide-41
SLIDE 41

William Sandqvist william@kth.se

Acquisition time tACQ

Every time one has chosen/changed channel the sampling capacitor CHOLD must have time to recharge to the analog voltage. This will take about 5 µs. A 5 µs delay can simply be programmed as:

nop2(); nop2(); nop(); /* 5 us 4 MHz clock */;

slide-42
SLIDE 42

William Sandqvist william@kth.se

AD-clock pulses

AD-converter can use a maximum clock frequency of 250 kHz. If the PIC processorn clock is 4 MHz this must firs be divided 16 times before it can be used as AD-clock. This frequency divider is provided. ADCON1=0b0.101.0000;

10 2

80 1010000 = kHz 500 s 4 = µ =

AD AD

f T

slide-43
SLIDE 43

William Sandqvist william@kth.se

Start AD and wait for done

Start AD- conversion: GO = 1; Wait for AD- conversion done: while(GO) ;

slide-44
SLIDE 44

William Sandqvist william@kth.se

AD-conversion takes time

s 2 5 4 ) 11 2 ( s 4 µ = ⋅ + µ =

AD

T

The conversion takes approximately 2 + 11 AD clock pulses. If one ignores the fact that the PIC processor must do something (?) With the AD- converted value (which also takes time), then the theoretically maximum sampling rate becomes:

kHz 2 , 19 s 52 1

max

= µ =

S

f

slide-45
SLIDE 45

William Sandqvist william@kth.se

AD-conversion takes time

If one converts alternating two channels (stereo?) then there will also be the setting time of sampling capacitor TACQ = 5 µs. kHz 8 , 8 s] [ 5 52 5 52 1

max

= µ + + + =

S

f The PIC processor can handle most industrial control processes - but it is of course totally inadequate as a "signal processor" for sound effects!

slide-46
SLIDE 46

William Sandqvist william@kth.se

Many setup possibilities

slide-47
SLIDE 47

William Sandqvist william@kth.se

AD-conversion – step by step

  • 1. Configure Port:
  • Disable pin output driver (See TRIS register)
  • Configure pin as analog (See ANSEL register).
  • 2. Configure the ADC module:
  • Select ADC conversion clock (ADCON1, ADCS<2:0>).
  • Configure voltage reference (ADCON0, VCFG).
  • Select ADC input channel (ADCON0, CHS<3:0>).
  • Select result format (ADCON0, ADFM).
  • Turn on ADC module (ADCON0, ADON)
  • 3. Start conversion set the GO/DONE bit. (ADCON0, GO)
  • 4. Wait for ADC conversion to complete, polling the

GO/DONE bit. (ADCON0, GO)

  • 5. Read ADC Result (ADRESH, ADRESL)
slide-48
SLIDE 48

William Sandqvist william@kth.se