Important changes to forums

We’re making some changes to the Mbed forums. From 10th December 2019 all new discussions will take place on our new forum site. You can continue to reply to existing threads for the next two weeks. After that we will archive this forum so you can return to useful posts in the future.

Sine Wave Frequency Generator

05 Jul 2011

Hey, everyone.

I am a second year undergraduate research intern. I am trying to program the mbed to generate the signal data needed to start a frequency sweep on a waveform generator chip, but I am unsure of how to connect pins on the mbed with pins on the chip. I am implementing the code from the application notes of a very similar chip to the chip I am using (AD5930). The data sheet is found

So far, I have written the following code:

  1. include "mbed.h"

SPI spi(p5, p6, p7); mosi, miso, sclk

DigitalOut cs(p8);

int main() {

Setup the spi for 16 bit data, high steady state clock,

second edge capture, with a 1MHz clock rate




Select the device by seting chip select low

cs = 0;

Send 0x0FFF, the command to read the WHOAMI register


FStart LSB


FStart MSB


Frequency increment for LSB


Frequency increment for MSB


To obtain a stop frequency of 10MHz from an Fstart of 1MHz, the increment register is loaded by 105A


Deselect the device

cs = 1;

} }

If anyone wouldn't mind looking over the data sheets and helping me out I'd appreciate it. I'm not sure if I am supposed to connect the MOSI pin to the CTRL pin of the chip or what to do with the chip select pin and the MISO or SCLK pins. I know the program is fine though b/c when I look at the signal on an oscilloscope on the MOSI output it appears correct.

Thanks! Sarah

05 Jul 2011

Hi Sarah,

I think you are mixing the signals of the sweep generator and those of the serial interface.

From what I understand from the datasheet:

MCLK and CTRL are the signals for the generator

FSYNC, CLK and DATA are the lines for the serial interface

When you use the SPI interface for the serial interface you set FSYNC (aka cs) to low, write a 16 bit SPI value and then set FSYNC high again, and this for each control word you want to write to the control interface. Seems this serial interface is write-only so only the MOSI pin is needed (MISO stays unconnected) and SCLK (connect to CLK) and of course the cs (connect to FSYNC)



For the generator you need to output a steady clock to the MCLK input and then CTRL needs to be set or reset in sync with this clock to adjust the frequency increments and such. Maybe you can generate this with a Ticker and two port pins on the mbed (depending on the frequency you need).


09 Dec 2013


Did you ever get the AD5930 chip working? I'd like to use this device and it would be helpful if there is some code I could use to get a test set up and running for evaluation.

You need to log in to post a reply