Friday, 17 March 2017

Cassette Player Hack! CV Pitch Control




A little while back I decided to have a play experimenting with cassette recorders; making tape loops etc, and I got on ebay looking for a cheap player (having junked all the ones I owned years ago). I got quite lucky finding a job lot of FOUR identical Panasonic players for just over £20 for the lot!

Not only that but I found there is a service manual online complete with schematics and all kinds of lovely technical info


For my first experiment I wanted to add a pitch control, and it actually turned out to be easier than I expected!


In this player, when one of the buttons on the player is pressed, a switch supplies power at 6V to the motor. There doesn't seem to be any electronic speed control of the motor, and I think the faster FF/Rewind speed is implemented via gearing and mechanical ratio selection. Therefore all I needed to do was find some way to slow down the motor!

Doing this by reducing the motor voltage or current directly is a bit tricky - for example putting a potentiometer in series with the motor would not be a good approach as the pot would need to dissipate a lot of power and would likely get hot and the carbon track would soon burn out. 

Instead, the usual way of doing this type of speed control is to use Pulse Width Modulation (PWM) and some kind of electronic switch (e.g. a transistor). If you know synths, chances are you are familiar with PWM as a means of modulating a square wave to get a phasing kind of effect. What PWM does to a waveform is change the width of the "peaks" of a square wave relative to the "troughs" while keeping the frequency the same. As well as changing the audio character of the wave, PWM allows you to change the overall time a the square wave is "ON" vs "OFF" and therefore how much power the wave transfers averaged over time.

So lets say we feed the PWM'd square wave into a motor, the motor will spin faster as the proportion of time the power is ON vs OFF is increased. Therefore by controlling the PWM "duty cycle" (as this ratio is called) we can control the motor speed.

There are various ways to make a PWM signal, and the first thing I used was a circuit using a 555 timer chip (rather like this http://www.instructables.com/id/Simple-and-dirty-Pulse-Width-Modulation-PWM-Wi/). To actually drive the motor I didn't feed the oscillator output directly into the motor but instead fed it into the base of a TIP115 transistor (PNP Darlington Type), which was placed in series to the cassette motor positive wire (high side). This means the oscillator activates the transistor which then does the switching (as this is a PNP transistor, the switch is actually ON when the oscillator output is LOW)

This worked nicely and let me work the tape speed using a potentiometer to control the oscillator duty cycle. The frequency of the PWM carrier needed to be quite low for the motor to rotate rather than just whining). I went for about 70Hz.

Rather than a pot, what I really wanted was to be able to control the speed using a 5V CV (control voltage) signal which I can generate from a music sequencer. When I put +5V to the CV input I want the motor to run at normal speed. 0V should stop the motor. +2.5V should run at half speed (ideally). You get the picture...!

I could have done this with a 555 but it seemed like it might be hard to get a suitable circuit that would work right at the extremes (i.e. support 100% and 0% duty), plus I had a load of PIC12F1822 microcontrollers and know them really well (and they are same size as the 555) 

So I ended up with the following circuit (click to see full schematic)

The motor wires are shown at the right. The transistor (actually TIP115) is placed in series with the motor. 

The two diodes on the top right are 1N4001's and are there to drop off some of the 6V motor power voltage so that it is below the 5.5V limit of the PIC supply. The circuit is powered from the motor power supply so it powered only when a key is pressed on the player.

The diodes on the left are 1N4148 and clamp the incoming CV to the PIC power rails. 

R2 limits clamped CV current and I used 1k but it could be higher (e,g. 4k7). I soldered R2 directly to the socket, so it is not on the stripboard. 

I used a 100k Linear pot for the manual control with a 3.5mm jack that breaks the connection to the pot and overrides with external CV input. JP1 is a programming header.

The box in the middle is the PIC12F1822 microcontroller (DIP-8). Of course this a microcontroller based project, which is nothing without firmware! I'll include the firmware source below. 

The firmware works by having a loop in code actually do the PWM cycle (since I only want it to run at 70Hz there is no need to use the specialised PWM peripherals on the PIC). While the PWM cycle runs, the PIC's analog to digital converter (ADC) gets a 10 bit value from the CV input. I simply take the top 8 bits of the ADC reading and put them into my duty cycle variable.

On each PWM cycle the transistor is ON when the cycle starts and goes OFF when the duty counter (controlled by CV) is reached. So a lower CV will mean a shorter duty cycle.

Since the motor is switched on the high side, I need a PNP transistor. To turn the transistor ON I need to draw current from the transistor base (I think of the 'P' in PNP as 'pulling' a current out of it to switch it on - hmm yeah I know there's a 'P' in NPN too - shut up! :) 
So to turn on the transistor the PIC output PIN is set to a LOW output voltage so it can sink current from the transistor based. However since the PIC output pin will have a HIGH voltage lower than the transistor emitter (since PIC is powered at < 5.5V) that wont cut off the transistor. Therefore I switch the transistor during the PWM cycle by alternating the pin between output mode (with LOW state) and input mode (High impedence) where no current is sunk by the pin.

Conclusion : This is the only cassette player I've modded so far, but I am pretty sure that the same principle should be applicable to other players. One key fact with this one is that the low side of the motor is grounded, so I can power my circuit using the voltage difference between the motor supply and ground. I needed to make sure the motor voltage would not damage the circuit - in this player it is 6V so a couple of silicon diodes in series can drop this down into a safe voltage for the PIC (each diode drops off something like 0.4V)

Something else I did was to remove the erase head - this is because I want to use loops of tape and be able to record and overdub loops on the same player. An erase head will always leave a sound gap in a loop (corresponding to the physical gap between the erase and record/playback heads) and will prevent overdubs. In this player the erase head was a simple permanent magnet on a plastic arm which can simply be unclipped without damaging it (great if I need to erase anything later)

The tape I used is an answering machine outgoing message loop - works well but is quite long (30 seconds at normal speed). I might try making my own loops so they can be a bit shorter

This approach can only slow a tape down, not speed it up. I think you can only speed the tape up (at least using the same motor) by increasing the voltage, which might have consequences for other parts of the player circuitry. I think I prefer the effect of slowing playback right down to flappy graininess than speeding it up, but there is always the option of recording at slow speed to allow playback at faster speed.

First look inside

Simple 6V DC motor with grounded low side - nice!

Adding the wires to transistor and ground wire

The control circuit (will eventually be fitted inside player case)



The firmware source code - I am using SOURCEBOOST C but I think it should be fairly easy to port to other compilers or microcontrollers

#include

#pragma DATA _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _MCLRE_OFF &_CLKOUTEN_OFF
#pragma DATA _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_ON & _BORV_19 & _LVP_OFF
#pragma CLOCK_FREQ 16000000
typedef unsigned char byte;

void main()
{
        // osc control / 16MHz / internal
        osccon = 0b01111010;
        
        // configure analog input AN3 enabled
ansela = 0b00010000;
        // turn on the ADC
        // ADC clock is Fosc/32
        // Result left justified (8 bit value in adresh register)
        // Voltage reference is power supply (VDD)
        adcon1=0b00100000; //fOSC/32
        adcon0=0b00001101; // Left justify / Vdd / AD on // AN3

byte count = 0;
byte duty = 0;
delay_ms(250); // delay to allow settling of power supply before starting to drive motor
        for(;;) {
if(count == duty) { // end of duty cycle (or start of zero duty cycle)
trisa.2 = 1;    // set drive pin as input (high impedence, floating)
}
else if(!count) { // start of duty cycle when 8 bit count rolls over
lata.2=0; // drive output pin LOW to sink current 
trisa.2 = 0;    // and enable pin output mode
}
if(!count) { // at start of duty cycle we store the previous ADC result and 
// kick off a new ADC reading
duty = adresh;
adcon0.1=1;
}
++count; // duty cycle count (just allow 8 bit value to roll over to 0)
delay_us(50); // delay gives ~50-70Hz carrier
        }        
}




Tuesday, 14 March 2017

Calculator Music

When I was about 10, I really wanted a synthesizer! This was the start of the 80's and the cheapest synths probably cost about the same as cars or something. At 10 I didn't know anything about trying to make my own one, but I did discover that my stepdad's snazzy calculator would interfere with the radio.. and the buzzing tones it made changed pitch depending what combinations of keys I pressed ... .AWESOME!!! A SYNTH!!!!

Having got back into making weird noises over the last few years, I decided to try and recreate this formative experience. I racked my brain trying to remember what that calculator looked like - I thought it was a Texas Instruments one, and after a look at the Datamath Calculator Museum (http://www.datamath.org/) I got a little ping of recognition when I saw the TI-2550 (actually it was the number I remember - the calculator itself I remember looking very snazzy, compact and futuristic not like the clunky brick I saw online :-) And there was a reasonably priced one going on eBay!!

So here is the result - I think my expectations of synthesizer capabilites are rather higher these days - in my memory it wasn't restricted to about 3 notes or drowning in static, but here we go - it might still be interesting. I used a Moog MF Drive pedal for the distortion/lowpass (to try to make the static less harsh)

The pitch seems to be generated by RF interference from the keyboard matrix scanning and changes depending on the number of keys (and which keys) pressed together. It shows up in medium wave AM band. Tuning around changes the timbre of the sound but it still only ever manages about 3 notes plus an open drone - but just look at all that crazy stuff happening on the display!!!

I will probably open this up and see if I can get more sounds going on with it - I am wondering about bringing the display multiplexing into it - the refresh seems slow so maybe it can be played out at audio frequency - I wonder if the display signal can be fed back into the keyboard matrix scanning to get some crazy feedback loop going...?


Monday, 27 February 2017

Meet the WOBATRON


LED matrix displays are everywhere... I've made and used them in many projects. Typically the rows and columns of the display are driven by components called "shift registers" usually with eight outputs controlled by "shifting" in data, one bit at a time. when a "store clock" pulse is received all the data can be moved on to the output pins, lighting up a set of LEDs.

Using a microcontroller (i.e. a computer chip), information can be loaded onto the display shift registers one row at a time and used to show text and so on. Most displays work by "multiplexing" the rows so that there is only one row lit at a time, but the persistance of vision of our eyes makes it seem that all the rows are on at once.

A few weeks ago I was inspired by a chat with a friend (Brighton sound artist Lorah Pierre) to see what would happen if random noise signals were fed into the shift registers controlling the matrix instead of the usual orderly data from a computer. The easiest way to test that is simply to power it up and touch the data input wires! Stray electrical noise is enough to make the display think its getting data and for things to happen on the LEDs...

The next step was to try it with something a bit more controllable. I did some experiments with an LED matrix I'd already made for another project and LOVED the results, so I decided to make something a bit bigger and more flexible especially for the purpose.

The WOBATRON is an LED matrix made up of 16 x 16 white, 0.5W 8mm LEDs. These are fitted into a laser cut grid on a "honeycomb" pattern (which I though would look cooler than a square grid). The LED mounting sheet is 5mm acrylic with another sheet of 5mm acrylic in front, cut with the hexagonal baffles. The front diffuser is 3mm frosted blue acrylic.
Baffle construction

The LEDs are wired in a grid. Every LED has a 100 ohm series resistor (Since the rows and columns are not going to be multiplexed. I didn't want to share current limiting resistors between LEDs).

Matrix wiring

Driver boards for matrix
The rows and columns are driven by transistor arrays (2 x ULN2803 on low side, 2 x A2982 on high side). These are driven by 74HC595 shift registers with the following signal inputs going to the control box where they are broken out to 4mm sockets.

  • Column drive data line, shift clock line, store clock line
  • Row drive data line, shift clock line, store clock line
  • Output enable (pulled down when not connection) to allow display blanking

In the control box is a 74HC14 hex inverter chip which is used to create six individual square wave oscillators with frequency pots (100k with 1k resistor in series). Four are "high frequency" with 0.1uF capacitor, then two are lower frequency oscillators with 10uF and 4.7uF capacitors. All these six outputs go to 4mm sockets so they can be patched to the display signal inputs with external leads. There are 4k7 resistors inline with the outputs as to allow signals to be mixed together and to prevent problems due to outputs being shorted together.

Control box with patch cables

Control box circuit

Two of the oscillators also feed a pair of "linear feeback shift registers" (LFSRs). These are clever little circuits that work by feeding data into a standard shift register that is an exclusive OR function of some of its outputs. By some clever mathematical jiggery-pokery that is beyond me, it is possible to set this up to that the outputs of the shift register will cycle through all the 255 (exclusing 0) possible combinations of 8 bits, in a "random" order (of course its not random, it repeats time after time, but it is far from sequential)

I think these are the best bit of the control box, since they allow for some very complex (but repeatable) signals to be generated, which give the best patterns on the display!

I wanted to be able to control the "density" of this signal, so I put the 8 bits of the output into an R-2R DAC. This is another simple but clever circuit which does a binary addition of the 8 output bits of the shift register to generate a voltage level, just using a network of resistors of 2 values. This circuit is found inside most Digital to Analog Converters.
Output from R2R DAC fed by LFSR

Once I had an analog voltage level, I can compare it with a reference voltage (from a 100k potentiometer connected across the power rails) using an op-amp as a comparator. When the DAC output exceeds the voltage dialled up on the pot, the comparator output is HIGH. Since the DAC output is a "random" sequence varying over the whole voltage range, changing the comparator reference voltage allows the pot to dial up a "density" of HIGH values on the comparator output. This works well when fed into the data lines of the display.
Pulse train after comparator stage

The two comparator outputs (one from each LFSR-DAC-comparator circuit) also go to a pair of output sockets.

Now if an LFSR is in a state where all its output bits show zero, a zero will be fed back into it, so the sequence will not advance. When the circuit is powered up, there is a chance one or both LFSRs will be "stuck" in this state. To get around this there is a push button that will pull the LFSR inputs HIGH while pressed to get the LFSRs going if they are stuck.

I really love playing with this build! I could twiddle the knobs and stare into the display for hours (and I have done :). Its really hypnotic and trippy, especially when the oscillators are audible too (i just mix the signals through 100k resistors and feed to a mono audio output)

Despite the simple inputs, there are a lot of interactions possible between the signals that produce results that can only guessed at! Close frequencies which are mixed will produce beating, the shift registers "chop" the signals by sampling data inputs based on shift clock inputs and there is a kind of second order to this where the store clock is used. Then there are stroboscopic effects possible with the blanking input. I am sure I have only scratched the surface of what might appear at certain settings!

Here is a schematic of an earlier noise matrix build. The new one is very similar except the display is driven with transistor arrays on both the high and low sides and each LED has a series resistor. There are also now 6 oscillators and two noise generators, with all the signals patchable to matrix.



Sunday, 27 September 2015

Novation Release Custom Firmware API for Launchpad Pro!

The Novation Launchpad music controller has been around for several years in various form; it is a USB MIDI grid controller which is primarily designed to work with the Ableton Live program but can also be used as a MIDI controller on its own.

I am not a user of Live but I have always seen the potential of the Launchpad as part of a standalone MIDI sequencer, like a cheaper Monome. I bought my first Launchpad years ago and immediately got to work writing code to run against it.

 The original Launchpad showed up as a MIDI device (assuming you have Novations drivers installed) and you could open it using your programming language of choice (I was using C++ on Windows MIDI API).

Then when you press buttons you receive MIDI messages (notes for the grid and CC's for the menu buttons). Sending the same messages back to the controller turns the lights on and off. And it is pretty much that simple!

 My real aim was to get something that could run MIDI sequencers that were not tied to a PC, so I started looking at USB hosting from a microcontroller. The original Launchpad was not USB MIDI class compliant (that came with the Launchpad S) but used a custom interface based on interrupt endpoints. I pulled the descriptors and used an FTDI VNC2 USB host chip to implement sequencer sketches, which did work, but I had some issues with the early versions of FTDI's toolchain for the VNC2 and kind of ran out of steam.

Later on I started working on an Arduino shield where the VNC2 would just have the USB hosting duties, with the Arduino running the sequencer sketch. That project is still in the pipeline, but what I always thought to myself what would be REALLY good is if Novation opened up the Launchpad with a firmware API so developers like me could actually load custom firmware for sequencers, etc, into the Launchpad itself (in fact I've been wishing the same for lots of musical hardware – are you listening Arturia, Korg etc.. :)

 Anyway just last week I heard that they have actually gone and done it a couple of months back, with a custom firmware API for the Launchpad Pro!!! I immediately had the credit card in my hand and was unpacking a brand new Launchpad Pro the next day.

Check out the API here
https://github.com/dvhdr/launchpad-pro

 I can't quite express the awesomeness of this move my Novation!!! OK it may be a pretty niche thing right now, but I hope it sets a precedent where a creation of custom firmwares for these types of device really takes off.

 Anyway, I got started trying to make a version of one of the sequencers I originally built on the original Launchpad and the FTDI VNC2. Novation 's API provides a simple set of callbacks that you implement in your “app”. These are an initialisation routine and handlers for incoming MIDI messages, button presses etc. Plus there is a simple set of hardware abstraction functions for controlling the lights behind the buttons, sending MIDI etc.

 The architecture is 32-bit ARM and Novation helpfully provide a Ubuntu Virtual Machine image of a configured development environment using Eclipse and GNU C for ARM. A default firmware project is provided which it is pretty easy to start playing with. The make process invokes a utility to convert the output HEX files into a MIDI SYSEX which can be sent to the Launchpad Pro over USB.

In order for the device to take new firmware it needs to be set into a bootloader mode (by holding the Setup button when powering on).  I quickly discovered an issue; after uploading custom firmware, the Launchpad was not enumerating as a USB MIDI device any more (in fact it was lost to USB until put back into bootloader mode). After trying to work out what I was doing wrong, I contacted the Novation development team via Github and raised an issue which they have acknowledged and will hopefully soon fix.

Luckily the LPPro does have a “real” MIDI connection in the form of a pair of 3.5mm jack sockets which break out to standard 5-pin MIDI connectors via supplied cables. This “hard” MIDI connection does work, so I have been able to use this for now to get output from my sketch to play an external synth.

When you load new firmware into the LPPro you are actually replacing the factory firmware. The SYSEX file for the factory firmware is supplied with the SDK so you can easily switch back to it, however there is no source code available for the factory firmware. Maybe this is not so surprising, but it does mean you have to take an “all or nothing” approach to customising the LPPro. There is no option to “tweak” the factory functionality without rewriting it yourself first! I hope Novation address this – maybe it would need the high level functionality of, say, the factory “drum” and “note” modes to be ported to the custom firmware API so the source for those could be released for customisation without having to open up all the proprietary low level stuff.

 I am using a Windows 7x64 machine and I did find that sometimes the VirtualBox VM / VAGRANT package was getting in a funny state such that my VM login could not access the source code projects in Linux (probably something I was doing wrong). Also there was the annoying need to copy the output SYSEX file from VM out to host OS on every build so I could upload it to MIDI. I eventually decided to install the GCC-ARM compiler and Eclipse IDE natively on Windows, but that was not too hard and Novations VM package was invaluable to see how the setup should work.

Another thing that gets a bit tiresome is the procedure for putting the LPPro into bootloader mode (a process which needs a manual power cycle of the LPPro and needs USB to re-enumerate, so the LPPro device needs to be re-selected in MIDI-OX before the SYSEX can be sent). When debugging you do this a lot and it gets annoying, not to mention putting extra wear and tear on the power switch. A nice feature would be a special SYSEX command to put the LPPro into bootloader mode without a power cycle and ideally without any USB re-enumeration. Then the SYSEX loader could set bootloader mode before uploading and all the steps included in a makefile (maybe this bootloader command could be “unlocked” via a physical button combination if there is a worry about unwanted firmware updating)

 Anyway, I am not going to complain any more. I applaud Novation for releasing this API and I hope other manufacturers of music and/or other devices follow suit. Interesting times!

This is my first sequencer project, I expect to be doing lots more like this over the coming weeks and months :)

You can get my code (forked repo) here
https://github.com/hotchk155/launchpad-pro

Or if you just want the sysex
https://github.com/hotchk155/launchpad-pro/blob/master/build/launchpad_pro.syx


Monday, 24 August 2015

Hammer Pong's Last Stand?

After several months in storage, Hammer Pong is coming back out for a final moment of glory at the Brighton Mini Maker Faire on 5th September Then unfortunately it'll be stripped down for parts... unless you want it? http://www.ebay.co.uk/itm/-/151790857896?

Saturday, 29 November 2014

A mini mixer for my lovely Volcas

I heart the Korg Volca range! If you don't know them already then, chances are you never will, however - they are a set of self-contained, affordable and  (mostly) analog synth/sequencer modules. There is a drum machine, 303-ish bassline synth, and a versatile 3-voice synth (they tease us with a currently unavailable sampler unit too). I love 'em .... but this isn't a review of them so Google as required..!


Anyway, if you have Volcas you'll need some kind of mixer to combine their audio output for your listening pleasure, Even if you do have one (and I do own a Mackie mini mixer) the spontaneous mini-scratchpad style of the Volca's really needs something simple and lightweight that does not take a lot of setting up, so I decided to make my own passive mini mixer that I could keep set up with my Volcas. I keep my Volcas set up on a guitar pedalboard case so I wanted something I can keep, ready to roll, in there too.

A simple passive mixer would do trick (i.e. just a bunch of sockets and resistors with no power needed) and a Hammond diecast aluminium stompbox enclosure would fit nicely in my setup.

I used stereo sockets, pots and wiring - although I think the Volcas are all mono, so maybe I overdid it there, still - it keeps options open. My design has 4 stereo input channels which are combined into a single stereo output. The passive design works pretty well with the Volcas (the outputs are for headphones so they are pretty hot, an active mixer would be wasting time I think)




I jazzed up the enclosure using a piece of yellow/black 2-layer acrylic laminate which I laser-etched with a lo-fi pic of a good old C-60 (mix tape / mixer, geddit?)


Monday, 15 September 2014

Sound Art and Non-compliant Seagulls

Just had an amazing day at the Fort Process sound and art festival at Newhaven Fort!

It's the first festival I've seen run at the fort, but with its labrynths of tunnels, staircases, passages and caverns it turned out to be the perfect venue. It was rather like being at a mad scientist convention in the dungeons of some Bavarian castle, all resonating with otherworldly chimes, lush drones and earsplitting bursts of static, never being sure what you'll find around the next corner. Often sublime, occasionally ridiculous, sometimes frankly terrifying.

My involvement was with Sara Jane Glendinning's project; The Landing. The concept was that the local seagulls would get involved by landing on a surface made up of sixteen large switch pads on the roof on one of the old gun emplacement towers, enticed by food of course. The pads were set up to trigger arrays of spoken word samples, field recordings and musical sounds when stepped on. These sounds were mixed with the live sound from a microphone on the roof and played to the audience at the base of the tower. A camera on the roof also relayed live images of the pads.

We used a Teensy (Arduino clone) to read all the switches and send MIDI over USB to a Mac running Propellerheads Reason. And it all seems to be working beautifully... except the gulls didn't want to play ball. We tried chips, fish heads, fish guts, our best gull impressions, but they resolutely stayed hovering high above and didn't come anywhere near our tower. Usually in these parts (or at least on Brighton beach) the gulls will gather round to terrorise any al fresco diner like something out of Hitchcock's Birds, or will swoop out of nowhere and make off with the top half of your ice cream. Not the Newhaven gulls though.. they were a bit crap. Or maybe they were just deeply suspicious of a handout. Or maybe they are so used to doughnuts and burgers they have forgotten what a fish looks like...

It was not all lost though.. it was a windy day and occasionally the pads would trigger by themselves. There was a Dali-esque treat in store for those who wandered over to our monitor screen to see fish heads, arranged over what looked like a big chessboard, apparently chatting to each other ("No No No!", "Over Here!")!



The tower

The crap gulls

No no no no!