TechTip: Acquiring an Analog Waveform with MCC DAQ

To show how to capture an analog waveform using an MCC data acquisition device and various software platforms.

Intended Audience
Data acquisition system developers who need to digitize an analog waveform over time, and seek to understand waveform capture implementation in various software environments.

For very slowly changing analog phenomena, it can suffice to sample the signal rather infrequently, and often it is acceptable for the time delta between samples to vary, since the primary need is to obtain the present state of the signal. In such cases, a rather simple “software polling” of each AI channel may suffice. However, if the signal changes rapidly with respect to elapsed time, or if a frequency component of the signal is of interest to the user, much faster A/D sampling is required. In fact, not only is faster sampling required, but having a uniform and well-controlled time delta between samples is important.

MCC’s AI DAQ devices incorporate on-board timing circuits to uniformly pace readings from one or more AI channels. MCC DAQ devices also incorporate onboard memory to queue up data to periodically send efficiently-sized packets over the interface bus (commonly USB). Working in conjunction with the DAQ hardware is the MCC software driver, which receives the data packets, bundles them together into a larger buffer in memory, and makes the data and status available to the higher-level user program.

An application developer will want to scope out the project from the perspective of both AI sampling duration and data access needs. In other words, how long do I need to sample for, and do I need access to the data during the collection or not until the end. The most straightforward case is to collect data for a relatively short duration, and not process any data until it has all been collected. Extending the idea, one may need to start processing the data during the collection – for example to provide a live display to the operator. In this case the developer wants access to the data buffer while new data is still being added, which MCC facilitates with its Background mode. The most complex scenario is a very long collection time, whereby a circular buffer is necessary due to finite computer memory. With new data constantly coming in, the application must be able to perform the desired mathematics, display, and perhaps log results to disk, efficiently enough to keep up. While not the focus of this article, MCC’s software driver supports this advanced need with its Continuous mode.

For a non-continuous scan, independent of the software platform, the following information must be specified:

  • AI channel numbers
  • Number of samples to collect
  • Clock rate
  • Input range
  • The memory buffer to store the data in

In addition to the A/D data, an error code is returned.

The examples below show how to perform a non-continuous scan using the Universal Library™, UL for Android™, NI LabVIEW™, DASYLab®, and DAQami™.

Universal Library

The following example shows how to perform a non-continuous scan using the Universal Library (UL) and Visual Basic:

LowChan = 0
HighChan = 0 'Collect from just channel 0
Count = 50000 'Specify the total number of samples to collect
Rate = 50000 'Specify the per-channel clock rate
Range = MccDaq.Range.Bip10Volts ‘Specify the +/- 10V input range
ULStat = DaqBoard.AInScan(LowChan, HighChan, Count, Rate, Range, MemHandle, Options)

The sample data is returned to a buffer in PC memory at the provided handle, while the error code is returned as the value of ULStat.

Next we copy the data from the memory buffer to a local program array, named ADData:

ULStat = MccDaq.MccService.WinBufToArray(MemHandle, ADData, FirstPoint, Count)

Up until now, the data has been transferred and stored in the counts format for efficiency purposes. We can convert to
voltage with the following UL function:

ULStat = DaqBoard.ToEngUnits(Range, ADData(0), EngUnits)

UL for Android
The following example shows how to perform a non-continuous scan using UL for Android and Java:

lowChan = 0;
highChan = 0; Collect from just channel 0
mode = ChannelMode.SINGLE_ENDED;
Specify configuration mode
range = Range.BIP10VOLTS; Specify the ±10V input range
samplesPerChan = 50000;
Specify the number of samples per channel
rate = 50000; Specify the per-channel clock rate
mUnit = AiUnit.VOLTS;
Specify voltage units
actualScanRate = mAiDevice.aInScan(lowChan, highChan, mode, range, samplesPerChan, rate, options, mUnit, mScanData);

Collect the values by calling the aInScan () function. The data is returned in the array named mScanData.

The following example shows how to perform a non-continuous scan using NI LabVIEW. The wiring diagram below shows the pertinent VIs and settings. Here the first channel (AiO) of hardware device # 0 is asked to return 50000 samples, at the rate of 50000 Hz, within the expected range of -10 V to +10 V. The resulting voltage data is available as the Measurement Array.

Non-programmers can consider using one of several packages that make collecting, displaying, and storing waveform data quite easy. One popular package is DASYLab.

The following example worksheet shows an Analog Input module with its output wired to a Y/t Chart Display module. The captured voltage waveform is shown on the chart display.

Double-clicking on the Analog Input module opens a dialog box you can use to enable the desired channels, select the input range, and specify the sample rate.

The following example shows the DAQami Acquisition page, where you set the Sample Rate and Sample Count.

The resulting data is plotted on the DAQami display page:

More Information
Please reach out to our support team on the Digilent Forum if you have any questions:

Additional TechTips are available here in Digilent Reference: App Notes, Tech Tips, and Other Documents