piclist 2001\01\01\003225a >
Thread: fast easy DAC with PIC
www.piclist.com/techref/microchip/devices.htm?key=pic
BY : Roman Black email (remove spam text)

Peter L. Peres wrote:

{Quote hidden}

To get best performance out of this it needs to be done
holistically, ie, hardware and software.

Assuming you can allow freq variance up to 100%, say from
100kHz to 200kHz. That is 50 to 25 PIC instructions at 20MHz.

Now lets start at the bum end, (always a good idea).
You need to drive a few, accurate, preset currents in
a load. And switch between these quickly. You need a
very high pwm frequency with small RC time constant.

The load is driven by a NPN transistor, with a 1 ohm
emitter resistor, so a base voltage of 1.6v gives one
amp (allowing 0.6v to turn on the transistor).

Table:
1A      = 1.6v (analogue pwm output)
0.8A    = 1.4v
0.6A    = 1.2v
0.4A    = 1.0v
0.2A    = 0.8v
0A      < 0.6v

Note that we have designed the hardware to suit this
software, we avoid the need to produce a very low
analogue voltage, or a midrange voltage. Our PIC pwm
can output between 0v-5v, but we choose the band
0.6v - 1.6v. This is significant!

So running a freq of 25 PIC instructions we output
5 on/20 off to get 20% duty cycle, giving us 1.0v
(simple!) we have 0.4A load current, a midrange
figure for example. And at 200kHz, nice fast
resonse. :o)

Now we change the ratio to give fine adjustment:

5:20    1.0000v         (highest allowed freq)
5:21    0.9615v
5:22    0.9259v
<snip>
5:44    0.5102v
5:45    0.5000v         (lowest allowed freq)

So now we have 25 separate values from 1v to 0.5v
still within our allowed freq range. There is almost
0.04v per division at the high end and 0.01v
per division at the low end.

Now try this:
6:19    1.2000v         (max f)
6:20    1.1538v
<snip>
6:43    0.6122v
6:44    0.6000v         (min f)

So now we have another 25 values from 1.2v to 0.6v.
You might also notice that the range that does not
overlap between these two examples is the 0.5v to
0.6v range in example 1, which just happens to be
the part of that range that has the finest resolution
and the most samples. :o)

Due to the ratiometric nature of this spread, there
is a nice spread of possible values with minimal
double values. And of course we can go to 4:x, 3:x,
7:x etc etc to get a very fine range of adjustment.
:o)
-Roman

PS. Did you know that the part of your brain that
understands formulae/math is a direct enemy to the
smart lateral thinking bit that provides the clever
solutions? Einstein was clever but never achieved
his major goals. Da Vinci was clever using the other
side of his brain, and would have been flying around
in the sky if the technology could have kept up with
his invention. Given a choice of being like Einstein
or Da Vinci, I would have to choose the smart one!
I'm bored, sorry. ;o)

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestmitvma.mit.edu

<3A5015A6.3E63@ezy.net.au> 7bit