Jump to content
  • 0

Gating on USB-2020

Houston Miller


I bought an USB-2020 sometime ago but am just now bringing it into an instrument. Although eventually I want to control in Linux, for now I just want to get it running in Windows. I am trying to sort out how to control gating on this system. What we have is a pulsed laser system with two detectors which we want to integrate within a gating window as fast as possible (which may be 10 microseconds?) and capture their ratio on a pulse by pulse basis. I didn't find much on github that points me in the right direction. What is the easiest way to test/code gating on this DAQ?

Revision: I looked at the ul.py code and it seems that this shouldn't be too bad.  I will report and/or delete this comment after I have a chance to dive in.

Edited by Houston Miller
More info found
Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0


Assuming you're using Microsoft C, the following is simple 32-bit console example that captures a buffer worth of data when trigger. It uses the external  TTL trigger along with the re-trigger option. Once the acquisition has started, a polling loop is used to monitor the current sample count. Between triggers, this count will remain steady. Therefore, the polling loop looks for the count to increase to indicate to indicate the buffer data has been refreshed. When this happens, it prints a message to the screen. 

For a test trigger signal, I used a device that has frequency timer output. The USB-2020 doesn't have a timer output so remove the code that has to do with the cbPulseOutStart and cbPulseOutStop functions.

Best regards,


/* Include files */
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include "cbw.h"

void main()
    /* Variable Declarations */

    int BoardNum = 0; //InstaCal board number
    int ULStat = 0;
    int LowChan = 0;
    int HighChan = 1;
    int ChanCount = 2;
    int Gain = BIP10VOLTS;
    long Rate = 200000;
    long curCount = 0;
    long curIndex = 0;
    long last = 0;
    short Status = 0;

    float resolution = 20.0f / 4096.0f;

    long bufferSize = ChanCount * 256 * 200; //must be a multiple of channenl count times 256

    //set error handling
    float Rev = (float)CURRENTREVNUM;
    ULStat = cbDeclareRevision(&Rev);
    cbErrHandling(PRINTALL, STOPALL);

    printf("Demonstration of cbAInScan() in BACKGROUND mode with external re-trigger option\n\n");

    //allocate memory
    HANDLE MemHandle = 0;
    WORD *ADData;
    MemHandle = cbWinBufAlloc(bufferSize);
    //user buffer
    ADData = (WORD*)MemHandle;

    //set the external trigger type
    ULStat = cbSetTrigger(BoardNum, TRIG_POS_EDGE, 0, 0);


        //Arm the acquisition
        ULStat = cbAInScan(BoardNum,

        //pulse out timer parameters 
        double freq = 100.0f;
        double duty = 0.5f;
        int cnt = 0;
        double intDelay = 1.0f;
        int idle = 0;
        int opts = 0;

        //my test device is a USB-1208HS
        //trigger signal from on board timer output to trigger input
        ULStat = cbPulseOutStart(BoardNum, 0, &freq, &duty, cnt, &intDelay, idle, opts);

        do //wait for initial trigger
            ULStat = cbGetStatus(BoardNum, &Status, &curCount, &curIndex, AIFUNCTION);
        } while (curCount < 1);

        last = curCount;

        while (!_kbhit())

            ULStat = cbGetStatus(BoardNum, &Status, &curCount, &curIndex, AIFUNCTION);
            if ((curCount - last) >= bufferSize)
                printf("Triggered! Count = %d,\t diff = %d\n", curCount, curCount - last);
                //ADData buffer has fresh data to use
                last = curCount;


    cbStopBackground(BoardNum, AIFUNCTION);
    printf("Completed...press any key to exit\n");


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...