Jump to content

Maxpfeiff

Members
  • Posts

    5
  • Joined

  • Last visited

Maxpfeiff's Achievements

Newbie

Newbie (1/4)

1

Reputation

  1. I am trying to use python and the waveforms SDK to do a few different things. So far, I have been using the example python files and I have gotten help from @attila. I want three different AD3's to share a clock signal based off of the reference of a "master device". I want the three to then output a digital out clock signal and measure with analog in channels. All of this is working to my knowledge. I am now trying to turn on the +- voltage supplies to +-5v on all of the devices and having trouble. Everything runs as it should to my knowledge except the supplies do no turn on. Here is my code. Any suggestions? from ctypes import * import sys import time import matplotlib.pyplot as plt import numpy as np from dwfconstants import * # Load the WaveForms library dwf = cdll.dwf # Initialize error message buffer szerr = create_string_buffer(512) dwf.FDwfGetLastErrorMsg(szerr) if szerr[0] != b'\0': print(str(szerr.value)) # Initialize device handle and list of device handles hdwf = c_int(0) rghdwf = [] cChannel = c_int() cDevice = c_int() sts = c_byte() cSamples = 30000 rgdSamples = (c_double * cSamples)() # Buffers for device name and serial number devicename = create_string_buffer(32) serialnum = create_string_buffer(32) # Get and print WaveForms version version = create_string_buffer(32) dwf.FDwfGetVersion(version) print("DWF Version: " + str(version.value)) # Enumerate connected devices dwf.FDwfEnum(c_int(0), byref(cDevice)) print("Number of Devices: " + str(cDevice.value)) print("Connect trigger lines between devices for reference clock and triggering") hdwfMaster = c_int(0) dwf.FDwfParamSet(DwfParamExtFreq, 10000000) # reference clock frequency dwf.FDwfParamSet(DwfParamFrequency, 100000000) # system clock frequency # Open each device and configure dwf.FDwfEnum(c_int(0), byref(cDevice)) for iDevice in range(cDevice.value): dwf.FDwfDeviceOpen(c_int(iDevice), byref(hdwf)) dwf.FDwfAnalogIOChannelNodeSet(iDevice, c_int(0), c_int(0), c_double(1)) # enable positive supply dwf.FDwfAnalogIOChannelNodeSet(iDevice, c_int(0), c_int(1), c_double(5.0)) # set voltage to 5 V dwf.FDwfAnalogIOChannelNodeSet(iDevice, c_int(1), c_int(0), c_double(1)) # enable negative supply dwf.FDwfAnalogIOChannelNodeSet(iDevice, c_int(1), c_int(1), c_double(-5.0)) # set voltage to -5 V dwf.FDwfAnalogIOEnableSet(iDevice, c_int(1)) # master enable if hdwf.value == 0: dwf.FDwfGetLastErrorMsg(szerr) print(str(szerr.value)) dwf.FDwfDeviceCloseAll() sys.exit(0) rghdwf.append(hdwf.value) 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.FDwfEnumDeviceName(c_int(iDevice), devicename) dwf.FDwfEnumSN(c_int(iDevice), serialnum) print("\t" + str(devicename.value)) print("\t" + str(serialnum.value)) 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 / 1e3 / 2)) # prescaler to 2kHz, SystemFrequency/1kHz/2 dwf.FDwfDigitalOutCounterSet(hdwf, iChannel, 1, 1) # 1 tick low, 1 tick high dwf.FDwfDigitalOutRunSet(hdwf, iChannel, c_double(0.0001)) dwf.FDwfDigitalOutIdleSet(hdwf, iChannel, DwfDigitalOutIdleLow) dwf.FDwfDigitalOutConfigure(hdwf, 1) # Configure each device to trigger on External Trigger 1 dwf.FDwfAnalogInTriggerSourceSet(hdwf, c_int(12)) # 12 = trigsrcExternal2 dwf.FDwfAnalogInFrequencySet(hdwf, c_double(1e6)) # Set acquisition frequency to 1MHz dwf.FDwfAnalogInConfigure(hdwf, c_int(1), c_int(1)) # Start analog input configuration # Wait for offsets to stabilize time.sleep(5) # Wait until the last configured device is armed hdwf.value = rghdwf[cDevice.value - 1] while True: dwf.FDwfAnalogInStatus(hdwf, c_int(0), byref(sts)) if sts.value == 1: # DwfStateArmed break time.sleep(3) # Generate trigger signal on the first device to start both generators and acquisition hdwf.value = rghdwf[0] dwf.FDwfDeviceTriggerPC(hdwfMaster) time.sleep(0.5) #Wait for acquisition to complete while True: dwf.FDwfAnalogInStatus(hdwf, c_int(0), byref(sts)) if sts.value == 2: # DwfStateDone break # Plot the results for iDevice in range(0, cDevice.value): hdwf.value = rghdwf[iDevice] dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts)) if sts.value != 2: # DwfStateDone print("Not triggered!") continue # Retrieve data from each channel and plot it dwf.FDwfAnalogInChannelCount(hdwf, byref(cChannel)) for iChannel in range(0, cChannel.value): dwf.FDwfAnalogInStatusData(hdwf, iChannel, rgdSamples, c_int(cSamples)) # Create a new figure for each channel plt.figure() plt.plot(np.fromiter(rgdSamples, dtype=float)) plt.title(f'Device {iDevice + 1}, Channel {iChannel + 1}') plt.xlabel('Sample Index') plt.ylabel('Voltage (V)') # Display the plots plt.show() # Ensure all devices are closed dwf.FDwfDeviceCloseAll()
  2. @attila Thank you so much. I am very new to python and the Waveforms SDK and API so sorry if my questions were trivial. Your help is greatly appreciated.
  3. 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
  4. 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()
  5. Is there a way to sync 3+ AD3's. I essentially want to expand "dual-mode" beyond just two AD3's. I think I just need the devices to share a clock signal so that they can use the Wavegen feature simultaneously as well as use the oscilloscope simultaneously. I am hoping to get them synced within 10ns for both features.
×
×
  • Create New...