DIGITAL_INPUT.EXEThe sample program DIGITAL_INPUT.EXE is provided with <strong>CompuScope</strong> <strong>SDK</strong> for C/C++ for Windows.The sample program is provided for use with digital input <strong>CompuScope</strong>s like the CS3200. Conceptually, adigital input <strong>CompuScope</strong> is just like analog input <strong>CompuScope</strong> with its analog signal conditioning frontend and A/D converter chips replaced with a digital input buffer. Because of the similarity in the operationof the analog and digital <strong>CompuScope</strong>s, Gage uses exactly the same set of subroutines (the API) to accessboth types of <strong>CompuScope</strong>s. Gage has modified the operation of some API subroutines for digital input<strong>CompuScope</strong>s so that they fit the functionality of these boards.Three important differences exist that must be considered when programming a digital input <strong>CompuScope</strong>1. <strong>CompuScope</strong> Mode. – For an analog <strong>CompuScope</strong> the operating mode, SINGLE or DUAL, specifiesthe number of channels on which to acquire analog signals. For digital input <strong>CompuScope</strong>s, however, themode parameter is used to specify the digital input width. The <strong>CompuScope</strong> 3200, for instance, can beconfigured for 8, 16 or 32 bit input width. In this way, memory usage is optimized. For example, a<strong>CompuScope</strong> 3200 with 2 Mega Bytes of on-board memory can capture 2 Mega Samples in 8-bit mode, 1Mega Samples in 16-bit mode and one-half Mega Samples in 32-bit mode. In order to control the mode,the programmer must set the board.opmode to GAGE_SINGLE_CHAN for 8-bit mode,GAGE_DUAL_CHAN for 16-bit mode and GAGE_QUAD_CHAN for 32-bit mode.2. Logic Input Levels. – One may specify the logic input levels for digital input <strong>CompuScope</strong>s. Forinstance, for the single-ended <strong>CompuScope</strong> 3200, the logic level may be selected to be either CMOS (witha logic threshold of about 2.5 Volts) or TTL (with a logic threshold of about 1.4 Volts). The selection ofeither logic level is done through the analog input range control for channel A, which has no meaning on adigital input <strong>CompuScope</strong>. For selection of the CMOS logic level, the programmer must select the ±5Volts input range and for TTL, the ±1 input range. So the programmer should set board.range_a toGAGE_PM_5_V for CMOS logic and should set board.range_a to GAGE_PM_1_V for TTL logic.3. External Sampling Clock Inversion. – Most digital input applications require the use of an externalclock. In digital electronics, the digital data are generally stable on either one clock edge or the other(rising or falling). The user’s device under test may have differential signal propagation delays, whichmeans that the clock and digital data may take different times to arrive at the digital <strong>CompuScope</strong>. Theuser, therefore, may not know upon which clock edge the data are stable. Consequently, the user must becapable of selecting on which clock edge the digital signals are sampled. The sampling clock edge may beselected using the use_invert_clock variable. If the use_invert_clock variable is set to 0 then the digital<strong>CompuScope</strong> will sample on the rising edge of the input external clock. If the use_invert_clock variable isset to 1 then the digital <strong>CompuScope</strong> will sample on the falling edge of the input external clock.The DIGITAL_INPUT sample program captures a digital signal in single-(8 bit), dual-(16 bit), or quad-(32bit) mode from a digital input <strong>CompuScope</strong>. All captured data are written to separate ASCII data files.Data are stored as unsigned integers in decimal format with ranges 0-255, 0-32767 and 0-4,294,967,295 for8, 16 and 32 bit modes respectively.In order to view the resulting files, you will have to run Microsoft Excel or another program, whichallows you to import ASCII data. You can also use any text editor. In Microsoft Excel, data files can beread by opening them from the File menu. Excel’s Import Wizard will guide you through importing thedata. Select “Delimited” for the type of data, and “Tab” as the delimiter for the data. You can then plot thedata.Page 50<strong>CompuScope</strong> <strong>SDK</strong> <strong>Manua</strong>l
Description of the Routines used by the sample programFollowing are the routines used by the sample program DIGITAL_INPUT. A brief description for all theGage API routines used by each of the following routines is also given. For detailed description of all theGage API routines, please see the <strong>CompuScope</strong> API Reference <strong>Manua</strong>l.int CALLBACK WinMain . . . . . . . .This is the main routine in DIGITAL_INPUT.C. In this routine, we first initialize the <strong>CompuScope</strong> driverand hardware and verify the board structure for the <strong>CompuScope</strong> boards.We make setting adjustments using the board_settings routine and then prepare the <strong>CompuScope</strong> boardfor data capture with the SetBoard routine.We then start the acquisition. Two driver routines: gage_triggered and gage_busy are used to monitor theprogress of the trigger event and the completion of the current data acquisition, respectively.Once the acquisition is complete, we determine the relevant addresses by callinggage_calculate_addresses. The data record is transferred to PC RAM using PCI bus-mastering bygage_transfer_buffer_3.For 8 bit mode, gage_transfer_buffer_3 routine returns 8 bit samples in an int8 space.For 16 bit mode, gage_transfer_buffer_3 routine returns 16 bit samples in an int16 space.For 32 bit mode, gage_transfer_buffer_3 routine returns 32 bit samples in an int32 spaceAfter the data are read, we save the data from the digital input to an ASCII data file called D_INPUT.DATin the current working directory.Gage API routines used by gage_transfer_buffer_3:gage_get_driver_info:gage_start_capture:gage_triggered:gage_force_capture:gage_busy:gage_abort_capture:gage_transfer_buffer_3:Fills a structure or record with the relevant information from thedriver variables about the current <strong>CompuScope</strong> board settings.Prepares the <strong>CompuScope</strong> hardware for data acquisition.Determines if the <strong>CompuScope</strong> hardware has encountered a triggerevent.Forces the capture of data by the <strong>CompuScope</strong> board(s).Determines if the <strong>CompuScope</strong> board is busy capturing the data.Used to regain control of the <strong>CompuScope</strong> board(s).Copies the number of sample points requested from the<strong>CompuScope</strong> board’s memory space from the specified channel tothe supplied buffer using bus-mastering. This routine returns anoffset to the beginning of the d-word aligned buffer that the driveruses.<strong>CompuScope</strong> <strong>SDK</strong> <strong>Manua</strong>l Page 51