Jump to content
  • 0

ScanShift or ScanScreen simultaneously for analog and digital inputs


spri

Question

Because the ScanScreen and ShiftScreen acquisition modes ignore triggers, how do I know precisely when they start the first acquisition?  Is it possible to start the analog and digital scan-acquisitions simultaneously to ensure that both data streams are reading/displaying with a common time axis?  Or do I misunderstand how these types of acquisition work?

My previous approach was to generate a slow pulse and use the rising edge as a trigger to simultaneously start single acquisitions on both analog and digital scopes, then plot and repeat on the next pulse. But this is tedious, I can't get it to play nice with threading, and it means I only get snapshots of my data instead of seeing the whole stream. 

Thoughts?

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

Thanks. I have tried this and things look better (the pulses are occuring around the same time), but I am still having a hard time getting it to work perfectly (they aren't totally synchronized). Over the course of a single 20-second acquisition, the relative position of my data samples seems to shift around some -- see the two snips about 5sec apart during the same trial. The blue pulse should by synchronized with the rising edge of the black pulse. I have verified with an external oscilliscope that the pulses are occurring simultaneously, so it must be the synchronization of the acquisition/plotting which is failing. Is this a problem with how I am configuring the scopes, or is it an artifact of how I am reading from the buffers and updating the plot? Either way, thoughts on how to fix it?

image.png.2290a405a96946dec1ea2b46ebaf21cc.pngimage.png.6ac777af12d8f9d2785833eb1feb8d5b.png

 

Code:

            #configure digital in               
            cSamples = 200 # set number of sample to acquire
            rgwSamples = (c_uint16*cSamples)()
            rg1 = (c_double*cSamples)()   #rg = pointer to allocated buffer to copy the acquisition data
            rg2 = (c_double*cSamples)()   #rg = pointer to allocated buffer to copy the acquisition data

            sts = c_int()


            self.dwf.FDwfDigitalInAcquisitionModeSet(hdwf, c_int(1))
            self.dwf.FDwfDigitalInTriggerSourceSet(hdwf, trigsrcAnalogIn)
            self.dwf.FDwfDigitalInDividerSet(hdwf, c_int(int(hzSys.value/(100*self.xRate)))) #sample rate at same freq as X-Ray
            self.dwf.FDwfDigitalInSampleFormatSet(hdwf, c_int(16))            # 16bit per sample format
            self.dwf.FDwfDigitalInBufferSizeSet(hdwf, c_int(cSamples))
            self.dwf.FDwfDigitalInTriggerPositionSet(hdwf, c_int(cSamples/2)) # trigger position in middle of buffer
            
            #configure analog in 
            self.dwf.FDwfAnalogInAcquisitionModeSet(hdwf, c_int(1))
            self.dwf.FDwfAnalogInFrequencySet(hdwf, c_double(int(hzSys.value/(100*self.xRate))))
            self.dwf.FDwfAnalogInBufferSizeSet(hdwf, c_int(cSamples)) 
            self.dwf.FDwfAnalogInTriggerPositionSet(hdwf, c_double(0)) # trigger position in middle of buffer           
            self.dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(-1), c_bool(True))
            self.dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(-1), c_double(5))
                    
            # begin acquisition on both analog and digital
            self.dwf.FDwfDigitalInConfigure(hdwf, c_bool(0), c_bool(1))
            self.dwf.FDwfAnalogInConfigure(hdwf, c_int(0), c_int(1))  
            

            while True:
                
                self.dwf.FDwfDigitalInStatus(hdwf, c_int(1), byref(sts))            
                self.dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts))
                if sts.value == DwfStateDone.value :               
                    break
                                                         
                #read data            
                self.dwf.FDwfAnalogInStatusData(hdwf, c_int(0), rg1, len(rg1)) # get Analog channel 1 data from buffer
                self.dwf.FDwfAnalogInStatusData(hdwf, c_int(1), rg2, len(rg2)) # get Analog channel 2 data from buffer  
                self.dwf.FDwfDigitalInStatusData(hdwf, rgwSamples, 2*cSamples) # get Digital data
                
                #set up plots
                self.canvasQ.figure.clear()    
                myplt = self.canvasQ.figure.add_subplot(111)
    
                myplt.set_ylabel('signal')
                myplt.set_xlabel('samples')
                myplt.set_xlim(0,cSamples) 
                myplt.set_ylim(-0.05,1.05)
    
                rgpy=[0.0]*len(rgwSamples)
                rgpy1=[0.0]*len(rg1)
                rgpy2=[0.0]*len(rg2)
                for i in range(0,len(rgpy)):
                    rgpy= 1 & rgwSamples                       
                for i in range(0,len(rgpy1)):
                    rgpy1=rg1
                    rgpy2=rg2            
                myplt.plot(rgpy, 'k')   
                myplt.plot(rgpy1, 'r')
                myplt.plot(rgpy2, 'b') 
                
                plt.pause(0.1)
                self.canvasQ.draw() 

Link to comment
Share on other sites

On 12/21/2017 at 12:28 PM, attila said:

Hi @spri

For synchronous analog/digital acquisition set DigitalInTriggerSource to AnalogIn, start DigitalIn then start AnalogIn.
This will ensure the digital and analog start at the same time even for scan acquisitions, +/-1 sample delay due to different signal paths.

AnalogInDigitalIn_Acquisition.py

Sorry for my confusion, but I think I'm hearing two different things from you on synchronizing the start of the scan acquisition. Trigger or no trigger?

Link to comment
Share on other sites

Hi @spri

Sorry for the confusion created. The scan screen and shift modes ignore the trigger.
You could use record mode with trigger, which returns only the new samples since the previous status call and you keep/display only the last N samples. Specifying zero for FDwfAnalogInRecordLengthSet it will run indefinitely.

ACQMODE Constants

FUNC Constant Capabilities

acqmodeSingle

Perform a single buffer acquisition. This is the default setting.

acqmodeScanShift

Perform a continuous acquisition in FIFO style. The trigger setting is ignored. The last sample is at the end of buffer. The FDwfAnalogInStatusSamplesValid function is used to show the number of the acquired samples, which will grow until reaching the BufferSize. Then the waveform “picture” is shifted for every new sample.

acqmodeScanScreen

Perform continuous acquisition circularly writing samples into the buffer. The trigger setting is ignored. The IndexWrite shows the buffer write position. This is similar to a heart monitor display.

acqmodeRecord

Perform acquisition for length of time set by FDwfAnalogInRecordLengthSet.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...