Saturday, July 30, 2016

The Ultrasaw explained

While looking at the Matrixbrute from Arturia I noticed that it has an additional waveform called the Ultrasaw. I have heard about it previously, but got curious about exactly what it was and started looking at the documentation.

Apparently it is two additional saw waves with the same frequency as the first one, but phase shifted. The phase shift varies and is controlled by two built in LFOs. One wave has a constant phase shift rate while the other one is user variable.

I began thinking about how I would create such a circuit. Then I discovered that Yves Usson, designer of the xxxBrutes, had actually posted the MiniBrute circuit diagram on his site Hack a Brute.

I have studied the circuit closely and it seems half of the design matches my initial thoughts, but how the wave is phase shifted is really quite simple and ingenious. It resembles how my saw sub oscillator works, by shifting parts of the original wave up and down.


Let me explain.



The circuit looks like this (disclaimer: I do not own this circuit diagram, nor have I asked for the permission of Arturia or Mr. Usson to post it here. It is not in the public domain and is only reprinted here for educational use).

Figure 1

I have separated the circuit into three logical parts:
- The LFOs controlling the rate of phase change (left)
- The phase shifter (center)
- The wave mixer and volume control (right)

The LFOs

The LFOs consists of two main parts. To the left is a triangle wave oscillator. According to the MiniBrute documentation, the top one is fixed at 1Hz while the bottom one is user variable between 0.1Hz and 10Hz. The triangle wave design is the exact same one as the one in Texas Instruments' "Op amps for everyone", see Circuit 1-9 here or A.5.8 on page 446 of the original book. (PS: The book uses a unipolar power supply while the MiniBrute has a bipolar (+/- 12V) PSU).

To the right of the triangle wave oscillators is a triangle-to-sine wave converter. Its design is the same as the one in mr Usson's Yusynth VCO module.

Formula A-49 in the TI book gives us the amplitude of the triangle wave oscillator: Amplitude = +/- 24V * 47kOhm / 2 * 120kOhm = +/- 4.7V.

I have not calculated the output amplitude of the sine converter. Neither do I know the amplitude of the input saw wave, but it would be a reasonable guess that it is +/- 5V, a common value in synths.

A sine wave amplitude of +/- 5V would give a +/-100% phase shift in the phase shift in the next stage. Since a phase shift of -10% is really the same as a +90% percent shift, it seems unnecessary to have a shift larger than +/- 50%. It could even be that a smaller range is desireable, who knows. In the next section I'll assume that both the phase shift CV (sine LFO output) and the saw wave amplitudes are +/- 5V. It makes no difference for the understanding of the circuit.

The phase shifters

This is the funny part. The phase shifter circuits take a control voltage (the output from the LFOs) and the output from the MiniBrute's saw wave oscillator, and shifts the saw wave phase back or forward.

But how?

For simplicity, lets forget that the CV is coming from an LFO and instead treat it like a constant value. The control voltage (CV) desides how much we want to shift the saw wave back or forth. It does this by comparing the CV with the saw wave. When the rising input saw wave reaches the same value as the CV, thats where the shifted wave will start its cycle. This means that the phase shift is relative to the frequency of the input wave, it stays the same (in percent or degrees) even if the input saw wave's frequency changes. (This, by the way, was what I got right in my initial idea).

When the circuit has found where it wants to reset the saw wave, it sort of "chops off" the top of the input wave and moves it to the bottom of the wave instead. It then re-centers the wave for an even amplitude, and voilĂ , the saw wave has been shifted.

The detection and shifting happens in three sub circuits that are then summed to get the shifted wave:
1) The original saw wave
2) A comparator that compares the saw wave and the CV
3) An inverter that inverts the CV

Number 1 and 3 are simple to understand, but number 2 requires a bit of explanation.

An op amp without any feedback acts as a comparator. Whenever the input on the positive terminal is higher than the input on the negative terminal (usually called V ref), the output will instantly change to equal the positive supply voltage. If the input on the positive terminal is below the input on the negative terminal, the output will change to equal the negative supply voltage.

In our circuit the saw wave is connected to the negative terminal and acts as Vref:

Figure 2

Here is a graph that shows the how the input saw wave and the CV relate to the output of the comparator:
Figure 3

Again, whenever the saw wave is lower than than the CV, the output is 12V. When the saw wave is higher than the CV, the comparator output drops to -12V.

The output is scaled by the 220kOhm resistor and the diode at its output. PS: I have not thought enough about what the diode actually does. It may chop of the negative output from the comparator. For now we'll assume that the output is bipolar and scaled to +/- 5V.

Now, this is where the magic happens. The output from the comparator is summed with the original saw wave and the inverted CV, and out pops a shifted wave. Lets see how.

First, lets see what happens when we sum the saw wave with the comparator output
Figure 4

To make things easier to understand, I've color coded the parts where the CV is higher than the wave red and the parts where the CV is lower than the wave blue. As mentioned earlier, the point where the color changes from red to blue is the point where we want the phase of the output wave to start.

Summing the saw wave and the comparator output effectively moved the blue parts down and the red parts up, in a way that makes the lines align again. the fourth graph in the figure above shows how the result (red) is phase shifted in relation to the initial saw wave (grey dotted lines). It is however also shifted vertically.

So how do we fix this? Take a closer look at the first graph in figure 4. The top corner of the red triangles are what becomes the top corners of the resulting wave. The top corner should be at exactly 5V in the output. The comparator output will move the tip upwards 5V, but since the corner starts at a positive voltage instead of 0V it will end up higher than 5V. Thus, we have to move it back down a bit. How much? Well, things had been ok if the corner was initially at 0V, But it is at CV volts (remember, that is the definition of the corner, the intersection between the CV and the saw wave). Thus, we have to move everything downwards by CV volts:


The last graph in figure 5 shows the result - the saw wave has been phase shifted. The two operations in figure 4 and 5 plus the scaling of the comparator output happens simultaneously in the summer of the Phase Shift blocks of the circuit.

Finally the two saw waves are summed and sent through the SuperSaw (!) amount pot RP1A, which acts as a voltage divider scaling the output to between 0 and 100%. The SawAnimator out is then mixed with the raw saw wave elsewhere.

Thursday, July 14, 2016

XM8 progress

I've been working a lot on the xm8 lately. All the work has been gui related, and now I have a working matrix, virtual controllers, setup for nodes, controllers, links and more. I am working on a visual tool to create whole control surfaces and it's looking pretty good. No major feature is missing except for a gui for wifi configuration. I still have a bit of work to do on input configuration serialization (and deserialization on the microcontroller) but things are coming along nicely. Of course there are tons of things to add, like voice assignment, arpeggiator or sequencer functionality, cloud storage etc, but these aren't necessary in the initial version.

Screenshots will be up soon.

Wednesday, May 25, 2016

A dac as a replacement for a VCA

A DAC may be used to digitally control the attenuation of a signal by connecting the signal to the DACs Voltage reference input. Most DACs only allow a positive reference voltage lower than the positive supply voltage, so one has to use a device called a multiplying DAC, such as the MX7521.

A circuit like this may be called a NCA (numerically controlled amplifier) or DCA (digitally controlled amplifier)

Some possible devices:
MX7520 - single 10bit dac @ NOK 32,-
MX7501 - single 12bit dac @ NOK 51,-
AD5414 - dual 12bit dac @ NOK 96,-
DAC8803 - quad 14bit dac @ NOK 211,-

Saturday, March 26, 2016

T-baneklokke - coundown clock

Some time ago I grew tired of my wife asking if she had to leave soon to get to the metro in time. I did what any sensible techie would and made her a battery powered countdown clock.

The clock counts down to a selectable time, and repeats the countdown every 15 minutes (the normal interval for the metro over here). Three minutes before it is time to leave, the clock display starts flashing slowly to get your attention. Then, once you should have left, the clock counts UP, blinking fast, as you still have time to make it if you walk briskly. Once your time is TRULY up the countdown to the next metro starts.

To save batteries, the clock goes into as low power mode as possible after about an hour, and you have to switch it off and on again to restart it.

The clock is built using an Arduino, and has a battery powered real time clock to remember the time while powered off.

To make it truly stand alone I added the possibility to set the time and time-to-leave using buttons.

The clock was built into a custom made plexiglass box, and the outside covered with a design printed onto photo paper with a sticky back side. I used my wife's Cameo vinyl cutter printer to cut the paper - I just love that machine!

Here are some pictures from the process:
The Arduino with the RTC module to the right, time-set buttons in the middle and 7 segment display at the bottom.

To keep the top and bottom of the case in place while gluing on the sides, I built a little Lego rig. We all use Legos for prototyping, don't we?


The finished box

Sanded down to make the photo paper stick. 

Power switch and stand-offs added.

Everything fits snuggly. Notice that I kept the USB input to be able to update the software if necessary


Voila! The finished product. Now my wife is never late for the metro ever again. Riiight.


Sunday, March 6, 2016

Roland resistor nets for the IR3109

While researching IR3109 based filters I came across the schematics for the Jupiter 6. It has a neat multi mode filter, but the schematics show three resistor networks, and the resistor values for those are not shown.

Luckily, someone has figured out that the same resistors are used in the MKS80, which has most of the values - though not all of them.

From a bit of guessing I have come up with what I believe is the values and internal connections.

RM0688 - The schematics do not show the value for the resistor between 2 and 3, but it is rather safe to assume that it is a 100k resistor like all the others.

RM0690 - The MKS80 schematics shows a 7.7k resistor between 2 and 1. The Jupiter 6 schematics show two resistors without values, one from 1 to 2 and one from 1 to 3. As a 33k and a 10k resistor in parallel equals a 7.7k resistor, and these values are already used in the net, it is very likely that these are the missing values. If we at the same time assume that the positions are reverse those in the other half of the net, just like in the RM0688, we get the schematics above. PS: I have yet to see a usage of this net where 2 and 3 are not connected, so it is in reality only the combined value that matters.

RM0891
The resistor nets have different part numbers and designations in the various synths:

13919128 - RM0688 - RKM8C066
13919130 - RM0690 - RKM8C068
13919132 - RM0891 - RKM9F561/683GP

Friday, February 26, 2016

typedef, structs and function pointers

Just a quick reminder about structs and typedefs in C:


A named struct is created like this:

struct MyStruct{
  int anInt;
}

A custom type like this:

typedef int MyType;


The two syntaxes may be combined like this

typedef struct MyStruct{
  int anInt;
} MyType;


In use you can then either write

void myFunction(struct MyStruct someValue);

or

void myFunction(MyType someValue);


in the latter case omitting the struct keyword.


Function pointers


A variable containing a pointer to a function can be written like this:

returnType (*pointerName)(parameterType)

For example:

void (*myFunctionPointer)(int)


The pointer is then for example assigned like this:

myFunctionPointer = &someFunction;


Combined with typedef you can get:

typedef void (*myFunctionPointerType)(int)

and then use myFunctionPointer as a type:

myFunctionPointer aFunction = &someFunction;

Sunday, February 21, 2016

XM8 32 channel CV works

I've spent some time the last few days getting the sample and hold part of the 32 channel DAC to work properly.

As is usual, I messed some things up in the initial design. The DAC board is connected to the 32ch sample/hold via a connector. This goes in a U-shape but I forgot that this means that pin 1 on connector one becomes pin 2 on the other and vice versa. As power as well as signals are transferred through this connector, nothing worked right. Weirdly enough though, nothing broke, it just got very hot.

From the initial tests I learned a few things:

- The type of opamp used with the DAC matters, at least visibly on the scope. Using a stock TL07x opamp produces slight a slight overshoot when the DAC output changes a lot. Using a AD8672 precision opamp instead removes the overshoot.

The S&H circuit shows a similar overshoot when it is set. As the S&H is all TL074 it could be that it is fixed in a similar manner. I just don't know how much it matters.
The output as seen between the DAC and the sample and hold shift register - the initial rising curve shows the output from the DAC. The drop is caused by the enabling of the shift register, connecting the DAC to the sample and hold which is currently at its most negative, so it takes a short amount of time before it charges to the same level as the DAC. The peak is where the charging of the sample and hold capacitor overshoots. It is of the same kind but more dramatic than then one we see in the DAC output photos above and may be caused by the TL074.
A more detailed photo showing the charging and overshoot.

- I connected the output of the S&H to the pitch and filter inputs of a Moog Little Phatty. It worked very well, but I got an audible clicking noise four times per second. It went away when I removed sampling of all but one input potentiometer from the PIC32, so it may not be a problem in real life where the potmeters will be sampled from a completely separate circuit.

- At very high frequencies there is a slight ringing to the sound, I presume this is some kind of aliasing. I could not hear much of it when I turned off sampling of all potmeters but it should be investigated further.

- Oscilloscopes have a horizontal scale calibration potmeter. I spent hours trying to understand why the results I got did not seem to match the output frequency I was expecting, untill I realised that I had made two crucial mistakes: The oscilloscope scale was way off (fixed by connecting a function generator) and I had not set the internal PLL divider in the PIC32 correctly (it was running five times slower than expected!)


The output of one of the 32 sample and hold cells when running at full speed with 32 operating cells. DAC switches between +/- 5V.


Just for fun: My test rig. From left: Four potmeters that sets the CV (read using the ADC in the PIC32), a solderless breadboard that just reconfigures one of the ribbon cables, the EasyPIC fusion 7 development board from Mikroelektronika, which contains the PIC32, and on top of it: four quarter inch jacks connected to outputs 29,30 ,31 and 32 of the DAC circuit. To the right: My Moog Little Phatty


Wednesday, February 10, 2016

XM8 DAC board works after all

It's been almost a year since I designed the XM8 DAC and sample and hold boards. When testing the original DAC board I couldn't make it work.I suspected I had broken the DAC chip, and at $20-30 per chip I did not want to waste another untill I had verified my design.

The AD5547 DAC is a 38 pin smd component, with 0.5mm pitch. A real pain in the ass to solder. To breadboard it I had to order an adapter PCB. First time off I got an 0.8mm pitch adapter which of course was useless. Then I designed and ordered another adapter. Due to lack of time and other projects having priority, I never got around to soldering and trying it.

About a week ago I finally worked up the courage and found the time to try breadboarding the circuit. It worked flawlessly and let me write a code example that could be adapted to the PCB version.

Today, after about one hour of trial and error, and with six toddlers screaming and crying around me, I got the original board working! Without any modification! (I did however mess up and somehow connected analog or digital ground to +3v3 (I think) when trying to connect the two grounds, giving me some very weird results. After reconnecting however, everything works like it should.

Here is a picture of the result. The code runs at almost maximum speed on an 80MHz PIC32MX. The output is increased by 10 every time the DAC is updated, giving us about 6500 steps per rise. The scope is set to 2v/square vertically which shows a perfect +/-5V swing.

Horisontally the scope is set to 0.5ms/square which means that each rise takes about 2,5ms which gives a frequency of about 400Hz and a sample rate of 2.5MHz

The assembly code of the loop is 23 commands long. On the 80MHz microcontroller we should be able to run the loop at about 3.5MHz if each command takes one clock cycle, so 2.5MHz seems entirely reasonable. I may have misunderstood something but I think this is the correct speed.