Is it possible to use a shift register as DAC?

Go To Last Post
51 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Today I have a pretty obvious Idea, but could not find someone that has done it anywhere: using a shift register as a cheap DAC.

The reason for this is that DAC's are not often found in your local electronics shop, opposed to these shift registers.

So, can an AVR such as an AtTiny send serial data to a shift register, which will contain a resistor ladder, therefore becoming a DAC? or does the shift register take too long to change state? What are the reasons this is impractical?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Shift registers are often used extra (slow) IO's, so yes easy done, if it's to slow depends on what do you need, don't expect it to be better than about 8 bit, and speed depends of your AVR, but if it's placed on a SPI it can go rather fast 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

It's not so much impractical as it is a bit silly to implement using discrete components something you can get for free with a PWM pin, or using an existing IC with better accuracy and comparable cost. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jaldunate wrote:

Today I have a pretty obvious Idea, but could not find someone that has done it anywhere: using a shift register as a cheap DAC.

The reason for this is that DAC's are not often found in your local electronics shop, opposed to these shift registers.

So, can an AVR such as an AtTiny send serial data to a shift register, which will contain a resistor ladder, therefore becoming a DAC? or does the shift register take too long to change state? What are the reasons this is impractical?

 

Sure, you can connect a resistor ladder to a shift register.

If you choose a shift register with an Output Latch,  (aka HC595, HC4094 etc), then 'take too long to change state' does not apply.

You first shift the new data, then strobe the latch, to update.

 

Search on Digikey, you will find newer small MCUs these days often include DACs.

 

Another DAC approach is to use the Serial-peripherals like SPI or UART, as DACS, by sending a bit-pattern.

That uses a simple low-pass RC, so is very cheap, but is limited to low slew rate DACs designs.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And don't forget the buffer to get a nice low impedance output.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So, you will be using several AVR pins to drive the shift register.  Shift registers are cheap, but it still costs to purchase and build and board space.

 

Compare to putting the resistor ladder on an AVR port...miniDDS, anyone?

http://www.radanpro.com/Radan240...'s%20AVR%20pages%20-%20MiniDDS.htm

 

Perhaps the shift register has more drive than AVR pins?  Depends on what you are driving, then.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

that of the cost increas of the pcb is a good argument, I must say. Maybe If it's some educational purpose, the idea could ne worth. the other aspect that is interesting to the idea od shoft registers as DAC is the possibility to chain them, thus obtaining some sort of 16 bit depth (probably the nonlinearity of the system will be larger than the precision point). Now, could an ATTiny be fast enough to send these 8 or 16 bits at an audio pace? Could it go anywhere beside making sawtooths?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your link is broken!  Try again.....

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Does you local electronics shop, which doesn't sell DACs, sell precision (ie 0.1%) resistors?  If they only sell 1% resistors then you're only going to be looking at 6- or 7-bit accuracy.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Two issues with shift register DAC. One is the time required to shift in each new value, but that also happens with ANY serial interface DAC, whether I2C or SPI. The second MAY be worse unless you use a double-register device. You get the a "ripple" of the new value as it shifts in. After a few clocks, the output represents part of the old value and part of the new. A double register device lets you shift, then latch. The change-over from old value to new is then nearly instantaneous but  with a delay due to the shift process.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Pardon me for asking, but are you using a Serial-to-Parallel shift register like a 74HC595 or a Parallel-to-Serial shift register like a standard UART?

 

A 74HC595 is going to use five pins (clock, data, latch, gnd, V+) and you have the overhead of creating the clock and shifting the data bits.  An SPI Serial-to-Parallel shift register is going to difficult to find and most-likely expensive. 

 

A parallel-to-serial that is used to create audio (like the 1980s speech synth IC SPO256-AL2 ) is still going to have a lot of processor overhead if it is putting out a serial stream from a table of bytes.

 

I believe that the cheapest pseudo-DAC for an AVR is still to use the fast PWM mode of a timer along with a fast system clock (like the 16MHz Arduino).  This gives an 8-bit DAC, but you can do a lot with 256 analog levels.  For more precision than that, I suggest a Maxim stand-alone DAC chip.  Or, if you transfer the DAC output to a PC, use the audio output with a WAV file.  The audio output on the PC is dual independent channel, 16-bit output, but its voltage range is limited to about 2 volts peak-to-peak, centered around ground.   You would need an instrumentation op-amp to enlarge this range and to re-bias the center point of the output voltage.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think that we are over the time with "ripple" values. 4094 and 74595 have a latch pin.

 

10 chips (80 outputs) can be updated in less than 20us.  

 

I have used 4*4094's as a LCD driver for a custom display. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jesper's DDS is #43 on this site http://www.radanpro.com/Radan240...

 

CORRECTION: None of the links work on page 43. Sorry.

Ross McKenzie ValuSoft Melbourne Australia

Last Edited: Sat. Nov 26, 2016 - 12:33 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Adding shift registers for more I/O is common, and an R2R network can make a decent dac. Main limitation is of course the resistor tolerance.

In the place I live all electronics shops seem to dissapear lately, so even buying a shift registor locally is getting difficult.

 

For hobby purproses it would be more logical to buy a few dac's and/or adc's.

(Unless you have really 0 budget).

 

It's been a long time I saw the Jespers black/green page. I seem to recal he had even lost his own site (source) some years ago, and was aking aroun if anyone had backups.

But a simple search will give plenty of info. The mini dds keeps on living.

https://duckduckgo.com/html?q=je...

 

And if you want to play, you can get a kit directly from Ali for about USD9.

https://www.aliexpress.com/whole...

Beware that this kit needs 3 power supply voltages. Vcc for the AVR and +/- for an opamp.

 

 

 

 

 

 

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

Last Edited: Thu. Nov 24, 2016 - 11:29 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:

Does you local electronics shop, which doesn't sell DACs, sell precision (ie 0.1%) resistors?  If they only sell 1% resistors then you're only going to be looking at 6- or 7-bit accuracy.

 

Well, it depends. While they might have an absolute precision of 1 % to the printed value, if you get them from the same reel then their relative deviation might be well an order of magnitude less (or even better) than their absolute precision. And since you are looking for identical values for each of the resistors, but don't care about the absolute resistor value, that's a cheap way to go. Even with 5% resistors, taken from the same reel you will observe that their relative deviation is way less than those 5 %.

Einstein was right: "Two things are unlimited: the universe and the human stupidity. But i'm not quite sure about the former..."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

CHaN gets 16bits by using two PWM channels together:
http://elm-chan.org/works/sd8p/report.html
You'll be hard pressed to achieve true 16-bit precision with even a lucky batch of 0.1% resistors.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"Read a lot.  Write a lot."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

joeymorin wrote:
CHaN gets 16bits by using two PWM channels together:

 

Nice little audio player, but it sure does not have 16-bit precision / resolution / accuracy / whatever.

In the schematic he uses an rc filter with a series R of 1k for one channel and 270k for the other channel.

This could be correted for in software but it seems highly unlikely because of the goal of a simple audio player for this project.

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Paulvdh wrote:

Nice little audio player, but it sure does not have 16-bit precision / resolution / accuracy / whatever.

In the schematic he uses an rc filter with a series R of 1k for one channel and 270k for the other channel.

This could be correted for in software but it seems highly unlikely because of the goal of a simple audio player for this project.

 

I don't think you can correct that in SW, as you always have deadband steps.

 

At those R values, I make that around 12.1 bits of DAC precision, at the steps, which is  probably ok for a simple audio player.

 

Of course, the Author could have specified 470k // 560k for that second resistor, and got a much closer fit.

Or, you could use 220K + 33k~39k, depending on if you want to compensate the Pin-resistance as well.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In most systems where a DAC is used, (unless it's a meter of some kind ), you don't need it very accurate(just monotonic ), because there is a feedback, like volume (you want a bit up but don't really care if it's 75 or 76, or the voltage to a motor, where the real measure is

the RPM used as a feedback etc. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi all,

i'm bouncing this old thread as i'm planning on doing something similar, an idea is that a DAC made using a 74HC595 and a resistor ladder plus an op amp can possibly handle a bigger voltage swing.

hence, there is still some motivation of doing something as such

 

i've been looking at the MCP4725 and it is very attractive for my purpose as it handle 12 bits DAC in a tiny form factor

MCP4725 I2C 12 bit DAC

http://ww1.microchip.com/downloa...

there are even ready made breakout boards e.g. from sparkfun for that purpose

https://learn.sparkfun.com/tutor...

 

another idea is to use a 74HC595 resistor ladder DAC as a programmable voltage source.

e.g. lets just say that i want to automate the plotting of transistor characteristic curves

it would require a voltage source that can be digitally controlled.

 

the thing is MCP4725 probably handles say between GND 0V - VDD (say 3.3 or 5v)

and lets say i want to plot characteristic curves up to 20v i'd need to scale / amplify that into the range

 

i'm wondering which might be the better option e.g.

 

make a diy 74HC595 resistor ladder and a regular op amp, which i'd probably be able to choose one that can operate in the output voltage range i need e.g. using LM358

or

use a regular DAC e.g. MCP4725 and i can still use the same opamp e.g LM358 to amplify / scale the voltages to the ranges i need

 

 

Last Edited: Fri. Aug 10, 2018 - 05:45 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

It is actually hard to get 8 bit monotonic operation with the normal tolerances of off-the shelf resistors. Use a real DAC and all that is taken care of, for you.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Unless your local chip supply is very limited (as earlier in this thread) why wouldn't you simply spend your shekels on a real DAC with serial interface?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks

using the ready made DAC do feel like a 'winner' here at least for being simpler with the number of components used

the costs really 'break even' as some of the made-in-china 74hc595 goes for a few cents in pieces of 10s or 20s.as do the 'cheap' op amps like lm358 which is priced in similar ranges of a few cents on ebay etc

 

but the effort to build that resistor network , components etc would be more a hassle than MCP4725 which is designed for an accuracy of 12 bits built in

using the MCP4725 i figured could be as simple as the DAC and a single transistor amplifier in the simplest setup, but i'd guess using an op amp would give better linearity etc

 

a benefit it seemed with the diy 74hc595 DAC it seemed is that if it is simply a breadboard setup, the resistors can be swapped etc hence it can be 'tuned'

and i'm not sure if after all if using that single op amp and resistor ladder DAC would make it more adaptable to unconventional voltages and setup e.g. that the op amp runs on 12v rails while the mcu and 74hc595 runs on 3.3v or 5 v single supply rails. it seemed whether i use the MCP4725 + and opamp or a transistor output stage i'd still need to deal with problems of interfacing the differing voltage ranges

the diy 74hc595 resister ladder DAC it would seemed may be simplier as it is made up of discrete components while a MCP4725 and an op amp e.g. LM358 may add a little of a black box in interfacing different voltage rails

Last Edited: Fri. Aug 10, 2018 - 07:02 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You generally need to buffer a DAC's output to drive whatever it is you wish to drive, so an op-amp is generally part of the circuit.

Once you have an op-amp you can, obviously, scale the output voltage to whatever you wish.

 

I totally agree with using a real DAC these days, either a stand-alone DAC chip, or a micro with a DAC built in.

 

The Xmegae5 series is a small Xmega chip with a DAC.

 

Others exist.

 

Welcome to the forum.

 

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@ag123

 

Do you need 12 bit accuracy?  Only reason I ask is I saw 20v requirement and I have a bunch of these I would be willing to send you some of if it helps:

 

http://www.analog.com/media/en/t...

 

Then again, I see this:

https://www.mouser.com/Search/Re...

 

so for under a buck you get 12 bits, and another $0.50 for the opamp and a few resistors and you are golden.

 

I'd go for the MCP solution and be done with it.

 

East Coast Jim

 

 

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?  - Lee "theusch"

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks i should have done more searches on the internet for DACs laugh

AD558 is pretty much more cost effective than MCP4725

and yes the interesting thing is it works up to 15v single supply on the DAC itself - it is really a single chip solution for the higher voltage ranges

 

i've actually ordered a piece of MCP4725 breakout module for a dollar delivered on aliexpress, hence i'd make do with that first.

 

i got myself thinking about this as i've got a couple pieces of 74hc595 shift register, some 1% resistors and some lm358 op amps

i may try some breadboard experiments with a shift register DAC  as i've not literally built a DAC with a shift register and an op amp though it'd seem pretty simple to do. i may try that out on a breadboard

 

my thoughts are that if one has some spare 74hc595, 1% resistors and op amp e.g. lm358 lying around, it would seem rather handy to make diy DACs out of them

it may after all be useful than simply leaving the components lying around

 

thanks much for all the responses !

Last Edited: Fri. Aug 10, 2018 - 08:06 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ag123 wrote:
AD558 is pretty much more cost effective than MCP4725

 

Really?

 

https://www.mouser.com/Analog-De...

 

almost $21.00usd each as opposed to maybe $3.00 in parts? 

 

If you want a few PM me your address and I will send them to you.  I havent used them in ages.  You could connect them to a 74HC595 and control them with three wires and an AVR smiley

 

JIm

 

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?  - Lee "theusch"

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

oh well, as i'm a hobbyist meddling with Arduino  and stuff, i tend to take some risk and go for the lower costs

 

on ebay i'm seeing prices for AD558 going for around usd 2.50 - usd 3

https://www.ebay.com/sch/i.html?...

but some of the chinese sites e.g. aliexpress / taobao etc one may get some cheaper ICs for the same SKU

 

the trouble with some chinese dealers is that you run a pretty high risk a chip may be defective or in a worst case simply fake

and some of those cheapest ones may not offer returns

 

but generally i find those on amazon/ebay/aliexpress are more 'respectable' and you tend to get the real things you ordered. in comparisons, sometimes for very small quantities, the costs is actually the shipping costs

and in my region, it turns out it is sometimes cheaper (e.g. 'free' shipping) and i take a risk with them

i've seen AD558 going for below a dollar usd in the 'china' sites (not amazon/ebay/aliexpress), but one may really be taking a risk that they may not work after all

 

 

Last Edited: Fri. Aug 10, 2018 - 08:41 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Depends on what you really need.  If you just want high resolution (meaning a lot of steps) & don't care too much about the absolute accuracy (other than you can minutely step up & down the voltage), then a filtered 16bit pwm can give you 10000+ slow moving steps (due to needing some strong filtering).  You'd probably want enough (heavy) filtering to reduce the ripple to less than a single step.  But it is tough to beat a nice dac these days & some avrs include them.

When in the dark remember-the future looks brighter than ever.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ag123 wrote:
thanks using the ready made DAC do feel like a 'winner' here at least for being simpler with the number of components used the costs really 'break even' as some of the made-in-china 74hc595 goes for a few cents in pieces of 10s or 20s.as do the 'cheap' op amps like lm358 which is priced in similar ranges of a few cents on ebay etc   but the effort to build that resistor network , components etc would be more a hassle than MCP4725 which is designed for an accuracy of 12 bits built in using the MCP4725 i figured could be as simple as the DAC and a single transistor amplifier in the simplest setup, but i'd guess using an op amp would give better linearity etc  

 

Yes, if you need 12b, a 'proper' DAC wins over a resistor-ladder, as you need expensive precision resistors to get anywhere near 12b.

You also need an opamp, as a single transistor will not be linear enough.

 

DocJC wrote:

I totally agree with using a real DAC these days, either a stand-alone DAC chip, or a micro with a DAC built in.

 

That 'micro with DAC' is becoming much more cost competitive, a quick scan on Digikey shows just how you can get a micro-for-free, when you buy these DACs (with micro included :) ) 

 

MCP48FVB01-E/UN 10MSOP  $0.53560 @ 100 for 1 x 8b DAC

MCP4725                              $0.75190  @  100 for 1 x 12b DAC

MCP4728            10-MSOP     $1.48  @  100 for 4 x 12b DAC

 

ATTINY212-SSNR  SOIC8       $0.37 @ 100 for 1 x 8b DAC

ATSAMD10D13A-MNT 24QFN  $0.48 @ 100 for 1 x 10b DAC

ATTINY1614-SSNR  14SOIC    $0.61 @ 100 for 3 x 8b DAC

EFM8BB31F16G-B-QFN24 24QFN  $0.69 @ 100 for 2 x 12b DAC

EFM8BB31F64G-B-QFN24 24QFN  $1.09 @ 100 for 4 x 12b DAC

 

Notice how at all the price points, you can buy a MCU+DAC, for less than the dedicated DAC alone.

Of course, those MCUs also usually include ADCs too, so you can do quite a bit more of your "i want to plot characteristic curves up to 20v"

 

If you want to create curve-tracer to > 20V, I also saw this go past recently - 2 or 3 channels of current sense, allows you to include Ib, Ic for example in transistors.

https://www.microchip.com/pressr...

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:

Depends on what you really need.  If you just want high resolution (meaning a lot of steps) & don't care too much about the absolute accuracy (other than you can minutely step up & down the voltage), then a filtered 16bit pwm can give you 10000+ slow moving steps (due to needing some strong filtering).  You'd probably want enough (heavy) filtering to reduce the ripple to less than a single step.  But it is tough to beat a nice dac these days & some avrs include them.

 

You can also make a 'hybrid PWM DAC', where you use 2 x 8b PWM, to get the filter frequency much higher, and merge those with precision R:256R analog OpAmp/Mixer, which is just 2 precision resistors.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can also make a 'hybrid PWM DAC', where you use 2 x 8b PWM, to get the filter frequency much higher, and merge those with precision R:256R analog OpAmp/Mixer, which is just 2 precision resistors.

Interesting idea!   You can also make a sharper filter, that has a long effective time constant, yet settles quickly (cascading a few sections).

When in the dark remember-the future looks brighter than ever.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Who-me wrote:

You can also make a 'hybrid PWM DAC'....

 

Can you please post a schematic showing this idea?

Thanks!

 

--Mike

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avr-mike wrote:

Who-me wrote:

You can also make a 'hybrid PWM DAC'....

 

Can you please post a schematic showing this idea?

 

It's simple enough : PWM0 --- R ------+-------- LPF --->

                              PWM1 -- 256R ---+

PWM0 is the coarse PWM, full scale in 256 steps, and PWM1 is the fine PWM a full sweep of that is 1/256 the size of PWM0, so interpolates 

The resistors do need to be precision, so PWM0=N+PWM1=255, is one LSB different from PWM0-N+1 + PWM1=0 

Spice should confirm how precise they need to be....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

???

 

Using one PWM for the course voltage, and another for the "fine tuning", looks great on paper.

Properly configured one could have 256 fine steps within each of the 256 course steps, for a total of 65,536 levels, (17 bits).

 

Personally, I think building a 16 or 17 bit DAC from PWM and summers and low level parts is darn near impossible.

Wave your hand over the board and the circuit drifts enough to trash the most significant bit ( s ).

 

It is still very difficult to get a full 16-bits out of a 16-bit chip, very carefully designed, and all on the same substrate.

 

Of course if one is up for the challenge, one could use a 741 op-amp for the output stage!

 

Real world electronics sometimes differs, significantly, from theoretical, paper, designs.

 

JC

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the schematic, I get it now.

 

I agree with what DocJC said regarding the limitations of this

idea but see a potential use for the /256 PWM as a precision

bias adjustment, if such a thing was needed.

 

--Mike

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

the circuit drifts enough to trash the most significant bit ( s ).

Well, I hope its the LSB.  Yep, you gotta account for parts drift, offsets, etc ...might be way more than the LSB.

Too many newbies think they are just gonna show up & measure a fraction of a microvolt with no worry. Oh & they just clip the gnd lead any old place on the board!  

When in the dark remember-the future looks brighter than ever.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, I hope its the LSB. frown

 

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jaldunate wrote:

Today I have a pretty obvious Idea, but could not find someone that has done it anywhere: using a shift register as a cheap DAC.

The reason for this is that DAC's are not often found in your local electronics shop, opposed to these shift registers.

So, can an AVR such as an AtTiny send serial data to a shift register, which will contain a resistor ladder, therefore becoming a DAC? or does the shift register take too long to change state? What are the reasons this is impractical?

 

Why not use an R2R ladder. It's a little 10 pin resistor module that costs about $0.50. You connect an MCU port to the 8 pins of the ladder, one end to ground and the other end is your 0 to 5 volt output... very nice and linear.

 

Of course, you can't put much of a load on the output since it may have a 10K or more output impedance, but an op-amp buffer solves that problem.

 

If you want more resolution, use two ports and two R2R ladders, connected like this:

 

[GND] --- [Lower 8 bit R] --- [OUTPUT][GND END] --- [Upper 8 bit R] --- [16 bit output 0 to 5 volts]

 

Then just write the LS byte to the lower register and the MS byte to the upper (or do a single 16 bit write if your MCU supports that).

 

A 16 bit DAC like that will cost you about one dollar (maybe two dollars if you add an op-amp buffer).

 

If you want to use a DAC chip, take a look at the Analog Devices AD7302. It's a dual 8 bit DAC with a buffered rail-to-rail output that will give you a 0 to 5 volt output swing - no op-amp buffer needed.

 

Gentlemen may prefer Blondes, but Real Men prefer Redheads!

Last Edited: Thu. Aug 23, 2018 - 02:20 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Krupski wrote:
If you want more resolution, use two ports and two R2R ladders, connected like this:

 

Care is needed to not confuse 'more bits' with more precision.

Any cascaded circuit still needs to be monotonic, and that needs extremely well matched steps. Even to hit 8 bits needs better than 0.4%, if you want more than 10, you need better than 0.1%

Smarter to just buy a MCU with a 12b DAC - it will cost less than your 2% tolerance 2 x R2Rs !

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There is another "gotcha" with this simple shift-register/DAC idea.

 

If a buffered shift register is NOT used (that is, one with a second rank of latches on the output pins), you will get a noise spike in the output every time new data is shifted in. 

 

Commercial DACs are built with the appropriate buffering to avoid this. Of course, you CAN get buffered shift registers, but that "rock bottom" price goes up just a bit.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ka7ehk wrote:
Of course, you CAN get buffered shift registers, but that "rock bottom" price goes up just a bit.

 

? The real world actually works a little differently.

The lowest price Shift register at Digikey is the Buffered HC595, not the apparently simpler unbuffered variants.

Why ? The volumes in stock give a clue -- over 200,000, which show the massive volumes the HC595's are made in.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Its pretty tough luck if you can't stand any variation at the moments the dac setting changes...even with buffered chips, there will be some finite glitch, since all the outputs don't change at the exact same ns.  High-end dacs have to fight this with special anti-glitch measures, and even then its a battle to get to some minimal warble.  Its so much easier to bite the bullet when you need a high-end dac...to just go get one.

When in the dark remember-the future looks brighter than ever.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Who-me wrote:

Krupski wrote:

If you want more resolution, use two ports and two R2R ladders, connected like this:

 

 

Care is needed to not confuse 'more bits' with more precision.

Any cascaded circuit still needs to be monotonic, and that needs extremely well matched steps. Even to hit 8 bits needs better than 0.4%, if you want more than 10, you need better than 0.1%

Smarter to just buy a MCU with a 12b DAC - it will cost less than your 2% tolerance 2 x R2Rs !

 

You are completely correct to worry about monotonicity... I built and tested a 16 bit DAC using two Bournes 10K R2R ladder SIP modules (which cost $0.95 each from Digi-Key - my "50 cents" assertion was a bit off!) and used my DVM to record each voltage level and recorded it via the USB port.

 

Each discrete level was different than the previous or next value, and looking at the waveform on the 'scope showed a nice straight line.

 

I especially looked at the points where the ladders "jumped" (that is, for example, between 0x00FF and 0x0100) and there was no discernible glitch.

 

A high quality 16 bit DAC chip would probably outperform my two R2R ladders, but for most applications, mine is "good enough".

 

Specifically, the final project that I built (just for fun) was a 30 second (240K bytes at 8000 samples per second) recording of the "Mister Softee Ice Cream Truck" jingle.

 

I stuffed the 240K data into the PROGMEM of a Mega 2560 board and wrote a tiny program, timer interrupt driven at 8000 Hz. to read the progmem and dump it to the port where the R2R ladder was connected.

 

Connected to an amplifier and a horn speaker, it sounded IDENTICAL to "the ice cream truck" and I almost died laughing when I drove down a street with the thing blaring and watched people come running out for ice cream!

 

They frantically looked for the ice cream truck, not even looking at me or considering that the music was coming from me.  I still LOL thinking about it!  laugh

 

Gentlemen may prefer Blondes, but Real Men prefer Redheads!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Krupski wrote:
I almost died laughing when I drove down a street with the thing blaring and watched people come running out for ice cream!

 

https://www.youtube.com/watch?v=...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 the 'scope showed a nice straight line.

 

I especially looked at the points where the ladders "jumped" (that is, for example, between 0x00FF and 0x0100) and there was no discernible glitch.

Well, the scope can be particularly bad at showing such things, unless you are zoomed way in (which presents its own problems).  At 16 bits @5V, each step is 76microvolts  (0.000076V)...so being off a few steps (or having a few steps worth of settling) would be completely invisible.  So use care when "inspecting" a DAC output for monotonicity.  Even a very mismatched 8 bit DAC can appear to draw a "straight line".   The scope graticle has perhaps 50 markings (steps), compared to 65000 steps on a 16 'bitter. That's dividing each scope graticle mark into 1300 levels!

When in the dark remember-the future looks brighter than ever.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Krupski wrote:
Each discrete level was different than the previous or next value,

it's not just a matter of being different - the difference must always be in the right direction.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

Krupski wrote:

Each discrete level was different than the previous or next value,

 

it's not just a matter of being different - the difference must always be in the right direction.

 

Well of course I checked that as well. Actually I wrote a tiny program in BASIC to calculate each delta (difference between two adjacent samples) and do two things:

 

(1) Average them all out to see what the average "step size" in millivolts was.

(2) Make sure that each value was LARGER than the previous.

 

We're not talking about spacecraft guidance to the moon without any mid course corrections... it's just an Arduino!

 

Finally, from Wikipedia:

 

The R-2R ladder DAC which is a binary-weighted DAC that uses a repeating cascaded structure of resistor values R and 2R. This improves the precision due to the relative ease of producing equal valued-matched resistors (or current sources).

 

So there!  cheeky

Gentlemen may prefer Blondes, but Real Men prefer Redheads!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Krupski wrote:

You are completely correct to worry about monotonicity... I built and tested a 16 bit DAC using two Bournes 10K R2R ladder SIP modules (which cost $0.95 each from Digi-Key - my "50 cents" assertion was a bit off!) and used my DVM to record each voltage level and recorded it via the USB port.

Each discrete level was different than the previous or next value, and looking at the waveform on the 'scope showed a nice straight line.

I especially looked at the points where the ladders "jumped" (that is, for example, between 0x00FF and 0x0100) and there was no discernible glitch.

A high quality 16 bit DAC chip would probably outperform my two R2R ladders, but for most applications, mine is "good enough".

Certainly, for your application, that was "good enough".

Bourns only commit to 2% tolerance, but you can hope that two separate parts, are from the same batch, and well within that. Mostly, you will get lucky, and they may match better than 1/10 of that, at least initially.

The ear is also quite forgiving.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

All this talk about 1% resistors and built-it-yourself DACs is making me want to go into the closet and get out my bell-bottom pants and polyethyene disco shirt, 'cause it's 1977 all over again!

 

For goodness sake's, if you need a DAC, use a DAC.  Here's a 16-bit serial DAC on eBay for 18 American pennies:  https://www.ebay.com/itm/10pcs-P...

 

If you live in a place where you aren't allowed to send 180 American pennies to China for a packet of 10 16-bit DAC ICs, then I suggest that you put all your belongings in a big old sack and sneek out of this idiot place so that you can spend the rest of your life living in a place where you can make the world a better place with your superior electronic designs and 18 cent DACs.

 

Now can we stop annoying the young people with demented ramblings about building a DAC out of op-amps and resistors????

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 Here's a 16-bit serial DAC on eBay for 18 American pennies:  https://www.ebay.com/itm/10pcs-P...

That's completely amazing & sad.  Everything's a commodity, to soon turn into worthless scrap.  I just saw a HUGE pile of brand new large screen LCD TV"S that have some issues...anyone gonna fix 'em??...nope, no time, bury them.

2 million working ones will be arriving each week, like a river.

 

Never heard of this having a "name":

It’s digital input timing format is Least Significant Bit Justified (LSBJ), or so called

Japanese input format

 

I was about to make a 16bit DAC out of some old tubes...guess I'll make a stereo. 

When in the dark remember-the future looks brighter than ever.