Signal Generators

cancel
Showing results for 
Search instead for 
Did you mean: 

Streaming large data using PCI-5421 using MATLAB

Hi,

I am trying to stream a large array of data using the PCI-5421 function generator using MATLAB.

 

I keep getting an error saying I am not writing fast enough to the streaming waveform...i should reduce sampling frequency or write more frequently.

 


Here is how the flow of the code looks.

*******************************************************************************

% Assume 'signal_data' as a big array say of length 80000000 samples or more
%sampling frequency of this array is 10 MHz.
ChannelName='0';

%configure the output mode to download waveforms in order user specify
invoke(ictObj.Configuration,'configureoutputmode', 2);  

%to single trigger mode
invoke(ictObj.Configurationfunctionstriggeringandsynchronization,'configuretriggermode','0',1);

%to clear arbitrary waveform memory
invoke(ictObj.Configurationfunctionsarbitrarysequenceoutput,'cleararbmemory');

%to allocate onboard memory
stream_arb = invoke(ictObj.Configurationfunctionsincrementalwaveformwrite, 'allocatewaveform','0', 20000);

attributeaccessors = get(ictObj, 'ConfigurationFunctionsSetGetCheckAttributeSetAttribute');
RepCapIdentifier  = get(ictObj, 'RepCapIdentifier');
RepCapIdentifier = [double(RepCapIdentifier) 0];

%setting streaming attribute handle
invoke (attributeaccessors, 'setattributeviint32',RepCapIdentifier, 1150324 ,stream_arb);

%writing waveform data to onboard memory
invoke(ictObj.Configurationfunctionsincrementalwaveformwrite,'writewaveform','0',stream_arb,20000,signal_data);

invoke(ictObj.Configurationfunctionsarbitrarysequenceoutput,'createarbsequence',1,stream_arb,1);

invoke(ictObj.Waveformcontrol,'initiategeneration');
%enable output
Enabled=1;
invoke(ictObj.Configuration,'configureoutputenabled',ChannelName,Enabled);

for i = 1: length(signal_data)/20000 %dividing into so many iterations
  invoke(ictObj.Configurationfunctionsincrementalwaveformwrite,'writewaveform','0',stream_arb,b,x);
  invoke(ictObj.Configurationfunctionsarbitrarysequenceoutput,'createarbsequence',1,stream_arb,1);
end

 

********************************************************************************************************************************

Any suggestion is welcome.

 

0 Kudos
Message 1 of 7
(6,618 Views)

At minimum the 5421 has 8 mb of memory on the card. I'm not sure about your code but is there a way to change the number of samples you are sending to the card? Can you up the amount of samples you are sending at one time?

Carl W.
Applications Engineering
National Instruments
0 Kudos
Message 2 of 7
(6,603 Views)

Yes, I am using the 8Mb version and I can increase the number of samples being sent to the card at once....

0 Kudos
Message 3 of 7
(6,598 Views)

Hi Carl,

So if I keep changing the sampling rate or size of data being written, i either get the error i mentioned before or i get 'memory not free trying to write too fast'.....Dont seem to find a balance between the two..

 

Any suggestion is welcome

 

Shommo

0 Kudos
Message 4 of 7
(6,589 Views)

Streaming data to the 5421 is a little tricky.

On one hand, you need to keep up.

On the other hand, you need to make sure you don't overflow (overwrite a piece of a waveform that has not been generated yet).

 

One of the examples (LabVIEW) we ship shows how to do that. It uses Script Mode and places Marker Events throughout the waveform being generate. You can read them back in software so you know roughly where the arb is in the waveform generation. Basically, before writing new data, you wait for the next marker event to be generated. Once you detect it, you know the Arb generated some portion of the waveform and that you can overwrite that part of the waveform.

 

I don't have niFgen installed. If you have LabVIEW in your system, you can check it out. If not, perhaps someone can paste a screenshot of the block diagram for this example showing how to do this?

Marcos Kirsch
Chief Software Engineer
NI Driver Software
0 Kudos
Message 5 of 7
(6,584 Views)

Hi Marcos,

Thanks for the suggestion...Ended up finding the right balance to stream by checking available memory over few iterations...use of Marker events sounds the better and more accurate way to go though.

0 Kudos
Message 6 of 7
(6,574 Views)

Hi Shommo,

 

In NI-FGEN 2.9, we added a new attribute NIFGEN_ATTR_STREAMING_WRITE_TIMEOUT to facilicate streaming write process.This attribute by default is not used, i.e. the write failed immediately if the space is not available.

 

If you use that attribute, you can push more data into the driver without having to explicitly checking for available memory. The driver will handle that for you internally, and reduce the overhead of making multiple calls into the driver. Just make sure that you pick a reasonable timeout value so that you don't get an early timeout.

 

 

0 Kudos
Message 7 of 7
(6,570 Views)