DAC Board for Gadgeteer

Few proto board are on the way. I’ll get at the end of next week … Sad enough no black silk this batch, but the usual boring green … :’(

Is this is your first designed board?

It’s the first gadgeteer, but not first ! i also Made board by myself.
But this time I’ve changed the pcb supplier and them for proto qty offer only green silk.
Will see

The PCB are on the way, seems to be good enough although THT.
As I could imagine I’m getting crazy for Samtec connectors. I bought samples from 4UCONN but this good guys ship in April from China, so I’ll get here in May (if lucky).
I know that GHI sell them, but to get here in Europe too much money for shipment.
That’s what I was thinking until I saw Farnell prices!! … In europe only Farnell Element14 (price is like diamonds) has in stock so I bought few pieces :’(, and I will receive on monday :P.

Ok, first module up and running on Hydra …

:frowning: no black silk …

This is assembled board …

Looking good!

Now I’ve done a small driver for the board.


using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace HydraDacTest
{
    public enum Gain
    {
        GAIN_2X = 0,
        GAIN_1X = 1
    }

    public enum Channel
    {
        CHANNEL_A = 0,
        CHANNEL_B = 1
    }

    public class DacBoard: IDisposable
    {
        int _socketnum;
        SPI DacSpi;
        SPI.Configuration SpiConf;

        public DacBoard(int socketnum, int SpiKhz)
        {
            _socketnum = socketnum;
            GT.Socket socks = GT.Socket.GetSocket(socketnum, false, null, null);
            SpiConf = new SPI.Configuration((Cpu.Pin)socks.CpuPins[6], false, 0, 1, false, true, (uint) SpiKhz, socks.SPIModule);
            DacSpi = new SPI(SpiConf);
        }

        public void DAC_Output(Channel ch, Gain g, uint value)
        {
            UInt16[] datatx = new UInt16[1];

            PhyDAC_Output((byte)ch, (byte)g, value, datatx);
            DacSpi.Write(datatx);

        }

        void PhyDAC_Output(byte ch, byte gain, uint valueDAC, UInt16[] txbuf)
        {
            byte temp;

            // Send High Byte
            temp = (byte)((valueDAC >> 8) & 0x0F);         // Store valueDAC[11..8] to temp[3..0]
            byte wrreg =  (byte)((ch << 7) | (gain << 5) | 0x10 | temp);  // Define DAC setting, see MCP4921/22 datasheet
            //txbuf[0] = wrreg;

            // Send Low Byte
            temp = (byte)(valueDAC & 0x00FF);              // Store valueDAC[7..0] to temp[7..0]
            txbuf[0] = (UInt16) ((wrreg << 8) | temp);                               // Send low byte via SPI
        }
        
        public void Dispose()
        {
            SpiConf = null;
            DacSpi = null;
        }
        
    }
}

..
// using example
       void ProgramStarted()
        {
            GT.Timer tm = new GT.Timer(100);
            tm.Tick += new GT.Timer.TickEventHandler(tm_Tick);
            DACvalue = 0;    
            updown = 1;
            dac = new DacBoard(4, 10000); 
            Debug.Print("Program Started");
            //tm.Start();
            Thread dacthread = new Thread(new ThreadStart(ThreadDac));
            dacthread.Start();
        }

        void SetDacValues()
        {
            if (updown == 1 && DACvalue >= 4096)
            {
                DACvalue = 4095;
                updown = -1;
                PulseDebugLED();
            }
            else if (updown == -1 && DACvalue < 0)
            {
                DACvalue = 0;
                updown = 1;
                PulseDebugLED();
            }
            dac.DAC_Output(Channel.CHANNEL_B, Gain.GAIN_1X, (uint)DACvalue);
            DACvalue += (updown * 4);
        }

        void ThreadDac()
        {
            while (true)
            {
                SetDacValues();
                Thread.Sleep(5);
            }
        }



Awesome!

What kind of sample rate can you get out of that?

A nit before you go too far. Here are the .NET Naming Conventions on my site:

Hope those help. Conventions are important when developing a public API.

Pete

Hi Pete,
I’ll take a look to the specs, thank you for the link.

I need this weekend to make better test and better driver, but at first impression I get no more than 900 hz (with SPI 15MHZ) using a wave sysnthetized in a table (256 points waveform) with pure .NET. On a Pic18F 40Mhz I get 30Khz, executing few other task (C native compiled).
Really I need DAC not for waveform generating, but It will be nice to know real limit in .NET MF.

In any case I see on the datasheet that one clock period take min 30ns + other delay to settle the dac out and CS, it will become 30*16ns + 50ns = 530ns at the best that means more than 1,8 MHZ teoretical 1ch performance … 256point wave = ~7,3 khz waveform …

Thanks. That’s consistent with what I experienced when I interfaced with a DAC some time ago. I was interested in it for generating real-time sound (synthesizer stuff), but NETMF is waaaaay too slow for something like that, where you want at least 22KHz, if not 44KHz stereo. It’s just not its sweet spot.

So, what are your plans for the DAC?

Pete

Well Pete,
for my needs this is fast enough, I don’t need a DDS like board. I will need soon. In any case I will put on the wiki as soon as I’ll finish up the driver. May be someone is interested.
Probably I will make in a few week a board for DAC and ADC with R2R amplifier, both on the same board but I’m thinking to Analog Device chips.
I’m looking to AD9851 DDS for a new project, and I would drive it with Hydra.

Pete,
may be you are interested in this chip : Mixed-signal and digital signal processing ICs | Analog Devices
I had never used, but a collegue that works in audio devices seems quite happy with it.

Finally on codeshare you can find driver and example for the DAC MCP4922 module.

I’ve few module available if someone is interested. I sell for of $22 plus shipping. Please mail me : dome at ledonet dot it

Congrats! Looks good!