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:using-mcc-daq-digital-io [2023/06/14 05:45] – created Scandiwebdaq-and-datalogging:documents:using-mcc-daq-digital-io [2023/07/27 21:28] (current) – Arthur Brown
Line 1: Line 1:
-====== TechTip: ====== +====== TechTip: Utilizing Digital Inputs / Outputs with MCC DAQ ======
- +
-===== Acquiring an Analog Waveform with MCC DAQ =====+
  
 **Objective**\\  **Objective**\\ 
-To show how to capture an analog waveform using an MCC data acquisition device and various software platforms.\\ +To show how to write to a single digital I/O bit using an MCC data acquisition device and various software platforms.
  
 **Intended Audience**\\  **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.\\ +Data acquisition system developers who need to monitor or control digital states, and seek to understand its implementation in various software environments.
  
 **Overview**\\  **Overview**\\ 
-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.\\ +Digital signals, by definition, are those which can represent just two states, such as on or off. Examples include a warning lamp being lit or dark, a door being latched or unlatched, and a relay being closed or open. Numerically the two states are represented as 1 and 0, or Boolean (true and false). As in most hardware architectures, such individual bits are concatenated together to form bytes and words for more efficient data transfer. Such is the case for the hardware ICs used in modern DAQ devices. Usually, the input and output capability is provided in groups of 8 bits, and all 8 are read or written to in parallel fashion.
  
-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.\\ +In some applications you will want to control or monitor a set of signals exactly at the same time, so be sure to group those signals onto the same port. But for some signals, while you may physically wire them to the same port, you may decide to read or write to them sequentially. In addition to port-wise operations, MCC provides bit-wise operations that automatically mask the remaining bits from the individual bit you want to focus on.
  
-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.\\ +A common question is “how fast should I sample my digital inputs?”, and the answer invariably is: frequently enough so you do not miss a change-of-state. Note that digital inputs generally are not self-latching, nor do they automatically detect input changes. You must read (poll) them on a regular basis, and it is up to your software to decide if the current reading represents a change from the prior reading. For outputs, since they are latched, you need not write to the port again unless you require a change of state.
  
-For a non-continuous scan, independent of the software platform, the following information must be specified:\\ +While real-world digital signals are predominantly unidirectional, DAQ devices usually offer bi-directional capability so as to be adaptable to a wider set of applications. Generally, a DAQ device’s digital ports will power up as inputs. You will need to set (i.e. configure) the direction of each port on the DAQ device for the desired direction. Some devices are bit-configurable for further flexibility. The configuration is to be done once for each digital port, at the start of the program.
  
-  *AI channel numbers +For a software-paced digital output operation, independent of the software platform, two steps are required: Set the direction of the port to output, then later write a value to the port/bit. The former is performed just once, while the latter can be repeated as needed throughout the application.
-  *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 following information must be specified:
  
-The examples below show how to perform a non-continuous scan using the [[ https://www.mccdaq.com/daq-software/universal-library.aspx | Universal Library™,]] [[ https://www.mccdaq.com/daq-software/universal-library-android.aspx | UL for Android™,]] [[ https://www.mccdaq.com/daq-software/universal-library-extensions-lv.aspx | NI LabVIEW™,]] [[ https://www.mccdaq.com/products/DASYLab.aspx | DASYLab®,]] and [[https://www.mccdaq.com/daq-software/DAQami.aspx | DAQami™.]]\\ +  *Port Number 
 +  *Port Direction 
 +  *Data value to output 
 +   
 +And the following information is returned:
  
-**Universal Library**\\ +  *Error code
  
-The following example shows how to perform a non-continuous scan using the Universal Library (UL) and Visual Basic:\\ +The examples below show how to perform a non-continuous scan using the Universal Library™, UL for Android™, NI LabVIEW™, DASYLab®, and DAQami.
  
-LowChan = 0\\  +**Universal Library**\\  
-HighChan = 0 'Collect from just channel 0\\  +The following example shows how to first configure, and then control, a digital output using the Universal Library (UL) and Visual Basic:
-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)\\ +
  
 +<code>
 +PortType = MccDaq.DigitalPortType.AuxPort ‘Specify which digital port
 +Direction = MccDaq.DigitalPortDirection.DigitalOut ‘Specify the output direction
 +ULStat = DaqBoard.DConfigPort(PortType, Direction) ‘Configure the port
 +BitNum = 0 ‘Specify which bit in the port to control
 +BitValue = 1 ‘Specify the value to write
 +ULStat = DaqBoard.DBitOut(PortType, BitNum, BitValue) ‘Write the value out
 +</code>
  
 **UL for Android**\\  **UL for Android**\\ 
-The following example shows how to perform a non-continuous scan using UL for Android and Java:\\ +The following example shows how to configure and control a digital output using UL for Android and Java:
  
-lowChan = 0;\\  +<code> 
-highChan = 0; //Collect from just channel 0\\  +DigitalPortType = AUXPORT; //Specify which digital port 
-mode = ChannelMode.SINGLE_ENDED; //Specify configuration mode\\  +DigitalDirection = OUTPUT; //Specify the output direction 
-range = Range.BIP10VOLTS; //Specify the ±10V input range\\  +mDioDevice.dConfigPort(DigitalPortType, DigitalDirection); //Configure the port 
-samplesPerChan = 50000; //Specify the number of samples per channel\\  +bitNum = 0; //Specify which bit in the port to control 
-rate = 50000; //Specify the per-channel clock rate\\  +bitState = true; Specify the Boolean value to write mDioDevice.dBitOut(DigitalPortType, bitNum, bitState); //Write the value out 
-mUnit = AiUnit.VOLTS; //Specify voltage units\\  +</coded>
-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.\\ +
  
 **NI LabVIEW**\\  **NI LabVIEW**\\ 
-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.\\ +The following example shows how to control a digital output bit using LabVIEW. The wiring diagram below shows the pertinent VIs and settings. Here just the first bit (Do0) of the Auxport on hardware device #0 is configured for output, and then it is tasked with outputting the true/false value the operator enters\\ 
  
-{{https://files.digilent.com/resources/measurement-computing/Reference Images/TT-AI-Waveform-ULx.png?700x133}}\\ +{{https://files.digilent.com/reference-images/TT-DIO-ULx-wiring-diagram.png?625x152}}\\ 
  
 DASYLab\\  DASYLab\\ 
-Non-programmers can consider using one of several packages that make collecting, displaying, and storing waveform data quite easy. One popular package is [[ https://www.mccdaq.com/products/DASYLab.aspx | DASYLab.]]\\  +Non-programmers with digital signals to monitor and control can consider the popular DASYLab package. A Digital Output module is shown below, with its data input wired to the output of a Switch Control module. At run time, the operator can select either on or off, resulting in digital output bit D0 of the DAQ hardware toggling to either a 1 or 0.\\ 
- +
-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/resources/measurement-computing/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/resources/measurement-computing/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/resources/measurement-computing/Reference Images/TT-AI-Waveform-DAQami-01.png?616x217}}\\  +
- +
-The resulting data is plotted on the [[ https://www.mccdaq.com/daq-software/DAQami.aspx | DAQami]] display page:\\ +
  
  
-{{https://files.digilent.com/resources/measurement-computing/Reference Images/TT-AI-Waveform-DAQami.png?700x404}}\\ +{{https://files.digilent.com/reference-images/TT-DASYLab-DO.png?342x231}}\\ 
  
 +Double clicking on the Switch module allows you to access a menu where you can specify how often the switch position will be monitored. Below we see that 1 Hz is selected, resulting in digital output bit D0 on the DAQ hardware being updated every second to match the operator’s selection.\\ 
  
-More Information\\  +{{https://files.digilent.com/reference-images/TT-DASYLab-DO-timebase.png?379x225}}\\ 
-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]]