Using Quick-Control Function Generator

Quick-Control Function Generator

A new way to communicate with instruments, Quick-Control Instruments, was introduced in R2011b with the Quick-Control Oscilloscope. In R2012a, a second instrument class is introduced – the Quick-Control Function Generator. You can use this new function generator, or fgen, for simplified fgen control and waveform generation.

Create the Quick-Control Function Generator object using the Instrument Control Toolbox™ fgen function. It simplifies controlling function generators and performs arbitrary waveform generations without dealing with the underlying drivers.

You can use the Quick-Control Function Generator for any function generator that uses an underlying IVI-C driver. However, you do not have to directly deal with the underlying driver. This fgen object is easy to use.

The documentation examples use a specific instrument, a Tektronix® AFG 3022B function generator. This feature works with any instrument that has IVI-C fgen class drivers. You can follow the basic steps, using your particular instrument.

Quick-Control Function Generator Prerequisites

To use the Quick-Control Function Generator for an IVI-C fgen, ensure the following software is installed:

  • Windows® 32-bit or Windows 64-bit platforms

  • VISA shared components

  • VISA

    Note, the following examples use Agilent® VISA, but you can use any vendor's implementation of VISA.

  • National Instruments® IVI® compliance package NICP 4.1 or 4.3

  • Your instrument's device-specific driver

You can use instrhwinfo to confirm that the required software is installed.

% Check that the software is properly installed.
instrhwinfo('ivi')

Generating Waveforms Using the Quick-Control Function Generator

The first example shows the general workflow to use for the Quick-Control Function Generator for a standard waveform. The second example shows the general workflow to use for the Quick-Control Function Generator for an arbitrary waveform. These examples use a specific instrument, but they work with any function generator using an IVI-C driver as long as the instrument and the driver support the functionality. You can follow the basic steps using your particular function generator.

Generate Standard Waveform

In this example, an electronic test engineer wants to create a simple sine waveform to test the clock operating range of a digital circuit.

  1. Ensure all necessary software is installed. See Quick-Control Function Generator Prerequisites for the list.

  2. Create an instance of the function generator.

    % Instantiate an instance of the fgen.
    myFGen = fgen();
  3. Discover available resources. A resource string is an identifier to the instrument. You must set it before connecting to the instrument.

    % Find resources. 
    availableResources = getResources(myFGen)

    This returns a resource string or an array of resource strings, for example:

    ans =
    
    ASRL::COM1
    GPIB0::INTFC
    GPIB0::10::INSTR
    PXI0::MEMACC
    TCPIP0::172.28.16.153::inst0::INSTR
    TCPIP0::172.28.16.174::inst0::INSTR
    
  4. Set the resource for the function generator you want to communicate with.

    myFGen.Resource = 'GPIB0::10::INSTR';
  5. Connect to the function generator.

    connect(myFGen);
  6. Specify the channel name from which the function generator produces the waveform.

    selectChannel(myFGen, '1');
  7. Configure the function generator.

    You can configure any of the instrument's properties that are settable. Configure the waveform to be a continuous sine wave and then configure various settings as shown.

    % Set the type of waveform to a sine wave.
    myFGen.Waveform = 'sine';
    
    % Set the output mode to continuous. 
    myFGen.Mode = 'continuous');
    
    % Set the load impedance to 50 Ohms. 
    myFGen.OutputImpedance = 50);
    
    % Set the frequency to 2500 Hz. 
    myFGen.Frequency = 2500);
    
    % Set the amplitude to 1.2 volts. 
    myFGen.Amplitude = 1.2);
    
    % Set the offset to 0.4 volts. 
    myFGen.Offset = 0.4);
    
  8. Enable signal generation with the instrument, for example, output signals.

    In this example, the enableOutput function enables the function generator to produce a signal that appears at the output connector.

    % Enable the output of signals. 
    enableOutput(myFGen);
    

    When you are done, disable the output.

    % Disable the output of signals. 
    disableOutput(myFGen);
    
  9. After configuring the instrument and generating a signal, close the session and remove it from the workspace.

    disconnect(myFGen);
    clear myFgen;

Generate Arbitrary Waveform

In this example, an electronic design engineer wants to generate a complex waveform with MATLAB®, then download them into the function/arbitrary waveform generator and output them one after the other, and then finally remove the downloaded waveforms afterward. In this example we are using the GPIB interface.

  1. Ensure all necessary software is installed. See Quick-Control Function Generator Prerequisites for the list.

  2. Create an instance of the function generator.

    % Instantiate an instance of the fgen.
    myFGen = fgen();
  3. Set the resource.

    myFGen.Resource = 'GPIB0::10::INSTR';
  4. Connect to the function generator.

    connect(myFGen);
  5. Specify the channel name from which the function generator produces the waveform.

    selectChannel(myFGen, '1');
  6. Configure the function generator.

    You can configure any of the instrument's properties that are settable. Configure the waveform to be a continuous arbitrary wave.

    % Set the type of waveform to an arbitrary wave.
    myFGen.Waveform = 'arb';
    
    % Set the output mode to continuous. 
    myFGen.Mode = 'continuous';
    
  7. Communicate with the instrument.

    In this example, create the waveform, then download it to the function generator using the downloadWaveform function. Then enable the output using the enableOutput function, and then remove the waveform using the removeWaveform function.

    % Create the waveform. 
    w1 = 1:0.001:2; 
    
    % Download the waveform to the function generator. 
    h1 = downloadWaveform (myFGen, w1);
    
    % Enable the output. 
    enableOutput(myFGen, h1);
    

    When you are done, remove the waveforms.

    % Remove the waveform. 
    removeWaveform(myFGen);
    
  8. After communicating with the instrument, close the session and remove it from the workspace.

    disconnect(myFGen);
    clear myFgen;

Quick-Control Function Generator Functions

The fgen function uses the following functions, in addition to standard functions such as connect and disconnect.

FunctionDescription
selectChannel

Specifies the channel name from which the function generator produces the waveform.

Example:

 selectChannel(myFGen, '1');
getDrivers

Returns a list of available function generator instrument drivers.

Example:

drivers = getDrivers(myFGen);

See the note following this table about using a SCPI-based driver for Agilent function generators.

getResources

Retrieves a list of available instrument resources. It returns a list of available VISA resource strings when using an IVI-C function generator.

Example:

res = getResources(myFGen);
selectWaveform

Specifies which arbitrary waveform the function generator produces.

Example:

selectWaveform (myFGen, wh);

where wh is the waveform handle you are selecting.

downloadWaveform

Downloads an arbitrary waveform to the function generator. If you provide an output variable, a waveform handle is returned. It can be used in the selectWaveform and removeWaveform functions.

If you don't provide an output variable, function generator overwrites the waveform when a new waveform is downloaded and deletes it upon disconnection.

Example:

 % Download the following waveform to fgen
 w = 1:0.001:2;
 downloadWaveform (myFGen, w);
 % Download a waveform to fgen and return 
    a waveform handle
 wh = downloadWaveform (myFGen, w);
removeWaveform

Removes a previously created arbitrary waveform from the function generator's memory. If a waveform handle is provided, it removes the waveform represented by the waveform handle.

Example:

 % Remove a waveform from fgen with waveform 
     handle 10000
  removeWaveform (myFGen, 10000);
enableOutput

Enables the function generator to produce a signal that appears at the output connector. This function produces a waveform defined by the Waveform property. If the Waveform property is set to 'Arb', the function uses the latest internal waveform handle to output the waveform.

enableOutput (myFGen);
disableOutput

Disables the signal that appears at the output connector. Disables the selected channel.

disableOutput (myFGen);
reset

Sets the function generator to factory state.

Using a SCPI-based Driver for Agilent Function Generators

If you are using a SCPI-based Agilent function generator such as the 33220A, you will see the following when you use the getDrivers function on an fgen object myFGen.

drivers = getDrivers(myFGen);

drivers = 

Driver: Agilent332x0_SCPI
Supported Models:
   33210A, 33220A, 33250A

The _SCPI after the instrument name indicates this is using a SCPI driver instead of the IVI driver.

Quick-Control Function Generator Properties

The fgen function can use the following properties.

PropertyDescription
AMDepth

Specifies the extent of Amplitude modulation the function generator applies to the carrier signal. The units are a percentage of full modulation. At 0% depth, the output amplitude equals the carrier signal's amplitude. At 100% depth, the output amplitude equals twice the carrier signal's amplitude. This property affects function generator behavior only when the Mode is set to 'AM' and ModulationResource is set to 'internal'.

Amplitude

Specifies the amplitude of the standard waveform. The value is the amplitude at the output terminal. The units are volts peak-to-peak (Vpp). For example, to produce a waveform ranging from -5.0 to +5.0 volts, set this value to 10.0 volts. Does not apply if Waveform is of type 'Arb'.

ArbWaveformGain

Specifies the factor by which the function generator scales the arbitrary waveform data. Use this property to scale the arbitrary waveform to ranges other than -1.0 to +1.0. When set to 2.0, the output signal ranges from -2.0 to +2.0 volts. Only applies if Waveform is of type 'Arb'.

BurstCount

Specifies the number of waveform cycles that the function generator produces after it receives a trigger. Only applies if Mode is set to 'burst'.

ChannelNames

This read-only property provides available channel names in a cell array.

Driver

This property is optional. Use only if necessary to specify the underlying driver used to communicate with an instrument. If the DriverDetectionMode property is set to 'manual', use the Driver property to specify the instrument driver.

DriverDetectionMode

Sets up criteria for connection. Valid values are 'auto' and 'manual'. The default value is 'auto', which means you do not need to set a driver name before connecting to an instrument. If set to 'manual', a driver name needs to be provided using the Driver property before connecting to instrument.

FMDeviation

Specifies the maximum frequency deviation the modulating waveform applies to the carrier waveform. This deviation corresponds to the maximum amplitude level of the modulating signal. The units are Hertz (Hz). This property affects function generator behavior only when Mode is set to 'FM' and ModulationSource is set to 'internal'.

Frequency

Specifies the rate at which the function generator outputs an entire arbitrary waveform when Waveform is set to 'Arb'. It specifies the frequency of the standard waveform when Waveform is set to standard waveform types. The units are Hertz (Hz).

Mode

Specifies run mode. Valid values are 'continuous', 'burst', 'AM', or 'FM'. Specifies how the function generator produces waveforms. It configures the instrument to generate output continuously or to generate a discrete number of waveform cycles based on a trigger event. It can also be set to AM and FM.

ModulationFrequency

Specifies the frequency of the standard waveform that the function generator uses to modulate the output signal. The units are Hertz (Hz). This attribute affects function generator behavior only when Mode is set to 'AM' or 'FM' and the ModulationSource attribute is set to 'internal'.

ModulationSource

Specifies the signal that the function generator uses to modulate the output signal. Valid values are 'internal' and 'external'. This attribute affects function generator behavior only when Mode is set to 'AM' or 'FM'.

ModulationWaveform

Specifies the standard waveform type that the function generator uses to modulate the output signal. This affects function generator behavior only when Mode is set to 'AM' or 'FM' and the ModulationSource is set to 'internal'. Valid values are 'sine', 'square', 'triangle', 'RampUp', 'RampDown', and 'DC'.

Offset

Uses the standard waveform DC offset as input arguments if the waveform is not of type 'Arb'. Use Arb Waveform Offset as input arguments if the waveform is of type 'Arb'.

Specifies the DC offset of the standard waveform when Waveform is set to standard waveform. For example, a standard waveform ranging from +5.0 volts to 0.0 volts has a DC offset of 2.5 volts. When Waveform is set to 'Arb', this property shifts the arbitrary waveform's range. For example, when it is set to 1.0, the output signal ranges from 2.0 volts to 0.0 volts.

OutputImpedance

Specifies the function generator's output impedance at the output connector.

Resource

Set this before connecting to the instrument. It is the VISA resource string for your instrument.

SelectedChannelReturns the selected channel name that was set using the selectChannel function.
StartPhase

Specifies the horizontal offset in degrees of the standard waveform the function generator produces. The units are degrees of one waveform cycle. For example, a 180-degree phase offset means output generation begins halfway through the waveform.

Status

This read-only property indicates the communication status of your instrument session. It is either 'open' or 'closed'.

TriggerRate

Specifies the rate at which the function generator's internal trigger source produces a trigger, in triggers per second. This property affects function generator behavior only when the TriggerSource is set to 'internal'. Only applies if Mode is set to 'burst'.

TriggerSource

Specifies the trigger source. After the function generator receives a trigger, it generates an output signal if Mode is set to 'burst'. Valid values are 'internal' or 'external'.

Waveform

Uses the waveform type as an input argument. Valid values are 'Arb', for an arbitrary waveform, or these standard waveform types – 'Sine', 'Square', 'Triangle', 'RampUp', 'RampDown', and 'DC'.

Creating Shared Libraries or Standalone Applications When Using IVI-C or VXI

When using IVI-C or VXI Plug&Play drivers, executing your code will generate additional file(s) in the folder specified by executing the following code at the MATLAB prompt:

sprintf('%s',[tempdir 'ICTDeploymentFiles'])

On all supported platforms, a file with the name MATLABPrototypeFor<driverName>.m is generated, where <driverName> the name of the IVI-C or VXI Plug&Play driver. With 64-bit MATLAB on Windows, a second file by the name <driverName>_thunk_pcwin64.dll is generated. When creating your deployed application or shared library, manually include these generated files. For more information on including additional files refer to the MATLAB Compiler documentation.

Was this topic helpful?