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.