Sunday, September 29, 2013

Midi to control voltage converter

I've started working on this little circuit which will allow me to use a MIDI keyboard as control voltage for my VCO. Since MIDI is a serial protocol, I will need a microcontroller to interpret these signals. I will also need a DAC to get my control voltages. The DAC needs to be of the higher bit-type, since the VCO will need careful tuning to sound nice. I didn't find any simple microcontroller with more than 5 bits DAC, which is all little small. I did however find a nice cheap combo. A 12-bit I2C controlled DAC, MCP4725, and a 8 pin microcontroller with built in support for both UART and I2C, PIC12F1822. The DAC needs a voltage reference as both reference and supply, ZRC400F01 seems to work. All components are on the cheap and costs me less than 3€ for the lot. DAC and reference are small, surface mount components, so they are trickier to prototype with.
Midi 2 VCO converter, first steps. 

DAC

The DAC part can be seen to the right in the schematic. I've tested it out using an Aardvark I2C host adapter I borrowed from work, and it seems to work fine. When I choose the voltage reference, I thought that the 4.096V reference would fit well with a 12 bit DAC (0.001V/bit), but the DAC isn't perfectly rail to rail, so I effectively get a 0-4V DAC. I might just upgrade this with a 5V reference instead. Ideally it would be better with a higher voltage DAC since I intend to build a 1 octave/V VCO, and 0-4 V only gives me 3 octaves (4 if I upgrade to 5 V).

Microcontroller

Microcontroller  is seen to the left in the schematic. The symbol for the PIC doesn't have the correct pin descriptions, but is generally the same as the one I use, regarding supply, IO's and programming pins. I made a hello world program that blinks an LED using interrupts. This may seems simple, but it gives me a starting point where I know that IO's, clocks and interrupts are working. 
Next thing will be getting some UART communication working, and connecting it to the I2C bus.
Some Hello World!-action. Microcontroller to the right, DAC and reference to the left.

Microcontroller source code

1:  //Hello world with LED connected to RA0 on a PIC12F1822  
2:    
3:  #include <xc.h>  
4:    
5:  //Configuration bits  
6:  #pragma config WDTE=OFF, PWRTE = OFF, MCLRE=OFF, BOREN=OFF, FCMEN=OFF, CLKOUTEN = OFF, IESO=OFF, FOSC=INTOSC, CPD=OFF, LVP = ON, BORV = 0  
7:    
8:    
9:  void main()  
10:  {  
11:    //0 Internal oscillator, 3 <fosc> on, 6-4 31kHz  
12:    OSCCON = 0b00000000;  
13:    
14:    //Interrupt controller  
15:    //5 Timer0 overflow interrupt enabled  
16:    //7 Global interrupt enabled  
17:    INTCON = 0b10100000;  
18:    
19:    //Timer0  
20:    TMR0 = 0x00;  
21:    
22:    //Option Register  
23:    //2-0 Prescaler 1:4  
24:    //3 prescaler assigned to Timer0  
25:    //4 timer edge, high to low  
26:    OPTION_REG = 0b11010001;  
27:    
28:    //TRISA  
29:    //All A I/O's are set as outputs  
30:    TRISA = 0b0000000;  
31:    
32:    //PORTA  
33:    //RA0 is set  
34:    PORTA = 0b00000001;  
35:    
36:    //Loop forever, interrupts when Timer0 overflows  
37:    while(1)  
38:    {  
39:    }  
40:    
41:  }  
42:    
43:  //Interrupt routine  
44:  interrupt void isr (void)  
45:  {  
46:    //Ghost register of PORTA  
47:    int GPORTA;  
48:    
49:    //Read latch A into ghost register  
50:    GPORTA = LATA;  
51:    //Toggle bit 0  
52:    GPORTA = GPORTA^(1<<0);  
53:    //Write back into port register  
54:    PORTA = GPORTA;  
55:    
56:    //Clear interrupt flag  
57:    TMR0IF = 0;  
58:      
59:    return;  
60:  }  
61:    

Saturday, September 14, 2013

White Noise Generator + updated keyboard and mixer

Keyboard and mixer

I updated the keyboard by buffering the output with an emitter follower op amp. First I used a rail to rail op amp from microchip: MCP6271. I did forget that it had a maximum power spec of 6V, and I fed it 9V, so it started smoking after a while. It did work for quite a some time though... I replaced it with a ua741, but needed to fed that one with +-9V, to get a low enough output voltage. I really need to stock up on op amps...
 The mixer was updated with some 1% resistors for the inverter. I should probably use 1% resistors for the unity gain input and feedback resistor, to get a gain closer to 1 for that input. I also AC-coupled the other input, since DC-coupled signals puts the synthesiser out of tune.
Updated mixer schematic


White Noise Generator

I also built a simple white noise generator. It works by putting a NPN transistors base-emitter junction in reverse bias and overcoming the breakdown voltage of about 6V. By doing this, the junction will create white noise. Since the junction will conduct at first, and when it conducts the emitter voltage will drop, causing the transistor to stop conducting, which builds up the voltage above breakdown again, and so on. This happens really fast and thus noise is produced. The noise is very low voltage. I couldn't pick up the unamplyfied noise with my scope, and amplifying it with a 10000 gain opamp amplifier barely made it visible above the noise floor of the scope. So I used two opamps and amplified to the whole swing af the opamps.
 The noise can now be mixed  with the VCO control voltage, but it really creates a very broken and harsh sound. So it's probably better to mix it with the VCO output. I'll try that next time. I should probably also build another mixer, so that I can mix a wave with the control voltage, and the noise with VCO output, now I need to choose...
 On the next mixer I will get an op amp that can be turned off, so that I can use a gate signal from the keyboard to turn it on when playing a tune. As it is now, a high amplitude AC-coupled signal can have levels high enough to stimulate a VCO tune, which cause background noise when not pressing any buttons.
White Noise Generator schematic

White Noise Generator and mixer sharing the same quadruple op amp.


Monday, September 9, 2013

Summing amplifier mixer

I made a simple mixer for the synthesiser . It's a summing amplifier with two inputs, of which one is AC-coupled with a 47uF cap, so that the created high pass filter will still pass 0.1Hz signals through. My first idea was that this could be used to add some signal on top of the voltage passed on to the VCO, to create some pitch vibrato. This idea worked, but still failed, since the synthesiser gets totally out of tune when doing this. The problem is that what I thought of as unity gain from the summing amplifier, isn't really unity gain, since I'm using 5% resistors. The small change in gain can throw of the tuning, there is as little as 200mV difference between two semitones.
 Also, the simple keyboard uses a wild variety of potentiometers, who's resistance will be a part of the feedback network of the summing amplifiers. Thus the keyboards output needs buffering. I'll get back on the topic as soon as I'm done doing that.

Summing amplifier mixer, schematic

Summing amplifier mixer, actual board

Thursday, September 5, 2013

Simple VCO keyboard

To be able to play a bit on the synthesiser, I made a simple keyboard out of some old scrap I had in the junk bin. The construction is very simple: a potentiometer as voltage divider between rail and ground and a push button between output and wiper. Each button is tuned with the potentiometer and output is connected to the VCO. I made a full octave, starting with C, which gives 12 buttons and 12 potentiometers. Its was a bit boring to assemble, but works great.
VCO keyboard

Sunday, September 1, 2013

Unstable opamps, VCO and low pass filter

As I mentioned earlier there was some oscillation problems with the VCO sawtooth output. The problem was easily solved by biasing the opamp high. This makes the opamp faster and gives it a higher phase margin, thus making it more stable when driving capacitive loads. Since this solved the problem, I removed the opamp buffer from the output. The low pass filter had the same kind of issue, and it was solved in the same way.
 The filter also suffered from some clipping, which I solved by replacing R1 with a potentiometer and trying out the best value, which was 3.45k\(\Omega\). When P1 was set to the lowest resistance, there where some oscillations in the output. This was solved by putting 1k\(\Omega\) in series with each potentiometer terminal. I'll see if I can get my function generator to sweep out a bode plot of the filter, to see some details on it's characteristics.
Updated active filter schematics

 To get some higher tones out of the VCO, replaced C1 with a smaller capacitor. I needed a few tries to find a good match. A small capacitor gave a higher frequency, but the wave forms got scewed, probably due to unmatched resistors in the input stage. A smaller capacitor also raised the lower end frequency too high. This shows that I probably need to find a better VCO design, to get a higher bandwidth.

Thursday, August 29, 2013

Low pass filter and VCO update

VCO update

I added an LED to indicate the oscillation frequency of the VCO.  I also found an old power amplifier in the electronics junk room in the basement. From that I harvested a whole bunch of RCA jacks and a couple of very nice potentiometers. The jacks will be great for connecting modules, since RCA cables are shielded and easy to find/cheap. I disconnected the voltage source for the VCO, so now you have a choice of connecting either the voltage divider or another external voltage source to control the VCO.

I also discovered that when connecting the triangle wave output to a speaker (+ amplifier) i got some high frequency oscillations superimposed upon the triangle wave. I think these oscillations arise due to driving a capacitive load which is in the cabling or perhaps a DC-block capacitor in the amplifier. I'm going to deal with this later, but the TLC721 is a programmable opamp and is currently programmed as low biased. This is the slowest and most energy effective mode with a phase margin of 34°. The high bias mode has a phase margin of 47°, which might make the difference in this case. A first I thought that the output needed to be buffered, so I added an emitter follower opamp. This removed the oscillations from the original output opamp, but transferred the problem to the buffer output instead.

Superimposed oscillations on sawtooth wave. Upper waveform is from stage connected to amplifier. Lower waveform is from stage before output buffer.

Active Low Pass Filter

From The Art of Electronics, I took the simplest active filter circuit i could find. It's a two pole low pass Butterworth filter, which consists of two identical capacitors and two identical resistors, making up the filter, one opamp and two resistors for gain control.
Having two identical resistors that make up the filter gives a problem when making a variable filter, since you will need a double gang potentiometer. Lucky enough I found a couple of those in the power amplifier I mentioned. I took one that goes to 50k\(\Omega\). The -3dB frequency of the filter is given by
\[f_0 = \frac{1}{2 \pi RC}\]
with the lowest frequency being 20Hz, that gives me:
\[C = \frac{1}{2\pi 50000\Omega 20\text{Hz}} = 150 \text{nF}\]
with higher cutoff frequency with lower resistance in the potentiometer.

I added RCA jacks and the whole thing looks like this:
Active low pass filter schematic

Active low pass filter to the right

works like expected as well...


Monday, August 19, 2013

Voltage Controlled Oscillator

I'm looking into how analogue synthesizers work and plan to build a couple of modules. The first module to build is a VCO, Voltage Controlled Oscillator. I found a simple one in The art of Electronics which i built on a copper plane, Jim Williams style.
 Schematics and images are shown below.
VCO on copper plane. A potentiometer is used as voltage source.

VCO schematic based on design from The Art of Electronics.
In The Art of Electronics, 1% resistors are used in the input stage of the first Op-Amp. I didn't have any such resistors at home, but it seems to work well with 5% resistors. Max frequency is about 50Hz, which means this design isn't very useful as instrument, but it gave me something basic to start with. Also, voltage output from sawtooth and square wave where quite different. The square wave comes from a comparator with the full supply rail as swing.
Sawtooth and square wave output from VCO.

In the junk room in my cellar, I found an old power amplifier with a lot of RCA jacks on the back, which I'll use to connect the different modules to each other. More on this topic later on.