AnsweredAssumed Answered

AD9144 and Libiio - How to Clear the Buffer?

Question asked by mohsenYazdi on Aug 23, 2017
Latest reply on Aug 25, 2017 by mohsenYazdi

I am trying to use Libiio to control the output of an AD9144 DAC. The following is a graph of the waveform I want to output (a modulated Gaussian, consisting of 4000 samples):

Target waveform: a modulated Gaussian waveform consisting of 4000 samples.
I used Libiio, to create the buffer data and pushing it to the hardware successfully:
1) Creating buffer data for 2 output channels.
2) Disabling all channels expect the ones I want to use as outputs (voltage0 and voltage1).
3) Creating a buffer for the device using iio_device_create_buffer.
4) Copying buffer data to buffer using memcpy.
5) Pushing buffer using iio_buffer_push.
I get the following from scope (I give identical data to both channels so they overlap and you see only one wave):

As you can see, the repetition period is 4 microseconds which make sense since 4000 samples sampled at 1GSPS gives a period of 4 microseconds. So far so good.
At the end of my program, I destroy the buffer using iio_buffer_destroy.


The problem comes when I want to upload another wave after outputting the first one. For example, I changed my waveform to contain 2000 samples (I also changed the standard deviation so it is easier to distinguish it from the first wave):

Now when I run my program again, I see the following on the scope:

So it seems like I am not clearing the buffer properly. A portion of the buffer being used still contains the samples from the previously uploaded data.

Now if I re-run my program several times with the new waveform (2000-sample waveform), I finally get the following outcome:

As you can see the period is now 2 microseconds which correctly corresponds to 2000 samples sampled at 1GSPS.


The problem is I want to be able to get clean signal from run to run if I change my waveform or its length. So I have three questions:
1) How can I properly clear the buffer?
2) Is there a maximum size for buffer?
3) Should I use private functions of libiio library for this purpose?


In addition, I tried to upload the waveforms using iio-oscilloscope and experienced the same problem. But the problem is not deterministic. Sometimes, it works, sometimes it doesn't.


I also used iio_buffer_cancel function, but still the problem exists.

AD9144 is hosted AD-FMCDAQ2 evaluation board hosted on Virtex-VC707 evaluation board. A microblaze hosting an IIO linux is controlling the DAC.