Main Content

Generate Sine Wave Using NI-FGEN Instrument Driver

This example shows how to generate a sine wave on a function generator using the National Instruments® NI-FGEN driver in simulation mode.

Requirements

To run this example, you must have the NI-FGEN instrument driver version 21.8 installed on your computer.

Before running this example, make sure that the NI Measurement and Automation Explorer (NI MAX) recognizes the NI-FGEN driver.

Verify NI-FGEN Installation

Use the ividriverlist command to check if the NIFGEN software package is installed correctly. If installed correctly, NIFGEN is listed as one of the modules installed on the Windows machine.

list = ividriverlist
list=15×4 table
             VendorDriver          MATLABDriver            IVIClass                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              SupportedModels                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
          __________________    __________________    __________________    _________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

    1     "IviACPwr"            "IviACPwr"            "IVIACPwr"            {[""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   ]}
    2     "IviCounter"          "IviCounter"          "IVICounter"          {[""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   ]}
    3     "IviDCPwr"            "IviDCPwr"            "IVIDCPwr"            {[""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   ]}
    4     "IviDigitizer"        "IviDigitizer"        "IVIDigitizer"        {[""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   ]}
    5     "IviDmm"              "IviDmm"              "IVIDmm"              {[""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   ]}
    6     "IviDownconverter"    "IviDownconverter"    "IVIDownconverter"    {[""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   ]}
    7     "IviFgen"             "IviFgen"             "IVIFgen"             {[""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   ]}
    8     "IviPwrMeter"         "IviPwrMeter"         "IVIPwrMeter"         {[""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   ]}
    9     "IviRfSigGen"         "IviRfSigGen"         "IVIRfSigGen"         {[""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   ]}
    10    "IviScope"            "IviScope"            "IVIScope"            {[""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   ]}
    11    "IviSpecAn"           "IviSpecAn"           "IVISpecAn"           {[""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   ]}
    12    "IviSwtch"            "IviSwtch"            "IVISwtch"            {[""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   ]}
    13    "IviUpconverter"      "IviUpconverter"      "IVIUpconverter"      {[""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   ]}
    14    "KtRFPowerMeter"      ""                    "IVIPwrMeter"         {["8481A"    "8481B"    "8481D"    "8481H"    "8482A"    "8482B"    "8482H"    "8483A"    "8485A"    "8485D"    "8487A"    "8487D"    "E4416A"    "E4417A"    "E4418B"    "E4419B"    "E9325A"    "E9326A"    "E9327A"    "L2051XA"    "L2052XA"    "L2053XA"    "L2054XA"    "L2055XA"    "L2056XA"    "L2057XA"    "L2061XA"    "L2062XA"    "L2063XA"    "L2064XA"    "L2065XA"    "L2065XT"    "L2066XA"    "L2066XT"    "L2067XA"    "L2067XT"    "N1911A"    "N1912A"    "N1913A"    "N1914A"    "N1921A"    "N1922A"    "N432A"    "N8262A"    "U2000A"    "U2000B"    "U2000H"    "U2001A"    "U2001B"    "U2001H"    "U2002A"    "U2002B"    "U2002H"    "U2004A"    "U2021XA"    "U2022XA"    "U2041XA"    "U2042XA"    "U2043XA"    "U2044XA"    "U2049XA"    "U2051XA"    "U2052XA"    "U2053XA"    "U2054XA"    "U2055XA"    "U2056XA"    "U2057XA"    "U2061XA"    "U2062XA"    "U2063XA"    "U2064XA"    "U2065XA"    "U2066XA"    "U2067XA"    "U8481A"    "U8485A"    "U8487A"    "U8488A"    "U8489A"]}
    15    "NIFGEN"              "NIFGEN"              "IVIFgen"             {["NI PCI-5401"    "NI PCI-5402"    "NI PCI-5406"    "NI PCI-5411"    "NI PCI-5412"    "NI PCI-5421"    "NI PCI-5431"    "NI PXI-5401"    "NI PXI-5402"    "NI PXI-5404"    "NI PXI-5406"    "NI PXI-5411"    "NI PXI-5412"    "NI PXI-5421"    "NI PXI-5422"    "NI PXI-5431"    "NI PXI-5441"    "NI PXIe-5413 (1CH)"    "NI PXIe-5413 (2CH)"    "NI PXIe-5423 (1CH)"    "NI PXIe-5423 (2CH)"    "NI PXIe-5433 (1CH)"    "NI PXIe-5433 (2CH)"    "NI PXIe-5442"    "NI PXIe-5450"    "NI PXIe-5451"    "PCI_5402"    "PCI_5406"    "PCI_5412"    "PCI_5421"    "PXI_5402"    "PXI_5404"    "PXI_5406"    "PXI_5412"    "PXI_5421"    "PXI_5422"    "PXI_5441"    "PXIe_5442"    "PXIe_5450"    "PXIe_5451"                                                                                                                                                                                                                                                                                                           ]}

Connect to Instrument

Connect to a simulated NI function generator using ividev with the instrument's MATLAB driver name and resource name. This example uses the NIFGEN driver's simulation mode to run without physically connecting any hardware. Since simulation mode is enabled, the resource name can be specified as empty.

dev = ividev("NIFGEN","",Simulate=true)
dev = 
  NIFGEN with properties:

                 Model: "NI PXI-5421" 
          Manufacturer: "National Instruments" 
          SerialNumber: "" 
          ResourceName: "" 
          VendorDriver: "niFgen" 
              Simulate: 1 

    DataMarkerEventIDs: ["DataMarker0", "DataMarker1", "DataMarker2", "DataMarker3", ... ] 
       FIFOEndpointIDs: [] 
        MarkerEventIDs: ["Marker0", "Marker1", "Marker2", "Marker3"] 

                Output: [1x1 Output] 
     ArbitraryWaveform: [1x1 ArbitraryWaveform] 
      StandardFunction: [1x1 StandardFunction] 
                Clocks: [1x1 Clocks] 
                Events: [1x1 Events] 
              Triggers: [1x1 Triggers] 
            Instrument: [1x1 Instrument] 

Show all functions

Configure Measurement Parameters

Reset the instrument to a known state and automatically configure the measurement parameters.

reset(dev);

Configure Output Mode and Waveform

Specify waveform configuration parameters such as channel name, waveform amplitude, and frequency.

channelName = "0";
amplitude = 2.0;
frequency = 10e6;
dcOffset = 0;
startPhase = 0;

Configure the type of waveform generated using the configureOutputMode function. In this example, the instrument is configured to generate a standard sine waveform.

configureOutputMode(dev,"OUTPUT_FUNC");
configureStandardWaveform(dev,channelName,"WFM_SINE",amplitude,dcOffset,frequency,startPhase);

Initiate Waveform Generation

After you configure the function generator with the specified parameters, initiate the waveform using the initiateGeneration function.

initiateGeneration(dev);

Enable Output

Once the waveform generation begins, enable the output of the function generator.

enable = true;
configureOutputEnabled(dev,channelName,enable);

Clean up

Disconnect and clear the ividev object from the workspace.

clear dev

See Also

| |

Related Topics