Jump to content
  • 0

Streaming analog signal data to AD2


logicmax

Question

The project I am working on requires me to constantly update the analog output signal with a new waveform while being triggered by a consistent 5khz trigger signal.  Everytime I run the analog out configure command I miss a few pulses.  is there any way to avoid that?

I am using the funcPlay function for the Analog output and trigger off of Trigger Ext 1. 

  I update the displaySample data and push it out with the following: 

  FDwfAnalogOutNodeDataSet(hdwf, channel, AnalogOutNodeCarrier, displaySamples, Samples);
  FDwfAnalogOutConfigure(hdwf, channel, true);

 

Thanks for any insight you can bring

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Hi @logicmax

1. If you are using the Play mode the DataSet (prefill) and Configure (start) needs to be called only in the initialization. The following data chunks sent with PlayData, see AnalogOut_Play.py

2. If you are generating a periodic signal (FGen) and want to change the signal or other parameters:
FDwfDeviceOpen(...)
FDwfDeviceAutoConfigureSet(hdwf, 0); // the device will be configured only when calling FDwf###Configure
...
FDwfAnalogOutConfigure(hdwf, channel, 1); // start Wavegen
loop:
   ...
   FDwfAnalogOutOffsetSet(...)
   FDwfAnalogOutNodeDataSet(...)
   FDwfAnalogOutConfigure(hdwf, channel, 3); // apply, do not change state

image.png.be98f8edd1b6e8e05976be5af627f635.png

3. A non-intended usage of Play mode, if you only want to change the generated periodic signal could be using the FDwfAnalogOutNodePlayData.
With this method the full device buffer size of data should be sent and frequency set as sample rate.
This method should be faster than 2. since only the data is sent, other configurations are not applied.

2-3 Depending on the generator rate you may notice altering samples at the output, from the previous and new signal. This due to the concurrence between write to device buffer and reading from this to the output.

image.thumb.png.30d5efd5e2d81abecb8e1cf225b4ff24.png

Link to comment
Share on other sites

  • 0

Hi @logicmax

The following example starts by generating a sawtooth then switches to square signal using FDwfAnalogOutNodeDataSet.
Generated by AD2 and captured with ADP.

image.thumb.png.f2468c80d55dca64eb25f6e9d42b7786.png

import sys
import time
from ctypes import *

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")

hdwf = c_int()
channel = c_int(0) # AWG 1

print("Opening first device...")
#dwf.FDwfEnum(0,0)
dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf))

if hdwf.value == 0:
    print("Failed to open device")
    szerr = create_string_buffer(512)
    dwf.FDwfGetLastErrorMsg(szerr)
    print(str(szerr.value))
    quit()

dwf.FDwfDeviceAutoConfigureSet(hdwf, c_int(0)) 

dwf.FDwfAnalogOutNodeEnableSet(hdwf, channel, 0, c_bool(True))
dwf.FDwfAnalogOutNodeFunctionSet(hdwf, channel, 0, c_int(31)) #funcPlay
dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, channel, 0, c_double(0.8))

cBuffer = c_int(0)
dwf.FDwfAnalogOutNodeDataInfo(hdwf, channel, 0, 0, byref(cBuffer))
dwf.FDwfAnalogOutNodeFrequencySet(hdwf, channel, 0, c_double(1e3*cBuffer.value)) # 1kHz to sample rate
rgdSamples = (c_double*cBuffer.value)()

for i in range(0, cBuffer.value): # saw
    rgdSamples[i] = 2.0*i/cBuffer.value-1.0
    
dwf.FDwfAnalogOutNodeDataSet(hdwf, channel, 0, rgdSamples, cBuffer)

dwf.FDwfAnalogOutConfigure(hdwf, channel, c_bool(True)) # start

print("sawtooth started")
time.sleep(5)

for i in range(0, cBuffer.value): #square
    if i<cBuffer.value/2:
        rgdSamples[i] = -1
    else:
        rgdSamples[i] = 1

dwf.FDwfAnalogOutNodePlayData(hdwf, channel, 0, rgdSamples, cBuffer)

print("change to square")
time.sleep(5)

print("done")
dwf.FDwfAnalogOutReset(hdwf, channel)
dwf.FDwfDeviceClose(hdwf)

 

Edited by attila
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...