Fast Analog Input  (FAI) Functions

Except the software transferring, all the other analog sampling methods, including DMA, bus-master DMA, interrupt etc., are identified as FAI (Fast Analog Input) functions. The operation modeling and flow control in all kinds of FAI sampling methods are similar.

For more detailed information about FAI flow, please refer to the Interrupt transferring and DMA transferring:

Initiate a sampling data buffer

In FAI data operation, the size of buffer is not determined by the FIFO size. However, before you engage sampling, you must set up your sampling count, i.e. the size of sampling data buffer in our example should be the sample count that you want multiplies with the size of one sample . Commonly we need to create a sampling data buffer first and pass the pointer to the driver for later acquisition. The buffer is created by the user, commonly according to your sampling count, but used in the kernel mode by the driver. In order to have enough space and make sure the data not to be lost, the buffer size (sampling count) needs to be set properly.

     Please refer to the table below for setting buffer size:  
Condition\Method Buffer Size( Unit: the size of one sample)
Even Multiple of the FIFO/2 Size Multiple of the count of channels (recommended) >4K(recommended)
Cards with and using FIFO Interrupt  
Bus-Master DMA    
Cards without or not using FIFO Interrupt  

For the cards use FIFO, if it is sampled by interrupt, the buffer size should be an even number and a multiple of half the FIFO size, while it is recommended to be a multiple of the channel count. If it is bus-master DMA, there is no limit to the size of buffer, while 4k bytes is recommended.

Engage the data sampling

Interrupt mode data sampling will be started by the DRV_FAIIntStart function. The DRV_FAIDmaExStart function is for bus-master DMA.
Different sampling methods need different settings. The corresponding structure for each method needs to be created first and uses its pointer as a function parameter in order to pass all necessary settings, including the previous initiated buffer, to the driver.

Please note that DAS cards only support the functions the hardware supports. For example,  PCI1712 supports bus-master DAM sampling. Trying to call an unsupported function will get an error code. Please refer to function support tables and the Hardware Manual for more details.

Data transfer

Once the data sampling is engaged, users have to know the current sampling status and transfer data from sampling buffer to user buffer in time for later operation. Two methods are used to get the sampling status. One is to enable the required events (by calling DRV_EnableEvent) and wait for the event notification (by calling DRV_CheckEvent), then check the status (by calling DRV_FAICheck); the other is to check the data transferring status repeatedly (by calling DRV_FAICheck). When the event is signaled or the checked status indicates that either buffer is full, call the data transfer function (DRV_FAITransfer) to fetch data from sampling data buffer to user buffer.

Following is a list of the Events supported in FAI:

ADS_EVT_INTERRUPT Triggered when a certain number of interrupts occur. The number is specified when applications call the DRV_EnableEvent.
ADS_EVT_BUFCHANGE
ADS_EVT_AI_HIBUFREADY
ADS_EVT_AI_LOBUFREADY
Generally, in the high speed analog input operation, user's buffer is divided into two equal parts, the low buffer and the high buffer. Data from the device will fill them separately. This event will be signaled when either buffer is full. Applications can call the DRV_FAICheck to check which buffer is full, and then call the DRV_FAITransfer to take away the data in this buffer. If the data hasn't been taken away in time, the event ADS_EVT_OVERRUN will be signaled.
ADS_EVT_TERMINATED
ADS_EVT_AI_TERMINATED
Triggered when a high speed analog input operation finishes, or when applications call the DRV_FAITerminate.
ADS_EVT_OVERRUN
ADS_EVT_AI_OVERRUN
Triggered when the data in the buffer has not been taken away in time after an ADS_EVT_BUFCHANGE occurs. If ADS_EVT_OVERRUN occurs, the data would be overwritten by new ones.
ADS_EVT_TIME_OUT Triggered when no event has occurred during the wait interval in the DRV_CheckEvent.

The figure below explains how the sampling buffer works and when the data is transferred:

The four graphs above show the sampling buffer working on a proper cycle:

(1) The sampling data buffer is used as two equal size sections, the 1st half ( low half ) and the 2nd half ( high half ). When the sampling starts, the driver will write data starting from the 1st half.

(2) When the DRV_EnableEvent function is called, should the 1st half be full, the driver will create a buffer change event (ADS_EVT_BUFCHANGEGE, ADS_EVT_AI_HIBUFREADY, ADS_EVT_AI_LOBUFREADY) to notify the user's program. The user's program should transfer the data in time, otherwise the buffer will overrun if the 2nd half is full.

(3) At the same time, data sampling is keeping going on the 2nd half during the data transfer.

(4) When the DRV_EnableEvent function is called, should the 2nd half be full, a buffer change event (ADS_EVT_BUFCHANGEGE, ADS_EVT_AI_HIBUFREADY) will be signaled. The data sampling will be completed for non-cyclic mode, while for cyclic mode, data will log back to the 1st half again (graph 1).

As described above, if the data has not been transferred in time, the previously acquired data will be overwritten. See the figure below:


After the sampling, we need to copy the data from the sampling data buffer to the transfer buffer for analyzing (by calling DRV_FAITransfer, or copy by yourself and calling DRV_ClearFlag to notify the driver your behave), so that the transfer buffer should also be allocated. However, the size of the transfer buffer should be half of the sampling buffer.


Stop FAI functions

DRV_FAITerminate is used to stop the data sampling.

When the user calls the DRV_EnableEvent function and enables the Terminate event, should the DRV_FAITerminate function be called or the operation is completed under non-cyclic mode, the driver will stop the operation and free some resources and send the ADS_EVT_TERMINATED or ADS_EVT_AI_TERMINATED event to the user. Then the user can do operation such as closing the device in the event handling function.

In non-cyclic mode, when the operation completes, the driver will stop automatically. If the user does not call the DRV_EnableEvent, the event ADS_EVT_TERMINATED or ADS_EVT_AI_TERMINATEDwill not be enabled. In cyclic mode, the operation will not be stopped until the user calls the DRV_FAITerminate.

Calling the DRV_EnableEvent to enable the ADS_EVT_TERMINATED or ADS_EVT_AI_TERMINATEDevent is recommended.

For more detailed information about how to use the flow, please refer to Interrupt transferring and DMA transferring.


FAI related Functions
Function Purpose
DRV_EnableEvent On the device indicated by the DeviceHandle, it enables or disables a specified event by specifying the corresponding EventType. This function supports all types of events for DMA and interrupt operation. After the event is enabled, the DRV_CheckEvent can be called to check the type of signaled event.
DRV_CheckEvent On the device indicated by the DeviceHandle, it checks the specified event status and clears the event.
DRV_FAIIntStart On the device indicated by the DeviceHandle, it initiates a single-channel FAI (Fast Analog Input) operation with the interrupt transfer, by way of specifying an AI channel and pre-initiating the sampling buffer for data storage.For detailed information about FAI transfer, refer to Interrupt Transferring.
DRV_FAIIntScanStart On the device indicated by the DeviceHandle, it initiates multi-channel FAI (Fast Analog Input) operation (scanned channel by channel) with the interrupt transferring mode, by way of specifying the starting AI channel and channel number as well as pre-initiating sampling buffer for data storage.
DRV_FAIDmaExStart On the device indicated by the DeviceHandle, initiates a single-channel FAI (Fast Analog Input) operation with bus-master DMA transfer, by way of specifying an AI channel and pre-initiating the sampling buffer for data storage. This function is used to support the bus-master DMA on PCI series devices;
DRV_FAICheck On the device indicated by the DeviceHandle, it retrieves the current status of FAI (Fast Analog Input) operations. The return status contains operation running status (running/stopped or complete/incomplete), buffer overrun status (overrun/not overrun) and sampling buffer status (not ready: 0, first half ready: 1, second half ready: 2). This function is usually used to know when and which part's data of the sampling buffer is ready to be sent to user’s buffer by the DRV_FAITransfer.
DRV_ClearFlag On the FAI (Fast Analog Input) device indicated by the DeviceHandle, it clears the event flag.
DRV_FAITerminate On the device indicated by the DeviceHandle, it stops the running FAI (Fast Analog Input) operation by safely resetting hardware, releasing resources and sending a terminate event to the user.
DRV_FAITransfer Transfers data from FAI (Fast Analog Input) sampling buffer to user's buffer. If the buffer is “HalfReady” (checked with function DRV_FAICheck), then the data must be transferred (FAITransfer) in order to avoid being overwritten.