Can I drive a piezo directly with this DAC?

Here is the DAC in question:

I know it's typical to use an opamp with one, but I don't have a lot of space on my board and a piezo is more than loud enough for my needs, so I don't really see the point in adding another chip just to drive a tiny speaker which may or may not be marginally louder.

Also, on a related note, does anyone know if it is realistic to expect to be able to update said DAC at 44khz, while also updating a shift register on the same bus, say, 60 times a second? I'll be running an Atmega328 at 16mhz.

Lastly, I recently recall seeing mention of using an interrupt to update a DAC. Is there a good reason to use an interrupt rather than simply updating it in a loop with everything else?

Oh, btw, the plan for the DAC is to do some basic FM synthesis with maybe a couple channels being mixed. I'm trying to reproduce the sound of this:

At first I considered playing back a sample of the sound, but the original sound isn't really a loop, so it doesn't sound right when you loop it or speed it up and slow it down.

I've got some folks waiting on the boards for these, and I don't know if I'm gonna be able to reproduce the sound or if I'll just have to go with beeps, so I figured the best course of action was to just include a dac in the circuit which would give me a number of options for the sound so I can just update the software at a later date if I can improve the sound effects.

Oh and in case you're interested in seeing just how densely packed the board is, well, this is what I've got so far, and as you can see there aren't yet any caps for the IC's on there or connectors for the servos or touch switches or most of the leds on the thing:

I'm sure I'll find a way to make it all fit though. :slight_smile: I was thinking recently about switching to one of the stick of gum atmegas which have more digital pins. That would allow me to get rid of the 4051 and the TPIC. Kind of a toss up though as far as space savings go I guess, though.

Been considering surface mount tech too. Not sure I'm comfortable just jumping into that though. I don't wanna spend $200 getting boards made only to have them be useless because I can't get the hot plate method to work. Plus I don't know a lot about all the different styles of surface mount components so I can pick ones that would be easiest to mount.

Feeding a 12 bit dual D/A into a piezo is rather like feeding a pig strawberries, you can but there is little point.
The absolute maximum current is 25mA so you should use a resistor to limit the current to that.

I recently recall seeing mention of using an interrupt to update a DAC. Is there a good reason to use an interrupt

The good reason is that you don't get any variability in the update rate like you would if you left it in a free loop.

The good reason is that you don't get any variability in the update rate like you would if you left it in a free loop.

Yeah, but is that really any different from a loop which checks to see if it is time to do and update and then does one if it is?

I guess I'm just averse to interrupts because I'm not familiar with them. Don't know if the CPU triggers them or if the bootloader code does it or what, or when they'll trigger and when they'll fail to trigger. By updating everyhting in a loop I know exactly what will happen when.

Feeding a 12 bit dual D/A into a piezo is rather like feeding a pig strawberries, you can but there is little point.

I understand that the sound quality of a piezo isn't that great. And maybe what you're saying is there's a cheaper dac I could use, but I picked that one cause the wave shield uses it and I don't know enough about them to select a more appropriate one.

But surely you're not saying that there's no point in connecting a dac to a piezo at all? I mean piezos may not produce great sound, but they can do a lot more than single tones at one volume level. My old cellphones used to produce some pretty neat sounding polyphonic ringtones.

I mean ya see the board I have to work with there. Not a lot of room. I don't expect to get awesome sound. I just want something better than BEEP BEEP BEEP using the tone command. And bit banging won't work well because it takes so much cpu and can't produce the high frequencies needed.

The absolute maximum current is 25mA so you should use a resistor to limit the current to that.

Yep, planned to do that. I did that on the other PKE circuits I built, on your reccomendation.

Don't know if the CPU triggers them or if the bootloader code does it or what,

In this case it is one of the timers that triggers it. You can also use external pins.
The problem with a loop is that the loop itself is subject to interrupts. You can see this if you have a loop just toggling a pin and look at it on an oscilloscope. You will see a regular square wave that glitches occasionally. That is the house keeping interrupts kicking in.

By updating everyhting in a loop I know exactly what will happen when.

So you see you won't.

And bit banging won't work well because it takes so much cpu

Bit banging an SPI is not much slower than the SPI hardware. The point is you will have to transfer two bytes with the hardware but you only need to bit bang 12 bits. You might be better off just using 8 bits of data as you will get the speed up and not loose much noticeable resolution.

A point on the video clip - what noise on it are you trying to make?

Richard:
View the end of the video, starting around 1:20. That's the main sound I'm trying to replicate. The other sounds are similar, but too quiet really to hear.

I've analyzed the sound with various tools to try to determine how to reproduce it, and unfortunately it seems like it might be frogs and crickets sped up, but there are several strong frequency bands in the effect and I can see that they're pulsed at a certain rate and how they change in frequency over time, so I'm hoping I can replicate it to some degree.

It seems like there's two main components to it. The "chirping" and the "croaking" which change frequency at different rates as it speeds up. And each of these two components is like a chord with maybe five to seven different frequencies playing at once. Also, the "croaking" changes in volume over time.

I can't even change the volume over time using the tone functions, nevermind playing something like 14 different notes at the same time. And the frequency of the sounds is too high for PCM to reproduce. I need around a 28khz sampling rate to reproduce the sound, accoridng to my tests with the original sound effect, which falls in line with nyquist theory and the highest frequency sounds in the effect being around 14khz. If I'm not mistaken, PCM can only go up to around 22khz. which in my tests produced a muddy effect.

I have an even stronger opinion than Grumpy_Mike about using a 12-bit DAC with a piezo transducer (speaker). It is massively gross overkill. Completely unnecessary and a waste of both design and operational power resources. An 8-bit DAC would be overkill. You might (if you were lucky and using it in a quiet environment) hear a slight difference with a 4-bit DAC vs. just driving the piezo directly from an Arduino digital output pin.

I can see how a 12-bit dac might be overkill, but the chip is cheap, and I don't know a less expensive alternative.

But to suggest I go with no dac at all? With no dac all I can do is play beeps at different frequencies. I can't even vary the volume of them.

With a dac though I could get sound similar to this out of a piezo:

Granted the first one isn't a piezo speaker per se, but I couldn't find many videos of them in action. But surely you've heard those birthday cards that play music and stuff. I bought one for my dad which played the star wars theme and I was blown away by how good it sounded.

...

Oh hey, I found that card on Youtube. Jeez, people will post anything there!

That sort of "tuned" fast clanging sound you could generate with a 50-cent surplus pager vibrator motor and a little piece of brass (like a tiny bell or a piece of a finger-cymbal).

Heh, it's a little more complicated a sound than that, and besides, such a solution would be prone to breaking.

Of course, you realize that the props used in the movie didn't actually generate any sounds. They were added by Foley artists and sound designers and mixers and had nothing to do with the little hand props.

Yes, I know the real prop didn't make sounds, but this is a prop for people to use on halloween and at conventions, and it wouldn't be as fun if the sound effects were added in post. :slight_smile:

Have you actually (re)created the sound yet? If so, then post the WAV file. If not, then how do you know what it will take to play it back?

No, I haven't recreated it yet. It's not exactly trivial to do!

But I have isolated the original effect and cleaned a short segment of it up:
http://ectoprops.com/gbfans/pke1.mp3
http://ectoprops.com/gbfans/pke2.mp3

Slowed down, as I mentioned before, those sound suspiciously like frogs and crickets, and not at all like something computer generated. Which means I have my work cut out for me trying to generate it from scratch. But if I just try to play that loop there, it doesn't sound right at different speeds, and being able to adjust the speed is something the user needs to be able to do with the prop.

So, I kinda don't really know what I'm gonna do with the sound effect yet. But I do know that if I don't include a dac, then my options would be extreemely limited, and I worked within those constraints when I made the sounds for one of my other meters:

That sound there is just two or three tones played repeatedly, and the startup sound isn't much different. For that I was trying to replicate this:

It's not bad, but I couldn't really get the zing of the startup sound with only square waves to work with. And I don't think I can get the pleasant tone of the movie meter with square waves either. Using a dac would give me a lot more options in that regard.

Bit banging an SPI is not much slower than the SPI hardware.

What is SPI?

The point is you will have to transfer two bytes with the hardware but you only need to bit bang 12 bits. You might be better off just using 8 bits of data as you will get the speed up and not loose much noticeable resolution.

I think what you're saying here is that bit banging isn't really any slower than using a dac?

But beyond that, what are you saying? Are you saying doing 8-bit bit banging would be faster? Or are you suggesting switching to an 8-bit dac? I have nothing against switching to an 8-bit dac, but I don't know much about dacs. I wanted to use that dac cause the wave shield used it and I know where to get it. But there's a hundred other dacs on mouser and digikey and maybe some are 8-bit but I don't know which ones are suitable to the task of generating sound and which aren't.

Also, something concerns me here. You seem to be implying bit banging would be just as fast as updating a dac. But the bit banging code seen here can only do samples up to 8000hz:
http://www.arduino.cc/playground/Code/PCMAudio

Does that mean I can't hope to update a dac much faster than 8000hz if I have to transfer one bit at a time to it?

A point on the video clip - what noise on it are you trying to make?

All the noises the little meter makes. The prop I'm making has an adjustable speed, and those clips show the meter running at three differnet speeds, all of which I need to simulate. All those noises are fairly similar though. Mainly it seems like the pitch increases as the meter speeds up, but the rate of the chirps or whatever you want to call them seems to stay the same, varying slightly in speed and volume over time.

My concern isn't so much about finding space for the speaker, but rather finding space on the board itself for another 8-pin dip for the opamp needed to drive it.

The interior of this thing is like 2" wide, 5" long, and 1.5" deep, with a handle that's around 4" long and 1" wide and deep. In that space I have to fit:

  • Main circuit board with all the components you see, plus a bunch of additional capacitors, resistors, and molex connectors.
  • A "wing" on each side with 7 leds each, which are 1/2" wide and 1/4" thick and have their own circuit board inside because I don't want to have to individually wire up 14 leds for every one I build.
  • 8-pin connectors for said wings.
  • Two nano size servos.
  • Two battery packs, one for servos, one for main board because using only one battery caused the leds to dim whenever the servos started moving. (Probably go with a 9v in the handle for the main board and use something larger for the servo in the main body.)
  • Potentiometer in handle. Switch in handle.
  • 5 leds, two touch switches, and a regular switch on front panel.
  • Approx 1" wide circuit board for main screen with 14 leds on it. (Seen in schematic.)
  • And a speaker of some kind, with circuitry to drive it.

It's gonna be a very tight fit, and the board you see there is about as large as I can make it. I might be able to get it a little larger, but every extra half inch on the board is a half inch less for all the wires I gotta cram in there.

The flip-side of the coin is that if you really need 12-bit (or even 8-bit) resolution to play back the sounds with acceptable fidelity, then the piezo transducer most likely isn't up to the the task.

I don't need 12-bit or even 8-bit. 6-bit would probably be just fine. But 1-bit ain't gonna cut it. And a 6-bit resistor ladder would take up more space than an opamp... unless I could use one of those resistor arrays, but I don't think you can use those? And even then it would still take up almost as much space as the opamp.

Of course I could get rid of some of the dip switches if I really needed to. And I could even swap them out for jumpers instead. If I cut those down to just four, I could get rid of that multiplexer. But I was kinda saving that for in case I need more room for all the other stuff. If I get rid of those and stick that opamp in there just to get slightly better sound, then I have nowhere to go for extra space if I need it for the capacitors and connectors.

And if you're wondeirng why I haven't put all that stuff on there to find out if I have space, well, I just haven't had time to do that yet. But I have a general idea of how much space it'll all take up, so that's what I'm working with at the moment.

Oh and btw, here's another fan built one, so you can see that it is possible to get most of this stuff in there:

I'm trying to build a high-end version of that board: better sound, less glitchy/noisy servos, more accurate leds and animation.

The trimpots on my board for example are to account for servos moving too far or not far enough when you specify 90 degrees. That other board doesn't handle that. The other board doesn't have resistive touch switches either.

Oh, and my circuit board is roughly the same size as the one in there. That's why I know it'll fit without having actually assembled the whole thing yet.

What is SPI?

It's the protocol you are going to have to use to talk to the chip you want to use.
http://www.arduino.cc/playground/Code/Spi

You can implement it in two ways, by using the built in hardware or by bit banging the lines. Note bit banging has nothing to do with the link on PWM you posted.

That link I posted isn't pulse width modulation. It's pulse code modulation:
http://www.arduino.cc/playground/Code/PCMAudio

But that's neither here nor there. I don't know where the whole bit banging thing came from. I thought at some point you were suggesting I use PCM instead of a DAC and referred to it as bit banging, but I don't see any reference to bit banging until I mentioned it myself, so now I don't know where it came from. I must haave seen the term used in some other post I was reading while doing my research.

Anyway, so when you were talking about bit banging I guess you were suggesting I manually send the 12 bits out to the dac. Or you were just responding to what you thought was me talking about doing that.

Sorry, I've been sick as a dog the past couple days, I was a bit out of it. :slight_smile:

Okay, so with PCM out of the equation...

If I can send this audio data to the dac with a hardware method, shouldn't I? Wouldn't that take the least cpu time?

That link I posted isn't pulse width modulation. It's pulse code modulation:

Yes it is the top line of code says:-

Plays 8-bit PCM audio on pin 11 using pulse-width modulation (PWM).

It uses PWM to output an analogue signal.

but I don't see any reference to bit banging until I mentioned it myself,

Yes I though you were talking about how to control that chip. I didn't know you weren't using the term correctly. :wink:

I guess you were suggesting I manually send the 12 bits out to the dac.

Yes. As the built in SPI transfers always 8 bits at a time there are some inefficiencies in you having to always transfer 16 bits when you only need 8.
There are lots of other D/A converters here:-

I think you are better outputting a wave than trying to algorithmically generate one.

I think you are better outputting a wave than trying to algorithmically generate one.

Why's that? Compared to designing the circuit writing code to do FM synthesis would be a breeze. :slight_smile: I may have only 8 months of circuit design experience, but I've been programming for over 25 years.

Should have enough CPU for it. I mean I was playing 8-channel mod files on a 16-mhz 386 doing PCM on a tiny PC speaker years ago...

I mean it would be hard to get something that sounds just like that with FM synth, never did like trying to make FM synth instruments... but I've got playing the sample as a fallback if I need it.

My main concern is that the original sample I have is kinda noisy and I'm not sure how well the speaker would be able to reproduce it. Can't have it being too quiet. Plus there's the ram issue. I can't fit even the whole short version of that sample in the Arduino's flash ram. I'd have to fit about a third of that in there. And then I'd have to alter the pitch and volume of it as I play it back.

Lotta issues to deal with trying to cram all this into such a small space.

There are lots of other D/A converters here:

But there's only five which have 8 bits or less, and the only one of those which is a DIP has 28 pins.

The only one of those five which might be small enough is a SMT part:
http://uk.farnell.com/maxim-integrated-products/ds4404n/5bit-dac-4ch-i-c-adj-14tdfn/dp/1593296

But I'm not actually sure how big it is cause I'm not familiar with SMT, and as I said before I kinda don't wanna get into SMT parts on this build. Too risky.

But I'm not actually sure how big it is

The data sheet says 3mm X 3mm however it's not the eases surface mount part to use because the connections are on the under side. This means you can't use a soldering iron and have to go with a oven or solder paste and a hot air gun. Mind you those packages are OK to mount in the "dead bug" fashion but it is not a neat solution.
However it is an I2C interface and that is not too suitable for audio signals as you can't get the refresh rate very high, although it will run at 400KHz. (that's the clock frequency so divide by ten and get 40K samples / second but that doesn't give you time for anything else.

Found these 8-bit ones on Digikey and Mouser:
http://mx.mouser.com/Semiconductors/Integrated-Circuits-ICs/Data-Conversion-ICs/DAC-D-A-Converters/_/N-6j74uZscv7?P=1yzxgbsZ1z0jd2sZ1z0jd1kZ1z0w0s5Z1z0z7v3&Keyword=dac&FS=True&Ns=Pricing|0

Don't really know the difference between them. I know very little about DACs. For example those cheap ones on Mouser, the first one lists itself as requiring an external voltage reference, while the others use an internal voltage reference of a little over 2v. Not sure what that's about. Is that the max voltage they will output? Why 2v though? Why not 3v or 5v?

This is why I wanted to use the DAC with the wave shield. At least that I know will work. :slight_smile:

The data sheet says 3mm X 3mm however it's not the eases surface mount part to use because the connections are on the under side. This means you can't use a soldering iron and have to go with a oven or solder paste and a hot air gun.

If I were to get into SMT parts, I'd go with a hot plate and solder paste. It seems like the easiest method to me, from the videos I've watched on it.

I'm just afraid of all the ways I could screw it up. Knowing my luck the actual soldering would go fine, but I'd screw up the board design and end up with all my smt pads being covered with solder mask.

Mind you those packages are OK to mount in the "dead bug" fashion but it is not a neat solution.

Does that mean mount it upside down and then solder wires onto it? :slight_smile: NO THANKS.

However it is an I2C interface and that is not too suitable for audio signals as you can't get the refresh rate very high, although it will run at 400KHz. (that's the clock frequency so divide by ten and get 40K samples / second but that doesn't give you time for anything else.

Hm... Those other dacs I linked to are SPI and a quick check indicates that is a lot faster than I2C.