Tuesday, March 22, 2005

The interface nitty-gritty

Okay, I'm a bit bored of all this mechanics talk. I'm still working on the case, but I thought I'd talk about the interface for a change.

To recap, the aim of the inteface is to provide a MIDI in port that will take note on/off and velocity data messages on a specified channel and not only individually switch the keys of the SS30 on and off but also individually set their amplitude from the velocity data.

I have found from experimenting that if instead of simply shorting the key inputs to ground (as with the original keyboard) place a 10K potentiometer between the input and ground you set the loudness of the note played by that key. I'd suspected this was the case previously as the volume of the keys across the keyboard wasn't uniform and I'd put this down to the dirty contacts creating an impedance where there should have been a zero ohm contact.

So, if I can set a resistance across the key inputs from a combination of the note on/off and velocity data then I'll have a velocity sensitive MIDI interface for the SS30!

There are severals way to do this but I think they boil down to these two:

1) Use a DAC to set the gate voltage to a JFET acting an amplifier with gain between 0 and 1
2) Use a dedicated digital potenetiometer.

So which is better? The dedicted digital potenetiometers can be found in packages containing 6 pot's each. They would ceratinly make wiring easy and would keep the number of components low. I will err on the side of simplicity and persue these for now. If they become unworkable I may have to switch to the DAC-FETs solution.

So how am I to get the right MIDI data to these digital pots? I need a microcontoller to decode the MIDI data and then drive the pots and the simplest and most popular solutiuon with other people doing this kind of task is the range of 8-bit micros from Microchip Technology known as PICs (Programmable IC's) . I'm not going to say much more about them now but I will want one with an SPI (Serial Peripheral Interface) bus to drive the digital pot's.

Time for some maths! Hooray!

MIDI is transmitted at 31250 baud (31250 bits/s). Which means each bit's period is 1/31250 = 32us. Messages are transmitted in 10 bit packets with 8 data bits plus start and stop bits. So the message period is 320us.

Typical clock rate of a higher-end PIC is 40MHz (e.g. 18F458). This gives a clock period of 25 ns but a 100ns instruction cycle period with some assembler instructions (e.g. goto) taking 2 instruction cycles.

The SPI bus on a 40MHz PIC has a max clock rate (for 40MHz device) of 10Mbps. Which is 100ns per bit.

So what? Well, part of the key to this design is going to be the time avalibale to set a key after receiving a MIDI note message. The time avaliable would be 32us without a UART module in the PIC. Without a UART the program will have to be available every 32us to read the next bit but with a UART it only needs to read every byte which will arrive at the message rate of 320us.

320us is time to carry out 320 x 10e-6 / 100 x 10e-9 = 3200 single assmebler instructions or transmit as many bits on the SPI bus which should be plenty of time to decode the bytes and when neccessary update the digital pots for the 49 keys.

Analogue Devices make a 6 pot device, the AD5206 . The 5206 takes 11 data bits on the SPI bus, 3 to select the pot and 8 to set the postion of the wiper. So each pot is randomally accessable giving a fast access time. 9 of these could be used in parallel with a 4-16 line decoder selecting which device the data is for. This would give a write time in the region of a few micro seconds. With 9 AD5206’s daisy-chained (which might be easier to wire up) over 99 instructions would be needed per write but we're still well within the 3200 available.

But the PIC can only output a whole byte at a time so 11 bits will be tricky to manage.

The Maxim have a 6 pot packege DS1806 which clocks in 48 bits to set up the 6 pots. This equates to 4.8 us per device or 43.2 us for 9 devices in series which is still comfortably within the 320us. Good.

The only issue with the Ds1806 packge is that the resistance is linear and there are only 64 steps. If the key inputs respond in a logarithmic fashion, which I would expect, then I would have to re-scale the input velocity logarithmically. This can be done but as there are only 64 steps this may make the response a bit 'grainy'. The AD5206 is better in this respect as it has 256 steps but there remains the problem of writing 11 bits on the SPI bus.

An approximate log scale can be made from the linear taper by adding a resistor between the the wiper and ground as shown here. The flaw in this approach is that the 'pad' resistor is present even when the potentiometer is at zero ohms. More work needs to be done to see if this can be made to work.

That's enough for now...

No comments :