Jump to content
  • 0

Using ScanShift Acquisition Mode in WaveForms SDK


tj38

Question

Hi, I am trying to figure out how to use either ScanShift or ScanScreen acquisition mode for Digital Inputs into the Analog Discovery. And well, I can't get it to work, and haven't really been able to find any information online. My overall goal is to be able to stream out the digital data, so that I can capture and store more (continuous) data than the 16 kB buffer size. This doesn't have to run fast, I need to capture at 10,000 samples per second.

The problem seems to be that the Digital In is staying in a "trigger" state. I am using Python, and using the function:

dwf.FDwfDigitalInStatus(hdwf, c_int(1), byref(sts))

always sets sts to c_int(3), which according to dwfconstants.py file (included in python samples folder with the SDK), this corresponds to stsTrig.

 

Here is one version of the code I have been playing with, it is modified from the DigitalIn_Acquisition.py sample program (note I can switch to C, if that would be easier, I am not actually very familar with Python):
 

    """
       DWF Python Example 5
       Author:  Digilent, Inc.
       Revision: 10/17/2013
    
       Requires:                       
           Python 2.7, numpy, matplotlib
           python-dateutil, pyparsing
    """
    from ctypes import *
    from dwfconstants import *
    import math
    import time
    #import matplotlib.pyplot as plt
    import sys
    
    #declare ctype variables
    if sys.platform.startswith("win"):
        dwf = cdll.dwf
    else:
        dwf = cdll.LoadLibrary("libdwf.so")
    
    hdwf = c_int()
    sts = c_byte()
    
    #print DWF version
    version = create_string_buffer(16)
    dwf.FDwfGetVersion(version)
    print "DWF Version: "+version.value
    
    #open device
    print "Opening first device"
    dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf))
    
    if hdwf.value == hdwfNone.value:
        print "failed to open device"
        quit()
    
    ofile = open("DigInTestData.txt", 'w') #open file in write mode
    print "File opened to write."
    ofile.truncate() # delete existing content
    
    print "Preparing to read sample..."
    
        
    # generate counter (Connecting these pins back to the inputs to test)
    for i in range(12, 16):
        dwf.FDwfDigitalOutEnableSet(hdwf, c_int(i), c_int(1)) #(dRef, chan, Enable(1)orDisable(0))
        dwf.FDwfDigitalOutDividerSet(hdwf, c_int(i), c_int(33332*(1<<(i-12)))) #(dRef, chan, clock_divider)
        dwf.FDwfDigitalOutCounterSet(hdwf, c_int(i), c_int(1), c_int(1)) #(dRef,chan,clkcycs_low,clkcycs_high)
    
    dwf.FDwfDigitalOutConfigure(hdwf, c_int(1)) #(dRef, Enable(1)orDisable(0))
    
    
    #ScanShift Mode
    dwf.FDwfDigitalInAcquisitionModeSet(hdwf, acqmodeScanShift) #TH:(dRef, acqmode)
    
    #sample rate = system frequency / divider, 100MHz/1
    dwf.FDwfDigitalInDividerSet(hdwf, c_int(10000)) #TH: 1->10,000 #(dRef, clk_divider)
    # 16bit per sample format
    dwf.FDwfDigitalInSampleFormatSet(hdwf, c_int(8)) #(dRef, Format(8,16,or32))
    # set number of sample to acquire
    cSamples = 1
    rgwSamples = (c_uint8*cSamples)() #rgwSamples is a ?pointer? to a ctype array acting as a "buffer"
    dwf.FDwfDigitalInBufferSizeSet(hdwf, c_int(cSamples)) #(dRef,BufSize) duh...
    
    rgpy=[]
    
    #dwf.FDwfDigitalInTriggerAutoTimeoutSet(hdwf, c_double(0.2097152))
    dwf.FDwfDigitalInConfigure(hdwf, c_bool(0), c_bool(1)) #(dRef,reconfig?,StartRec)
    while True:
        dwf.FDwfDigitalInStatus(hdwf, c_int(1), byref(sts)) #(dRef,ReadData(TorF), status_variable)
        print "STS VAL: " + str(sts.value)
        if (sts.value == stsTrig.value):
 #only changed to stsTrig so that it will escape this loop
            break
        time.sleep(1)
    print "   waiting to finish"
    time.sleep(1)
    
    # begin acquisition
    for I in range(0,100):
        # get samples, byte size
        dwf.FDwfDigitalInStatusData(hdwf, rgwSamples, cSamples) #(dRf,point->databuffer,numOfDataBytes2Copy)
        rgpy.append(rgwSamples[0])
    
    dwf.FDwfDeviceCloseAll()
    for num in rgpy:
        ofile.write(str(num)+'\n')
        
    for i in range(0,15):
        print(str(rgpy))
    ##
    ##print()
    ##print(str(rgpy[0]))
    
    
    print "...written to."
    ofile.close()
    print "and closed."

 

This just results in one value be stored in all 100 spots. An example of a shell output:
 

    DWF Version: 2.7.5
    Opening first device
    File opened to write.
    Preparing to read sample...
    STS VAL: 3
       waiting to finish
    8
    8
    8
    8
    8
    8
    8
    8
    8
    8
    8
    8
    8
    8
    8
    ...written to.
    and closed.

 

Any help/advice anyone can give me would be greatly appreciated; I am really new to all of this.

 

Link to comment
Share on other sites

12 answers to this question

Recommended Posts

Hello,

I sent you the newer software/SDK version in private message.
You will find in this the DigitalIn_Record.py example, which generates a counter and records a large number of samples in text file.

Hi Attila

Could you also send me the newer Version of the SDK? I searched everywhere on your homepage and I didn't find any SDK with the DigitalIn_Record.py file in it. The newest SDK I found on your homepage is the Waveform 2.7.5.

Any help would be greatly appreciated

Thank you in advanve

Matthias

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...