langster1980

I'm an electronics engineer and uber geek. I mostly spend my time working on electronics projects. I do a lot of development using microcontrollers - particularly using the arduino and mbed....

langster1980 wrote 58 posts

Designing A USB Breakout Board!

I often need to intercept USB signals for decoding and measurement purposes.  I cut a cable apart last time I needed one but to be honest I much prefer doing things properly.  I also noticed that nobody seems to sell a similar product on Ebay, Aliexpress or Amazon!  I did find a vendor in the USA on tindie:

USB Inspector
Image Copyright – Misperry via Tindie

https://www.tindie.com/products/misperry/usb-inspector/?pt=full_prod_search

I also found this product on tindie which is similar but has a current monitoring circuit built in:

https://www.tindie.com/products/Kaktus/usbuddy-usb-development-tool/?pt=full_prod_search

A friend of mine and blog reader found this one:

https://friedcircuits.us/50?search=usb

Either of these products would work for my purposes but the first product’s shipping costs from the USA seem a little extravagant and I only wanted one or two.

The second product uses pin headers to allow connection which are a bit close together for my liking. It’s often the way of things.  When I cannot obtain what I want I make my own!

The circuit is very simple:

The PCB layout is a little more complicated.  I would like to keep the board as small as possible but maintain the recommended conductor impedance that a USB cable should have.  By maintaining the impedance it means that signals can be correctly measured and power is not needlessly wasted.  The USB specification document is possibly one of the hardest pieces of technical literature I have had to read.  I don’t recommend it unless absolutely necessary:

http://www.usb.org/developers/docs/usb20_docs/#usb20spec

There is also a standard for USB cables which dilutes the information into a slightly more readable format (note – I am being overly sarcastic):

BS EN 62680-2-3:2015

The standard is not free to read however…but memberships to local and university libraries yields useful results.

A USB 2.0 cable must have many specifications but the two most critical that I am interested in are:

  • Cable impedance – 76.5 Ω to 103.5 Ω
  • Current carrying capability – 500 mA (standard) or 1.5 A from a dedicated charging port.

The information on the current carrying capability is confusing as there is mention of 5 amps on the wikipedia article:

https://en.wikipedia.org/wiki/USB#Power-use_topology

So based upon the above information we need to ensure the board layout has tracks capable of carrying 1.5 Amps of current at 5 Vdc and that the data pairs D+ and D- are routed as a differential pair with 90 ohms impedance.  I picked 90 ohms as a reasonable middle value and it was cited in this application note from Silicon Labs:

https://www.silabs.com/documents/public/application-notes/AN0046.pdf

Here is a useful article on layout guidelines for differential pairs:

http://www.eetimes.com/document.asp?doc_id=1144365

Basically I want to make sure my breakout board doesn’t ruin the USB signals by interrupting them. USB cables are actually proper transmission lines and the cable should be screened and the internal cables twisted to maintain uniform impedance.  The D+ and D- tracks which are differential signals will need to be routed close together above a solid ground plane (Microstrip transmission line) ensuring that both tracks are exactly the same length.  Most PCB routing software like eagle have built in calculators and tools to assist with this.

Here is an excellent (and free) online trace width calculator:

http://www.4pcb.com/trace-width-calculator.html

I entered the following information into the calculator:

  • Current: 1.5 Amps (I’m going with the lower value specified)
  • Copper thickness: 35 µm (Standard 1 oz copper thickness for FR4 PCB material)
  • Temperature Rise: 10 °C (Just a guess)
  • Ambient Temperature: 25 °C (Just a guess)
  • Trace Length: 35 mm (just a guess for now)

I’m only going to have a two layer PCB so I’m only interested in external traces.  Here is what the calculator came up with:

  • Required Trace Width: 525.491 µm or 0.525491 mm
  • Resistance: 33.612 mΩ
  • Voltage Drop: 50.419 mV
  • Power Loss: 75.628 mW

So that sets the PCB track thickness to be at least 0.6 mm.  I may well go with 1 mm as space should not be a problem.

Next we need to set the track impedance above a ground plane which is otherwise known as a microstrip transmission line.  Here is another very useful (and free) calculator:

https://www.eeweb.com/toolbox/edge-coupled-microstrip-impedance

If people need to read up on what an edge coupled microstrip layout is then please check out the link below.  It is essentially a method of setting the impedance of PCB tracks based upon the thickness and width of the track, the thickness of the dielectric material (FR4 PCB) and Wheeler’s Equation.

https://en.wikipedia.org/wiki/Microstrip

Transmission line theory is complicated and to be honest I have no intention of attempting to simplify it…I’m not sure that I could.  Basically this is some of the RF black magic people talk about…. I’m trying to keep things simple.  I would suggest that anyone who is serious about electronics and electrical signal propagation needs to have a basic understanding of transmission line theory and how to layout PCB tracks to properly interface connectors with circuits.

Here is what I fed into to the calculator:

Trace Thickness: 35 µm (Standard 1 oz copper thickness for FR4 PCB material)
Substrate Height: 1.6 mm (Standard FR4 PCB)
Trace Width: 1.5 mm (I chose 1 mm value above but went for 1.5 mm to get the right impedance)
Trace Spacing: 0.12 mm (I chose this value as a guess after trying a few different values)
Substrate Dielectric: 4 (This is the relative permittivity of FR4 PCB material)

The calculated result gives a differential impedance of 89.8 Ω – close enough!  So all that’s needed is to set the D+ and D- tracks to be 0.12 mm apart and 1.5 mm thick and try to keep the tracks the same length…If we manage that we have the 89.8 Ω impedance needed to ensure that the USB signals remain unaffected when we use the PCB.

Now that we have all of the track properties calculated we can design the PCB layout.  There is a tool in Eagle for doing this that ensures that the differential tracks are routed together.  You have to label the net names with an ‘underscore P’ and an ‘underscore N’.  I set the label for my D+ and D- nets to ‘TEST_P’ and ‘TEST-_N’ but any sensible names will do.  I then routed the +V and GND tracks manually and then set the autorouter to route the top layer.  I cannot seem to get the differential pair tool to work otherwise.  Here is what the board layout looks like:

Edit – I have updated the design after some valuable feedback from Aamir Ahmed Khan (Thank you!) – I did not remember to set the track separation distance in my original layout, I have rectified that and my calculations.  Here is the new and now hopefully correct layout.  (Note to self – I should not rush when designing PCB layouts and writing informative blog posts!).  I found the easiest way to do this was to set the grid to 0.2 mm spacing with the alternative at 0.1 mm and route the differential tracks by hand one after the other.  That enabled me to ensure the tracks were correctly separated and of the correct thickness.  I also set the ground plane isolation to be 0.2 mm to ensure the track on the bottom layer was correctly isolated…Lets see if this works!  I hope the PCB fabricators are able to etch the board for me with such precise track isolation…I can always run a scalpel down the gap though.

I will probably get the whole thing manufactured by Elecrow and for that I will need a bill of materials.

Qty Device Package Parts Vendor Part Number Description







1 USB 2.0 Socket USB X1 Farnell 2134385 AMP USB 2.0 connector
4 Ring_Test 1X01_LONGPAD +V, D+, D-, GND Ebay.co.uk 292175228920 Ring Test Connector
1 M02PTH3 1X02_LONGPADS JP7 Farnell 3418285 Standard 2-pin 0.1″ header pins
1 USB 2.0 Connector USB-A-H JP1 Farnell 1696544 USB Connectors

Here is the PCB render:

My plan is to have ten boards made, keep two for myself and flog the rest!

That’s all for now – Langster!

Having electronic breakout boards manufactured in China by Elecrow

I have an online shop where I sell some of the items I have designed and written about.  I normally have the PCBS made in china and then populate them and test them myself at my local hackspace or when I’m in a rush on the kitchen worktop – Note to young engineers: a surer method of annoying your significant other I have yet to find!

It is often quite stressful and difficult for me to hand solder surface mount components. I have to test and fault find the circuit and get everything working….after that shipping the orders in good time only compounds the issues.  It’s all about being prepared and patient…I am not always good at being prepared and then my patience wears thin!

I get my PCBS made in China by a company called Elecrow:

https://www.elecrow.com/

They sell all sorts of useful bits and pieces for the electronics hobbyist and also have a PCB manufacturing service and now more recently a PCB assembly service.

I have had at least fifty PCBS made by Elecrow and the quality has always been excellent.  The price has always been acceptable and the service excellent.  I may have also quietly lost my temper with my ineptitude in assembling surface mount components on small printed circuit boards and decided to see how much it would actually cost to get the whole product made by Elecrow.

I saw the new service advertised on the site and clicked on the appropriate page:

https://www.elecrow.com/pcb-assembly-p-366.html

Next I uploaded the gerber files for the project in a zip file along with the bill of materials with at least two sources for the components and the package sizes.  Ensuring the design is correct and the bill of materials is correct is critical…I cannot stress this part enough!

The initial price I paid to have the project assessed and the printed circuit boards and solder stencil made was £32.05 or $41.76 USD. This all started on a Sunday night on the 23rd of June.

A very helpful lady named Shelley got in contact within a day to say the order had been received but production would not start as they couldn’t open the bill of materials spreadsheet I had sent with the gerber files.  I made the mistake of not uploading the bill of materials in the Microsoft Excel format, very quickly resolved by resending the BOM in the correct file format.

Shelley got in contact within a few days to provide a quote for fitting the standard components or for fully populating the PCB.  The full cost was another £61.41 or $80 USD for ten fully completed PCBS which I thought was quite reasonable so I sent the money over and hoped for the best.

I also sent through some basic instructions and tips on how to populate the PCB gained from my own experience in doing it – I didn’t want anyone else to struggle populating the PCBS like I had and I also wanted to be sure that when the boards arrived they worked first time!

On the 12th of July Shelley emailed to say that the boards had been manufactured and that component population was about to start.  She did say that they had issues with the Op-Amp I had chosen but this was sorted pretty quickly….luckily my circuit will work with just about any Op-Amp so I wasn’t too worried.

On the 18th of July I got an email from someone named Sunshine to say that the my order was complete and shipped by DHL.  I didn’t actually bother tracking it but it arrived today on the 24th of July, well packaged in a sturdy cardboard box and bubble wrap.  Each PCB was individually wrapped in a zip lock anti-static bag with some anti-static foam on the header pins.

Every single one of the boards worked perfectly.  Here are some photos of the PCB etc…I didn’t take any of my smiling face!!!  The coin is a one pence sterling coin for scale.

Populated Pressure Sensors From Elecrow!
Check out the reflow soldering!

For the price (£93.46 or $121.76) I am very happy with the service that Elecrow provided and I will be getting more of these boards and other boards fully populated when I need to.  Shelley did say that If I get a higher quantity of PCBS made up the price quoted would reduce.  I just hope I manage to sell them all so that I can get more things made…maybe I should spend more time advertising over designing and blogging?!??

I doubt that I will ever sell enough of these to retire but I do enjoy keeping my hand in the manufacturing process – it is very useful to know how to get things made and if I ever do come up with a cunning plan…I mean product I can realise it fairly quickly and efficiently with Elecrow’s help.

That’s all for now – Langster!

How to make a Twin T Notch Filter

Analogue Electronics can be hard!  If an engineer doesn’t do much design or calculations all the time the skills can be lost.  I have personally probably forgotten far too much.  Helpfully there are reference materials both online and in books to help remind ourselves what we need to do!

I need to design and implement a band stop filter.  This because I need to make some circuit measurements and the 13.56 MHz signal (inherent to the circuit being measured) is swamping the input stage of a spectrum analyser.  I would like to be able to measure all the signal above 30 MHz without it being affected by out of band noise.  This is a common problem when using sensitive electronic instrumentation…what appears on screen is not always correct due to unknown out of band noise.

A Twin T Notch Filter Circuit

The go to circuit of choice in these situations is known as the Twin T Notch filter.  It’s a great filter circuit that is easy to implement because of its low component count.  The websites below discuss the theory behind band stop filters and Twin T Notch filters:

https://en.wikipedia.org/wiki/Band-stop_filter

http://mysite.du.edu/~etuttle/electron/elect15.htm

http://www.radio-electronics.com/info/circuits/rc_notch_filter/twin_t_notch_filter.php

https://www.allaboutcircuits.com/textbook/alternating-current/chpt-8/band-stop-filters/

The quick way to design such a filter is to set the required parameters and then use the formula given. The parameters for my filter are:

  • Must use preferred component values
  • Must not filter signals above 30 MHz
  • Must have at least 30 dB of rejection at 13.56 MHz

The formula for calculating the component values is:

Now we can either plug some numbers into the formula above and try and get close to where we want to be or we can use an online calculator tool.  I am all for quickness and see little point in doing mathematics when I don’t have to!  Here is a very useful site for calculating Notch filter component values:

http://sim.okawa-denshi.jp/en/TwinTCRtool.php

Credit should definitely be given to the engineers and Okawa-Denshi Electronics Design in Japan!

The useful thing about simulators is the component values can be selected based upon those available and not some pie in the sky value…some less helpful calculators prescribe using component values which either do not exist in the real world or require the skill of a police detective to obtain!

I also have found that when using online circuit calculators it is important to fix at least one of the component values before you start calculating things.  I entered 13.56 MHz as the centre frequency for the filter and set the value of C1 to 10 pF and C2 and C3 to 4.7 pF as these are real world (preferred) values in the E6 series.

Useful site for preferred values:

http://www.matrixtsl.com/courses/ecc/index.php?n=Capacitors.PreferredValuesCapacitors 

The online calculator did it’s thing and provided the circuit below:

The Centre frequencies were:

  • Flow = 13.555950 MHz
  • FHigh = 13.679649 MHz

The frequency response of filters is often shown as a special type of graph known as a Bode plot. This is shown below:

I have no doubt that if properly constructed this circuit would provide the filter response I’m looking for – It has 40 dB of rejection at 13.56 MHz, it doesn’t filter the signal for frequencies above 30 MHz but the resistor values whilst available are not values I have readily to hand.  Because of that I’m going to tweak the capacitor values and run the calculator again.

I have changed the values of C2 and C3 to 22 pF which follows the rule that C2 and C3 must be roughly double C1….Here is the circuit that the calculator came up with:
Again…this circuit would probably work but I’m still not happy with the resistor values.  They are hard to obtain.  I’m going to increase the values of the capacitors again and see what happens.  The values I have chosen are C1 = 15 pF, C2 and C3 = 82 pF

The resistor values are now much more common and available.  Lets hope the filter response is good enough.

The Centre frequencies were:

  • Flow = 13.496806 MHz
  • FHigh = 13.654780 MHz

The corresponding Bode plot:

From the numbers given and by interpreting the Bode plot this circuit meets my requirements. If I wanted I could fit a 22 pF capacitor in the C1 position and a similar result will be obtained.  That will also change the resistor values as well:

I’m liking these values the most as I am certain I have all of these components available.  I wasn’t sure if I have a 15 pF capacitor. It’s not a value I use much – easily obtained from any good component vendor but always best to use what you have!

The resistor values are now much more common and available.  Lets hope the filter response is good enough.

The Centre frequencies were:

  • Flow = 13.374485 MHz
  • FHigh = 13.587897 MHz

The corresponding Bode plot:

Now that we have our component values we need to calculate the power requirements.  In this case I want to be able to put as much electrical power through the filter as possible.  The signal strength of the 13.56 MHz signal in my case will be at least 20 Watts.  Therefore each component must be capable of withstanding that power level without being burnt out.

I happen to know that the 13.56 MHz signal will be coming from a signal generator and amplifier at +30 dBm.  If we convert +30 dBm into Watts we find that it is 1 Watt.  So all components need to be rated for one Watt or better. Just for fun here is the formula:

dBm = 10 * Log10 * 1 * 10^-3 (Watts)

We need to rearrange to get Watts:

10^-3 (Watts) =10^(dBm/10)) 

If we now plug the values in we get:

10^-3 (Watts) =10^(30/10))

Which is equal to 1000 * 10^-3 Watts or 1000 milli-Watts which is 1 Watt 

So all of the resistors need to be 1 Watt rated or better.  I’m going to need a small enclosure with connectors for this circuit and that means I’m probably going to need a printed circuit board.

I have used these diecast boxes in the past for this purpose – they are useful because they come with BNC connectors already fitted:

They are made by Pomona Electronics and are available from most good electronics vendors like RS components and Farnell Electronics.  My only complaint is the cost – £28.04 – yikes!

The datasheet for the box is here:

http://www.farnell.com/datasheets/63791.pdf?_ga=1.89445531.125022660.1487507564

The dimensions of the Box are below:

Rather unhelpfully the inner dimensions are not provided – I hate it when that happens. However it isn’t too much of a concern, reasonable estimations can be made.

If the printed circuit board is 36 mm x 33 mm and when populated is less than 25 mm high it will fit the above box well enough.

Here is how the layout came out:

I have chosen to use surface mount components throughout and 2512 size resistors so that the power requirements are met.  The board should easily fit inside the enclosure chosen.  The dimensions shown are in mm – for those that might be interested.

Just for fun here is how the PCB will look when populated:

ISO view of the Notch Filter PCB
The top side of the Notch Filter PCB
The side view of the Notch Filter PCB

Just for fun and because I wanted to practice my 3D drawing and modelling skills I have drawn up the Pomona 3231 Box.  It is available for download at the 3D warehouse if people are interested. Here is the PCB inside the box:

Top view of the PCB in the 3231 Pomona Box

ISO view of the PCB in the 3231 Pomona Box

Finally all that is left to do on this is create a bill of materials and calculate the total cost for this Filter.  I normally buy my components from Farnell Electronics but anywhere would do.

Component Value Quantity Footprint Part Number Cost (£) Notes
Resistor 390 Ohms 5 2512 2476478 0.604 3 Watt resistor from Farnell
Resistor 27 Ohms 5 2512 2476450 0.604 3 Watt resistor from Farnell
Capacitor 82 pF 10 0603 722078 0.015 C0G from Farnell
Capacitor 22 pF 10 0805 1759489 0.0323 C0G from Farnell
PCB N/A 10 N/A N/A 14.04 10 PCBS from Elecrow
Pomona 3231 Case N/A 1 N/A 1234948 28.04 From Farnell

Unfortunately I could not get an 0805 82 pF capacitor which is annoying but I can fit an 0603 part. The total cost for the above is £43.34 – That is enough components and PCBS to make one complete unit with plenty of spares.  The cost of a single unit alone is £29.70 which I think isn’t too bad.  Those pomona cases are very expensive – I might investigate a cheaper solution at some point.
The good news is all of the resistors I found are 3 Watt parts which means the filter will be able to work with high power signals!
The more astute readers may know that it is possible to buy a notch filter from various RF vendors.  I did consider these options and for those that may be interested the following websites have them on sale:

I couldn’t find one that specifically sells a 13.56 MHz Band Stop Filter although I suspect such products do exist.  I doubt that I would be able to buy one for less than £30
If I do decide to make one of these I will test it and provide the results and photos.  Hopefully this was of interest to someone – Take care always – Langster!

Designing a pressure sensor using Velostat

In the previous post I designed a circuit which was supposed to read in when pressure was applied to a custom sensor made from velostat.

The first post on the Piano conversion

I made a sensor out of some single sided FR4 printed circuit board material, some foam tape, two pieces of wire, a small 1 cm x 1 cm piece of velostat and some sticky tape!

Custom Pressure Sensor using Velostat

This is just a prototype and may not be my final version of the sensor. I wanted to see how well velostat worked and how it would behave. It seems to work really well!

I found from measurements with my multimeter that when the pressure sensor is not touched the resistance across the wires is 30 kΩ. When pressure is applied it drops to 1 kΩ. That should be more than good enough for the purposes of detecting a key-press!

The constructed pressure sensor

Next the PCB designed in the previous post was etched, drilled and populated. It etched well and I populated it with the designed components:

The Underside of the PCB 
The topside of the PCB with components

I then wrote some quick test code for the arduino because I’m leaning towards using an arduino for the microcontroller:

/*

Pressure Sensor test Code
For Electronic Piano
(c) A. Lang 2016

*/

// These constants won't change. They're used to give names
// to the pins used:
const int analogInPin = A0; // Pressure Sensor connected to A0

int sensorValue = 0; // value read from the pressure sensor via the amplifier stage
float outputValue = 0; // value output to the Serial port

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}

void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);

// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.println();

// wait 10 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(10);
}

The code is very similar to code I had written before – what is it with me and pressure sensors at the moment! I then uploaded the code to the arduino and tested it – It didn’t work as planned – I may have been a little disappointed at this point….

I then thought about my circuit and looked at the schematic:

The original Key Press schematic

I realised I had made a mistake. I didn’t account for how the velostat would behave in terms of it’s resistance. I thought it would have a resistance of around 1 kΩ and vary….it doesn’t it’s resistance is 
30 kΩ and varies down from that when pressure is applied. Because of this I need to tweak my circuit from behaving as a two stage buffer to a simple analogue comparator and buffer. Luckily it won’t be too hard to change things!
Here is the new circuit:
Add caption
The Key Press Schematic Version 2 

The new circuits works in a similar fashion as the previous one. The velostat pressure sensor makes up a voltage divider. The output of the voltage divider is connected to an analogue comparator made with the first op-amp in an LM358 dual op-amp IC. The negative input has a 2.75 V reference set by the 8.2 kΩ resistor and the 10 kΩ resistor. The output of the 1st op-amp is then connected to a buffer amplifier with a gain of two and then the output is connected to a FET and an LED. The output will be sent to the ADC of the micro-controller which will probably be an Arduino.

To test the circuit I removed a 10 kΩ resistor and then added a 7.5 kΩ resistor (because I couldn’t find an 8.2 kΩ resistor). Here is a photo of the modification:


Here is the modified PCB layout although I probably won’t etch this board again. I’m going to re-design it to use surface mount components and be a smaller form factor. It would be nice if each board fit snugly under each piano key.

The New Key Press Layout
I then connected the circuit back up to the arduino and pressed the sensor! It worked. The LED lit up – although I wish I had used a brighter LED…but SUCCESS!! So sweet...

Here is a graph I made from the serial monitor results. It looks very similar to the simulated oscilloscope trace from the first post!

The results from the serial monitor

So now we have a valid method of reading key presses we need to scale things up – and shrink a few things down. I will redesign the key press PCB layout to use surface mount components to take up as little room as possible. Then we need to look at multiplexing all of the signals together…and for that I’m going to use the 74HC4076 integrated circuit breakout board.

That’s all for now people – take care!

Converting an upright piano to an electronic midi piano

The Manchester Hackspace has recently moved.  When the move occurred there were two old upright piano fortes found in the corner of the new place…I asked to keep them!  I have been meaning to attempt a conversion from an acoustic mechanical piano to an electronic one for a very long time. Tuning my old walnut cased iron framed piano is becoming too difficult.  I miss being able to play in tune and with other instruments.  I also seriously miss being able to compose music and I used to use midi extensively to achieve that.  I haven’t the space to write, play and record every instrument….so instead I used to use midi software on an external computer and have that record, notate and sequence the different parts to make create my opus!  Years ago I had access to an Atari ST 520FM which had built in midi ports – it made this very easy, I also had access to a Clavinova CLP-360 Yamaha electronic piano.  It was awesome and I miss it dearly…

So rather than let my creative talents go to waste I plan on tuning one of the pianos up as much as possible and restoring it to as near working condition as possible.  This can then be kept for posterity or donated to a worthy cause…It was looking a little shabby when I found it but I have cleaned it up and opened up the panels:

Here are some photos of the piano:

A classic Upright Piano with the covers off!

The iron frame and the strings

The pedals, the sustain has definitely seem some action!

Another side shot of the slightly…better piano!

There are actually two pianos physically they look very similar but one was in much better shape than the other.  Here is a video of the better one…One of the D flat keys does not have a bridal strap and so won’t play or return.  I’m going to replace that strap but other than that it’s got a nice action and is very easy to play…better than my own!  It was however horribly out of tune…

I have a piano tuning kit I bought off ebay for doing my own tuning so I broke it out and set to it. Tuning a piano is an art…it’s difficult and takes skill and practice.  I did get it mostly in tune, some of the higher and lower notes beat me and I will spend a bit more time on it.  I am jealous of how easily played this piano is…my own keys are much stiffer and harder to play…mine also is in B flat…this piano tuned to A (440 Hz) without too much issue.

Here is the piano now tuned…hopefully it sounds better! EDIT – I haven’t got a video of the tuned piano to share yet – I will upload one soon.  The internet needs more of my poor piano playing skills shared!

The plan with other piano is to remove the hammer action and strings and place some sensors underneath the keys. The sensors will connect to a microcontroller which will then send out midi data which can be used to drive a midi based synthesizer which will in turn be connected to an audio amplifier and a couple of speakers mounted inside the cabinet. The benefits of doing this are:

  • The piano will always be in tune!
  • A midi synthesizer can produce thousands of different voices – a whole orchestra and more!
  • The piano can be used as a midi Jukebox and a band in the box.
  • It is a great excuse to investigate touch pressure sensor technology.

Here is the current plan in a diagram

There are many aspects and parts to the project which will need careful thought and consideration.  I don’t want to lose the piano’s playability. If I remove the action – the mechanical part of the piano which converts the key press to strike a note the piano won’t play as well. Here is a video I found on youtube which shows how a piano key functions:

I think in order to make this work it will be necessary to add a spring mechanism to where the key would normally pivot the action mechanism to get the key to return to it’s original position. I am not great at mechanical engineering – here is my chance to improve!

It will also be necessary to sense the note being played. Most electronic pianos have a maximum number of keys being able to be played at the same time – this is known as polyphony.

An explanation on Note Polyphony

It would be nice to be able have at least a 32 note polyphony without any noticeable lag or delay. I’m not going to be playing pieces like this but being able to play 32 notes a once puts this device in the category of a reasonable electronic piano.

https://en.wikipedia.org/wiki/Two_hundred_fifty-sixth_note

So lets recap the requirements of the input section:

  • Sense at least 32 simultaneous key presses
  • record how long each note was held for 
  • record how hard the note was pressed

To do this we will need a pressure sensor which can easily be built and placed underneath the key of the piano.

I recently took some inspiration from this project:

http://liamtmlacey.com/vintage-toy-synthesiser

Liam used a sensor material known a velostat. It is a very interesting material which converts pressure into an electrical signal – it’s electrical resistance changes as pressure is applied. I bought some from Proto-Pic

Velostat from Proto-pic

My plan is to combine the velostat into a simple resistive divider circuit which is then connected to the analogue input of a microcontroller and use this to ‘sense’ the note or notes being played.

A piano has 88 keys! If we want to sense them being played we need a way of reading in 88 analogue inputs. An arduino has six analogue inputs….an arduino mega has a few more but still not enough! We could use multiple microcontrollers but that makes things awkward and expensive as we need to then to synchronize them all…yikes!

I think this will require some analogue multiplexing in order to work well and not be overly cumbersome….I looked at a couple of the analogue multiplexers available and settled on this one:

74HCT4067 – Analogue Multiplexer

It’s basically a single throw sixteen throw switch which can be controlled by a microcontroller. There lots of breakout boards available on the internet. I bought this one:

Ebay shop – 74HC4067 breakout board

I haven’t used it yet….my first plan is to test and model the analogue input stage…then connect it to the multiplexer and then use that to scale up for 88 keys.

In order to make this work we will need a lot of multiplexers:

88 keys / 16 channels = Number of multiplexer devices needed

therefore 5.5 devices (six) in reality.

Before that we need to make a sensor measurement stage.  I’ve decided to use a buffered simple resistive divider circuit:

The Sensor Measurement Stage

The above circuit is an approximation of how the electronics will read a key press.  The circuit functions as follows:

The momentary switch and the 10 kΩ potentiometer model the behaviour of the velostat material. I don’t have much information on the resistivity of the velostat but I have tried it and I do know that it’s resistance does vary with pressure – I measured it with a multimeter. The resistor R1 makes up a voltage divider circuit. When the piano key is pressed the resistance of the velostat changes which is detected by the LM358 Op-Amp. The resistor R5 and the capacitor C1 make up a low pass filter. It might not be necessary but I’m trying to ensure that no external electronic noise is presented to the op-amp. I only want to measure key presses, nothing else. The first op-amp is configured as a non-inverting amplifier with a gain of two. The 100 pF capacitor limits the bandwidth of the op-amp restricting it’s operation to low frequencies, another way to limit noise being passed on to other parts of the circuit. The second op-amp stage is again a simple non-inverting op-amp stage with a gain of two. The output signal presented to the next stage will be between zero and three and a half volts. That should be more than enough range present to detect key presses with good sensitivity. The output will be connected to an analogue to digital converter which will probably be a ten bit ADC integral to the microcontroller. The op-amp is an LM358 but just about any op-amp will do for this circuit…There is nothing inherently special about that component. The circuit has been simulated connected to an oscilloscope. Here is the output:

The oscilloscope output – the pulses represent a unique keypress

The simulation appears to work perfectly which is always good…This circuit will have to be reproduced eighty-eight times so we will need to design a small and easy to build circuit.  For now I’m going to make a though-hole version because it’s easy to prototype.  Once I’m happy everything works I will probably make a sixteen input version which will be connected to the analogue switch.

The Schematic of the key press circuit

I added an LED because I think it would be nice to see when the key has been pressed without having to attach it to a measurement device like an oscilloscope. It makes it easier to test the circuit. I also added a screw terminal to input the power – nearly forgot that.

The Top Layer of the PCB
The bottom Layer with dimensions in mm

Just for fun here is the circuit rendered in 3D:

ISO render of the populated PCB

Top render of the populated PCB

If the circuit works as intended I will re-engineer this board with surface mount components to reduce the physical size of the board and have eighty-eight boards made…

Here is the parts list for the key press circuit:

Qty Value Device Parts Description Farnell Code Unit Price (£) Cost for Circuit (£)
1 N/A 5 mm LED – Red LED1 LEDs 2335725 0.051 0.051
1 100 pF Capacitor C2 25 V Ceramic Capacitor 1141765 0.0709 0.0709
6 10 kΩ Resistor R1, R2, R3, R4, R5, R6 5% 1/4 Watt Carbon Film Resistor 2329474 0.024 0.144
2 10nF Capacitor C1, C3 25 V Ceramic Capacitor 1216435 0.275 0.55
1 220 Ω Resistor R7 5% 1/4 Watt Carbon Film Resistor 2329899 0.037 0.037
1 LM358 Dual Operational Amplifier IC1 Jellybean op-amp 2295980 0.34 0.34
3 N/A 5 mm Screw terminal connector JP1_SENS, JP2, JP3_POWER Standard 2-pin 0.1 pitch 2493614 0.16 0.48
1 2N7000 N Channel MOSFET Q1_2N7002 Jellybean N-Channel MosFET 9845178 0.158 0.158
Total in £ 1.8309

Not too bad at all…It does not take into account the cost of the PCB or my time building and testing the circuit.  I intend having the PCB for the surface mount version made professionally – eighty – eight times so that will cost a little more!

That’s all for now – next post on this will probably show the board in operation and a prototype key press sensor:

http://langster1980.blogspot.co.uk/2016/06/designing-pressure-sensor-using-velostat.html

555 Flyback Driver and Plasma Speaker Part III

So here is the complete Plasma speaker circuit in all it’s glory!

It actually creates a significant amount of high voltage and works very well.  I would caution anyone else attempting to replicate this circuit to please be very careful.  I haven’t given myself a shock yet but it could happen and will hurt if it does….Exercise sensible precautions please!

Here is the previous post in case people need to catch up:

555 flyback driver and plasma speaker part II

I have found that the 3D printed HV probe holders work quite well.  I also have found that setting the distance between the probes is critical to obtaining a reproducible arc and that the constant re-strike of the arc causing the audio to sound terrible.  From experimentation I have found that the audio signal from my mobile phone is more than enough to drive the 555 modulation pin when it isn’t capacitively coupled.  When capacitive coupling is added the audio is barely heard.  The capacitor on the audio input reduces the hissing considerably.  Here is a video showing the current audio output of the plasma speaker…it sounds pretty terrible but it does work:

I have decided to do two things….improve the HV probes and provide a simple class A audio amplifier to the pin 5 input of the 555.  This should improve the sound and get rid of the horrible hissing!

So to that end I have designed a very simple single transistor class A amplifier using a BC548 transistor.  Here is the schematic:

In designing the circuit I referred to this website…which is rather useful for this kind of thing:

http://www.learnabout-electronics.org/Amplifiers/amplifiers40.php

I knew how to design a Class A amplifier well enough but I had forgotten how to select the components values correctly…in particular I wanted to increase the low frequency response and limit the bandwidth of the amplifier to reduce the high frequency response.

The circuit works fairly simply…An audio signal from a suitable source is presented at the 3.5 mm headphone jack input – only one side of the audio signal is provided – this amplifier is mono. This is then passed to C1 – a 1 uF electrolytic capacitor which is used to remove any dc offset and chosen in such a way as to not overly affect the bass response of the amplifier (more on this later).  The next components in the circuit are R3 and R4 which bias the NPN BC548 transistor into constantly being ON.  These values are set by ohms law.  We need at least 0.7 volts to turn an NPN transistor ON. Lets do the maths just for fun:

Ohms Law; V / R = I

In this case:

V: 12 Volts
Rt: R3 + R4 which is 120 kΩ + 10 kΩ = 130 kΩ

I = V / Rt

I = 12 V / 130 kΩ

I = 9.23076923077 * 10^-5 A or 92.3 µA

The voltage applied to the base of the BC548 transistor can be calculated by = I * R4
therefore the voltage applied to the base of the BC548 transistor:

92.3 *10^-6 A * 10 kΩ

The voltage applied to the base of the BC548 transistor is 0.923 Volts or 923 mV

The circuit has been designed so that 0.923 volts is always applied to the base pin of the transistor to ‘bias’ the transistor ON.  The audio signal applied will increase this voltage and be amplified.  The next components applied to the collector of the transistor are a 10 kΩ potentiometer and a 100 Ω resistor.  At the emitter of the transistor we have another 10 kΩ  potentiometer and a 10 uF capacitor. All of these components combined set the gain of the amplifier. There are formulae that can be applied to calculate the amount of gain.  I guessed at it…It’s not particularly important in this case. When the potentiometers are at maximum (according to my simulations) the input signal is amplified roughly 130 times greater than the input…the amount of gain is controlled both 10 kΩ  potentiometers which can be set by the operator.  The 10 uF electrolytic capacitor C3 is known as the emitter decoupling capacitor and is added to prevent any stray audio signal being present on the emitter pin of the transistor.

Finally at the output of the amplifier we have a 1 nF ceramic capacitor C4 and a 10 uF electrolyitic capacitor C2.  The electrolytic capacitor C2 prevents any dc voltage being passed to the next stage of the circuit, in our case, pin 5 of the 555 timer. C4 is used to limit the bandwidth of the amplifier.  In this case I have set all of the capacitor values to set the amplifier’s frequency bandwidth to be between 200 Hz and 20 kHz which is roughly the range of human hearing.

I simulated the circuit in order to check what the output would be like and check the gain would be sufficient and to verify the frequency response.  It was helpfully not clipped and gave a good amplified approximation of what was to be expected.

Here are the results of the simulation…I have placed probes at the more interesting points in the circuit:

Simulation Schematic

Here is the simulated oscilloscope output:

The input signal is shown with the blue trace, the red trace shows the amplified output.  The output is inverted but that won’t matter in this case.

The really good thing about simulating circuits is that the frequency bandwidth can be checked without actually building the circuit.  Here is the simulated audio frequency response of the amplifier:

If the capacitor values C1, C3 and C4 are changed for different values the frequency response of the amplifier is significantly affected.  C1’s value changes the bass frequency responses, C3 changes the treble response and C4 changes the bandwidth of the amplifier.  In this case I have tweaked the values to try to give the best response between 200 Hz and 20 kHz without losing too much bandwidth.

Because its me I’ve designed a simple single sided PCB for this circuit.  It could easily be made on veroboard (stripboard) or using some other method.

Top Layer of PCB
Bottom Layer of PCB


Here is a render of the PCB to show how it will look once etched and populated:

Top View of Class A Amplifier Render
ISO view of Class A Amplifier Render

Here is the bill of materials:

Part Value Device Description Vendor Part Number Quantity Cost
(£)
12VDC_INPUT N/A M025MM Standard 2-pin 5mm screw terminal Farnell 9632972 1 0.245
AUDIO_OUT N/A M025MM Standard 2-pin 5mm screw terminal Farnell 9632972 1 0.245
C1 1uF CAP_POLPTH1 Electrolytic Capacitor Farnell 1236686 1 0.0464
C2 10uF CAP_POLPTH1 Electrolytic Capacitor Farnell 9451056 1 0.034
C3 10uF CAP_POLPTH1 Electrolytic Capacitor Farnell 9451056 1 0.034
C4 1nF CAPPTH1 Ceramic Capacitor Farnell 1141779 1 0.0758
C5 100uF CAP_POLPTH1 Electrolytic Capacitor Farnell 1902882 1 0.0345
C6 100nF CAPPTH1 Ceramic Capacitor Farnell 1141775 1 0.0721
JP1 N/A AUDIO-JACKPTH 3.5mm Audio Jack Farnell 1608405 1 0.534
R2 100 RESISTORPTH-1/4W ? Watt Carbon Film Resistor Farnell 9342397 1 0.0523
R3 120k RESISTORPTH-1/4W ? Watt Carbon Film Resistor Farnell 9342540 1 0.0492
R4 10k RESISTORPTH-1/4W ? Watt Carbon Film Resistor Farnell 9342419 1 0.0523
RV1 10k POTALPS-KIT PCB Mount Variable Resistor Farnell 1191725 1 1.4
RV2 10k POTALPS-KIT PCB Mount Variable Resistor Farnell 1191725 1 1.4
T1 BC549 BC549-NPN-TO92-CBE BC549 NPN Transistror Farnell 2453797 1 0.238
Total 4.5126

Again I haven’t factored in the cost of the PCB or it’s manufacture but it would be reasonable to estimate the total cost of the project to be around £6.00

Here is a quick video showing the circuit in operation with the plasma speaker.  The audio is very much improved!

Now I need to get back to putting the HV section and the electronics into some sort of casing.  That’s all for now – take care people!

555 Flyback Driver and Plasma Speaker

I haven’t really had much electronics inspiration at the moment.  It can be like that sometimes…So I decided to fill my time with a display project.  I’m going to build a simple plasma speaker!  These are essentially just a high voltage arc being modulated with audio to produce sound.  They aren’t particularly good at producing sound and are quite dangerous so they aren’t used apart from for effect.

WARNING – This is a High Voltage circuit!  Using Flyback transformers without due care and attention is DANGEROUS. Lethal voltage and current is present when operating this circuit.  The author is not responsible for anything which occurs by constructing or operating this circuit!

There are lots of tutorials and videos on YouTube and Instructables about this subject.  I used the site below as my inspiration:

http://www.instructables.com/id/Audio-modulated-flyback-transformer-driver/?ALLSTEPS

Here is the schematic diagram for the circuit:

The circuit is fairly simple in operation.  Power is supplied via a standard 12 Vdc 5 amp power supply via the DC barrel socket or via the 5 mm screw terminal JP1.  The 12 volt supply is smoothed by the 100 uF and 100 nF capacitors.

The main part of the circuit is made up of a 555 timer in astable mode.  Astable means there will be a constantly repeating 12 volt peak square present at pin 3.  The frequency of the square wave is set by the 50 k potentiometer RV1.  The mark space ratio of the square wave (the width of each pulse and the gap between each pulse) is set by the 50 k potentiometer RV2.  The output at pin 3 is used to drive two bipolar transistors which in turn drive a high current, high voltage N-type MOSFET.  The MOSFET will drive a flyback transformer which will have it’s output at the secondary spaced so as to draw a high voltage arc.  The flyback transformer will be connected externally via the 5 mm screw terminal JP3.

The audio signal for the plasma speaker will be coupled to the circuit via the 5 mm screw terminal JP2.  This will take in a standard audio signal either from an audio amplifier or directly from an audio source such as an MP3 player or a signal generator – I haven’t decided yet!

To make things easy for me and to ensure this circuit works as intended I simulated the circuit first. It works perfectly well.  The voltage generated by flyback transformer at the secondary should be around 1.7 kV assuming I have guessed at the turns ratio of the flyback transformer correctly.

I then designed a printed circuit board for the circuit.  I find it much easier to lay circuit boards out than to use stripboard to create circuits however stripboard would work perfectly well.

Here is the PCB layout:

Plasma Speaker Top Layer
Plasma Speaker Bottom Layer
Both layers with dimensions

In designing this layout I was trying to make the circuit as small as possible but still use through hole components.  I find it much easier to work with through hole components when prototyping.  If I was going to make more of these circuits I would design with surface mount components and reduce the size to less than 50 mm x 50 mm.  This way I can get PCBS made for a reasonable price in China by Elecrow.

Just for fun I’ve rendered the circuit in 3D using Sketchup so that I can visualise how the circuit will look once it is complete.  It also means I can spot any potential construction and layout issues before I etch and populate the PCB.

Isometric Render of populated Plasma Speaker PCB
Top View of Plasma Speaker PCB

In order to populate the PCB the following components will be required:

Part Value Description Vendor Part Number Cost (£)

C1 10 nF Ceramic Capacitor Farnell 1141772 0.0851
C2 100 nF Ceramic Capacitor Farnell 1141775 0.0721
C3 220 nF Ceramic Capacitor Farnell 2395774 0.132
C4 100 nF Ceramic Capacitor Farnell 1141775 0.0721
C5 100 uF Electrolytic Capacitor Farnell 2346578 0.1178
D1 UF4007 High Speed Diode Farnell 4085310 0.372
IC1 ICM7555 CMOS 555 timer Farnell 9488243 0.528
J1 n/a 2.5mm DC barrel Jack Farnell 1737246 0.469
JP1 n/a 5mm Screw terminal Farnell 2493614 0.16
JP2 n/a 5mm Screw terminal Farnell 2493614 0.16
JP3 n/a 5mm Screw terminal Farnell 2493614 0.16
JP4 Jumper 2 pin header Farnell 3418285 0.27
KK1 SK104 Heatsink TO247 Heatsink Farnell 1892329 1.06
Q1 BC549 TO92 NPN Transistor Farnell 2453797 0.232
Q2 BC559 TO92 PNP Transistor Farnell 2453808 0.232
Q3 IRFP250 TO247 High Power MOSFET Farnell 8649260 1.26
R1 270 Ohms ¼ Watt Carbon film Resistor Farnell 9339353 0.0356
R2 22 Ohms 1 Watt Carbon Film Resistor Farnell 1565366 0.0664
R3 150 Ohms 1 Watt Carbon Film Resistor Farnell 1565346 0.0664
RV1 100 k-Ohms ALPS PCB mount Potentiometer Farnell 1191742 1.28
RV2 100 k-Ohms ALPS PCB mount Potentiometer Farnell 1191742 1.28

The total cost of components, not including the PCB or flyback transformer will be:

£8.12

Flyback transformers can be very easily sourced from old televisions, junk shops and everyone’s favourite online auction site:

Ebay – Flyback Transformer

They are currently on sale for £7.81 – I remember them being cheaper but they are becoming more rare!

I’m guessing at the cost of making and etching a PCB for this project at £3.00

That brings the total cost to £18.93

Not bad I suppose…I’ll probably etch and populate a PCB and test the circuit in the next post.  That’s all for now

Take care people – Langster!