Questions on DAC (R2R) and opamps

Discussion in 'General Electronics Chat' started by Little Ghostman, May 8, 2014.

  1. Little Ghostman

    Thread Starter Member

    Jan 1, 2014
    I am still at home because of inflammation. So no op this week.
    I am doing a little work on my model train layout, at some point I will have access to a special board with integrated codec etc for speech synthesis, however at the moment I need some information for something slightly different.
    I am NOT looking for chip solution's, I am looking for some information on an experiment I am wanting to do. I have googled and I have watched the excellent tutorial on DAC's from Alan from here. Most of it I am ok with, I do however have a few question's that I would be grateful if you could answer or if you have any decent links (pdf's would be great).
    What I would like to is a kind of sound synthesizing, the following is the set up and what I would like to try, I am not really looking at single chip just plug this in kind of thing though.

    On my model layout I have some of the Loco's and other parts fitted with controller chip's, mainly 32 bit micro's but there is also some 8 & 16 bit pics and DSP's, I want to be able to synthesize some sounds, these are to be stored in some cases on chip, but in other cases will stored elsewhere and called up over my coms network.
    In an ideal world I would get say a WAV or other sound file, play this through matlab or maybe some other software and sample with say a 12 or 16 bit ADC, some of the sounds will be generated by spread sheet or other way's (this dosnt matter for now), what I need to do is take a sound and turn it into a digital code, this can then be manipulated if needed and then played back via a DAC.
    I would like to build the DAC myself, size wise I was thinking maybe 16 bits, I have some precision smd 50R resistor that are 0.01%, but I dont have many and they are expensive! So my plan is to use some smd 1% resistor's, I have all kinds of values and most are nearly full reels, so the plan would be to measure them on the bench meter and get them as closely matched as I can (the meter is 6 digits).
    Any sugestion's on the best resistor value? I will use two in series for the 2R part. The other problem is power supply, for most of the DAC's I need to use 12V or lower, I have seen some designs for DAC's that use a opamp on the output and would prefer to use this method, I can get opamps but some of the micro's I am using have opamps built in.
    This is the tricky bit. Do I need a dual supply? I have to take the supply for most of it from the track, this is a constant 12V or 14V depending on section, I have heard of a way of making a dual supply with a opamp as virtual ground?? If I have to use a -supply how is this done with the Opamp?
    Any other comments etc welcome. I understand there are probably better ways to do this, however I am kind of fixed on doing it the hard way :D. If I can get over this hurdle I will explain the other part of what all this is for.


    On the sound sampling side I mentioned using sound files for the initial samples, bu some of the sounds I might need to sample myself. I have some micro's that will sample 12 bit at 1Msps, obviously I dont need that amount as such, so what frequency would you sample a sand at, and what resolution would you suggest? We are not talking concert hall sound quality, I do however need to manipulate the sounds once sampled, some of this will be on the fly.

    Other Info

    I intend to store some of the sounds temporary on the micro's in there flash memory area (program area), some of the chips have upto 1Mb of memory so I have some room. Also most of the sounds will be passed to the chips just before it's needed.

    DAC Opamp

    Any suggestions for the TYPE of opamp I need (rail to rail etc).


    Some sounds will be output via small 8 ohm speaker, and some via a piezo type speaker, I will where needed use a small amplifier for the sound output.

    Thanks for helping

  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    I can make no comments on single/dual supplies based on a blank sheet of paper.

    wav files contain the digital sample data in unencoded form, meaning you can pull the info directly out of a wav file and hand it off to your D2A. Or, use a PWM output on the micro and just pass it there. I've done that, storing wav files on a SD card for a micro to send to it's PWM. Sounded decent with the cheapest PC speakers I was using. All you need is a simple low pass filter between the PWM and the amp.

    Same thing for sampling: your PC sound card is all you need to make custom wav files.
  3. alfacliff

    Well-Known Member

    Dec 13, 2013
    another method would be to use a bucket brigade chip. these chips store audio as analog voltages. constructed much like an eprom, they store small samples of the incoming audio in each cell, and are played bck by the address of the chip. these are used in the (popular?) record it yourself greeting cards and as stored messages in systems. they would not need any of your processor time, and store the messages for years.
  4. MrChips


    Oct 2, 2009

    I have used Windbond sound recorder chips to make a voice ID Call Display. When the phone rings it announces the name of the caller if the phone number is in your phone list otherwise it announces the last four digits of the phone number.

    This way you can choose not to interrupt your dinner when the telemarketers call without having to get up to answer the phone.
  5. AnalogKid

    AAC Fanatic!

    Aug 1, 2013
    An R-2R DAC network sits between digital signals switching analog currents and an analog output voltage that has an output impedance and drives the next bit of electronics (usually an opamp). The lower the value of R, the lower the output impedance. This reduces the small error that comes from a non-zero output impedance driving a non-infinite input impedance. Rule of thumb, the two impedances should be at least 100:1 apart. Also, larger R means more voltage noise. So small R is good.

    But small R increases the current being switched by the digital inputs, particularly the upper bits, and this increases the small voltage error that comes from the fact that the switch (usually a single transistor) does not have a zero ohm "on" resistance. So small R is bad.

    In summary, the value of R is a tradeoff between switch impedance errors and output impedance errors. Fortunately there are very high input impedance opamp buffer circuits, so you can work backwards from there. To see how the pros did it, download datasheets for old parts from Analog Devices and National Semi. They usually state the R value.

    This response is based on a voltage mode DAC because most people find it easier to grasp conceptually, but there also is a current mode topography. More on that if you want it.

  6. Little Ghostman

    Thread Starter Member

    Jan 1, 2014
    Thanks a lot for the great answers! I havnt had chance to reply because I have been trying to work a few things out using MATLAB, so too work backwards....

    I am going to start with a voltage DAC first, I did come across a current one, and this I will try out after I gt the voltage one sorted :D.
    I did consider other chips but decided against, one reason is I need DAC's for two different jobs, one is my curve tracer/component tester/scope screen saver. The other is for the model rail, I am going to need to make several, if it works well then I will need to make alot of them (one for each loco).
    The other reason I chose not to go the chip route for sound is manipulation, the project is in stages but the end goal is synthesized sound, so for example as the loco accelerates the sound will reflect this.
    I had a look at a sound file (WAV) in matlab, what it gives me is a list of floating point numbers, highest being 9.xxxxx lowest being -8.xxxxxxx, with most around 0.00xxx.
    So my first question is, are these voltages?
    I need to work with a smaller file because the one I am using has too many elements for matlab at times.
    I tried to convert the numbers by taking the value then *32768+32768.
    But I am thinking I have this wrong (I was following something in a tutorial).

    Next question how do I convert the numbers in a WAV file (16bit), into non floating point, then into binary?

    Actually that's probably a meaningless question so disregard it.

    I need to read up more, I am missing chunks of understanding sorry!

    The virtual earth question I am not sure what information to give, I have a +12V supply (train track), from that I need to make a dual supply for the opamp so it can output the voltage to a speaker.

    Sorry guy's I am not being clear, the pain killers are making it really hard to think properly (OXYCODON), most of what I have written dosnt make much sense to me :(.
    I will be back when I can form a question correctly, sorry again


    I just found part of my problem. When I opened the file in matlab, it put then in a excel type grid. I used the command open(variablename);

    it gave me a long list such as -0.0108
    But when I came to just copy and paste them I found its only displaying part of the number, I copy the column and paste into notepad and the numbers are actually more like the following sample


    Some of the numbers (not many) are greater than 1.

    So anyone know what these numbers represent? I had assumed voltage, but that seems daft now
  7. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    You can download my little freeware sound program from here;


    You can use it to open a WAV file, then edit and view and play the contents, then it can export as pure 8bit raw binary mono, ready to playback in your PIC etc.

    It also does resampling of the frequency. So if your micro has a playback rate at a weird freq like 15625Hz (because of its timer speed etc) you can load a standard 22.5kHz WAV file, and convert it to exactly 15625 Hz, then export as binary mono.

    It was designed as a support program to do exactly the thing you are doing now. :)
    djsfantasi likes this.
  8. Little Ghostman

    Thread Starter Member

    Jan 1, 2014
    Thanks RB, I really like that! I have had a hard time working out what the WAV file actually was, matlab didnt help by hiding most the digits!
    I will give it a whirl and let you know how it goes :D, I am hoping the end result will ne pretty unique

  9. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    Yeah that little program is good for that.

    It converts any (uncompressed) WAV file format to 8bit mono unsigned. Which is very simple for working with the numbers.

    And if you want to put multiple sound effects into one file it can do that, and you can assign start points to each sound (which are included in a very simple header at the start of the file). So then your project only needs to load that one file and it has multiple sound effects and pointers to where each sound is.

    The help file that comes with it explains all that. :)
  10. crutschow


    Mar 14, 2008
    I doubt than any analog signal can be stored for minutes much less years as a charge in a chip. Bucket brigades are typically used to store analog signals for short term signal delay/audio effects. The messages in greeting cards, etc. are likely stored as digital words in EPROM.
    colinb likes this.
  11. gootee

    Senior Member

    Apr 24, 2007
    For your audio output amps, there are simple ways to make them with a single supply, even with most op amps that appear to need a dual supply (basically, you just raise the input's "AC zero" point to half the single DC supply's level, and use series input and output caps). Many datasheets for audio-type op amps and chipamps show both dual-supply and single-supply circuit topologies. See, for example, the second schematic in the LM1875 datasheet, at or (Although that particular chip won't work for your application, because it needs a higher supply voltage than you have, the same circuit topology will work with most op amps and chipamps.)

    LM1875 datasheet is at .

    if you do decide that you want to use a dual-supply topology, use something like the circuit in Fig 3 of the LM675 datasheet, to split the single supply and form a virtual ground. Many types of op amps and chipamps would work, in that circuit, in place of the LM675.

    LM675 datasheet is at .

    You would probably want to add 100 uF or more from input to ground, and 47 uF or more from each output to the virtual ground.
    Last edited: May 16, 2014