Good morning,
I'm Alessandro.
I'm trying to acquire from two analog input channels of the Analog Discovery 2, whose acquisition must be triggered by an external Arduino signal (0V->5V square wave) at port T1. One acquired analog input channel (called SIGNAL) is a multi-step analog signal at KHz rate (BLUE in the pictures) that I want to sample at each bit (samples are shown in BLACK).
Then the Arduino trigger signal is split and fed it to the remaining analog input of the Analog Discovery, so that this trigger is present both at T1 port (to trigger the acquisition) and recorded at the remaining analog input of the Analog Discovery (called TRIGGER, shown in ORANGE in the pictures).
Therefore it is possible to see when the acquisition of SIGNAL happens with respect to the TRIGGER rising edge.
As you can see from the pictures, TRIGGER rising edge is synchronized with the SIGNAL, but the acquisition sometimes happens 2 samples in advance. Do you know why this could happen? I would like to start the acquisition everytime with the TRIGGER rising edge. Thank you.
Here it is the Python code I used to acquire the signal:
sts = c_byte()
sampling_frequency =10000#500000
hzAcq = c_double(sampling_frequency)
nSamples =300
rgdSamples1 =(c_double * nSamples)()
rgdSamples2 =(c_double * nSamples)()
rgwDigital =(c_uint16 * nSamples)()
cAvailable = c_int()
cLost = c_int()
cCorrupted = c_int()
fLost =0
fCorrupted =0
sampling_time =1/ sampling_frequency
############ set up acquisition ################
dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(0),c_bool(True))# the acquired channel is the scope 1+,1-
dwf.FDwfAnalogInAcquisitionModeSet(hdwf, c_int(3))# record
dwf.FDwfAnalogInFrequencySet(hdwf, hzAcq)
sRecord = nSamples / hzAcq.value
dwf.FDwfAnalogInRecordLengthSet(hdwf, c_double(sRecord))# -1 infinite record length
dwf.FDwfAnalogInTriggerPositionSet(hdwf, c_double(0.0* sRecord))# trigger at time zero############ set up trigger ######################
dwf.FDwfAnalogInTriggerAutoTimeoutSet(hdwf, c_double(0))# disable autotrigger
dwf.FDwfAnalogInTriggerSourceSet(hdwf, trigsrcExternal1)# trigsrcDetectorAnalogIn
dwf.FDwfAnalogInTriggerTypeSet(hdwf, c_int(0))# trigtypeEdge
dwf.FDwfAnalogInTriggerChannelSet(hdwf, c_int(1))# channel 2 is used as TRIGGER (+2,-2)
dwf.FDwfAnalogInTriggerLevelSet(hdwf, c_double(1.8))# 0V# dwf.FDwfAnalogInTriggerHysteresisSet(hdwf, c_double(0.01)) # 0.01V
dwf.FDwfAnalogInTriggerConditionSet(hdwf, c_int(0))# trigcondRisingPositive################# ACQUISITION #########################
sts = c_byte(0)
rgdSamples1 =(c_double * nSamples)(0)
rgdSamples2 =(c_double * nSamples)(0)
rgwDigital =(c_uint16 * nSamples)(0)
cAvailable = c_int(0)
cLost = c_int(0)
cCorrupted = c_int(0)
fLost =0
fCorrupted =0print("Starting oscilloscope")# dwf.FDwfAnalogInConfigure(hdwf, c_int(0), c_int(1))
dwf.FDwfAnalogInConfigure(hdwf, c_int(True), c_int(True))
iSample =0whileTrue:
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 =1if cCorrupted.value:
fCorrupted =1
iBuffer =0while cAvailable.value >0:
cSamples = cAvailable.value
# we are using circular sample buffer, make sure to not overflowif iSample + cAvailable.value > nSamples:
cSamples = nSamples - iSample
dwf.FDwfAnalogInStatusData2(hdwf, c_int(0), byref(rgdSamples1, sizeof(c_double)* iSample), c_int(iBuffer),
c_int(cSamples))# get channel 1 data
dwf.FDwfAnalogInStatusData2(hdwf, c_int(1), byref(rgdSamples2, sizeof(c_double)* iSample), c_int(iBuffer),
c_int(cSamples))# get channel 2 data
dwf.FDwfDigitalInStatusData(hdwf, rgwDigital, c_int(sizeof(c_uint16)* nSamples))
iBuffer += cSamples
cAvailable.value -= cSamples
iSample += cSamples
# print(str(cAvailable.value), str(cSamples), str(iSample), str(iBuffer))
iSample %= nSamples
# print(str(cAvailable.value),str(cSamples),str(iSample), str(iBuffer))if sts.value ==2:# when sts assumes value equal to 2 it exits from the loop (end of acquisition)breakif iSample !=0:
rgdSamples1 = rgdSamples1[iSample:]+ rgdSamples1[:iSample]
rgdSamples2 = rgdSamples2[iSample:]+ rgdSamples2[:iSample]if fLost:print("Samples were lost! Reduce frequency")if fCorrupted:print("Samples could be corrupted! Reduce frequency")
rgdSamples1 = numpy.array(rgdSamples1, dtype=float)
rgdSamples2 = numpy.array(rgdSamples2, dtype=float)
Question
Alessandro
Good morning,
I'm Alessandro.
I'm trying to acquire from two analog input channels of the Analog Discovery 2, whose acquisition must be triggered by an external Arduino signal (0V->5V square wave) at port T1. One acquired analog input channel (called SIGNAL) is a multi-step analog signal at KHz rate (BLUE in the pictures) that I want to sample at each bit (samples are shown in BLACK).
Then the Arduino trigger signal is split and fed it to the remaining analog input of the Analog Discovery, so that this trigger is present both at T1 port (to trigger the acquisition) and recorded at the remaining analog input of the Analog Discovery (called TRIGGER, shown in ORANGE in the pictures).
Therefore it is possible to see when the acquisition of SIGNAL happens with respect to the TRIGGER rising edge.
As you can see from the pictures, TRIGGER rising edge is synchronized with the SIGNAL, but the acquisition sometimes happens 2 samples in advance. Do you know why this could happen? I would like to start the acquisition everytime with the TRIGGER rising edge. Thank you.
Here it is the Python code I used to acquire the signal:
Link to comment
Share on other sites
3 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