Függvénygenerátor program myDAQ-al

A Fizipedia wikiből
A lap korábbi változatát látod, amilyen Magyarkuti (vitalap | szerkesztései) 2019. szeptember 17., 12:27-kor történt szerkesztése után volt.

The following program generates a sinusoidal signal on an analog output using a NationalInstruments DAQ card (for example myDAQ). It uses the built-in sample clock of the device (hardware-timed data generation).

Creating a Task for handling the analog output:

    OutTask = new NationalInstruments.DAQmx.Task();
    OutTask.AOChannels.CreateVoltageChannel(DevID, "",
       Vmin, Vmax, AOVoltageUnits.Volts);
  • DevID: string identifying the device and the output terminal. For example: "myDAQ1/ao0".
  • Vmin and Vmax is used to set the range of the analog output. In the case of the myDAQ device, -10, 10 V is the maximum output range.

For hardware-timed data generation, the timing of the Task also has to be specified:

    OutTask.Timing.ConfigureSampleClock("", SampleRate,
    SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, numPnts);
  • SampleRate: double value, defines the number of samples generated in 1 second. The maximum sample rate available using the myDAQ device is 200 kHz.
  • SampleQuantityMode.FiniteSamples: sets the data generation to finite mode. Using finite mode, data generation stops automatically after reaching the end of the output data.
  • numPnts: number of points to be generated (length of output data)

Note: the length of the generated signal: L (sec) = numPts / SampleRate

Finally, an AnalogSingleChannelWriter object is created and associated with the Task handling the output:

    analogWriter = new AnalogSingleChannelWriter(OutTask.Stream);

To start generating the signal, first a double array has to be created. Then the array is passed to the AnalogSingleChannelWriter object and the DAQ card starts generating the data using the selected analog output. In the below example, a sinusoidal signal is generated.

    // Generate data for output
    double[] outData = new double[numPnts];
    for (int i = 0; i < numPnts; i++)
    {
         outData[i] = Math.Sin((double)i / numPnts * 2 * Math.PI);
    }
 
    // Start Output
     analogWriter.WriteMultiSample(true, outData);