Jump to content
  • 0

Syncing Digital Out with SDK


Maxpfeiff

Question

Hi. I am trying to sync two AD3's using waveforms SDK. I want to use an external trigger to start the digital clock signal on both devices. My issue right now is that when I call dwf.FDwfDigitalOutConfigure() the clock signal starts without waiting for a trigger. I'm sure there is a way to do this, but I can't figure it out. I have been looking at the example python files and that is how I got to this point. Here is my code so far. Any suggestions?

from ctypes import *
import sys
import time
from dwfconstants import *

# Load the WaveForms library
dwf = cdll.dwf

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

cDevice = c_int()

dwf.FDwfEnum(c_int(0), byref(cDevice))
print("Found " + str(cDevice.value) + " devices")

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

# Open device
for iDevice in range(cDevice.value):
    dwf.FDwfDeviceOpen(c_int(iDevice), byref(hdwf))
    print(f"Configure Device {iDevice +1}")
    if hdwf.value == 0:
        print("Failed to open device")
        sys.exit(1)

    for iChannel in range(cChannel):

        # enable output for DIO 0
        dwf.FDwfDigitalIOOutputEnableSet(hdwf, c_int(0x0002))  # 1<<1
        # set value on enabled IO pins
        dwf.FDwfDigitalIOOutputSet(hdwf, c_int(0x0000))  # DIO-0 low
        # configure and start clock
        hzSys = c_double()
        dwf.FDwfDigitalOutInternalClockInfo(hdwf, byref(hzSys))

        dwf.FDwfDigitalOutEnableSet(hdwf, c_int(0), c_int(1))  # 1kHz pulse on DIO-0
        dwf.FDwfDigitalOutDividerSet(hdwf, c_int(0), c_int(int(hzSys.value / 1e4 / 2)))  # prescaler to 2kHz, SystemFrequency/1kHz/2
        dwf.FDwfDigitalOutCounterSet(hdwf, c_int(0), c_int(1), c_int(1))  # 1 tick low, 1 tick high
        dwf.FDwfDigitalOutRepeatTriggerSet(hdwf, c_int())
        dwf.FDwfDigitalOutTriggerSourceSet(hdwf, c_int(0), trigsrcExternal1)
        # Start the channel, this will wait for the trigger
        dwf.FDwfDigitalOutConfigure(hdwf)

# Configure Trigger-1 pin to output the triggerPC signal for the last device
dwf.FDwfDeviceTriggerSet(hdwf, c_int(2), 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(5)

print("Done.")
dwf.FDwfDeviceCloseAll()

 

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Hi @Maxpfeiff

See the manual and Device_Synchronization.py example.
AD3, ADP3X50, ADP2230 can also use system reference clock.

The digital-out is one instrument, the channels can't run independently.

Use trigsrcExternal1...

image.png

 

image.png

Link to comment
Share on other sites

  • 0

As I said I have been using the python examples and that is how I have gotten this far. I know that digital out is one instrument. Is it implied in my code somehow that it is not? I have used dwf.FDwfDigitalOutTriggerSourceSet(hdwf, c_int(0), trigersrcExternal1 ) to set the trigger to external 1, however when I call dwf.FDwfDigitalOutConfigure() the clock signal that I have configured to output starts without waiting for a trigger. What am I doing wrong here

Link to comment
Share on other sites

  • 0

Hi @Maxpfeiff

There are multiple issues in your script:
- I don't know why are you setting output enable for DIO-1 but in comments mention DIO-0. The digital-io setting would override digital-out function for the driven channel.
- you are reconfiguring the same digital-out DIO-0 twice
FDwfDigitalOutTriggerSourceSet has 2 arguments not 3
- FDwfDigitalOutConfigure has 2 arguments not 1
- I don't know what you want with FDwfDigitalOutRepeatTriggerSet
- there is one digital-out instrument in the device, but you are including it in your channel loop like digital-out channels could be controlled separately
- FDwfDeviceTriggerSet channel argument like all indices in the API are 0 based, there is not trigger #2 only #0 and #1

 

See the following example which configures all digital-out channels for each connected device to output 1kHz clock. DigitalOut_Devices.py
The 'first' device outputs TriggerPC on Trigger2 (#1) and each device starts on T2.
It also configures the 'first' device to output reference clock on T1 (#0) and others use this as reference clock input. This is supported by newer devices AD3, ADP223, ADP3X50
You can further use FDwfDigitalOutWaitSet and DwfParamFreqPhase to tune trigger and reference clock signal wire delays between devices.

"""
   DWF Python Example
   Author:  Digilent, Inc.
   Revision: 13/6/2024
   Requires:
"""

from ctypes import *
from dwfconstants import *
import math
import time
import sys

if sys.platform.startswith("win"):
    dwf = cdll.dwf
elif sys.platform.startswith("darwin"):
    dwf = cdll.LoadLibrary("/Library/Frameworks/dwf.framework/dwf")
else:
    dwf = cdll.LoadLibrary("libdwf.so")

version = create_string_buffer(16)
dwf.FDwfGetVersion(version)
print(f"DWF Version: {version.value}")

dwf.FDwfParamSet(DwfParamOnClose, 0) # continue running after device close

cDevice = c_int()

dwf.FDwfEnum(0, byref(cDevice))
print(f"Found {cDevice.value} devices")

print("Connect trigger lines between devices for reference clock and triggering")

hdwf = c_int(0)
hdwfMaster = c_int(0)

dwf.FDwfParamSet(DwfParamExtFreq, 10000000) # reference clock frequency
dwf.FDwfParamSet(DwfParamFrequency, 100000000) # system clock frequency

# Open device
for iDevice in range(cDevice.value):
    dwf.FDwfDeviceOpen(iDevice, byref(hdwf))
    if hdwf.value == 0:
        continue
    
    dwf.FDwfDeviceAutoConfigureSet(hdwf, 0) # the instruments will only be configured when FDwf###Configure is called

    if hdwfMaster.value == 0:
        hdwfMaster.value = hdwf.value
        dwf.FDwfDeviceParamSet(hdwf, DwfParamClockMode, 1) # reference clock output on Trigger 1
        dwf.FDwfDeviceTriggerSet(hdwf, 1, trigsrcPC) # Trigger 2 outputs TriggerPC
    else:
        dwf.FDwfDeviceParamSet(hdwf, DwfParamClockMode, 2) # reference clock input on Trigger 1
        
    print(f"Configure Device {iDevice +1}")
    
    dwf.FDwfDigitalOutTriggerSourceSet(hdwf, trigsrcExternal2)
    hzSys = c_double()
    dwf.FDwfDigitalOutInternalClockInfo(hdwf, byref(hzSys))
    cChannel = c_int()
    dwf.FDwfDigitalOutCount(hdwf, byref(cChannel))

    for iChannel in range(cChannel.value):
        dwf.FDwfDigitalOutEnableSet(hdwf, iChannel, 1)  # DIO-0
        dwf.FDwfDigitalOutDividerSet(hdwf, iChannel, int(hzSys.value / 1e4 / 2))  # prescaler to 2kHz, SystemFrequency/1kHz/2
        dwf.FDwfDigitalOutCounterSet(hdwf, iChannel, 1, 1)  # 1 tick low, 1 tick high
        
    dwf.FDwfDigitalOutConfigure(hdwf, 1)

print("Triggering to start generators...")
dwf.FDwfDeviceTriggerPC(hdwfMaster)
dwf.FDwfDeviceCloseAll()

 

Captured 2 DIOs from 2 devices with a 3rd device:

image.png

Link to comment
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
×
×
  • Create New...