Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
daq-and-datalogging:documents:acquiring-analog-waveforms [2023/06/14 05:50] – created Scandiwebdaq-and-datalogging:documents:acquiring-analog-waveforms [2023/07/27 21:28] (current) – Arthur Brown
Line 1: Line 1:
-====== TechTip: ====== +====== TechTip: Acquiring an Analog Waveform with MCC DAQ ======
- +
-===== Acquiring a Single Analog Input Value with MCC DAQ =====+
  
 **Objective**\\  **Objective**\\ 
-To show how to read a single analog input value using an MCC data acquisition device and various software platforms.+To show how to capture an analog waveform using an MCC data acquisition device and various software platforms.\\ 
  
 **Intended Audience**\\  **Intended Audience**\\ 
-Data acquisition system developers who need to occasionally read an AI channel, and seek to understand its implementation approach in various software environments.+Data acquisition system developers who need to digitize an analog waveform over time, and seek to understand waveform capture implementation in various software environments.\\ 
  
 **Overview**\\  **Overview**\\ 
-Analog input DAQ devices are usually touted for their high-speed continuous AI sampling prowess. But when used in this manner, the amount of data generated can be overwhelming to sift through and store. To facilitate transferring such large amounts of data over the system bus, data is usually queued up into large packets or blocks, which could delay the availability of a particular data point. To complement the high speed multi-channel AI scanning, MCC DAQ devices also support the other end of the spectrum – reading a single AI value from one AI channel.+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.\\ 
  
-For USB DAQ, the time required to read a single value from one AI channel varies by DAQ model, but is generally from 1 ms to 5 ms. When you make that reading request, your program waits for the resultant data point from the DAQ device. This is referred to as polling, or software paced reading, since no pacer clock or hardware memory queue is utilized.+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.\\ 
  
-Often the user will set up a software timer (or timed loop) since a new voltage reading is often needed over and over. Other tasks, such as sending a value to a DAQ output channel based on the voltage input value, can also reside in the loop. Such a loop is often referred to as a control loop, and as such requires timely input readings. No software timer or looping is shown in this document, for the sake of simplicity.+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.\\ 
  
-As the number of AI channels in your application and/or the sample rate increases, this single-read approach may not meet your overall throughput needs. Also, if your application does not need “access” to each and every sample as it becomes available, such as in the case where you will process data in larger arrays or analyze data only at the end of the run, then you should consider the waveform/array capture scenario.\\ +For a non-continuous scan, independent of the software platform, the following information must be specified:\\ 
  
-Independent of the software platform, the following information must be specified for each analog input read:\\  +  *AI channel numbers 
- +  *Number of samples to collect 
-  *AI channel #+  *Clock rate
   *Input range   *Input range
-   +  *The memory buffer to store the data in
-And the following two pieces of information are returned:\\ +
  
-  *Voltage reading +In addition to the A/D data, an error code is returned.\\ 
-  *Error code +
-   +
-The examples below show how to sample a single AI reading using the Universal Library™, UL for Android™, NI LabVIEW™, and DASYLab®.\\ +
  
-Universal Library\\  +The examples below show how to perform a non-continuous scan using the [[/software/universal-library/start| Universal Library™,]] [[ /software/universal-library/android/start | UL for Android™,]] [[/software/universal-library/labview/start| NI LabVIEW™,]] [[/software/dasylab/start| DASYLab®,]] and [[/software/daqami/start| DAQami™.]]\\  
-The following example shows how to sample an AI value using the Universal library (UL) and Visual Basic:\\ + 
 +**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)\\ 
  
-Channel = 0 ’Specify channel # 0\\  
-Range = MccDaq.Range.Bip10Volts ’Specify the ±10 V input range\\  
-ULStat = DaqBoard.VIn (Channel, Range, DataValue, Options)\\  
  
-The voltage reading is returned as the DataValue, while the error code is returned as the value of ULStat.\\  
-  
 **UL for Android**\\  **UL for Android**\\ 
-The following example shows how to sample an AI value using UL for Android and Java.\\ +The following example shows how to perform a non-continuous scan using UL for Android and Java:\\ 
  
-<code> +lowChan = 0;\\  
-//Establish connection to the DAQ device +highChan = 0; //Collect from just channel 0\\  
-mDaqDevice.connect(); +mode = ChannelMode.SINGLE_ENDED; //Specify configuration mode\\  
-// Read AI channel 0 +range = Range.BIP10VOLTS; //Specify the ±10V input range\\  
-AiDaqDevice mAiDevice = mDaqDevice.getAiDev(); +samplesPerChan = 50000; //Specify the number of samples per channel\\  
-aInValue = mAiDevice.aIn(0, ChannelMode.SINGLE_ENDED, Range.BIP10VOLTS, +rate = 50000; //Specify the per-channel clock rate\\  
-AiUnit.VOLTS) +mUnit = AiUnit.VOLTS; //Specify voltage units\\  
-</code>+actualScanRate = mAiDevice.aInScan(lowChan, highChan, mode, range, samplesPerChan, rate, options, mUnit, mScanData);\\ 
  
-The voltage reading is returned to aInValue.\\ +Collect the values by calling the aInScan () function. The data is returned in the array named mScanData.\\ 
  
 **NI LabVIEW**\\  **NI LabVIEW**\\ 
-The following example shows how to sample an AI value using LabVIEW. The wiring diagram below shows the pertinent VIs and settings. The first channel (AiO) of hardware device #0 is asked to return one measurement value within the expected range of -10 V to +10 V.\\  +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.\\  
-  + 
-{{https://files.digilent.com/resources/measurement-computing/Reference Images/TT-ULx-AI-Polled.png?538x184}}\\ +{{https://files.digilent.com/reference-images/TT-AI-Waveform-ULx.png?700x133}}\\ 
  
 DASYLab\\  DASYLab\\ 
-Non-programmers who need to take occasional readings should consider the popular package DASYLab. The following example worksheet shows an Analog Input module with its output wired to a Digital Meter display module. The voltage reading is presented in the meter display.\\ +Non-programmers can consider using one of several packages that make collecting, displaying, and storing waveform data quite easy. One popular package is [[/software/dasylab/start| 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.\\  
 + 
 + 
 + 
 +{{https://files.digilent.com/reference-images/TT-AI-Waveform-DASYLab.png?700x431}}\\  
 + 
 +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.\\  
 + 
 +{{https://files.digilent.com/reference-images/TT-AI-Waveform-DASYLab-2.png?454x457}}\\  
 + 
 +**DAQami**\\  
 +The following example shows the DAQami Acquisition page, where you set the Sample Rate and Sample Count.\\  
 + 
 +{{https://files.digilent.com/reference-images/TT-AI-Waveform-DAQami-01.png?616x217}}\\ 
  
-{{https://files.digilent.com/resources/measurement-computing/Reference Images/TT-AI-Single-DASYLab-1.png?502x139}}\\ +The resulting data is plotted on the [[/software/daqami/start| DAQami]] display page:\\ 
  
-Double-clicking on the Analog Input module allows you to access menus where you can select the N samples mode. 
-Here we specify 1 for N (the number of samples.)\\  
  
-{{https://files.digilent.com/resources/measurement-computing/Reference Images/TT-AI-Single-DASYLab-2.png?453x457}}\\ +{{https://files.digilent.com/reference-images/TT-AI-Waveform-DAQami.png?700x404}}\\ 
  
-More Information\\  
-Please contact Measurement Computing Corporation if you have any questions or if you would like any further information.\\  
  
-  *Knowledgebase: [[https://kb.mccdaq.com/Default.aspx | kb.mccdaq.com]]\\  +**More Information**\\  
-  *Phone: 508-946-5100\\  +Please reach out to our support team on the Digilent Forum if you have any questions: [[https://forum.digilent.com/]]
-  *Fax: 508-946-9500\\ +
      
-Additional TechTips are available on our [[https://www.mccdaq.com/Technical-Articles | Data Acquisition Technical Articles web page.]]+Additional TechTips are available here in Digilent Reference: [[start]]