Jump to content
  • 0

Erratic behavior on DigitalIO pins on Discovery2


spri

Question

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:

image.png.a972916226e5eb9af0cdd300f57e98a9.png (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:

image.png.55dc418541ec361a3679a6f8dbd9e817.png  image.png.a171ee5aab39aaf3e740e93ba4fe5b4a.png

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): 

image.png.cf8b3a66cb862a27b5c2abf5c8046f7f.png 

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

Hi @spri,

This is the correct section for this topic. The main engineer that handles questions about the AD2 as well as WaveForms 2015 is out of the office for the next until next week. You might not get a response until next week. I am sorry about the inconvenience.

thank you,

Jon

Link to comment
Share on other sites

Hi @spri

It looks like you are configuring only DIO-0 line to output pulse.
The other unconfigured DIO lines, by default are in high impedance and you are seeing these floating lines randomly toggling.

In case you need you can configure the other DIO lines to output the same signal, like: dwf.FDwfDigitalOut***Set(hdwf, c_int(-1), ...) # -1 enable all lines or configure enabled lines
or mask the acquisition to see only the DIO-0 line, like:

rgpy[i] = 1 & rgwSamples[i]

 

Link to comment
Share on other sites

Thanks! I don't want to set all the pins to the same output because I may need to output on those pins in other parts of my code. But, it looks like adding the "1&" worked! Can you explain what that really does?  If I needed to send different signals on other pins and wanted to mask acquisition to only plot the output of the pin(s) I'm interested in, how would I go about doing that?  

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...