I have written a GUI that allows a user to specify pulse frequency, pulse width, etc and synchronize pulses on multiple digital and analog outputs (to synchronize several pieces of equipment in our lab). While plotting the digital output signal using the digitalIn code (copied from the DigitalIn_Acquisition,py sample), I get expected pulses about 70% of the time:
(50% duty cycle with logic-level square pulses, nice and simple and predictable)
... but then I see highly erratic behavior the rest of the time. The erratic behavior starts and stops seemingly at random, without any changes to my code (ie, I see the random behavior just starting/stopping the signal, or re-sampling on Digital-In without stopping the Digital-Out signal). I've even seen the weird behavior stop in the middle of sampling:
Usually when the erratic behavior occurs, I can see the signal I am sending, with a bunch of garbage on top. In the 2nd image above, I am trying to output a 50% duty cycle, which you can see occurring at the very bottom of the y-axis. The signal should go from 0 to 1, so anything above that is unexpected.
I have tried adding DigitalOutReset and IdleSet into my code to reset the baseline signal to zero, which has not worked. I thought the problem might be interference/noise from the devices connected to the Discovery2 so I unplugged everything but I am still seeing the same behavior. I've even seen traces of this behavior when running the provided DigitalIn_Acquisition.py sample code (see falling edges) -- though it hasn't been nearly the same extent of erratic-ness as when running my own code (this plot is the worst I've seen when running the provided sample code):
The pulses I am trying to send range from 10-300hz (using 100 counts per pulse), and I am sampling on DigitalIn at the same frequency (100 samples per pulse).
I have seen posts on the forum about problems with triggers at slower speeds -- is this problem similar? Any ideas what is going on, or how to fix it?
____
Pulse output code:
#initialize output on pin0 to 0
dwf.FDwfDigitalOutReset(hdwf)
dwf.FDwfDigitalOutIdleSet(hdwf, c_int(0), c_int(0))
dwf.FDwfDigitalOutConfigure(hdwf, c_int(1))
Scope code: (copied directly from digitalIn_acquisition.py)
#use DigitalIn to read output signal
#Use AnalogIn to read x-ray output signal
#sample rate = system frequency / divider, 100MHz/1
dwf.FDwfDigitalInDividerSet(hdwf, c_int(int(hzSys.value/(100*self.qRate))))
# 16bit per sample format
dwf.FDwfDigitalInSampleFormatSet(hdwf, c_int(16))
# set number of sample to acquire
cSamples = 1000
rgwSamples = (c_uint16*cSamples)()
dwf.FDwfDigitalInBufferSizeSet(hdwf, c_int(cSamples))
# begin acquisition
dwf.FDwfDigitalInConfigure(hdwf, c_bool(0), c_bool(1))
# print " waiting to finish"
Question
spri
I have written a GUI that allows a user to specify pulse frequency, pulse width, etc and synchronize pulses on multiple digital and analog outputs (to synchronize several pieces of equipment in our lab). While plotting the digital output signal using the digitalIn code (copied from the DigitalIn_Acquisition,py sample), I get expected pulses about 70% of the time:
(50% duty cycle with logic-level square pulses, nice and simple and predictable)
... but then I see highly erratic behavior the rest of the time. The erratic behavior starts and stops seemingly at random, without any changes to my code (ie, I see the random behavior just starting/stopping the signal, or re-sampling on Digital-In without stopping the Digital-Out signal). I've even seen the weird behavior stop in the middle of sampling:
Usually when the erratic behavior occurs, I can see the signal I am sending, with a bunch of garbage on top. In the 2nd image above, I am trying to output a 50% duty cycle, which you can see occurring at the very bottom of the y-axis. The signal should go from 0 to 1, so anything above that is unexpected.
I have tried adding DigitalOutReset and IdleSet into my code to reset the baseline signal to zero, which has not worked. I thought the problem might be interference/noise from the devices connected to the Discovery2 so I unplugged everything but I am still seeing the same behavior. I've even seen traces of this behavior when running the provided DigitalIn_Acquisition.py sample code (see falling edges) -- though it hasn't been nearly the same extent of erratic-ness as when running my own code (this plot is the worst I've seen when running the provided sample code):
The pulses I am trying to send range from 10-300hz (using 100 counts per pulse), and I am sampling on DigitalIn at the same frequency (100 samples per pulse).
I have seen posts on the forum about problems with triggers at slower speeds -- is this problem similar? Any ideas what is going on, or how to fix it?
____
Pulse output code:
#initialize output on pin0 to 0
dwf.FDwfDigitalOutReset(hdwf)
dwf.FDwfDigitalOutIdleSet(hdwf, c_int(0), c_int(0))
dwf.FDwfDigitalOutConfigure(hdwf, c_int(1))
#send custom pulses
dwf.FDwfDigitalOutEnableSet(hdwf, c_int(0), c_int(1))
dwf.FDwfDigitalOutDividerSet(hdwf, c_int(0), c_int(int(hzSys.value/(100*self.qRate))))
dwf.FDwfDigitalOutCounterSet(hdwf, c_int(0), c_int(100-self.qDuty), c_int(self.qDuty))
dwf.FDwfDigitalOutConfigure(hdwf, c_int(1))
Scope code: (copied directly from digitalIn_acquisition.py)
#use DigitalIn to read output signal
#Use AnalogIn to read x-ray output signal
#sample rate = system frequency / divider, 100MHz/1
dwf.FDwfDigitalInDividerSet(hdwf, c_int(int(hzSys.value/(100*self.qRate))))
# 16bit per sample format
dwf.FDwfDigitalInSampleFormatSet(hdwf, c_int(16))
# set number of sample to acquire
cSamples = 1000
rgwSamples = (c_uint16*cSamples)()
dwf.FDwfDigitalInBufferSizeSet(hdwf, c_int(cSamples))
# begin acquisition
dwf.FDwfDigitalInConfigure(hdwf, c_bool(0), c_bool(1))
# print " waiting to finish"
while True:
dwf.FDwfDigitalInStatus(hdwf, c_int(1), byref(sts))
# print "STS VAL: " + str(sts.value)
if sts.value == stsDone.value :
break
time.sleep(1)
# print "Acquisition finished"
# get samples, byte size
dwf.FDwfDigitalInStatusData(hdwf, rgwSamples, 2*cSamples)
self.canvas.figure.clear()
plt = self.canvas.figure.add_subplot(111)
plt.set_xlabel('samples')
plt.set_ylabel('signal')
plt.set_xlim(0,1000)
plt.set_ylim(-0.05,1.05)
rgpy=[0.0]*len(rgwSamples)
for i in range(0,len(rgpy)):
rgpy=rgwSamples
plt.plot(rgpy, 'r')
self.canvas.draw()
Link to comment
Share on other sites
4 answers to this question
Recommended Posts
Archived
This topic is now archived and is closed to further replies.