• 0

python trouble with funcCustom on AnalogDiscovery2


I am trying to create two square wave signals on the AD2 Analog instrument. Both signals should start at 5v, one should drop to 0v at the trigger, and the other should go to 0v after a certain delay time after the trigger (delay time = self.d/1000). Both signals should return to 5v at the same time (end of RunSet). I think I have to do this using the 'funcCustom' output, at least for the delayed signal. However, I am not able to get the funcCustom signal to give me the desired output. It just outputs 5v constantly after the trigger signal. (The funcSquare signal does what is expected). 

Is there an easier way to create this delay between two analog channels without using funcCustom? Or is there something wrong in my syntax for getting the funcCustom signal to work? 

Thank you! 


            self.dwf.FDwfAnalogOutNodeEnableSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_bool(True))
            self.dwf.FDwfAnalogOutNodeEnableSet(hdwf, c_int(1), AnalogOutNodeCarrier, c_bool(True))
            #set up external trigger input channel, configure to wait for trigger signal
            self.dwf.FDwfAnalogOutTriggerSourceSet(hdwf, c_int(-1), trigsrcExternal1)            
            self.dwf.FDwfAnalogOutTriggerSlopeSet(hdwf, c_int(-1), c_int(1)) # set to trigger on rising edge
            #set channel idles 
            self.dwf.FDwfAnalogOutIdleSet(hdwf, c_int(-1), c_int(1)) #set both channels to idle to offset value
            self.dwf.FDwfAnalogOutNodeOffsetSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_double(5.0)) #ch0-Qsys idles high
            self.dwf.FDwfAnalogOutNodeOffsetSet(hdwf, c_int(1), AnalogOutNodeCarrier, c_double(5.0)) #ch1-Xray idles high
            #set run duration
            self.dwf.FDwfAnalogOutRunSet(hdwf, c_int(-1), c_double(totald))  #set run duration on both channels         
            #calculate delay/run percentages 
            nhigh = int((self.d/1000)/totald*10000)   #10000 counts, calculate number of counts low&high as ratio of self.d(ms)/totald(s)
            nlow = 10000-nhigh
            rgdSamples = (c_double*10000)(*[1.0]*nhigh+[0.0]*nlow)

            #set up signal configuration
            #ch0=QTrig, needs to change voltage on trigger
            self.dwf.FDwfAnalogOutNodeFunctionSet(hdwf, c_int(0), AnalogOutNodeCarrier, funcSquare)  #create square wave with 100% pulse width
            self.dwf.FDwfAnalogOutNodeSymmetrySet(hdwf, c_int(0), AnalogOutNodeCarrier, c_double(0.0)) # 0% duty cycle at +amplitude, 100% at -amplitude
            #ch1=xray-trigs, need to change after trigger+delay using custom array
            self.dwf.FDwfAnalogOutNodeFunctionSet(hdwf, c_int(1),  AnalogOutNodeCarrier, funcCustom)  #create custom wave using rgdsamples data
            self.dwf.FDwfAnalogOutNodeDataSet(hdwf, c_int(1), AnalogOutNodeCarrier, rgdSamples, c_int(10000)) #custom data = rgdsamples
            self.dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, c_int(-1), AnalogOutNodeCarrier, c_double(5)) #5V amplitude on both channels
            self.dwf.FDwfAnalogOutNodeFrequencySet(hdwf, c_int(-1), AnalogOutNodeCarrier, c_double(1/totald)) #1 cycle = total xray+delay duration
            self.dwf.FDwfAnalogOutWaitSet(hdwf, c_int(-1), c_double(self.active.delay))  #set master delay        
            self.dwf.FDwfAnalogOutConfigure(hdwf, c_int(-1), c_bool(True)) #start analog


Share this post

Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Thanks for that pointer, but I had already tried that - when I replace the AnalogOutWaitSet with these two lines of code, both channels trigger at the same time using whatever delay period is specified for channel 0. Is there some additional argument (node?) which is required to make this work when using the SDK and not the Waveforms software?


            self.dwf.FDwfAnalogOutWaitSet(hdwf, c_int(0), c_double(self.active.delay))  #set master delay        
            self.dwf.FDwfAnalogOutWaitSet(hdwf, c_int(1), c_double(self.active.delay+self.d/1000))  #set delay


Share this post

Link to post
Share on other sites
  • 0

Hi @spri

Using the channels in master mode/synchronized, configured with -1, these will will be in the same state at the same time. You won't have different wait-run time.

The previous WF application screenshot translates to WF SDK code like:

dwf.FDwfAnalogOutNodeEnableSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_bool(True))
dwf.FDwfAnalogOutNodeEnableSet(hdwf, c_int(1), AnalogOutNodeCarrier, c_bool(True))

dwf.FDwfAnalogOutTriggerSourceSet(hdwf, c_int(-1), trigsrcExternal1)
dwf.FDwfAnalogOutRepeatSet(hdwf, c_int(-1), c_int(0)) # infinite repeat
dwf.FDwfAnalogOutRepeatTriggerSet(hdwf, c_int(-1), c_int(1)) # wait for trigger event in each cycle
dwf.FDwfAnalogOutIdleSet(hdwf, c_int(-1), c_int(1)) # idle output offset

dwf.FDwfAnalogOutWaitSet(hdwf, c_int(0), c_double(0)) # start immediately
dwf.FDwfAnalogOutWaitSet(hdwf, c_int(1), c_double(sDelay)) # wait after trigger
dwf.FDwfAnalogOutRunSet(hdwf, c_int(0), c_double(sTotal)) # run time
dwf.FDwfAnalogOutRunSet(hdwf, c_int(1), c_double(sTotal-sDelay)) # channels will stop at the same time

dwf.FDwfAnalogOutNodeFunctionSet(hdwf, c_int(-1), AnalogOutNodeCarrier, funcSquare)
dwf.FDwfAnalogOutNodeFrequencySet(hdwf, c_int(-1), AnalogOutNodeCarrier, c_double(1))
dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, c_int(-1), AnalogOutNodeCarrier, c_double(5))
dwf.FDwfAnalogOutNodeSymmetrySet(hdwf, c_int(-1), AnalogOutNodeCarrier, c_double(0)) # 0V while running, +5offset -5amplitude
dwf.FDwfAnalogOutNodeOffsetSet(hdwf, c_int(-1), AnalogOutNodeCarrier, c_double(5)) # +5V in idle

dwf.FDwfAnalogOutConfigure(hdwf, c_int(0), c_bool(True))
dwf.FDwfAnalogOutConfigure(hdwf, c_int(1), c_bool(True))


Share this post

Link to post
Share on other sites
  • 0

Thank you, that worked perfectly!

But, I'm a little confused still as to why my solution didn't work. When using -1 to configure the master run time, does that override individual channel settings on the wait time? 

Share this post

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now