Showing posts with label miniature synth. Show all posts
Showing posts with label miniature synth. Show all posts

Monday, August 29, 2011

Minature instruments again - synth redesign

Some more electronics goodies arrived in the post this weekend, so while the idea of making an X-Y CNC type framework is still very exciting, it's time to turn back to our miniature instruments idea. In in particular, we've been looking at our miniature synth.

Although we got a working keyboard up and running relatively quickly, when it comes to boxing it all up and putting it inside a nice neat enclosure, things have taken a turn for the worse. Using the existing key layout as a guide, we put together some designs for three different types of synth:
  • Mini-moog
  • Roland style keyboard
  • Yamaha keytar




The problem is, the actual keys part of a synthesizer keyboard are only a small part of the overall instrument. So while the keys look fine on their own, put them, inside an enclosure, and the whole thing looks enormous - especially when compared to the guitar and drums

Cutting out prototypes from cardboard is a much cheaper way to try out new ideas, without spending a fortune on laser cutting acrylic which could very well turn out to be useless!

So we've had to re-scale the keyboard part of our synth.
At first, we just scaled the plastic keys to about 80%, printed them out and tried to see how they'd fit in with the rest of the range. Of course, this didn't work - because the PCB will pretty much decide how big (or small) our keyboard can be. We've redesigned the PCB so that the pushbuttons for the keys are as close together as possible, and then used that as the basis for the new keys layout.

All in all, the final synth design is about 75% smaller than the first attempt.
But more importantly, it's a little more in-keeping with the rest of the instruments in the range.


Friday, August 19, 2011

Understanding synth playback values





A few people have asked how do we read back the values from the key presses on the synth. It's a relatively simple bit-masking process, but at first appears complicated.



The first thing to do is refer to the map of keypress values (above).

Because our inputs are active low as well as recording the value generated when each button is pressed, we've also written down the inverse of this value.



Say, for example, we press the first button on the PCB.

This returns the value 191.

We take the inverse of the value. Strictly speaking, what this means is we convert the value to binary, which gives us 10111111.

The inverse of this is 01000000.

You can get the same result by subtracting the initial value from 255.

So in this case, 255-191=64 (which is 01000000 in binary)



Because each key on the synth activates a unique bit in the binary sequence, any number of keys can be pressed at any one time.

If we press the low C key (first key to the left) and the Eb key (fourth from the left, including "black notes") the PC returns the value 189.



Converting 189 to binary and inverting (or subtracting from 255) and we get 66, which is represented by 01000010



As you can see from the previous example, both binary sequences begin 01.... so whenever the second bit in the binary sequence is one, we know that the low C key has been pressed.



By identifying the values for all the keys, we can plot which bit in each binary sequence represents which key-press on the keyboard. In our PC app, we'll monitor the last known value of these binary sequences to the current one and this will allow us to work out which key has just been pressed (and equally, which key or keys have just been released). With this information, we can trigger and stop sounds playing, to recreate a genuine playable synth.



See - it's nearly working already ;-)



Why the need for plotting all the values? It has been suggested that we should make the first pushbutton go to PORTB.0 (bit 0), the second button go to B.1 (bit 1) and so on, to simplify reading the data back. In fact, this is exactly what we did in the prototype. The beauty of breadboard prototypes is that you can have wires leading everywhere, looping over each other, winding in and out of other wires.

When you come to create a PCB, however, layout is critical. So our push buttons are actually laid out 17,16,1,2,7,8 and so on. While this doesn't make sense to the casuall observer, it's much easier to use a rigid layout pattern, and make allowances for it in firmware/code, than it is to stick rigidly to a set firmware/pinout and try to force your PCB layout to match it!




[edit - 10pm same day]

Here's a short video showing the custom software (note how it detects when the instrument has been plugged in and changes the interface - we really like that subtle little touch!) and a working demonstration of the synth







I need to remember to close the windows when shooting demo videos like this! And maybe turn the telly down a bit too. And, of course, make sure the volume is up on the PC before starting!



You can see on the video that the synth not only supports "key down" type events - i.e. triggers a sample when a key is pressed - but also raises "key up" events too - stopping a sound when you lift your finger off a key, just like a real synth! Chords are played to demonstrate that the miniature synth is truly polyphonic: multiple keys can play at once. I dread to think what it would sound like, but in theory you can press (and the PC will respond to) all 17 keys at the same time. Better than some early casio keyboards even!



Thursday, August 18, 2011

Working miniature synth (nearly)

Despite looking like a complicated instrument, the synth was actually one of the easiest to manufacture and to code the firmware for. In fact, it only took a few hours this afternoon to get a "working" miniature synthesizer!

As ever, the first thing to do was create a PCB with a working PIC microcontroller for the USB/HID interface







The acrylic keys sit over a large, single-piece, PCB.

There are 17 pushbuttons, arranged so that each one sits under the front-most edge of each individual key.







These pushbuttons are routed to the digital input pins on our old friend the 18F2455 PIC microcontroller.



After all our fancy routing and re-naming buttons, pins and ports, we forgot to connect the ground pin of the USB socket to the ground trace on the board! D'oh.



Since we discovered hot air soldering, and how surface mount components can be just as quick and easy as (and sometimes quicker and easier than) through hole components (no pesky drilling) we've decided to stick with the surface mount version of this chip, rather than the earlier favoured through-hole version.



That's all there is to this synth really - we've allowed for a rotary dial/potentiometer on one of the analogue pins, and perhaps a separate pushbutton to switch sustain on and off. But really, it's just a simple PCB with a load of buttons.



We decided to use the PIC's internal pull-up resistors on PORTB, which means that all input pins are high and when a button is pressed, the input goes low. Likewise, we wired the remaining buttons up the same way (high with no input, low when the button is pressed) which means that for 17 keys, we only used 9 pull-up resistors instead of needing one for each button.



The remaining 9 inputs were spread across PORTA and PORTC.

This makes reading the data back a little difficult but not impossible. We use three different byte-sized buffers, to report back the status of every button over USB. PortA is bit-masked by reading the value off the port, and OR-ing with the input pins not used (in our case, only RA1-RA5 are used, so we OR the value on PORTA with 1+64+128 = 193) This is because RA0 is the analogue input (2^0=1) and RA6(2^6=64) and RA7(2^7=128) are not used, so we will always report these bits as high (not pressed) irrspective of their state.



By doing this, we should get a unique combination of numbers on the three buffer bytes, for every combination of key presses. This allows up to 17 keys to be pressed and recognised - a truly polyphonic synthesizer!



To find out which buttons returned which values, we knocked up a simple VB app which reads the first three bytes back from the USB device and displays them on screen.







This photo shows how pressing the first "key" on the keyboard results in byte3 taking the value 191. We went through every single key, pressing each one in turn, and wrote down each of the three byte buffer values. This map of values will form the basis of our playback code.







Because the input pins are high when inactive and low when active (when the button is pressed) we can invert the key buffer values (subtract from 255) to work out which key (or combination of keys) is pressed. When two or more keys are pressed, their values are simply OR-ed together.



For example, if a key with the inverse value 64 is pressed together with one having an inverse value of 4, together with one having the inverse value 1 (when playing a chord or triad, for example), the keyboard input buffer value will simply be 64+4+1=69



By taking the values from each of the three byte buffers, and using simple logic queries (AND/OR) we can easily identify exactly which combination of keys has been pressed at any one time.

Tuesday, August 16, 2011

Miniature playable synth

While waiting for the boards from PCBCart to arrive, we decided to look at other miniature instruments for the range.



Of course we'll need a miniature drum kit, for laying down the beats, and a bass guitar for laying down the grooves, will be more-or-less the same as a guitar (same functionality, maybe a bigger beefier shape). We've already made up a simple drumkit prototype, using some piezos and an existing miniature drumkit bought off eBay.



the gold coloured disks mounted under each drum skin are piezo tranducers, connected to digital inputs on the PIC microcontroller



What we need now is to manufacture the 'kit from scratch, now we've proved that the concept works. That can wait until we're visiting the local hardware store and can investigate the diameter of different plastic tubing! Another instrument we've yet to have a go at is a miniature synthesizer. There's a debate about which style to do first - a Moog, a Roland or a Yamaha Keytar?



At the minute it's not important - we're focussing on the functionality; the enclosure can be designed later! Here are some photos of the early synth development....







Rather than mess about with hinges and moving parts, we've just made the keyboard out of a series of "sprues", connected to a thick bar along the top. The idea is that there should be enough flex in the acrylic to allow the user to press the acrylic keys onto a series of soft-touch tactile push-buttons mounted onto a PCB underneath. These key presses will simply be digital inputs, allowing true polyphonic sound to be achieved.



Our miniature synth will have 17 keys, starting at middle C.

Why seventeen keys and not any other number? I wish I could say it was because of the number of available inputs or some other technical reason, but the truth is we all watched classic 80s synth clips on YouTube and after seeing how to play Axel F decided that 17 was the minimum number of keys required!







Whether the 18F2455 will have enough inputs for what we're trying to do (there will be other buttons such as pedal sustain, LED outputs and so on) or whether we'll need to move up to the bigger 40-pin 18F4550 still remains to be seen.......