• 0

How to capture individual Signals instead of a bus form with Digital Discovery


rxm

Question

Hi,

I am new to the Digital Discovery I am capturing data with the SDK and would like to get the data of each individual DIN pin separately instead of together in the same buffer.

My setup: Signals coming in from DIN0 and DIN2.

Code is given below.

What I would like to do is add DIN3 as clk and get the data for that signal in a separate buffer. Currently the data for both signals comes in as combined and I have not been able to find a way to capture it separately in the SDK. This can however be done with Waveforms2015 and I am trying to mimic that.

If I have to use a DIO as clk input, that would be fine too.


hzSys = c_double()
dwf.FDwfDigitalOutInternalClockInfo(hdwf, byref(hzSys))
divider_value = c_uint(int(hzSys.value/1e3))

pin_24_value = createdatavalue([0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f])

dwf.FDwfDigitalOutEnableSet(hdwf, c_int(0), c_int(1))
dwf.FDwfDigitalOutTypeSet(hdwf, c_int(0), DwfDigitalOutTypeCustom)
dwf.FDwfDigitalOutDividerSet(hdwf, c_int(0), divider_value)
dwf.FDwfDigitalOutDataSet(hdwf, c_int(0), byref(pin_24_value), 8*7)

#pin_25_value = createdatavalue([0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa])
pin_25_value = createdatavalue([0x00,0x00,0x00,0xff,0xff,0xff,0xff])

dwf.FDwfDigitalOutEnableSet(hdwf, c_int(1), c_int(1))
dwf.FDwfDigitalOutTypeSet(hdwf, c_int(1), DwfDigitalOutTypeCustom)
dwf.FDwfDigitalOutDividerSet(hdwf, c_int(1), divider_value)
dwf.FDwfDigitalOutDataSet(hdwf, c_int(1), byref(pin_25_value), 8*7)

dwf.FDwfDigitalOutConfigure(hdwf, c_int(1))

sts = c_byte()
dwf.FDwfDigitalInDividerSet(hdwf, c_int(10000))
dwf.FDwfDigitalInSampleFormatSet(hdwf, c_int(16))
nSamples = 8000
rgwSamples = (c_uint16*nSamples)()
dwf.FDwfDigitalInBufferSizeSet(hdwf, c_int(nSamples))
dwf.FDwfDigitalInTriggerSourceSet(hdwf, c_ubyte(3)) # trigsrcDetectorDigitalIn
dwf.FDwfDigitalInTriggerPositionSet(hdwf, c_int(nSamples))
dwf.FDwfDigitalInTriggerSet(hdwf, c_int(0), c_int(0), c_int(1<<1), c_int(0)) # DIO2 rising edge

dwf.FDwfDigitalInAcquisitionModeSet(hdwf, acqmodeRecord)

dwf.FDwfDigitalInConfigure(hdwf, c_bool(0), c_bool(1))
print ("   waiting to finish")


cAvailable = c_int()
cLost = c_int()
cCorrupted = c_int()
cSamples = 0
fLost = 0
fCorrupted = 0

while cSamples < nSamples:
    dwf.FDwfDigitalInStatus(hdwf, c_int(1), byref(sts))
    if cSamples == 0 and (sts == DwfStateConfig or sts == DwfStatePrefill or sts == DwfStateArmed) :
        # acquisition not yet started.
        continue

    dwf.FDwfDigitalInStatusRecord(hdwf, byref(cAvailable), byref(cLost), byref(cCorrupted))

    cSamples += cLost.value
    if cLost.value :
        fLost = 1
    if cCorrupted.value :
        fCorrupted = 1
    if cAvailable.value==0 :
        continue
    if cSamples+cAvailable.value > nSamples :
        cAvailable = c_int(nSamples-cSamples)

    # get samples
    dwf.FDwfDigitalInStatusData(hdwf, byref(rgwSamples, 2*cSamples), c_int(2*cAvailable.value))
    cSamples += cAvailable.value

print ("Acquisition finished")

dwf.FDwfDeviceCloseAll()

print ("Recording finished")
if fLost:
    print ("Samples were lost! Reduce sample rate")
if cCorrupted:
    print ("Samples could be corrupted! Reduce sample rate")

f = open("record.csv", "w")
for v in rgwSamples:
    f.write("%s\n" % v)
f.close()

 

Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Hi @rxm

The sample bits represent DIN or DIO lines. These are captured in parallel to ensure synchronous sampling.
You can shift and mask to get value for the lines separately like:
DIN X = (sample>>X) & 1
DIN 2 = (sample>>2) & 1

f = open("din0.csv", "w")
for v in rgwSamples:
    f.write("%s\n" % (v&1))
f.close()

f = open("din1.csv", "w")
for v in rgwSamples:
    f.write("%s\n" % ((v>>1)&1))
f.close()

 

Link to post
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