12bit SPI DAC/ADC using the UBW32

January 07, 2014

So I’ve been hacking together the basic building blocks to make a 12 bit synth module starter kit using the UBS32 and two 12 bit SPI chips from Microchip.

I had been doing this work using a Teensy 3.0 but that boards SPI libraries are so convoluted and broken that even after trying 4 different incarnations of the damn thing, I was still not able to get the damn board to spit out data at 24MHz over the SPI bus like it’s supposed to be able to do.

Even worse, since I’m trying to build this project as a standalone board, if I continued using the Teensy I’d have to plop the full Teensy hardware stack onto my board. No thanks!

Since I’ve also got a 24bit I2S project coming along with the dsPIC32 line, I figured I might as well prototype the next few projects using the PIC32MX460 on the UBW32 board.

And I just had success! No problems with the SPI libraries, no problems with weird peripheral interactions, no toolchain versioning issues, no power supply issues… Just hooked the damn pins up, pumped the 16 bit value into the SPI write methods and they plopped onto the chip. Same with the 32 bit value needed for the ADC.

Once again, I’ve found the Microchip line to be so much more easy to get my head around.

Still, after all of this, the maximum frequency I can dump out is a square wave at about 36 kilohertz. And that’s not fast enough for a digital VCO…. but it should be plenty for any CV control!

Next, I’ve gotta build an input buffer for the ADC so I can start recording CV’s….

EDIT:

Oops! today I looked through the code again and realized that I had forgotten to remove the delay’s in the output loop! 10 microseconds is obviously going to limit the frequency

After removing those silly delay’s, the frequency I’m getting is MUCH closer to what I expected! However, the portable oscilloscope I’ve got isn’t able to really show a clean wave (capacitance on the protoboard probably causing some filtering and clock edge mangling…but whatever…). Still, it’s pretty good, and the frequency is hovering around 230 kHz

WAY, WAY better then 40kHz!

So maybe there’s hope for a clean 12 bit digital VCO module after all…

Today was also going to include reading the ADC and spitting the read value back out to the DAC… and once again, the PIC32 line is hella easy to write SPI code for. So a little here… and a little there… annnd….

EDIT:

It’s working! I had to mush the 32 bit ADC transfer into two chunks of 16 bits since the DAC needs 16 bits in it’s transfer… But that was what was giving me hell on the Teensy 3.0 and the PIC32 just works!

So now, when I turn the knob, the ADC picks up the voltage (between 0 and 4095), hands the value over to the DAC, and the DAC spits out the same value! Sweet!

But, we still hit a problem:

When the SPI bus is running at 20 MHz, the ADC doesn’t accurately sample the incoming voltage. The chip’s data sheet says it can do 24MHz… so what’s the issue?

Well, the input isn’t buffered! And since high speed ADC’s need clean input, a non-buffered input messes with the sampling circuit.

I noticed this issue on the Teensy board but I was messing with the SPI code too much to be able to lay out the buffer circuit. Notice the third chip in the picture? That’s an opamp! It’s going to be used for an input buffer.

If it works, maybe I can finally get down to writing some fun synth related code!

EDIT:

Oops! Again… After reading through the data sheet a little more carefully, I realized at some point I had made an incorrect assumption about the chips I’m working with.

The MCP4921 DAC can run at clock rates of 20 MHz.

But the MCP3204 ADC can only run at clock rates of 1 or 2 MHz (at 2.7V and 5V respectively).

So, that limits what I can do on the input side of this system… I could probably do a course and fine pitch for a VCO… but I wouldn’t be able to do FM… but I could easily do most CV output!

What a fun learning experience! I guess the next step is to build a similar circuit with better converters! At least I have the SPI libraries working for the PIC32MX line!

And maybe an envelope generator…!

The working board hooked up. Saleae logic 8 watching the SPI lines…:

The working board hooked up. Saleae logic 8 watching the SPI lines...


James Hagerman

Written by James Hagerman

© 2026