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 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


#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;
++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 ( 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


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.