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! 


Saturday, 22 March 2014

How to make a Printed Circuit Board!

Its been a while since I posted!  One of the blog subscribers has asked me to write a step by step guide on how to make a printed circuit board.  There are many guides available online already and this is my version. I hope people find it useful.

There are several methods of making a permanent electronic circuit.  Engineers and makers alike use many different methods.  The most popular by far is making a printed circuit board or PCB.  The board material or substrate itself is a glass reinforced plastic sheet material is known as FR4.

FR4 wikipedia entry

Its a a glass reinforced plastic sheet designed specifically for the purpose of supporting electronic components.  The FR4 material is cladded or coated in copper on either one or both sides to allow the electrical circuit to be made.

PCB wikipedia entry

For hobbyists and makers there are two distinct methods of manufacturing a PCB.  The design or layout for the electronic circuit is drawn as a series of lines and shapes in a suitable piece of design software, printed on a transfer medium such as glossy paper or acetate sheet.  This design is then transferred to the copper clad FR4 sheet either by exposure to ultra-violet light or by using heat to transfer the design.

Before this can begin the following materials will need to be obtained:

1x piece of copper clad FR4 PCB material
It needs to be slightly larger than the total area of the design you intend to make.  If you are looking to use the UV exposure method ensure you buy UV resist coated FR4 PCB material.




Buy FR4 Single Sided PCB from EBAY - not UV resist coated and therefore much cheaper!

Buy UV coated single sided PCB from EBAY - UV coated and therefore more expensive

Some glossy paper or acetate sheet for transferring the design

120 GSM glossy paper - matt one side, smooth on the other (for the toner transfer method)

Inkjet compatible acetate sheet - (for the UV exposure method)

A clothes iron or a plastic film laminator - (toner transfer method)
As a clothes iron can be obtained just about anywhere I'm not going to provide a link!



A UV light source - (UV exposure method)
These aren't cheap so I made my own with a load of UV LEDS and a small power supply but a daylight bulb or a professional light box can also be used.

Professional UV exposure box - EBAY, very expensive!!

I made a UV light source similar to the one detailed here using LEDS, resistors and some veroboard and a 12V power supply.  The guide is also very informative:

How to make a UV Light Box - Cheaper, but you will need at least 30 UV LEDS, 30 75 Ohm Resistors, a 12V power supply, solder, wire, tools and a black plastic box to put the light source in.  You don't want to be able to see the UV light.  It damages your eyes!



UV BlackLight Bulb - Cheaper and quicker still - use a Blacklight to expose the design on to the PCB.



Some development solution - (UV exposure method)

Universal development granules - You will need to add tap water to the granules in order to make up the solution.  Follow the instructions provided.  You will need a plastic bottle to store the solution for later.



Another supplier of Development Solution

A plastic tray for the development solution and to hold the PCB material



An etch tank or plastic tray to hold and store the etching fluid
I made a special tank for this with a PCB holding net and an air pump to agitate the PCB etchant.


Some PCB Etching Fluid - (Both methods)

I use ferric Chloride which can be bought in powder or crystal form and then tap water is added to make up the PCB Etching Fluid



Finally some latex or rubber gloves, some eye protection goggles a lab coat or work clothes and some plastic tweezers - These should all be available on EBAY or locally in a hardware store.




Once you have obtained all of these things the process can begin...Exciting times!

The first thing you will need after you have got all of the required items is the PCB layout you wish to make a printed circuit board for.  There are several software packages that electronics engineers and makers use for this purpose.  I use EagleCad.  It's an open source program developed by cadsoft which can be downloaded here:


Next you will need to draw the schematic diagram and then design the PCB layout.  I won't go through the nuances of using the program here as it takes a long time and there is much to discuss.  If a tutorial on using eagle is needed please let me know in the comments section.

I have posted many images of schematics in various previous posts.  Below is an image for an arduino shield I have designed.  It's an audio amplifier using a very popular LM386 amplifier.


The parts list for this circuit:

1x LM386 audio amplifier
1x 10uF Electrolytic Capacitor
1x 220uF Electrolytic Capacitor
1x 47nF Ceramic or mica film Capacitor
1x 10 Ohm Resistor
1x 10k Potentiometer
100x Male pin Headers for connections
1x piece of single sided FR4 printed circuit board - dimensions to follow

Once I had drawn the schematic I laid out the electrical connections to make a single sided PCB:  The screen shot below shows the design and the components arranged and all of the tracks connected.  To make the PCB we will need to print out this design with just the blue tracks and green pads displayed.


So in order to do that I need to turn off the 'layers' in eagle that are not required:


At this point we are ready to start the preparations for making our PCB.  I will do the process for the UV transfer method first.

UV Transfer Method of making a PCB:

1.  With the PCB layout complete as above print out the layout with only Pads, tracks and overall dimensions of PCB displayed.  Load the printer with printer friendly clear acetate sheet.  Ensure printing is not scaled (1:1) or mirrored and is in black and white.  I like to make a PDF of my layout as I find it prints with a slightly darker hue.  I also use a laser printer as I have found these work better.

2.  Next its time to take the print out of the design on acetate and cut it to size.  After it's printed make sure you know which way up the design is.  You don't want to mirror the design!

3.  Next cut out the pre sensitised PCB to size.  Leave a little extra just in case at the edges.  Do not peel off the protective film and expose the PCB yet!  Once it's cut to size take the acetate print out of the layout (cut that to size) and place it on top of the PCB, Now peel off the protective film and place the acetate on the pre-sensitised copper layer - ensure you have the design the right way up as you don't want to mirror the layout!  Hold the layout in place with box clips or masking tape.  Make sure you don't obscure any of the layout!



4.  Expose the PCB and combined acetate layout to UV light for at least ten minutes.  Some experimentation at this stage may be necessary.  Sometimes it takes a longer or shorter time.  There is no empirically correct exact time.  Once complete remove the UV light source and then take the acetate off the copper clad PCB material.  Again take care not to mark the sensitive copper side with fingerprints.  I have heard that it is possible to expose UV sensitised PCBS using sunlight.  I don't know how long the boards are exposed for or how effective this is - I just know it should be possible as there is UV light present in sunlight...

5.  Make up some of the sodium hydroxide development solution following the instructions given.  Don't mix up more than you need as I find the solution does not keep well.  Place the exposed PCB in the developing tray (clean plastic tray or box).  Gently agitate the solution over the PCB until you start to see the layout appear as a brown or green coloured design.

 

As soon as the design is fully exposed remove the PCB from the development solution and place it in some clean tap water.  It is important to stop the development solution over exposing and clearing all of the tracks off.  If you over expose you will have to start again with a new piece of pre-sensitised PCB....practice makes perfect and I have had mixed results.  It is why I prefer to use the toner transfer method of making PCBS.

6.  Once the PCB design has been properly transferred to the PCB it's time to etch the uncoloured copper away using the ferric chloride or whichever etchant fluid you are using.  Place the PCB in the etch tank with the design facing up or into a plastic box filled with etchant or suitable etchant container.  Make sure it is not metallic as ferric chloride or any etchant for that matter eats through most metals!


7.  Gently rock and agitate the etchant for about ten minutes.  Using plastic tweezers or taking care roll the etch tank to one side so that you can see the design.  See if the unexposed copper has been removed.  If it hasn't continue agitating the solution until it has been completely removed.



8.  Remove the PCB from the etching fluid and clean it using tap water.  Be careful not to get etching fluid onto anything metallic.  You should be left with a very clean and detailed etched printed circuit board!

9.  Drill out any holes as required - my designs are nearly all through hole so I have lots of drilling to do!

10.  Finally populate and test your PCB - hopefully it will work first time - Good luck!

Toner Transfer method of making a PCB:

1.  Load a laser printer (it has to be a laser printer) with 120 GSM glossy paper.  Make sure the smooth side is the side that is presented to the toner ink. Print out the PCB layout with only the tracks, pads and dimensions present.  Be sure the printout is mirrored before you begin.



2.  Once you have the printout on glossy paper its time to get hold of the blank copper clad PCB material. Cut it to size and clean the copper using a polishing block or pencil eraser.  The copper area needs to be cleaned to remove any excess dirt or grease.  At this point I wear plastic or latex gloves to prevent finger prints.  You could also use wire wool.


3.  Heat up a clothes iron to as hot as possible - make sure there is no water in the iron (if its a steam iron). Place the printed PCB layout toner side down onto the cleaned copper side of the PCB.  If needed secure the printout in place using masking tape or box clips.  I use an old piece of wood to press down on when I iron on the design.  The heat causes the toner to transfer from the paper onto the PCB; About 5 minutes of ironing should see the design properly transferred.  Practice makes perfect!


4.  Once you are happy the design has been transferred turn off the iron and place the PCB into a bucket of cold tap water.  Be aware the PCB is probably quite hot so use suitable heat protective gloves or tongs! You can just leave the PCB to cool but I'm impatient!  Next soak the paper off the PCB exposing just the ink and the copper.  I like to use an old toothbrush to clean off the excess paper.

5.  Once complete inspect your transfer.  You should be able to read any text present and there should be no broken tracks.  If there are broken tracks you can touch them up using an acid resistant marker pen like the permanent markers used for writing on acetate sheets.  If the design didn't transfer well at all you can clean off the toner and repeat the process from step 3 onwards.  Again practice makes perfect and this is why I prefer the toner transfer method.  I can rectify mistakes early on.



6.  Now it's time to etch the PCB using the etchant of choice.  Place the PCB in the etch tank with the design facing up or into a plastic box filled with etchant or suitable etchant container.  Make sure it is not metallic as ferric chloride or any etchant for that matter eats through most metals!



8.  Gently rock and agitate the etchant for about ten minutes.  Using plastic tweezers or taking care roll the etch tank to one side so that you can see the design.  See if the uncovered copper has been removed.  If it hasn't continue agitating the solution until it has been completely removed.

9.  Once all of the uncovered copper has been removed take the PCB out of the etch tank and clean the PCB in tap water.  Once all of the ferric chloride has been removed, clean off the black toner using wire wool or something suitably abrasive.  You should be left with something similar to the picture below:


10.  After that it's time to drill any holes required using a suitable pillar drill and drill sizes before populating your PCB with components and soldering it up.  Hopefully if it was designed properly it will perform the function you require!

Well that's about it.  I hope this guide is useful to people.  Please comment or contact me if you need more help or information.  That's about it for now - take care always - Langster!

Wednesday, 29 January 2014

mbed controlling a 4D Systems uLCD-43PCT and four LEDS

Hi, I have been playing with the Mbed Microcontroller and the 4D Systems Capacitive 4.3' touchscreen.  In order to familiarise myself with the nuances of the system and because I was asked by a reader of the blog if something was possible....So here we go - this is an example of how to use the 4D systems touch screen to turn four leds on and off.  To keep things simple I am using the four LEDS already present on the Mbed LPC1768 however any LEDS connected to any pins could be used.

So here is the schematic - I'm a great believer in schematics!


I then loaded up 4D Systems graphical development environment - Workshop 4 ready to develop the touchscreen display:


Next to start a completely new project I clicked on the appropriate 'Create a new Project Button'  When presented with the following screen I scrolled down to the appropriate display type - in my case a 4.3 inch capacitive touch screen.  I chose the landscape non reversed orientation because I'm lazy and haven't really decided how I am going to mount the display, all possible permutations of orienting the display are catered for.


Click next when you are ready to continue and the following choose your development environment screen is displayed - Lets choose Visi-Genie because its the most simple and quick to use; I can't stress how good and easy this development environment is!!


The next screen displayed is the workshop for graphical development environment.  On the left side of the screen is what is referred to in the manual as the 'WYSIWYG' of the touch screen.  What you see is what you get - quite literally.  On the right side of the screen are all of the attributes available for the graphical screen objects that you as the designer may place on the WYSIWYG screen:


As I'm doing an example of lighting some external LEDS with some buttons lets add some button objects:

Click on the 'Buttons' tab and then on the fancy buttons icon ( icon with a spanner on an orange background) :-


Next click on the WYSIWYG touch screen to place a 'fancy button' - it will automatically be called winButton0:


On the right side of the screen the 'object inspector' will show all of the pertinent attributes for the winButton0 object.  Lets modify the button so that it is no longer a momentary button and give it a better label than winButton0 and lets also have the display show when the button has been actuated 'On' and 'Off':

Make sure the properties tab is selected

Click on the caption field and change it from winButton0 to something more appropriate - I chose LED 1

Click on the momentary field and change it from 'Yes' to 'No'

Expand the 'StatusWhenOff' field and change the BGcolor to Green and the caption to 'Off' or whatever you like

Expand the 'StatusWhenOn' field and change the BGcolor to Red and the caption to 'On' or whatever you like


You might notice that the WYSIWYG display updates the winButton0 object with your changes...and displays the correct caption and shows the button in 'Off' state.

Next click on the Digits tab and select a userLed object and then click on the WYSIWYG screen:


Update the object attributes for the userLed0 object so that it shines blue on activation - you could choose any colour you liked however the LEDS on the Mbed are blue so I thought it should match!

Once you have done all of that which should only take about five minutes we can then get on with the interactive part of the display control.  What we want to do is have the display send a message to the host microcontroller when the button state changes from 'off' to 'on'.  At the same time we would like to update the userLed0 object on the display from 'off' to 'on' so that the display userLed0 object matches the Mbed LED.  So what we are going to do is use the host microcontroller (Mbed) to poll for an event concerning the winButton objects.  If the winButton Objects report a message then we know that a button has been pressed and it's state will have changed from Off to On.  All we then have to do is get the host micro to send a message to the display telling the virtual LED to change state also and at the same time turn the corresponding actual LED on.

The way this is achieved is to click on the winButton0 object on the WYSIWYG screen and then click on the events tab and then click on the onChanged field.  There should be three options - Report Message, Form0 and userLed0Set - choose ReportMessage and click ok.




As there are four LEDS on the Mbed LPC1768 I repeated this process three more times so that there are four button objects and four virtual LED objects.  All the winButton objects need to be set up to respond on touch to light the corresponding virtual LED and report a message when their state changes.

This is what you should see now if you are ready for compiling and sending to the display:


Now is the time to save your project and ensure all settings are correct.  Save the project as something sensible - I called mine mbedTest but it can be called anything you like.  Click on the comms tab and ensure that your display is connected and the COM port for controlling the display is present. Next click on the project tab - Set the appropriate COM port speed for your project.  In this case speed is not an issue so I chose 9600 baud:


Now its time to upload our touchscreen layout to the display.  Click on the home tab and then click on the 'Build Copy Load' icon.  The design will be compiled and uploaded to the display.  You will be prompted to copy the files to the microSD also.  Once complete remove the microSD card from the reader and put it into the display.  You should be presented with your design on the display and when you touch the buttons they should respond appropriately  - <BIG GRIN>

That should have taken about ten minutes - it probably took longer to read all of this text, it certainly takes me longer to type it!

Now we are on to coding the firmware for Mbed LPC1768 which I am using as the host microcontroller.
Load up and log into the online compiler for the Mbed  in the browser of your choice:

Then start a new program using the blinky LED template, call the program something sensible.


Next import the library files mbed_genie.cpp and mbed_genie.h.  These are the library files which tell the mbed how to control the 4D systems touchscreen display.  Finally paste in the following code:

#include "mbed.h"
#include "mbed_genie.h"

DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);

bool winButton0Status = false; //holds the "status" of winButton0 object.
bool userLed0Status = false;   //hold the "status" of userLed0 object.

bool winButton1Status = false; //holds the "status" of winButton1 object.
bool userLed1Status = false;   //hold the "status" of userLed1 object.

bool winButton2Status = false; //holds the "status" of winButton2 object.
bool userLed2Status = false;   //hold the "status" of userLed2 object.

bool winButton3Status = false; //holds the "status" of winButton3 object.
bool userLed3Status = false;   //hold the "status" of userLed3 object.


//Event handler for the 4d Systems display
void myGenieEventHandler(void)
{
    genieFrame Event;
    genieDequeueEvent(&Event);

    if(Event.reportObject.cmd == GENIE_REPORT_EVENT) {

        // If the Reported Message was from winbutton0 and userLed0 is off

        if (Event.reportObject.object == GENIE_OBJ_WINBUTTON) {
            if ((Event.reportObject.index == 0) && (userLed0Status==false)) {
                printf("LED1 High \r\n");
                wait(0.1);
                winButton0Status=true;
            }
        }

        // If the Reported Message was from winbutton0 and userLed0 is on

        if (Event.reportObject.object == GENIE_OBJ_WINBUTTON) {
            if ((Event.reportObject.index == 0) && (userLed0Status == true)) {
                printf("LED1 Low \r\n");
                wait(0.1);
                winButton0Status=false;
            }
        }

        // If the Reported Message was from winbutton1 and userLed1 is off

        if (Event.reportObject.object == GENIE_OBJ_WINBUTTON) {
            if ((Event.reportObject.index == 1) && (userLed1Status==false)) {
                printf("LED2 High \r\n");
                wait(0.1);
                winButton1Status=true;
            }
        }

        // If the Reported Message was from winbutton1 and userLed1 is on

        if (Event.reportObject.object == GENIE_OBJ_WINBUTTON) {
            if ((Event.reportObject.index == 1) && (userLed1Status == true)) {
                printf("LED2 Low \r\n");
                wait(0.1);
                winButton1Status=false;
            }
        }

        // If the Reported Message was from winbutton2 and userLed2 is off

        if (Event.reportObject.object == GENIE_OBJ_WINBUTTON) {              
            if ((Event.reportObject.index == 2) && (userLed2Status==false)) {
                printf("LED High \r\n");
                wait(0.1);
                winButton2Status=true;
            }
        }

        // If the Reported Message was from winbutton2 and userLed2 is on

        if (Event.reportObject.object == GENIE_OBJ_WINBUTTON) {              
            if ((Event.reportObject.index == 2) && (userLed2Status == true)) {
                printf("LED Low \r\n");
                wait(0.1);
                winButton2Status=false;
            }
        }
        
        // If the Reported Message was from winbutton3 and userLed3 is off

        if (Event.reportObject.object == GENIE_OBJ_WINBUTTON) {              
            if ((Event.reportObject.index == 3) && (userLed3Status==false)) {
                printf("LED High \r\n");
                wait(0.1);
                winButton3Status=true;
            }
        }

        // If the Reported Message was from winbutton3 and userLed3 is on

        if (Event.reportObject.object == GENIE_OBJ_WINBUTTON) {              
            if ((Event.reportObject.index == 3) && (userLed3Status == true)) {
                printf("LED Low \r\n");
                wait(0.1);
                winButton3Status=false;
            }
        }
    }
}


int main()
{

    SetupGenie();

    genieAttachEventHandler(&myGenieEventHandler);

    printf("Langsters's mbed Visi-Genie LED demo \r\n");

    genieWriteContrast(15); //set screen contrast to full brightness

    while(1) {

        //check if winButton0 is High & set LED0 High 

        if (winButton0Status == true) {
            printf("Button 0 in On State! \r\n");     //send button status message
            genieWriteObject(GENIE_OBJ_USER_LED, 0x00, 1); // set virtual LED0 High     
            wait(0.1); // wait 100uS
            led1 = 1; // set actual LED1 High
            userLed0Status = true; // set userLed0Status High

        }

        //check if winButton0 is low & set LED low 

        else if (winButton0Status == false) {
            printf("Button 0 in Off state! \r\n");    //send button status message
            genieWriteObject(GENIE_OBJ_USER_LED, 0x00, 0); // set virtual LED0 Low      
            wait(0.1); // wait 100uS
            led1 = 0; // set actual LED1 Low
            userLed0Status = false; //set userLed0Status Low

        }
        
        //check if winButton1 is High & set LED High 
        
        if (winButton1Status == true) {
            printf("Button 1 in On State! \r\n");     //send button status message
            genieWriteObject(GENIE_OBJ_USER_LED, 0x01, 1); // set virtual LED0 High     
            wait(0.1); // wait 100uS
            led2 = 1; // set actual LED2 High
            userLed1Status = true; // set userLed1Status High

        }

        //check if winButton1 is low & set LED low 

        else if (winButton1Status == false) {
            printf("Button 1 in Off state! \r\n");    //send button status message
            genieWriteObject(GENIE_OBJ_USER_LED, 0x01, 0); // set virtual LED0 Low      
            wait(0.1); // wait 100uS
            led2 = 0; // set actual LED1 Low
            userLed1Status = false; //set userLed1Status Low

        }
        
        //check if winButton2 is High & set LED High 
        
        if (winButton2Status == true) {
            printf("Button 2 in On State! \r\n");     //send button status message
            genieWriteObject(GENIE_OBJ_USER_LED, 0x02, 1); // set virtual LED0 High     
            wait(0.1); // wait 100uS
            led3 = 1; // set actual LED2 High
            userLed2Status = true; // set userLed1Status High

        }

        //check if winButton2 is low & set LED low 

        else if (winButton2Status == false) {
            printf("Button 2 in Off state! \r\n");    //send button status message
            genieWriteObject(GENIE_OBJ_USER_LED, 0x02, 0); // set virtual LED0 Low      
            wait(0.1); // wait 100uS
            led3 = 0; // set actual LED1 Low
            userLed2Status = false; //set userLed1Status Low

        }
        
        //check if winButton3 is High & set LED High 
        
        if (winButton3Status == true) {
            printf("Button 3 in On State! \r\n");     //send button status message
            genieWriteObject(GENIE_OBJ_USER_LED, 0x03, 1); // set virtual LED0 High     
            wait(0.1); // wait 100uS
            led4 = 1; // set actual LED2 High
            userLed3Status = true; // set userLed1Status High

        }

        //check if winButton2 is low & set LED low 

        else if (winButton3Status == false) {
            printf("Button 3 in Off state! \r\n");    //send button status message
            genieWriteObject(GENIE_OBJ_USER_LED, 0x03, 0); // set virtual LED0 Low      
            wait(0.1); // wait 100uS
            led4 = 0; // set actual LED1 Low
            userLed3Status = false; //set userLed1Status Low

        }        
        

    }

}

------------------------------------------------------------------------------------------------------------

You can also import the code as an example from the Mbed cookbook here:

mbed 4D LED Test

The code is fairly simple to understand and is well documented so I'm not going to discuss it more here.

Here is a video showing the screen working - Enjoy.



That's all for now - Langster!