Event-Triggered Data Acquisition with ADwin

by
Doug Rathburn
Keithley Instruments, Inc.



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
There are many ways to acquire data on multiple channels. This application note shows only single-channel acquisition, but the ADwin product family supports many channels. The number of input channels and ADCs available are summarized in Table 1. Table 1 illustrates that it is possible to expand the capabilities and channel count of the event-driven data acquisition.

Table 1. ADwin Family Analog Input Selection
System Analog input channels Number of ADCs
ADwin-Light 8 1
ADwin-Gold 16 2
ADwin-Pro Up to 480 Configurable


Data Interchange between ADwin and the PC
Data can be dynamically shared between the PC and ADwin. Programs such as TestPoint, Visual Basic, C, and LabVIEW can read data from the ADwin memory or set parameters in memory. The memory locations are updated and used on the fly, a process that does not slow or interrupt the ADwin process while it runs. Variables can be defined for interchange as integers, floating-point numbers, or data arrays. The data arrays can be defined as short, integer, long, or floating-point numbers. The data is saved and updated in real time as the ADwin process is running, and, if the PC updates one of the registers, ADwin will use that new value during the next process execution.

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
For applications with large amounts of data that must be continuously transferred to the host PC, ADwin allows the data structure to be configured as a FIFO (First-In, First-Out) buffer. The data that is stored in the FIFO is read in the same order in which it was stored. An example of a FIFO ADbasic program declaration is:


     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
ADwin products are designed with their own microprocessors and memory, so it is possible to perform analysis of the measurement data before it is sent to the PC for display. If the digital signal processor (DSP) is chosen for the ADwin system, you can perform fast floating-point math operations that are useful for many filtering and Fourier transform operations. The clock rate of the DSP (ADwin-9) is 40MHz with an FPU running at 120 megaFLOPS (floating point operations per second).


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

  1. PC running Windows® 95, 98, NT4, or 2000
  2. ADwin-9 real-time control hardware
  3. ADbasic real-time development environment
  4. Custom wiring harness for connecting to test setup

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:

ADwin-Light   PC ISA bus plug-in boards
  • Analog inputs and outputs (one 12-bit A/D) - expandable
  • Digital I/O
  • Optional counters and quadrature encoder
  • ISA communication with the PC
ADwin-GOLD   Stand-alone, external system
  • 16 analog inputs (16-bit @ 10ms & 12-bit @ 0.8ms) - BNC connections
  • 2 analog outputs (16-bit) - expandable
  • 32 digital I/Os, in blocks of 8 as input or output
  • Optional counter (event counter, encoder interface, period cycle, PWM)
  • ISA or USB communication with the PC
ADwin-PRO   Industrial, modular 19-inch system
  • Up to 4 CPUs per system
  • Modular and expandable:
    • 480 analog inputs (multiplexed or parallel)
    • 120 analog outputs
    • 480 digital I/Os
    • Thermocouples, RTD, counter, filters, isolation, etc.
    • CAN-bus, Profibus, RS-232, RS-485, RS-422
  • ISA or USB for communication with the PC

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.