10 years, 11 months ago.

Help connecting DAC with 11u24

Hello guys , I am just starting to use my new mbed 11u24 board and I need to connect it to a DAC so that I can create an analog signal of specified frequency and amplitude . I have tried to connect my DAC using I2C initially without getting a good results and so I ve tried using the SPI to connect it , still with problematic responses . Could you please help me out here ? the DAC i am using is the DAC8512 f . Tech Sheets and Details http://www.analog.com/static/imported-files/data_sheets/DAC8512.pdf

Please post your code and a bit more detailed description of what goes wrong.

posted by Erik - 16 Dec 2013

Well , my problem is on how to connect the DAC to the actual Board in hardware terms and then how to program the conversion . The output I get is simply the initial signal that exists in the circuit , mostly from noise . My code :

first.cpp

#include "mbed.h"
DigitalOut myled(LED1);
int i=0;
int main()
{
    Serial pc(USBTX, USBRX);
    AnalogIn Vin(p18);
    I2C i2c(p28, p27);
    DigitalOut out0(p30);
    DigitalOut out1(p35);
    DigitalOut out2(p34);
    int output=0x00;
    int next=1;

    while(1) {
        myled = 1;
        wait(0.01);
        myled = 0;
        wait(0.01);
        pc.printf("output: %d\n",output);
        //pc.printf("Problem Bro\n");
        //i2c.write(output);

        // Send a byte to a SPI slave, and record the response

        SPI device(p5, p6, p7); // mosi, miso, sclk
        out1=1;
        out0=0;
        int response = device.write(output);
        output=output+0x01;
        if (output>=0x02) {
            pc.printf("Push up %d\n",i);
            out0=1;
            out1=0;

        }
        if (output==0xFF) {
            output=0x00;
        }
        if (next==2) {

        }

        if (next==1) {

        }



        i++;
        wait_us(10);
    }
}

posted by Antreas Antoniou 16 Dec 2013

Please use <<code>> and <</code>> around your code to make it readable (on seperate lines).

How to connect it is an awfully broad question, did you check the datasheet? It must have a simple schematic how it should be connected.

posted by Erik - 16 Dec 2013

I did check the data sheet and there was an explanation on how to use it with a micro controller and tried that , but I think that my code must have some sort of error at some point , I always use assembly to code micro controllers , it is my first time using C so I think I might have made some mistake

posted by Antreas Antoniou 16 Dec 2013

Okay so code should be the issue and not connection. But for example which output level do you get?

And just use <<code>> and <</code>> on a seperate line around your code, as you can see it is still unformatted.

posted by Erik - 16 Dec 2013

According to what I know my DAC should be producing at least some analog signal , problem is I only get noise and nothing else .

posted by Antreas Antoniou 16 Dec 2013

But which DC level do you get, and with noise how much noise do you get? (As in, a little bit is possible, alot shouldnt be possible).

I will look at your code in a bit, but since I dont have it myself no guarantees I can find anything.

posted by Erik - 16 Dec 2013

I think the problem must be in the bit where I change the bits from 0 to 1 and 1 to 0 of the LD and CS bits

posted by Antreas Antoniou 16 Dec 2013

by the way the editor for some reason shows output&gt;=0x02 My actual code is output>=0x02

posted by Antreas Antoniou 16 Dec 2013

For me it shows the arrows correct, but it is indeed a recent problem that it screws those things up.

First of all, you make a new SPI device now everytime the while loop runs, best to define it somewhere at the top.

Then your DAC expects 12 bits (16 also works), you only give it 8. That might give unpredictable results. Finally, try to keep your code as clear as possible. No if statements which don't do anything, and which pins are CS and which LD?

posted by Erik - 16 Dec 2013

out0 and out1 are LD and CS . CS selects the channel and LD loads the data to the DAC register . After reviewing it a bit I think I got what the problem is . Also I noticed the declaration of the SPI in the loop myself and fixed it after I posted it . So I should just give it a 12 bit input and see what happens . Thanks

posted by Antreas Antoniou 16 Dec 2013

Report back if it helps :)

Also it requires polarity and phase of 1 according to the datasheet, which corresponds to SPI mode 3. Have a look at: http://mbed.org/users/mbed_official/code/mbed/docs/a842253909c9/classmbed_1_1SPI.html#a7627faa611c3645626b6b627755fcae7

So set that before writing any data. Also if out1 is CS, then it is now the wrong way, CS should be low when writing data, high otherwise. LD should Always be high, only after a write it should become 0 for a short period and then 1 again.

posted by Erik - 16 Dec 2013

Hey man still no success , could you please check my code ?

=first.cpp

DigitalOut myled(LED1);
int i=0;

int main()
{
    Serial pc(USBTX, USBRX);
    AnalogIn Vin(p18);
    DigitalOut CS(p35);
    DigitalOut LDR(p30);
    int output=0x0001 ;
    int next=1;
    SPI device(p5, p6, p7); // mosi, miso, sclk
    device.format(16,3);
    while(1) {
        pc.printf("output: %d\n",output);
        LDR=1;
        CS=0;
        pc.printf("Push to input register %d\n",i);
        int response = device.write(output);
        pc.printf("Push to DAC register %d\n",i);
        CS=1;
        LDR=0;
        output=output+0x0001;
        if (output>=0x0FFF) {
            output=0x0000;
        }
        if (next==2) {
        //do something part 1
        }

        if (next==1) {
        //do something part 2
        }
        i++;
        LDR=1;
        pc.printf("Push to output register %d\n",i);
        wait_us(10);
    }
}
posted by Antreas Antoniou 17 Dec 2013

Hmmm, I don't really see why this wouldn't work. Can you list all the pins of the DAC and what you connected them to (and verify it).

Also try first checking which DC output level you have, and how much 'noise' is on it, second does it change if you set it in your code to be either 0, or full scale, and without incrementing it. So just a DC output.

posted by Erik - 17 Dec 2013

I tried doing the stable value test before , still all I get is something that I wouldnt call 'analog' if I turn the power down the output I get is a straight line , with the power working though I get a very strange shape , but the Vmax and V min is always very low , around a few mV , even with a full 0x0FFF or minimum 0x0000 I get nothing different , I have veified the pins a million times by now , even changed breadboard just in case . P35 is connected to CS p30 to LD p5 to data in and p7 to clock , also I have a positive 5v going in and I use grounding as well . Still something very weird is going on

posted by Antreas Antoniou 17 Dec 2013

1 Answer

10 years, 11 months ago.

After lots of tests and debugging I found the mistake which was a 2-part problem , first I needed to turn the output from closed mode to output mode using the 14 bit that I sent and also I needed to replace my oscilloscope as it was somewhat faulty .