domingo, 14 de abril de 2013

Playing with sound: wtv020sd & LM386

I must say I thought managing sound electronically was simpler than it actually is. Interferences, amplifier distortion, impedance matching, it is not easy to get acceptable quality without knowledge about amplification and speakers, so I didn't get it as good as I expected at the beginning, but learned some things that I am going to share, so you could reach some point better than mine.

The central part of the project was the wtv020sd module from sparkfun.

It is quite easy to manage with this library. You just have to consider this tips:

- Chip works at 3.3V, although some people is using it directly with arduino/atmega digital lines at 5V without problems.. The board from sparkfun comes with a 5V to 3.3V regulator, so there is no problem with the supply, but I prefer to shift digital lines level from atmega using a diode and a resistor, as recommended in tip #10 of this great document from Microchip ( I used a 3k3 resistor as recommended in the forum by ac2013)
- Micro SD standard also works at 3.3V, and it seems that this is the most delicate part, and depending on the SD card the module will work or will not at 5V.
- Take into account the manufacturer recommendations about audio format (ad4, samples here)
- Don't take into account the manufacturer recommendation about SD size limit 1GB, I am using it with a 2GB SD card, formated with FAT (not FAT32).
- The library works good, but you should add a delay in playVoice function, as it reads the busy pin to detect the song's end. 50ms before reading busy pin is enough

The module has two kind of outputs, one PWM to directly connect a speaker , and one 16 bit DAC to connect to an amplifier. The speaker output works perfect, and quite loud, with a 8 ohm speaker. But if you want it  louder you can use an amplifier stage, you have the circuit for LM386 in the manufacturer datasheet:

This is how I built it:

And here is where I reach my limits. I couldn't get a clear sound after the amplifier stage. Even keeping input lines as short as possible, and using all recommended capacitors, with exact values and including 10nF at pin 7 not shown in schematic but useful as I have checked by myself in other audio project, it is used to get 50dB of PSRR = Power Supply Rejection Ratio and it really improves results.

Amplification works quite fine using low values of 10K input potentiometer that regulates volume, but when I increase volume distortion appears. I must say that using LM386 N1  (325mW output power) it works fine even with high volume, but using LM386 N4 (1000mW output power) distortion appears with low volume.

I found this graph in the datasheet,

it relates distortion with output power, for 6V and 8ohm load at 1Khz, and that is exactly what I get, and that are my conditions on load and supply, I get distortion just when the output power is about a 10/20% of maximum (200mW) . So perhaps, if I increase supply and also increase load impedance, I could get same power with less distortion. Let's calculate:

Suppose P1 = V1*I1 = V1*V1/R1, is the power I have now, with 6V supply and 8ohm load

If  I double  voltage (12V) and quadruplicate load (32ohm) :V2= 2V1, and R2=4R1, then P2 = 4V1*V1/4R1= P1, and I2 = 0.5I1, I get the same output power but half output current, so probably less distortion (move the curve in the graph to the right), and that matches with the datasheet that says that 1W power can be obtained with 16V, and 32ohm load..But I don't know if all this reasoning is acceptable, I will apreciate comments, for example output voltage is not linear with input supply, that quits precision to my calculation but not quits all the reason.

Using 9V to supply LM386 I got better results in fact, I could move the potentiometer on the input pin almost to 30% or 40% without distortion. I also measured the input voltage from wtv020sd, that was 1,72V mean, quite high, amplified by a gain of 20 would be more than 30V, which is much more than the supply (= distortion). The maximum gain without distortion would be 9/1.7= 5, that's input pot to 25%.

No hay comentarios:

Publicar un comentario