Monday 5 May 2014

LM386 Stereo Amplifier

I have etched the PCB for the LM386 Ruby amplifier which I talked about in the previous post.  I haven't however populated the PCB as I got distracted!  That happens a lot...The reason I designed and built the amplifier was to provide a simple amplifier for a friend's project....turns out he wants to drive two speakers (Stereo) with mono sounds....and not a single speaker as I had originally understood.  Not to worry all of the previous work won't go to waste and it was development time well spent.

Previous post about the LM386 Ruby amplifier

All we have to do is double up the circuit and combine the volume control and gain controls and we have a stereo amplifier.  It will only be capable of 1 Watt output but that should be more than enough for our purposes.  So in order to combine the volume and gain controls we can use dual ganged potentiometers or dual variable resistors.

Dual gang Potentiometer or dual variable resistor
I also decided that if we aren't going to use the amplifier as a practice guitar amplifier then the gain control potentiometer can be removed to save costs - being able to manipulate the gain and overdrive the speaker is only really something guitar players like - MP3s sound horrible if the speakers are being overdriven.  I replaced it with a 10 uF capacitor which fixes the gain of the amplifier at 200 times whatever the input is up to 1 Watt Pk to Pk or 0.707 r.m.s.   It will be loud enough....I have tested it!!!

Here is the new Schematic:


Next I designed and laid out another PCB...I seem to be doing that a great deal these days....Hopefully I'm getting better at it.  I must use some surface mount components sometime to get with the times although I find through hole manufacturing much easier.  If I were getting PCBS professionally made I may well swap to surface mount.  Here is the new PCB layout:

Stereo LM386 Amplifier top layer

Stereo LM386 Amplifier bottom Layer



I also rendered the design to show how the populated PCB will look when it's been finished.  Here is how it might turn out....I left the dual gang potentiometer off as I intend to solder those on with wires. Here is the render:

Isometric view of how the PCB will look when populated

Top View of the populated PCB
I then went ahead and etched the PCB using the toner transfer method:
  • Print out the reverse image not scaled of the bottom layer on 120 GSM matt paper with a laserjet printer.
  • Using a suitable piece of copper clad PCB and a clothes iron transfer the PCB image to the copper clad PCB.
  • Soak off the paper using water and an old toothbrush to complete the transfer.
  • Etch off the excess copper using a suitable etchant (ferric chloride) in a tank.
  • Clean off the excess ink and lacquer the PCB if available (helps protect the PCB)
  • Drill the holes for the components using a 0.8mm and where necessary a 1mm drill bit and a dremel.
I then populated the PCB with the components in the following order:
  1. Solder the Audio jack connector in the holes indicated by the label U1
  2. Solder the 1M5 resistors (Brown, Green, Green, Gold) in the holes indicated by R2 and R5
  3. Solder the 3k9 resistors (Orange, White, Red, Gold) in the holes indicated by R3 and R6
  4. Solder the 2N5457 Field Effect Transistors (T0-92 three pin D shaped black component) in the holes indicated by U$1 and U$2.
  5. Solder the 47 nF capacitors (yellow component with No.473) in the holes indicated by C1 and C9.  You could substitute these values for 470 nF for an improved bass response...
  6. Solder in two wire links in the holes where the two red lines are on the top layer diagram
  7. Solder in the two 10uF capacitors in the holes marked C4 and C10 - check polarity.
  8. Solder in the two 8 pin IC holders in the holes marked IC1 and IC2.
  9. Solder in the two 100nF capacitors (yellow component with No.104) in the holes indicated by C2 and C6. 
  10. Solder in the two resistors (Brown, Black, Brown, Gold) in the holes indicated by R1 and R4
  11. Solder in the 47 nF capacitors (yellow component with No.473) in the holes indicated by C3 and C7. 
  12. Solder in the two 220uF capacitors in the holes indicated by C5 and C8 - check polarity.
  13. Solder in the three 5mm screw terminal connectors indicated by JP1, JP2 and JP3.
  14. Solder in the 100uF capacitor in the holes indicated by by C11 - check polarity.
  15. Solder in the DC Jack connector in the holes indicated by CN1.
  16. Solder wires to the dual gang potentiometer (use a different colour for each pin)
  17. Solder the potentiometer wires to the holes indicated by JP4 and JP5.  Ensure the middle pin of the potentiometer goes to the middle hole, and top to the top and bottom to the bottom.  Do not crosswire the connections!
Once all the components have been soldered in correctly before fitting the LM386 integrated circuits it is a good idea to apply power and check that the correct voltages are present on the correct pins. Apply 9 Vdc -12 Vdc from a suitable power supply or battery using the screw terminals on JP3 or via the DC Jack connector and ensure that this voltage can be measured on pin 6 of both integrated circuit holders using a multimeter set to measure DC voltage.  If the voltages are present then the circuit should work as anticipated.  If not check the soldering and check again.

Finally insert the LM386 integrated circuits with the pin 1 facing the audio jack socket.  Now it's time to connect some speakers.  Any 8 ohm speakers will be suitable for use with this circuit.  Connect the +VE speaker wire to the inner connection on the 5mm Screw terminals JP1 and JP2 and the -VE connection goes to the outer connection.

Finally attach a suitable audio source (MP3 player, mobile phone or Raspberry PI) to the audio jack input.  Connect a suitable power source as before and play a sound file or an MP3 of some kind...If nothing is heard increase the volume using the dual gang potentiometer.     

Hopefully you will now be enjoying some sweet amplified sounds!  Here are some pictures of my version fully populated:

The circuit fully populated and ready to go!

Fully populated PCB!

Here is a short video showing the Stereo Amplifier in action - Enjoy:


Well that is about it for this post - Next post I think will be on designing an enclosure for this amplifier and testing the LM386 Mono amplifier, take care people - Langster!

Saturday 3 May 2014

LM386 Ruby Amplifier

Recently a friend of mine at HACMan - the Hackspace in Manchester (Shameless plug - HACMan Website) was working on a project of their own when it transpired that they needed a simple audio amplifier. There are so many reference schematics and electronic circuits available for this purpose and this is my first attempt.  I have decided to use a very popular audio amplifier IC called the LM386.  It's an OP-Amp based integrated circuit designed for audio and instrumentation uses.  Here is it's datasheet:

LM386 Datasheet

It looks like this:


The device was first made in 1970's after the LM741 and LM324 by National Semiconductor.  It has a wikipedia entry but there isn't much information on it.  For those that are interested here is the link:

http://en.wikipedia.org/wiki/JRC386

It uses the standard OP-Amp pin out (inputs are on pins 2 and 3 and the output is on pin 5.  Power is applied on pin 6 and ground is applied to pin 4.  The gain of the amplifier is set by pins 1 and 8 and pin 7 is used for an optional bypass used to remove unwanted noise.

In order to use the device there are several reference circuits present in the datasheet and these will all work fine but because this integrated circuit has been around a long time there a also many other circuits around on the internet shared by enthusiasts everywhere.  Rather than 'reinvent the wheel' I am going to talk about an improved amplifier circuit called the Ruby LM386 Amplifier which builds upon the reference design and provides gain and volume control and an FET input filter.  I first learnt about the Ruby LM386 Amplifier from the most excellent website:

http://www.runoffgroove.com/ruby.html

It's a great site with loads of information about audio amplifier circuits and in particular the LM386. I chose the Ruby circuit because it has a low level of complexity, low component count and costs and sounded excellent!

Here is the circuit for the Ruby LM386 Amplifier:


I suppose I should really explain how this circuits works...The input jack shown on the left side of the diagram takes an audio signal from a suitable source such as an MP3 player or an Electric Guitar or Raspberry PI Audio output or whatever the user likes.  This signal will be an alternating signal at around 100 mV.  This input is sent directly to the gate of the 2N5457 JFET (Junction Field Effect Transistor). The drain of this transistor is connected to +12 Vdc and the source of the transistor is connected to 0 Vdc or ground via a 3k9 Ohm resistor as well as a 47nF capacitor.  The transistor will always be on as this device is an N-Type Junction field effect transistor - When the input signal exceeds the VGS off Threshold of the FET the transistor will NOT allow current to flow from the drain out to the source and to the rest of the circuit.  The VGS Off parameter for the 2N5457 is 6 Vdc according to the datasheet and therefore this transistor will always allow current to flow to the rest of the circuit as long as the signal voltage present at the gate is less than 6 Vdc.  In the case of this circuit we are using this FET as a signal level limiter and filter.  Signals which are too high and too fast stop the transistor switching on and are not amplified.  Signals which are too fast and too high cause audible hiss and pops and scratches to be heard by the user.

2N5457 datasheet

The next component in the circuit is a 47 nF capacitor.  This capacitor prevents any DC voltage being presented to the negative LM386 amplifier input and is known as a DC blocking capacitor.   The 47 nF cap also affects the circuit's bass response and changing this value to a higher capacitance will change the circuit's frequency response. The 10k variable resistor next is the volume control.  It is used to reduce the amount of signal presented to the LM386 amplifier negative input which directly affects the output - if there is less signal at the input there is less signal at the output. The gain of the LM386 amplifier (the amount the input signal can be increased) is set by the 1k variable resistor on pins 1 and 8.  The gain is the amount the input signal can be increased - not quite the same as volume but audibly the result is similar.  The gain sets the maximum loudness that can be achieved, the volume sets the amount of input signal present.  If the designer wants a fixed amount of gain this variable resistor could be replaced with a fixed resistor or for maximum gain leave the pins effectively not connected and place a 10 uF capacitor across these pins.

The 100 nF capacitor on pin 7 of the LM386 is a bypass capacitor - it removes some of the unwanted high frequency signals that might be present during the amplification stage - its necessary for high gain operation (which this is).  The output of the LM386 has a 10 Ohm resistor and a 47 nF capacitor connected to ground.  These components improve the bass amplifier response meaning lower sounds are reproduced better.  Next from the output of the LM386 amplifier is a 220 uF capacitor used to block any DC signal that might be introduced by the amplification and finally a speaker is present so that the user can hear the sound!

Here are the parts needed if one were going to make the circuit:

Qty Value Description Parts
1 - 3.5mm Audio Jack U2
1 - 2.0mm DC Barrel Jack CN1
1 100 nF 25V Ceramic Capacitor C4
1 100 uF Capacitor Polarized C1
1 10R 1/4W Resistor R3
1 10k 10k Variable Resistor U$2
1 1M5 1/4W Resistor R1
1 1k 1k Variable Resistor U$3
1 220 uF Electrolytic Capacitor C2
1 2N5457 2N5457 N-channel JFET U$1
1 3k9 1/4W Resistor R2
2 47 nF * 25V Ceramic Capacitor C3, C5
1 LM386 Audio power amplifier U1
1 8 Ohm Speaker 8 Ohm Speaker SP1

* If people want the improved bass response then the value for C3 should be 470 nF.

These parts are available from all good electronic component vendors - RS Components, Farnell, Rapid Electronics and one of my personal favourites in the UK - Bitsbox

They are a fantastic vendor and charge reasonable prices for low quantity orders and once an order is processed it is normally shipped and posted and arrives the very next day - awesome!

Once a circuit has been designed before constructing a finished version its always a good idea to prototype first.  I always prefer it when I have prototyped first because it means I can change values and see the results and tailor things if required.  Even better before prototyping if you have the software you can simulate.  I use National Instruments Multisim to simulate my electronic circuits but there are many available - LT Spice is also very good.  Here is a short video showing the circuit being simulated:


Just for fun I also used the circuit simulator to calculate the circuits frequency response.  This information tells the designer how well the amplifier will reproduce sound from low level bass sounds, through the mid tones and to the treble tones.  In practice this would be performed with a signal generator and a signal sweep from 20 Hz to say 20 MHz.  As I still haven't finished my signal generator we will have to settle for simualtion ;).   Here is the amplifier's frequency response - I performed an AC analysis on the output of the circuit:

LM386 Ruby Amplifier frequency response using a 47nF Capacitor at the input
What this graph shows is that lower frequency signals (bass sounds) are not as well reproduced as higher frequency sounds because the red trace is lower on the left side than on the right side.  The black vertical lines show the frequency range of human hearing.  If we were to change the circuit configuration and component values slightly it might be possible to improve the amplifier's frequency response - to try to make sure all the tones of the music are present .  The issue is that by changing the circuit response we will affect the mid tone and treble tone response which at the moment is very flat - all sound with middle and high frequency content will be very faithfully reproduced.  Electronic circuit design is often a compromise and this is one of those cases.  I have decided to keep the circuit as it is and leave nothing changed.  If the user were to change C3 from 47 nF to 470 nF the Bass frequency response is much improved...


Now that the circuit design has been completed it's time to layout a printed circuit board (PCB).  I used Eaglecad to design and place where the physical electronic components are sited on a piece of FR4 copper coated glass fibre sheet.  I will chemically etch some of the copper away to create the circuit. Once I have drilled the holes for the component legs the soldering can begin:

Top Layer of PCB Layout
Bottom Layer of PCB Layout
Just for fun and to show how this PCB would look when professionally made I rendered the design using Eagle3D a user language program (ULP) addon for EagleCad.  Here are the results:

Top Layer
Bottom layer

Here is how the PCB Will look when it's populated with components:

Eagle3D render with PCB Populated
I haven't actually made this PCB yet so I can't show pictures of the final product.  I have prototyped the circuit on breadboard however and here is a photo and some video of the prototype working.  

LM386 Ruby Amp on breadboard
The prototype circuit in operation playing some Vivaldi

I have now etched a PCB and made a permanent version of the Ruby Guitar Amp - Here it is in all it's completed glory:


Here is a quick demonstration of the Guitar amplifier playing an MP3 - I don't have an electric guitar at the moment :(


Well...that is all for now people, thanks for reading and please post any comments you might have.  I intend making some kits for this project available - watch this space...take care always - Langster

Bare PCBS for this project can be purchased here:

Lang Electronics Design Web Store

I have also shared the design files here, I hope this helps people make their own versions of this circuit:

Eagle Files for the LM386 Ruby Amplifier

UPDATE ---- Veroboad or Stripboard version for prototype construction

A youtube user watched the video of the circuit simulation asked if I could show how to construct this circuit using veroboard or stripboard.

Stripboard or veroboard is a product used by electronics engineers and hobbyists alike to construct electronic circuits.  I'll be honest I don't like using it very much.  I find it difficult to use and it takes me a very long time to place all of the components correctly and I always make mistakes and my circuits are always big and ugly!  It is also very common to make a mistake when soldering up the circuit and invariably components have to be removed and resoldered.  I prefer etching a PCB because then all of my parts fit the circuit board perfectly by design and no issues occur and I tend to make less mistakes!

There are some software packages designed to help with stripboard layout.  I never found them to be particularly good.  Here is a link to a website which discusses this further:

http://www.electroschematics.com/2270/veroboard-design-software/

I used a demo version of Lochmaster to layout a version of the LM386 Ruby amp.  I was pleasantly surprised about how easy it was to use the software and I may well consider using it again in the future. I feel it is a little expensive for the full version (the demo version is software limited, no saving or post editing etc) but it was just what was needed to show how to perform a stripboard layout of the ruby amplifier.  Here is a link to the website where it can be downloaded:

http://www.abacom-online.de/uk/html/lochmaster.html

Here are some screenshots of the layout for the Ruby Amplifier - I used a specific type of veroboard as requested:


Top side of  Veroboard LM386 Ruby Amplifier layout

Bottom side of Veroboard LM386 Ruby Amplifier layout
If I were making the circuit I would follow the steps below:

  1. Obtain all of the components required, including connecting wire of at least three different colours - I used Red (+VE), Black (0V) and Green (Signal)
  2. Obtain all of the tools needed - Soldering Iron, Solder, Wire cutters, wire strippers, pliers, desoldering tools etc.
  3. Get a printed copy of the schematic diagram to refer to.  Also print out the above two diagrams also - they may come in handy
  4. Solder all of the 0V wire link connections - there should be eight connections from wire links to the 0V bus (track running along the bottom)
  5. Solder all of the +VE wire link connections - there are only three connections needed
  6. Now it is probably a good idea to solder in the IC holder and the 2N5457 transistor - make sure the IC holder is the correct way around with pin 1 on the bottom and the 'bite' on the left side.  Make sure the transistor is in the correct orientation also...
  7. Solder in the resistors next - it doesn't matter which order or in which orientation.  Resistors work in either direction - perfectionists like to make sure they all face the same way (it makes it easier to read the values).
  8. Solder the small capacitors next (47nF, 47nF and 100nF), as with the resistors orientation is not important.
  9. Next it's time to solder the screw terminals for the input or output.  If needed the input screw terminals can be replaced with a 1/4" audio jack or similar connector.  The output screw terminal can be replaced with wires directly soldered onto the speaker - it's up to you the maker!
  10. Next it is time to solder the electrolytic capacitors (100uF and 220uF).  The polarity of these devices matters!  Please pay attention - the stripe on the body of the capacitor denotes the -VE terminal.  The 100uF capacitor is connected across if the incoming supply with the -VE terminal connected to 0V and the +VE terminal connected to +VE.  The 220uF capacitor +VE terminal is connected to the wire link coming from pin 5 of the LM386 and the -VE terminal is connected to the output screw terminal or to a pad connected to the speaker.
  11. Now it is time to solder the potentiometers or variable resistors.  Follow the diagram about and either directly solder the pots as shown or use wires and make the same connections - Its up to you as the maker to decide how the components are connected
  12. Finally check all of the connections and solder joints - check for short circuits and issues using a multimeter....fix any mistakes before carrying on - Good Luck!
  13. I like to count connections to the +VE and 0V referring to the schematic to make sure I haven't made any mistakes - there should be three +VE connections not including the power wires and there should be ten 0V connections if all of the components are connected.  There are also 6 wire link connections present in order for this circuit to work... 
The power from the battery or power supply is applied to the top two straight tracks labelled +VE and 0V.  Check that power is present between 0V and pin 6 on the IC before removing power and inserting the LM386 (we don't want to blow up the amplifier).  Next connect an audio source (MP3 player, signal generator or electric guitar) to the input screw terminals via wires or using a connector.  Finally make sure there is a speaker connected to the output via screw terminals or directly and then apply at 5 to 18V at 500mA to hear sound!  

I would then look at putting the circuit inside some kind of enclosure but thats for another post...

Enjoy!