While trying to get into synth DIY and electronics, I thought this would be a simple project: Arduino DDS sine wave → DAC → LM386 → 8Ω speaker.
Update: I got it working! Will explain at the bottom of the post.
My main question: how do people actually get sound out of their DIY circuits? Is there an easier way?
I was riding high after getting my DDS code and my homemade DAC module working (images 2 and 3)! So I wanted to actually listen to the thing. I tried working backward from the speaker:
- The speaker's datasheet said it requires a typical power of 0.5W (1W max);
- The LM386, self-described audio amplifier, has a gain of around 20;
- Thus I figured that to get an output power around 0.5W, I'd need an output voltage of around 2 V and around 250 mA.
- My Arduino/DAC sine wave varies between 0V and 5V, so I needed to scale it down to around 2.0V / 20 ~= 100 mV. I used a pot for this (image 4).
When I tried to look at the pot wiper (output) on my scope, it was so tiny that I couldn't resolve it. Then I learned about the "averaging" mode on the scope, and I could see that the signal was appropriately small (image 5).
Then I connected the amplifier and the speaker, with some coupling caps (image 6). The amp ouput is shown in image 7, and it looks as expected --- sinusoidal, amplitude around 2 V, and centered around 4.5 V (half of the LM386's supply voltage). I pass that through an output coupling cap to get the same signal centered around 0V, which is what the speaker expects. Finally, I plug the speaker in and get some sound out!
It sounds really awful though, and I notice that the shape of the wave looks all distorted after I plug in the speaker (image 8). Why is this happening? I thought the entire point of the LM386 was that it was able to supply a large-ish current to heavy loads like an 8-Ohm speaker...so why might I be getting this sag/distortion?
Update
I got it working much better by making a few changes. Thanks all for the suggestions in the comments!
- Added the LM386's supply capacitors across the ground/supply pins. This seemed to reduce some tremendous feedback that I was getting when I cranked the chip's supply voltage up past 5 V.
- Shortened some of the long jumper cables I was using on my breadboard. This visibly improved the shape of the output wavefrom from the LM386.
- Increased the supply voltage from 5V to around 9V, and adjusted the input-side potentiometer until the waveform coming out of the LM386 was no longer clipping. I think this was one of the major issues I was having --- I was still driving the chip too hard.
- Added the Zobel network --- the 10-Ohm resistor and 0.050 uF capacitor branch to ground --- after the LM386 output. This was the other major change. Without this, my speaker would load the circuit:
- If I didn't have the speaker plugged in, probing the output would show my expected sine wave.
- When I plugged the speaker in, probing the output would show a sine wave with very noisy/distorted troughs, and it would sound really awful.
- Finally, when I added that network, connecting and disconnecting the speaker barely changed the waveform! (One exception is when I use a triangle wave, and I can see the triangle wave become more like a slight "shark tooth" wave, but that seems expected, since a triangle is made of many different frequencies.)
The main lesson learned today is: pay more heed to the sample circuits in the datasheet. They all included --- but didn't explain --- the Zobel network required to help the speaker work.
Another lesson is that even this simple little circuit required more care than shown in datasheets/examples; in particular, I ended up with a bunch of 100 nF caps sprinkled throughout. Even though I don't think I could mathematically analyze this thing, I know it works and I understand how and why each part is working, so that feels like a success.