Jump to content
  • 0

c.brauer

Question

Hi!
I'm trying to use the analog discovery to generate a one-period log sine (frequency between 0.1Hz and 100kHz) and record both analog input channels at the same time. I have build a small Matlab script based on the "GSAcquiringAndGenerateData.mlx" example. I need to run on a much higher sampling rate than used in the example. I'd like to use 10MS/s.

Here is my script:

daqreset;
dq = daq("digilent");
addoutput(dq, "AD2_0", "ao0", "Voltage");
addinput(dq, "AD2_0", "ai0", "Voltage");
addinput(dq, "AD2_0", "ai1", "Voltage");
rate = 10e6;
dq.Rate = rate;

f = 500;
n = (rate/f);
t = (1:n)/rate;
output = sin(2*pi*f*t)';
data = readwrite(dq, output);

subplot(3,1,1);
plot(output);
title('output');
subplot(3,1,2);
plot(data.AD2_0_ai0);
title('ai0');
subplot(3,1,3);
plot(data.AD2_0_ai1);
title('ai1');

Input channels ai0 and ai1 are connected to the output channel ao0 using bnc cables (and the bnc breakout board). Additionally the signal is connected to my scope to see the output of ao0.

At 10MS/s the output looks like in the picture attached (sine_500Hz_at_10MS).

sine_500Hz_at_10MS.thumb.png.92243dc61401b23f1b8045746aa715aa.png

The matlab plot shows the desired output signal (one persiod sine with 500Hz) and the recorded data of ai0 and ai1 (500Hz_sine_10MS_matlab).

500Hz_sine_10MS_matlab.thumb.png.c5bf21483a993a7a295f6240b572a47e.png

When I reduce the sample rate to "only" 1MS/s the signal generated looks like it should (sine_500Hz_at_1MS), but the recorded data of ai0 and ai1 are time-shifted (500Hz_sine_1MS_matlab)

sine_500Hz_at_1MS.thumb.png.b74a71ff56ae1de1fb67530efeefa50e.png

500Hz_sine_1MS_matlab.thumb.png.ffcfe7b7f470a23821e2f3fd5174a2a2.png

If I lower the frequency of the signal to be generated I usually get a lot of "Samples lost" and "Samples corrupted" warnings in Matlab. As I want to generate one period with a constant sampling rate, the total amount of samples are higher with a lower frequency generated.

E.g. at 10MS/s and a sine with 50Hz a total of 200000 samples are needed. With 500Hz and 10MS/s 20000 samples are needed.

If I run the script with 1MS/s and a sine frequency of 5kHz, the generated signal on the scope looks fine, but the recorded data for ai0 and ai1 look like this:

5kHz_sine_1MS_matlab.thumb.png.de83c92f3727237e24098b9781b7fd5b.png

I also observed that when running the script with the "working" configuration (500Hz and 1MS/s) multiple times, most of the plots look ok, but sometimes the signals are completely off and I get these "Samples lost" and "Samples corrupted" warnings, so feels not very stable. It feels like the problem is somehow connected to the sampling rate and sample-count. When playing around with the sample-rate I sometimes get the error "Channels are set to run at incompatible rates: 1.2e+06, 1.20482e+06". Is there some restriction regarding the sample rate and or the sample-count ? Is there a more in depth example regarding the simultaious generation and aquisition of signals using "high" sample rate (> 10MS/S) ?

I'm running Matlab 2023 on a more or less beefy PC using Windows10. I have WaveForms v3.21.3 installed and I am using the Matlab-Addon aviable here (https://github.com/Digilent/matlab). I have installed the Matlab Support like outlined here: https://digilent.com/reference/test-and-measurement/guides/matlab-getting-started. The legacy support package was not installed before. The AD2 board is connected to my PC using a powered USB3 Hub. I'm also using a 1m, high quality USB2.0 cable with ferrites attached. But using other USB-ports shows the same problem. Until not I have not used an external 5V powery supply for the AD2 (and I don't think this is related to power problems).

It would be really great if someone could give me some hint on what's goning wrong here.

Some background information about what I need to do here:
I have an analog frontend for a special kind of electro-impedace-spectroscopy system. I need to control the frontend using a SPI bus (setting gain etc.) and some digital IO's. I also need to generate an sine as exaction signal with frequencies ranging from 0.1Hz to 100kHz. The analog onput channels are recording the system's answer. From here I'd like to use Matlab to do the rest of the data processing.

This is part of scientific research development and I'm doing the analog hardware development and digital signal processing of a proove-of-concept system. That's why we decided to use Matlab instead of Python because it's easier and more convienent for us to do the development of the dsp stuff in Matlab.

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

Hi @Val @c.brauer

The capture length at high rate is limited by the device buffer size.
The Analog Discovery 3 has buffer for 32k-64k oscilloscope samples in total. Up to this length it can capture up to 125MHz. Above this length record (data streaming) is used which may work up to about 12MS/s, but this depends on the host system.
ADP3X50 and ADP2230 have 128M and 256M sample buffer. The later one also has faster USB, 5Gbps.

Link to comment
Share on other sites

  • 0

Hi @attila

Thanks a lot for your response. What about Discovery 2? I never had "lost samples" with this device with the same settings. With ADP3450 even if use a slow sampling rate and a short record (say 1 s record with 1e4 sampling rate) I still get the same errors. With Discovery 2 a went up to 20 s and 2.5e4 sampling rate and never had any issues.

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...