I am developing a system including the wavegen, digital out triggers and oscilloscope based on the analog discover 2 and programmed with the SDK python.
The codes are shown as attached, currently the codes works well but I have three questions:
1. nSamples = int(8192), the datasheet shows the maximum record length is 16 k, however, when I increase the nSample to any value over 8192, the records went wrong. Since there are two analogIn channels, is that means the maximum record length for each channel is 8 k?
2. The time.sleep =3s issue, the python examples say the oscilloscope need 2 s to stabilize, I am wondering what is the minimum time interval between each time AnalogIn oscilloscope sampling? Since my application requires 500 times oscilloscope capture, decreasing the time interval helps a lot.
3. Currently I used one AnalogIn channel, and I am trying to use two AnalogIn channels and each channel triggered with rising edge of different digital out signal. However, I found that it seems like the two channels are triggered with only the first detected rising edge of the two trigger signals. I am wondering is there any solution to apply the two seperate triggers for the two oscillisope channels?
# align recorded data
if iSample != 0:
rgSamples1 = rgSamples1[iSample:]+rgSamples1[:iSample]
print("Recording done "+str(iSample))
if fLost:
print("Samples were lost! Reduce frequency")
if fCorrupted:
print("Samples could be corrupted! Reduce frequency")
List = [(16.8+j/50.000)*hzAcq.value/500.000]
for v in rgSamples1:
List.append(v)
with open("liqtest2075m.csv", "a") as f_object:
writer_object = writer(f_object)
writer_object.writerow(List)
f_object.close()
Question
Thomas Lee
Hi,
I am developing a system including the wavegen, digital out triggers and oscilloscope based on the analog discover 2 and programmed with the SDK python.
The codes are shown as attached, currently the codes works well but I have three questions:
1. nSamples = int(8192), the datasheet shows the maximum record length is 16 k, however, when I increase the nSample to any value over 8192, the records went wrong. Since there are two analogIn channels, is that means the maximum record length for each channel is 8 k?
2. The time.sleep =3s issue, the python examples say the oscilloscope need 2 s to stabilize, I am wondering what is the minimum time interval between each time AnalogIn oscilloscope sampling? Since my application requires 500 times oscilloscope capture, decreasing the time interval helps a lot.
3. Currently I used one AnalogIn channel, and I am trying to use two AnalogIn channels and each channel triggered with rising edge of different digital out signal. However, I found that it seems like the two channels are triggered with only the first detected rising edge of the two trigger signals. I am wondering is there any solution to apply the two seperate triggers for the two oscillisope channels?
Thanks!
Zeyu
hdwf = c_int()
sts = c_byte()
hzAcq = c_double(5e6)
nSamples = int(8192)
cAvailable = c_int()
cLost = c_int()
cCorrupted = c_int()
fLost = 0
fCorrupted = 0
#print(DWF version
version = create_string_buffer(16)
dwf.FDwfGetVersion(version)
print("DWF Version: "+str(version.value))
#open device
for j in range(1,50, 1):
print("Opening first device")
dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf))
rgSamples1 = (c_int16*nSamples)()
if hdwf.value == hdwfNone.value:
szerr = create_string_buffer(512)
dwf.FDwfGetLastErrorMsg(szerr)
print(str(szerr.value))
print("failed to open device")
quit()
print("Generating sine wave...")
# dwf.FDwfDigitalOutTriggerSourceSet(hdwf,c_int(0), c_int(8))
# dwf.FDwfDigitalOutTriggerSourceSet(hdwf,c_int(1), c_int(8))
dwf.FDwfDigitalOutDividerSet(hdwf, c_int(0), c_int(20))
dwf.FDwfDigitalOutDividerSet(hdwf, c_int(1), c_int(20))
dwf.FDwfDigitalOutDividerSet(hdwf, c_int(2), c_int(20))
dwf.FDwfDigitalOutDividerSet(hdwf, c_int(3), c_int(20))
# dwf.FDwfDigitalOutDividerSet(hdwf, c_int(4), c_int(20))
dwf.FDwfDigitalOutCounterInitSet(hdwf, c_int(0), c_uint(0), c_uint(1))
dwf.FDwfDigitalOutCounterInitSet(hdwf, c_int(1), c_uint(1), c_uint(1))
dwf.FDwfDigitalOutCounterInitSet(hdwf, c_int(2), c_uint(0), c_uint(1))
dwf.FDwfDigitalOutCounterInitSet(hdwf, c_int(3), c_uint(1), c_uint(1))
# dwf.FDwfDigitalOutCounterInitSet(hdwf, c_int(4), c_uint(1), c_uint(1))
dwf.FDwfDigitalOutEnableSet(hdwf, c_int(0), c_int(1))
# dwf.FDwfDigitalOutRunSet(hdwf, c_double(0.00005)) # 1ms run
# dwf.FDwfDigitalOutWaitSet(hdwf, c_double(0)) # 1ms run
# dwf.FDwfDigitalOutRepeatSet(hdwf, c_int(3))
dwf.FDwfDigitalOutCounterSet(hdwf, c_int(0), c_uint(4150), c_uint(27150)) # 100MHz base freq /(30+30) = 1.67 MHz
dwf.FDwfDigitalOutEnableSet(hdwf, c_int(1), c_int(1))
dwf.FDwfDigitalOutCounterSet(hdwf, c_int(1), c_uint(27050), c_uint(4250)) # 100MHz base freq /(30+30) = 1.67 MHz
# dwf.FDwfDigitalOutRunSet(hdwf, c_double(0.00005)) # 1ms run
# dwf.FDwfDigitalOutWaitSet(hdwf, c_double(0)) # 1ms run
# dwf.FDwfDigitalOutRepeatSet(hdwf, c_int(3)) # once
dwf.FDwfDigitalOutEnableSet(hdwf, c_int(2), c_int(1))
dwf.FDwfDigitalOutCounterSet(hdwf, c_int(2), c_uint(28350), c_uint(2950))
dwf.FDwfDigitalOutEnableSet(hdwf, c_int(3), c_int(1))
dwf.FDwfDigitalOutCounterSet(hdwf, c_int(3), c_uint(27300), c_uint(4000))
# dwf.FDwfDigitalOutEnableSet(hdwf, c_int(4), c_int(1))
# dwf.FDwfDigitalOutCounterSet(hdwf, c_int(4), c_uint(27300), c_uint(4000))
dwf.FDwfAnalogOutTriggerSourceSet(hdwf,c_int(0),c_int(12))
# dwf.FDwfAnalogOutTriggerSlopeSet(hdwf,c_int(0), DwfTriggerSlopeRise)
# dwf.FDwfAnalogInTriggerChannelSet(hdwf, 1) # 1st channel
# dwf.FDwfAnalogOutTriggerLevelSet(hdwf, c_double(0.5)) # 0.5V
dwf.FDwfAnalogOutNodeEnableSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_bool(True))
dwf.FDwfAnalogOutNodeFunctionSet(hdwf, c_int(0), AnalogOutNodeCarrier, funcSine)
dwf.FDwfAnalogOutNodeFrequencySet(hdwf, c_int(0), AnalogOutNodeCarrier, c_double((16.8+j/50.000)*hzAcq.value/500.000))
dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_double(5))
dwf.FDwfAnalogOutRunSet(hdwf,c_int(0), c_double(270000/(hzAcq.value*10))) # run for 2 periods
# dwf.FDwfAnalogOutWaitSet(hdwf, c_int(0), c_double(10000/hzAcq.value)) # wait one pulse time
dwf.FDwfAnalogOutRepeatSet(hdwf, c_int(0), c_int(1)) # repeat 5 times
dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(0), c_bool(True))
dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(0), c_double(5))
dwf.FDwfAnalogInAcquisitionModeSet(hdwf, acqmodeRecord)
dwf.FDwfAnalogInFrequencySet(hdwf, hzAcq)
dwf.FDwfAnalogInRecordLengthSet(hdwf, c_double(nSamples/hzAcq.value)) # -1 infinite record lengt
dwf.FDwfAnalogInTriggerAutoTimeoutSet(hdwf, c_double(0)) #disable auto trigger
dwf.FDwfAnalogInTriggerSourceSet(hdwf, 11)
# dwf.FDwfAnalogInTriggerSourceSet(hdwf, 2) #one of the analog in channels
dwf.FDwfAnalogInTriggerTypeSet(hdwf, trigtypeEdge)
# dwf.FDwfAnalogInTriggerChannelSet(hdwf, 1) # 1st channel
dwf.FDwfAnalogInTriggerLevelSet(hdwf, c_double(0.5)) # 0.5V
# dwf.FDwfAnalogInTriggerHysteresisSet(hdwf, c_double(0.5))
dwf.FDwfAnalogInTriggerConditionSet(hdwf, trigcondRisingPositive)
# dwf.FDwfAnalogInTriggerConditionSet(hdwf, trigcondFallingNegative)
# dwf.FDwfAnalogInTriggerAutoTimeoutSet(hdwf, c_double(0)) #disable auto trigger
dwf.FDwfAnalogInTriggerHoldOffSet(hdwf, c_double(0))
# dwf.FDwfAnalogInTriggerChannelInfo(hdwf, c_int(1), c_int(3))
print("Starting oscilloscope")
dwf.FDwfAnalogInConfigure(hdwf, c_bool(False), c_bool(True))
dwf.FDwfAnalogOutConfigure(hdwf, c_int(0), c_bool(True))
dwf.FDwfDigitalOutConfigure(hdwf, c_int(1))
time.sleep(3)
iSample = 0
while True:
dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts))
dwf.FDwfAnalogInStatusRecord(hdwf, byref(cAvailable), byref(cLost), byref(cCorrupted))
iSample += cLost.value
iSample %= nSamples
if cLost.value :
fLost = 1
if cCorrupted.value :
fCorrupted = 1
iBuffer = 0
#wait at least 2 sec
while cAvailable.value>0:
cSamples = cAvailable.value
# we are using circular sample buffer, make sure to not overflow
if iSample+cAvailable.value > nSamples:
cSamples = nSamples-iSample
dwf.FDwfAnalogInStatusData16(hdwf, c_int(0), byref(rgSamples1, sizeof(c_int16)*iSample), c_int(iBuffer), c_int(cSamples)) # get channel 1 dat
# dwf.FDwfAnalogInStatusData16(hdwf, c_int(1), byref(rgSamples2, sizeof(c_int16)*iSample), c_int(iBuffer), c_int(cSamples)) # get channel 2 dat
iBuffer += cSamples
cAvailable.value -= cSamples
iSample += cSamples
iSample %= nSamples
if sts.value == DwfStateDone.value : # done
break
dwf.FDwfAnalogOutReset(hdwf, c_int(0))
dwf.FDwfDigitalOutReset(hdwf)
dwf.FDwfDeviceCloseAll()
# align recorded data
if iSample != 0:
rgSamples1 = rgSamples1[iSample:]+rgSamples1[:iSample]
print("Recording done "+str(iSample))
if fLost:
print("Samples were lost! Reduce frequency")
if fCorrupted:
print("Samples could be corrupted! Reduce frequency")
List = [(16.8+j/50.000)*hzAcq.value/500.000]
for v in rgSamples1:
List.append(v)
with open("liqtest2075m.csv", "a") as f_object:
writer_object = writer(f_object)
writer_object.writerow(List)
f_object.close()
AnalogIn_Record_Trigger_int16_si5m.py
Link to comment
Share on other sites
2 answers to this question
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now