• 0
Sign in to follow this  
attila

Synchronize Awg Between Devices With Waveforms Sdk

Question

"""
   DWF Python Example
   Author:  Digilent, Inc.
   Revision: 2015/02/05

   Requires:            
       Python 2.7
   
   Start synchronized the AWG outputs of multiple Analog Discovery devices.
   Connect the Trigger-1 pin of each device together.
"""

from ctypes import *
import time
import sys

if sys.platform.startswith("win"):
    dwf = cdll.dwf
elif sys.platform.startswith("darwin"):
    dwf = cdll.LoadLibrary("libdwf.dylib")
else:
    dwf = cdll.LoadLibrary("libdwf.so")

#print DWF version
version = create_string_buffer(16)
dwf.FDwfGetVersion(version)
print "DWF Version: "+version.value

cDevice = c_int()

dwf.FDwfEnum(c_int(2), byref(cDevice)) # 2 = enumfilterDiscovery
print "Found "+str(cDevice.value)+" devices"

cChannel = 2
cOutput = cDevice.value*cChannel
hdwf = c_int()

#open device
for iDevice in range (0, cDevice.value):
    dwf.FDwfDeviceOpen(c_int(iDevice), byref(hdwf))

    if hdwf.value == 0:
        print "failed to open"
        quit()

    for iChannel in range (0, cChannel):
        print "Configure "+str(iDevice+1)+"/"+str(iChannel+1)
        
        # enable channel
        dwf.FDwfAnalogOutNodeEnableSet(hdwf, c_int(iChannel), c_int(0), c_int(True)) # 0 = AnalogOutNodeCarrier

        # configure
        dwf.FDwfAnalogOutNodeFunctionSet(hdwf, c_int(iChannel), c_int(0), c_int(1)) # 1 = funcSine
        dwf.FDwfAnalogOutNodeFrequencySet(hdwf, c_int(iChannel), c_int(0), c_double(1000.0))
        dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, c_int(iChannel), c_int(0), c_double(1.0))
        # set trigger source to external trigger 1
        dwf.FDwfAnalogOutTriggerSourceSet(hdwf, c_int(iChannel), c_byte(11)); # 11 = trigsrcExternal1

        #set different phase
        iOutput = iDevice*cChannel+iChannel
        dwf.FDwfAnalogOutNodePhaseSet(hdwf, c_int(iChannel), c_int(0), c_double(360.0*iOutput/cOutput))

        # start the channel, this will wait for the trigger
        dwf.FDwfAnalogOutConfigure(hdwf, c_int(iChannel), c_bool(True))

# configure Trigger-1 pin to output the triggerPC signal for the last device 
dwf.FDwfDeviceTriggerSet(hdwf, c_int(0), c_byte(1)) # 1 = trigsrcPC

# after open, before the first run wait a bit for the offsets to stabilize
time.sleep(5)

print "Pulse trigger to start generation..."
dwf.FDwfDeviceTriggerPC(hdwf);

time.sleep(60)

print "done."
dwf.FDwfDeviceCloseAll()

Share this post


Link to post
Share on other sites

1 answer 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this