There are two main methods, which are used to convert a digital value into an analog:
PWM is usually (but not always) done by a microcontroller. The conversion is done by varying the
on- and off-times of a square wave. Then this signal is fed into a low-pass-filter which removes all high frequencies.
The remaining signal is the analog value. (With a little ripple voltage of course, but it can be quite low.)
Lets assume that our rectangle signal has an amplitude of 5V and let us also assume that the on time is
30% of the period length (period length T=1/f) and the frequency is 1kHz:
^ U (voltage) | | 5V-|__. .__. .__. | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 0V-+------------------------------> t (time) | | | | 0 0.3ms 1ms 2msThe output signal after the lowpass the signal is 0.3ms*Khz*5V=1.5V because the lowpass genrates an average value.
^ U (voltage)
|
|
5V-|______. .______. .______.
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
0V-+------------------------------> t (time)
| | | |
0 | 1ms 2ms
0.7ms
A typical lowpass filter would look like this:
R1 R2
o----\/\/\/\--*--\/\/\/\--*--------o
| |
Input C1 ----- C2 ----- Output
----- -----
| |
o-------------*-----------*--------o
The components values depend on your PWM frequency.
Another common used technic is the R2R ladder. The conversion is done by a simple resistor network.
R(1) R(2) R(3)
.----------*---\/\/\/\---*---\/\/\/\---*---\/\/\/\---*-------------.
| | | | | |
| / / / / /
o \ \ \ \ \
Uref / 2R(1) / 2R(2) / 2R(3) / 2R(4) / 2R(5)
o \ \ \ \ \
| / / / / /
| | | | | |
--- | | | | |
\ \ \ \ ---
o o o o o o o o
| | | | | | | | Rf
| | | | | | | | .---\/\/\/\---.
.-------*-------------*-------------*-------------' | | |
| | | | | | |\ |
--- '-------------*-------------*-------------*----*----|-\ |
| \-----*---o Uout
| / o
.----|+/ |
| |/ ---
|
---
The current which flows through 2R(1) is determined by Uref. R(1) and 2R(2) is a voltage
divider which has a resistive load connected to it, that has the value of 2R (the rest of the
resistors). Therefore it halves the voltage Uref. The half voltage produces the half current
in 2R(2). The next resistors R(2) and 2R(3) are also a voltage divider, which has also a load
of 2R connected to it so the voltage on 2R(3) is Uref/4 and the current through 2R(3) is one
fourth if the current of 2R(1). The next two resistors ......
74HC373
.--------.
D0--| 3 2|-------|\/\/\/\|-----*-------o Out
D0| |Q0 20k |
| | \
| | / 10k
| | \
| | /
| | |
D1--| 4 5|-------|\/\/\/\|-----*
D1| |Q1 20k |
| | \
| | / 10k
| | \
| | /
| | |
D2--| 7 6|-------|\/\/\/\|-----*
D2| |Q2 20k |
| | \
| | / 10k
| | \
| | /
| | |
D3--| 8 9|-------|\/\/\/\|-----*
D3| |Q3 20k |
| | \
| | / 10k
| | \
| | /
| | |
D4--|13 12|-------|\/\/\/\|-----*
D4| |Q4 20k |
| | \
| | / 10k
| | \
| | /
| | |
D5--|14 15|-------|\/\/\/\|-----*
D5| |Q5 20k |
| | \
| | / 10k
| | \
| | /
| | |
D6--|17 16|-------|\/\/\/\|-----*
D6| |Q6 20k |
| | \
| | / 10k
| | \
| | /
D7| |Q7 |
D7--|18 19|-------|\/\/\/\|-----*
GND--|10 1|--GND 20k |
+5V--|20 11|--CLK \
'--------' / 20k
\
/
|
---
|
This D/A converter works with a reversed R2R ladder. All resistors should be 1%.
The 74373 is a octal D-latch which stores the value to convert. First, the data byte (D0-D7) should be assigned.
Afterwards, with the high transistion of CLK the value is stored into the latches and converted into an analog value
by the resistors. You should use a 74HC or 74HCT (if you need TTL compatible inputs) series , because
the CMOS logic has nearly 5V on high outputs and 0V on low outputs. Most TTL (or LSTTL) have only about 3.8V on high
and 0.2V on low. Click here to read more about logic levels. Youīll probably need a impendance converter (e.g. OP) at the output, because this circruit has a big ouput impendance. |
If you wanted to build a 1Bit A/D converter, the simplest thing would be to use a comparator. Now, you can also use comparators if you want a better resolution.
^ Uref
|
|
|
\
/ 1.5R
\
/
|
| |\ .---------.
*---|-\ | |
| | \----| E |
Uin | | / | |
o----*-------|+/ | N |
o-. | | |/ | |
| | \ | C |
--- | / R | |
| \ | O |
| / | |
| | | D |
| | |\ | |
| *---|-\ | I |
| | | \----| |
| | | / | N |
*-------|+/ | |
| | |/ | G |
| \ | |
| / R | |---------o
| \ | | Digital output
| / | L |---------o
| | | |
| | |\ | O |
| *---|-\ | |
| | | \----| G |
| | | / | |
*-------|+/ | I |
| | |/ | |
| \ | C |
| / R | |
| \ | |
| / | |
| | | |
| | |\ | |
| *---|-\ | |
| | | \----| |
| | | / | |
'-------|+/ '---------'
| |/
\
/ 0.5R
\
/
|
|
---
|
The circriut on the left side works in a very simple way. It is a 2Bit A/D converter. The reference voltage Uref is divided down into 4 voltages. The comparators compare the input voltage with them. Once the input voltage is higher than the voltage on the comparatorīs (-) input, its output goes high. If the input voltage rises, the bottom comparator is the first which goes high. Than the second from bottom and so on. The Logic encodes this into a binary 2Bit word. |
This way sounds a bit silly, but is quite widespread. It uses a comparator and a D/A converter.
.-------.
---- | |
\ | |
Input\ | DAC | |\
word / | |-----------|-\
/ | | | \--------o Uout
---- | | | /
'-------' .------|+/
| |/
|
Uin o---------'
o
|
---
It works the following way: first, the DAC outputs the lowest voltage it can.
If the state of the output is high, the input voltage is higher than the voltage outputted by the DAC.
Now the DAC voltage is increased, till the output goes low. Now you know that the input voltage is a little
bit lower than the actual input word (which is binary) and a little bit higher than the last input word.
Now, you know how big you voltage is. Thatīs all.
U ^ | .___________<--- Input voltage |_______. | /| | /| | | / | | / | |___| / | | / | /| / |<--- Ramp voltage | / | / | / | |/ |/ |/ | +--------------------------> t
U ^ | .___________<--- Input voltage |_____. | / | /|\ | /<--- Ramp voltage | / |_\_|/ | / | / |/ +--------------------------> t
(Transistor is a NPN Type)
R1
o----------\/\/\/\----*-----*-------o
Uref | | Uramp
o--. R2 |/C ----- o
| o--\/\/\/\---| ----- C |
| Discharge |\E | |
| o | | |
| | | | |
--- --- --- --- ---
If you use too big capacitators, the transistor may be damaged.
Also use a capacitator with a low temperature coefficient and leakage current.
^ +Ub ^ +Ub | | .---. | \ / D1 \ V / R2 --- \ | / .---. | \ / D2 | V | --- PNP| | T1 |/E .-----------o *-----| | Uramp | |\C | o | | | | | v I | | | | | | | *---*---.NPN --- \ C | C\| T2 R1/ ----- |----\/\/\/\---o \ ----- E/| R3 Discharge / | | o | | | | --- --- --- ---Again, if you use a too big capacitator, the transistor T2 may be damaged. Big capacitators cause also a long discharge time. Also use a capacitator with a low temperature coefficient and leakage current. I wouldnīt let go Uramp up to +Ub, because then the UCE of T1 gets very low and may cause a nonlinearity.
The best A/D converter doensīt help you much without a Sample and hold circruit, because
the input voltage isnīt allowed to change during a conversion cycle. Otherwise you get a wrong
result.
A sample and hold is circruit, which can "freeze" a voltage.
Look at this schematic. It is the a basic sample and hold circruit:
.---------.
| |
.---------. | |\ |
| | '---|-\ |
| |\ | .--------. | \--*------o
'---|-\ | | / | | / Uout
| \--*--|--/ L---|------*------|+/ o
| / | | | |/ |
o------|+/ '--------' ----- |
Uin |/ | S1 ----- |
o ____ o----' | C |
| Hold/Sample | |
| o | |
| | | |
--- --- --- ---
The two OPs are impendance converters. The input voltage Uin appears at the output
of the first OP. If the switch S1 is closed, the capacitator is charged to the
voltage Uin. If the input voltage changes, after a short time the capacitator has
the same voltage. The second OP buffers the capacitatorīs voltage to the output.
Once the switch opens, the capacitator is disconnected from the output of the first OP, but
it still holds the input voltage from the moment when the switch opened, so the
output voltage doesnīt change any more C should be a
cap with a low leakage current.
Copyright (C) 2003 by Wiesner Thomas
Last change: June 9th 2003