Event-Triggered Data Acquisition with ADwin by Introduction In many of today's production environments, it is extremely important to capture all the data coming from a particular process. Often, the data comes into the data acquisition system asynchronously and without warning. ADwin allows the data acquisition system to capture important information, analyze the data (filter, FFT, DFT, etc.), and respond to a decision (based on the data) in real time without the latencies inherent to Windows®. This application note is intended to illustrate a simple event-triggered data acquisition system that simulates the actions of an oscilloscope. ADwin can be configured to acquire many channels of data independently, but for simplicity and to illustrate the concepts involved, this note will only describe how to configure a single-channel data acquisition system. Figure 1 illustrates a simple ADwin data acquisition and control system for a single channel. Figure 1. Example of a Control System Using ADwin Test Description The ADwin product family is useful for measurement and control applications. ADwin products come with their own DSP processors with nanosecond response timing that controls a variety of inputs and outputs (I/O). The I/O includes ADCs (analog-to-digital converters), DACs (digital-to-analog converters), digital inputs, and digital outputs, which can monitor the process output with either analog or digital inputs. The processor then calculates the error between process output and the set point. A new level for either an analog or digital output is calculated to control the process and minimize this error. For this particular application, ADwin monitors one of its analog input channels, waiting for a rising edge. Once the rising edge passes a predetermined threshold point, data acquisition begins, and the data is stored in memory. Acquisition is not complete until a falling edge is detected or the memory is filled. If the falling edge is detected or the memory limit is reached, ADwin will interrupt the PC (running TestPointTM), which in turn transfers the data to the PC's memory for further analysis or presentation to the user. ADwin allows the PC to transfer the data out of the ADwin registers without slowing the ADwin processor, which maintains the real-time operation of the system. The programming language for the ADwin family is ADbasic. The hardware and ADbasic allow you to define integer and floating-point variables that are stored in registers that can be accessed while ADwin is running. The I/O registers can be easily accessed by most of today's popular programming environments, such as TestPointTM, LabVIEWTM, Visual Basic, or C. Methods and Techniques Multi-Channel Programming Table 1. ADwin Family Analog Input Selection
Data Interchange between ADwin and the PC All of the programs mentioned (TestPoint, Visual Basic, etc.) have either drivers or include files to communicate with the ADwin hardware, but TestPoint is the only program that supports the hardware interrupt from ADwin. When ADwin generates an interrupt (for example, executes the ACTIVATE_PC ADbasic command), the Action List of the ADwin Real-Time Object in TestPoint executes. Figure 2 shows an example of a Real-Time Object Action List from TestPoint. If another programming environment is used, data can still be read and sent to the ADwin hardware, but ADwin cannot trigger an event to occur. Figure 2. Example ADwin Real-Time Object Action List in TestPoint Data Interchange with FIFO Buffers DIM DATA_1[1000] AS INTEGER AS FIFO This declaration defines an array with: the data set number 1, a length of 1000 integer values, and a FIFO ring buffer structure. The commands FIFO_EMPTY and FIFO_FULL are available in ADbasic to determine if there is still storage space available while the ADwin process is executing. On-the-Fly Data Analysis Basic Programming Guidelines The following program listing shows an example of an event-triggered data acquisition algorithm implemented for all ADwin processor modules (implemented with only integer numbers). The program is written in ADbasic, which is the programming environment for the ADwin products. The program utilizes the TestPoint interrupt, which when sent enables TestPoint to execute an "Action List." |
#DEFINE ArrayIndex PAR_1 ' Passed to TestPoint for array size #DEFINE Reading PAR_2 ' Holds A/D counts #DEFINE Holdoff PAR_3 ' TestPoint passes back when ready #DEFINE EdgeFlag PAR_4 ' Detects rising/falling edge #DEFINE Index PAR_5 ' Index counter used locally #DEFINE LoopTime PAR_6 ' This is the time between loops #DEFINE Threshold PAR_10 ' Threshold for detecting edge Dim DATA_1[10000] As INTEGER ' Data array for A/D measurements Dim i As INTEGER INIT: ' INIT section runs once at beginning Threshold = 33000 ' Set initial value of threshold, in this case for ADwin-Gold ' For bipolar operation, 32768 corresponds to zero volts for the ADwin-Gold ' For bipolar operation, 2048 corresponds to zero volts for ADwin-Light SET_MUX(0) ' Select Mux channel 1 GLOBALDELAY = 1000 ' Time interval between each EVENT LoopTime = GLOBALDELAY ArrayIndex = 1 ' Initialize array size Index = 0 ' Initialize counter EdgeFlag = 0 ' Set edge detection flag Holdoff = 0 ' No holdoff For i = 1 to 10000 ' Initialize data array DATA_1[i] = 1 next i EVENT: ' EVENT is real-time loop execution START_CONV(1) ' Start A/D conversion ADC1 WAIT_EOC(1) ' Wait for end of conversion Reading = READADC(1) ' Read value from ADC1 IF ((Reading > Threshold) AND (Holdoff = 0)) THEN ' If zero, keep checking for edge INC(Index) EdgeFlag = 1 ' Rising edge detected DATA_1[Index] = Reading ' Save reading in array ENDIF IF (Index = 10000) THEN ' Is array full? Holdoff = 1 ' Set Holdoff flag ArrayIndex = Index ' Save global value of Index ACTIVATE_PC ' Generate PC interrupt Index = 0 ' Reset counter ENDIF IF ((Reading < Threshold) AND (EdgeFlag = 1)) THEN ' Pulse is over Holdoff = 1 ' Set Holdoff flag EdgeFlag = 0 ' Falling edge detected ArrayIndex = Index ' Save global value of Index ACTIVATE_PC ' Generate PC interrupt Index = 0 ENDIF FINISH: ' FINISH section runs once at end Index = 0 ' Reset variables Holdoff = 0 EdgeFlag = 0
Example Program The first downloadable example program (scope.bas) was written in and is meant to be compiled in ADbasic. A companion program written in TestPoint (scope.tst) is used to display the data from the test. Both programs can be downloaded via the Example Program link. NOTE: The test programs that are provided are intended to illustrate the concepts presented in this note. The programs may need to be altered in order to accommodate desired test parameters and timing. Equipment List
Alternative Solutions The ADwin product family offers many different form factors, processors, and I/O in which to create the PID controller. The ADwin family includes:
All three product variations can support up to 32Mbytes of RAM per processor and optional bootloader. The bootloader stores an ADbasic process(es) and begins running the process upon power-up. Therefore, once the ADwin hardware is programmed, it can be used as a stand-alone and without a PC. |
||||||||||||||||||