AnsweredAssumed Answered

mbed with AD9954

Question asked by ahambi on Nov 9, 2011
Latest reply on Nov 9, 2011 by DSB
Dear all,
I am trying to connect a DDS (AD9954) via the SPI interface to a mbed controller (www.mbed.org).  Since I never worked with electronic boards/ circuits and C it is a bit difficult for me to find my mistakes.
I found a code for the AD 9951 (http://mbed.org/forum/helloworld/topic/1664/?page=1#comment-8348) and modified it a bit. I use it in the form posted below.
I connected the pins as follows
DDS pinDDS functionmbed pinmbed function
25SCLK7sclk
23SDIO5 and 6mosi and miso
17FUD_DUT210_fud
15PWRDWNCTRL_DUT2ground
13RESET_DUT29rst
12CS_DUT2ground
I get no output on the oscilloscope and in the Terminal it just reads out
                          c2= 0
                               FTWO = 0
I really don't know what is going wrong. Maybe one of you can give me a tip?
#################### AD9954.h ###########################
<<code>>
#ifndef AD9954_H
#define AD9954_H
#include "mbed.h"
class AD9954 {
protected:
    SPI         _spi;
    DigitalOut  _cs;
    DigitalOut  _rst;
   
public:
    AD9954(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName rst) :
        _spi(mosi, miso, sclk), _cs(cs), _rst(rst)
    {
        // see http://mbed.org/handbook/SPI and page 23 why format 0
        _spi.format(8, 0);
        _spi.frequency(1000000);
        // master reset the device:
        _rst.write(1);
         wait(0.1);
        _rst.write(0);
    };
    // Write a 32bit register at the specified address.
    void write_reg_4byte(uint32_t address, uint32_t value) {
      // Instruction byte: page 25 in datasheet, we want to write (0), so 0100 + internal adress of the register to be written in
        _spi.write(0x00 | (address & 0x1F));
        _spi.write((value >> 24) & 0xFF);
        _spi.write((value >> 16) & 0xFF);
        _spi.write((value >> 8) & 0xFF);
        _spi.write((value >> 0) & 0xFF);
    }
   
    // Write a 24bit register at the specified address.
    void write_reg_3byte(uint32_t address, uint32_t value) {
      // Instruction byte: page 25 in datasheet, we want to write (0), so 0100 + internal adress of the register to be written in
        _spi.write(0x00 | (address & 0x1F));
        _spi.write((value >> 16) & 0xFF);
        _spi.write((value >> 8) & 0xFF);
        _spi.write((value >> 0) & 0xFF);
    }
       
    // Read a 32bit register at the specified address.
    uint32_t read_reg_4byte(uint32_t address) {
        uint32_t value = 0x00000000;
        _spi.write(0x80 | (address & 0x1F)); // Instruction byte
        value |= _spi.write(0x00);
        value = value << 8;
        value |= _spi.write(0x00);
        value = value << 8;
        value |= _spi.write(0x00);
        value = value << 8;
        value |= _spi.write(0x00);
        return value;
    } 
   
    uint32_t read_reg_3byte(uint32_t address) {
        uint32_t value = 0x000000;
        _spi.write(0x80 | (address & 0xF)); // Instruction byte
        value |= _spi.write(0x00);
        value = value << 8;
        value |= _spi.write(0x00);
        value = value << 8;
        value |= _spi.write(0x00);
        return value;
    }  
    // Write
    void CFR1_write(uint32_t reg) { write_reg_4byte(0x00, reg); }
    void CFR2_write(uint32_t reg) { write_reg_3byte(0x01, reg); }
    void FTW0_write(uint32_t reg) { write_reg_4byte(0x04, reg); }
   
    // Read
    uint32_t CFR1_read(void) { return read_reg_4byte(0x0); }
    uint32_t CFR2_read(void) { return read_reg_3byte(0x1); }
    uint32_t FTWO_read(void) { return read_reg_4byte(0x4); } 
};
#endif
<</code>>
####################### main #############################
<<code>>
#include "mbed.h"
#include "AD9954.h"
Serial pc(USBTX, USBRX);
DigitalOut myled(LED1);
DigitalOut _fud(p10);
AD9954 myDevice(p5, p6, p7, p8, p9);
int main() {
    _fud.write(0);
        // in register 2:
//bit3-bit7 contain the multiplication value for the clock. multiply the 10 MHz input by 10: [01010], the vco is then not in the upper range, therefore bit2=0,
        // from this follows bit7-bit0: 00 00 0101 0000 -> 00 00 50
        myDevice.CFR2_write(000050);
        // now we have a 100 MHz clock, the frequency tuning word for around 6 MHz output is ((12.5:2)/100)*2^(32) =268435456
        //= 10000000
        myDevice.FTW0_write(0x10000000);
// issue I/O update
    _fud.write(1);
    wait(0.1);
    _fud.write(0);
   
        uint32_t c2;
        c2 = myDevice.CFR2_read();   
        pc.printf("c2= %X\n", c2);
       
        uint32_t ftwo; 
        ftwo = myDevice.FTWO_read();   
        pc.printf("FTWO = %X\n", ftwo);
   return 0;
}
<</code>>

Outcomes