Products & Services Solutions Academia Support User Community Company

Learn more about Data Acquisition Toolbox   

Managing Output Data

The Analog Output Subsystem

At the core of any analog output application lies the data you want to send from a computer to an output device such as an actuator. The role of the analog output subsystem is to convert digitized data to analog data for subsequent output.

Before you can output data to the analog output subsystem, it must be queued in the engine. Queuing data is managed with the putdata function. In addition to this function, there are several properties associated with managing output data. These properties are given below.

Table 6-6. Analog Output Data Management Properties

Property Name

Description

MaxSamplesQueued

Indicate the maximum number of samples that can be queued in the engine.

RepeatOutput

Specify the number of additional times queued data is output.

Timeout

Specify an additional waiting time to queue data.

Queuing Data with putdata

Before data can be sent to the analog output hardware, you must queue it in the engine. Queuing data is managed with the putdata function. One column of data is required for each channel contained by the analog output object. For example, to queue one second of data for each channel contained by the analog output object ao:

ao = analogoutput('winsound');
addchannel(ao,1:2);
data = sin(linspace(0,2*pi*500,8000))';
putdata(ao,[data data])

A data source consisting of m samples and n channels is illustrated below.

Rules for Using putdata

Using putdata to queue data in the engine follows these rules:

Rules for Queuing Data

Data to be queued in the engine follows these rules:

Example: Queuing Data with putdata

This example illustrates how you can use putdata to queue 8000 samples, and then output the data a total of five times using the RepeatOutput property.

To run this example type daqdoc6_3 at the MATLAB Command Window.

  1. Create a device object — Create the analog output object AO for a sound card. The installed adaptors and hardware IDs are found with daqhwinfo.

    AO = analogoutput('winsound');
    %AO = analogoutput('nidaq','Dev1');
    %AO = analogoutput('mcc',1);
  2. Add channels — Add one channel to AO.

    chans = addchannel(AO,1);
    %chans = addchannel(AO,0); % For NI and MCC
  3. Configure property values — Define an output time of one second, assign values to the basic setup properties, generate data to be queued, and issue two putdata calls. Because the queued data is repeated four times and two putdata calls are issued, a total of 10 seconds of data is output.

    duration = 1;
    set(AO,'SampleRate',8000)
    ActualRate = get(AO,'SampleRate');
    len = ActualRate*duration;
    set(AO,'RepeatOutput',4)
    data = sin(linspace(0,2*pi*500,len))';
    putdata(AO,data)
    putdata(AO,data)
  4. Output data — Start AO and wait for the device object to stop running.

    start(AO)
    wait(AO,11)
  5. Clean up — When you no longer need AO, you should remove it from memory and from the MATLAB workspace.

    delete(AO)
    clear AO

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS