Search the Community

Showing results for tags 'analogin'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • News
    • New Users Introduction
    • Announcements
  • Digilent Technical Forums
    • FPGA
    • Digilent Microcontroller Boards
    • Non-Digilent Microcontrollers
    • Add-on Boards
    • Scopes & Instruments and the WaveForms software
    • LabVIEW
    • FRC
    • Other
  • General Discussion
    • Project Vault
    • Learn
    • Suggestions & Feedback
    • Buy, Sell, Trade
    • Sales Questions
    • Off Topic
    • Educators
    • Technical Based Off-Topic Discussions

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests

Found 7 results

  1. Hi. I have troubles using the trigger functions in the SDK to align the recording of a signal with the pattern generator (DigitalOut Instrument on AD2). What I want to do is essentially, using the SDK in a python script is: - I record a signal from the AWG on the AD2 I am sending through an analog circuit using two multiplexers. - I control the multiplexers with the digitalOut instrument on the AD2. - I want to align the starting point of the digitalOut-pattern and the starting point of the AnalogIn acquisition (record-mode, int16 data) As far as I understand from the SDK reference for this purpose I can trigger the analogIn with the digitalOut (use trigsrcDigitalOut from the dwf constants). However, when I implemented this, I get an undefined timelag between the acquistion of data and the start of the digitalOut signal. To illustrate this, I recorded the signal of one of the digital pins I use to generate the pattern for the multiplexers (I record the bare 16int ADC conversions, to read faster from the AD2). I sample at 1Mhz and the the pattern I output on this particular pin starts with (1,0,...) at 100Hz. As you can see, the timelag seems to be around ca. 1.5 ms. I also did another experiment, trying out the same thing in the WaveForms Software. Instead of outputting a custom pattern, I just output a clock at 100Hz on the same digital pin and record this signal through channel 1 of the oscilloscope. From what I understand, the two experiments should be pretty much equal, so I am puzzled I get this delay of approximately 1.5ms when I implement it with SDK functions. Does anyone have an explanation why the trigger is not correctly aligned in my python script, and why this timelag is not deterministic? Any help would be greatly appreciated! (PS: I can provide a code snippet, but right now my code is shared from different fies & classes, so it is not straightforward to copy it to here...) updated: I have a code snippet for illustration below: import math import sys import time from ctypes import * import matplotlib.pyplot as plt import numpy from dwfconstants 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") # declare ctype variables hdwf = c_int() sts = c_byte() hzAcq = c_double(1e6) nSamples = 2 ** 17 rgSamples = (c_int16 * nSamples)() cAvailable = c_int() cLost = c_int() cCorrupted = c_int() fLost = 0 fCorrupted = 0 # print(DWF version version = create_string_buffer(16) dwf.FDwfGetVersion(version) print("DWF Version: " + str(version.value)) # open device print("Opening first device") dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf)) if hdwf.value == hdwfNone.value: szerr = create_string_buffer(512) dwf.FDwfGetLastErrorMsg(szerr) print(str(szerr.value)) print("failed to open device") quit() ######################################################################################## # set up pattern generator data = [1, 0, 1, 0, 0, 1, 0, 0, 1] pin = 11 hzSys = c_double() dwf.FDwfDigitalOutInternalClockInfo(hdwf, byref(hzSys)) rgbdata = (c_ubyte * ((len(data) + 7) >> 3))(0) # array to bits in byte array for j in range(len(data)): if data[j] != 0: rgbdata[j >> 3] |= 1 << (j & 7) # var |= value is var = var | value print("bytestream of data " + str(pin) + ": " + str(list(rgbdata))) dwf.FDwfDigitalOutEnableSet(hdwf, c_int(pin), c_int(1)) dwf.FDwfDigitalOutTypeSet(hdwf, c_int(pin), DwfDigitalOutTypeCustom) dwf.FDwfDigitalOutIdleSet(hdwf, c_int(pin), DwfDigitalOutIdleLow) # set Divider to generate output at frequency f_scan. dwf.FDwfDigitalOutDividerSet(hdwf, c_int(pin), c_int(int(hzSys.value / 100))) dwf.FDwfDigitalOutDataSet(hdwf, c_int(pin), byref(rgbdata), c_int(len(data))) dwf.FDwfDigitalOutTriggerSourceSet(hdwf, trigsrcNone) # set up acquisition dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(0), c_bool(True)) dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(0), c_double(5)) dwf.FDwfAnalogInAcquisitionModeSet(hdwf, acqmodeRecord) dwf.FDwfAnalogInFrequencySet(hdwf, hzAcq) dwf.FDwfAnalogInRecordLengthSet( hdwf, c_double(nSamples / hzAcq.value) ) # -1 infinite record length dwf.FDwfAnalogInTriggerSourceSet(hdwf, trigsrcDigitalOut) # wait at least 2 seconds for the offset to stabilize time.sleep(2) print(f"Starting oscilloscope. Measure digitalout pin {pin}") dwf.FDwfAnalogInConfigure(hdwf, c_int(0), c_int(1)) # configure digitalOut instrument, don't run yet (enough time to fill buffer with data) dwf.FDwfDigitalOutConfigure(hdwf, c_int(0)) time.sleep(2) cSamples = 0 # start the digitalOut instrument dwf.FDwfDigitalOutConfigure(hdwf, c_int(1)) while cSamples < nSamples: dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts)) if cSamples == 0 and ( sts == DwfStateConfig or sts == DwfStatePrefill or sts == DwfStateArmed ): # Acquisition not yet started. continue dwf.FDwfAnalogInStatusRecord( hdwf, byref(cAvailable), byref(cLost), byref(cCorrupted) ) cSamples += cLost.value if cLost.value: fLost = 1 if cCorrupted.value: fCorrupted = 1 if cAvailable.value == 0: continue if cSamples + cAvailable.value > nSamples: cAvailable = c_int(nSamples - cSamples) dwf.FDwfAnalogInStatusData16( hdwf, c_int(0), byref(rgSamples, sizeof(c_int16) * cSamples), c_int(0), cAvailable, ) # get channel 1 data # dwf.FDwfAnalogInStatusData16(hdwf, c_int(1), byref(rgSamples, sizeof(c_int16)*cSamples), c_int(c), Available) # get channel 2 data cSamples += cAvailable.value dwf.FDwfAnalogOutReset(hdwf, c_int(0)) dwf.FDwfDeviceCloseAll() print("Recording done") if fLost: print("Samples were lost! Reduce frequency") if fCorrupted: print("Samples could be corrupted! Reduce frequency") f = open("record.csv", "w") for v in rgSamples: f.write("%s\n" % v) f.close() plt.plot(numpy.fromiter(rgSamples, dtype=numpy.int16)) plt.show()
  2. Hi, I'm recently working on the Waveforms SDK with the Analog Discovery 2. I manage to trigger my AnalogIn with the AnalogOut sinus that I generate. My aim is to acquire my sinus in order to calculate the phase shift. Is there a way to get the delay between the start of the AnalogOut generation and the trigger pulse attached to it ? Thank you. Here is the code that I'm using : FDwfAnalogOutNodeEnableSet(hdwf, 0, AnalogOutNodeCarrier, true); FDwfAnalogOutNodeFunctionSet(hdwf, 0, AnalogOutNodeCarrier, funcSine); FDwfAnalogOutNodeFrequencySet(hdwf, 0, AnalogOutNodeCarrier, 1000.0); FDwfAnalogOutNodeAmplitudeSet(hdwf, 0, AnalogOutNodeCarrier, 1); FDwfAnalogOutNodeOffsetSet(hdwf, 0, AnalogOutNodeCarrier, 1); FDwfAnalogOutRunSet(hdwf, 0, 2.0/1000.0); FDwfAnalogOutRepeatSet(hdwf,0,0); FDwfAnalogOutConfigure(hdwf, 0, true); FDwfAnalogInTriggerAutoTimeoutSet(hdwf, 0); FDwfAnalogInChannelRangeSet(hdwf, 0, 5); FDwfAnalogInBufferSizeSet(hdwf, 40); FDwfAnalogInFrequencySet(hdwf, 10000.0); FDwfAnalogInAcquisitionModeSet(hdwf, 0); FDwfAnalogInTriggerSourceSet(hdwf, trigsrcAnalogOut1); FDwfAnalogInTriggerTypeSet(hdwf, trigtypeTransition); FDwfAnalogInConfigure(hdwf, 0, true); while(true){ FDwfAnalogInStatus(hdwf, true, &sts); if(sts == DwfStateDone){ break; } } FDwfAnalogInStatusData(hdwf, 0, rgdSamples, 40); // This acquisition ins not starting at the offeset point but at the falling edge
  3. Hello, I have seen a lot of contradictory information online regarding the sampling frequency of the Analog Discovery 2 ADC channel. Is it possible to sample at around 30 MHz for 20s and store the data in a csv for example with a time stamp? Second Is it possible to run several processes on the board simultaneously such as: 1) 2x analog read and data storage 2) motor control 3) Waveform generator assumming I have enough cores on my computer to run there respective programs.
  4. Hi I am using analogIN record for acquisition of the signal. The problem I encountered is the fact that the acquired signal is randomly delayed in with repetition of the measurements. (see fig attached, where a same measurement is performed several time. Starting point always differ). Is there a particular reason for it and is there an elegant solution except the dirty one which compares delays of different measurements and performs the delay shift operation. Many thanks in advance. I used AnalogIn_Record.py from the example library and analog discovery 2. thanks & cheers, m
  5. I'm currently trying to synchronize analog pulses on both AWGs with digital pulses, and simultaneously run both analog scopes and the digital scope. I am trying to trigger all outputs and all scope acquisitions to happen simultaneously with a single PC-Trigger source using the SDK. First question: Why isn't there an AnalogInTriggerSlopeSet function? (You can set the TriggerSlope to rising edge for AnalogOut, DigitalOut, and DigitalIn). Without an AnalogInTriggerSlopeSet function, how do you set the AnalogInTrigger to respond to the same signal as the other three? Second Question: What prompts the change in Analog/DigitalInStatus from 'prefill' to 'armed' or 'done'? In the Acquisition code in the SDK, it looks like the status changes when the buffer fills? In my code below, why isn't it progressing to 2=Done to break out of the loop? It looks like it is getting stuck waiting for the trigger (which already happened). #digital pulse control setup self.dwf.FDwfDigitalOutEnableSet(hdwf, c_int(0), c_int(1)) # enable dIO pin 0 self.dwf.FDwfDigitalOutDividerSet(hdwf, c_int(0), c_int(int(hzSys.value/(100*self.qRate)))) # divider=internal clock/ (100counts*frequency) self.dwf.FDwfDigitalOutCounterSet(hdwf, c_int(0), c_int(100-self.qDuty), c_int(self.qDuty)) # set counts low, counts high from duty cycle print "configured digital output" # analog pulse control setup self.dwf.FDwfAnalogOutNodeEnableSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_int(True)) self.dwf.FDwfAnalogOutNodeEnableSet(hdwf, c_int(1), AnalogOutNodeCarrier, c_int(True)) # for second channel set master the first channel, slave channel is controlled by the master self.dwf.FDwfAnalogOutMasterSet(hdwf, c_int(1), c_int(0)); self.dwf.FDwfAnalogOutNodeFunctionSet(hdwf, c_int(-1), AnalogOutNodeCarrier, funcSquare) self.dwf.FDwfAnalogOutNodeFrequencySet(hdwf, c_int(-1), AnalogOutNodeCarrier, c_double(self.xRate)) self.dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, c_int(-1), AnalogOutNodeCarrier, c_double(0.5)) self.dwf.FDwfAnalogOutOffsetSet(hdwf, c_int(-1), c_double(0.5)) self.dwf.FDwfAnalogOutNodeSymmetrySet(hdwf, c_int(-1), AnalogOutNodeCarrier, c_double(symm)) #pulse width self.dwf.FDwfAnalogOutNodePhaseSet(hdwf, c_int(1), AnalogOutNodeCarrier, c_double(self.x2Phase)) #phase shift for second channel self.dwf.FDwfAnalogOutRunSet(hdwf, c_int(-1), c_double(self.xDuration)) #set run duration on all channels self.dwf.FDwfAnalogOutIdleSet(hdwf,c_int(-1), c_int(0)) print "configured analog output" #configure digital input scope self.dwf.FDwfDigitalInDividerSet(hdwf, c_int(int(hzSys.value/(100*self.xRate)))) #same sample rate as xray self.dwf.FDwfDigitalInSampleFormatSet(hdwf, c_int(16)) # 16bit per sample format cSamples = 1000 # set number of sample to acquire rgwSamples = (c_uint16*cSamples)() self.dwf.FDwfDigitalInBufferSizeSet(hdwf, c_int(cSamples)) print "configured digital input" #configure analog input scope self.dwf.FDwfAnalogInFrequencySet(hdwf, c_double(int(hzSys.value/(100*self.xRate)))) self.dwf.FDwfAnalogInBufferSizeSet(hdwf, c_int(1000)) self.dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(0), c_bool(True)) self.dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(0), c_double(5)) self.dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(1), c_bool(True)) self.dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(1), c_double(5)) rg1 = (c_double*1000)() #rg = pointer to allocated buffer to copy the acquisition data rg2 = (c_double*1000)() #rg = pointer to allocated buffer to copy the acquisition data print "configured analog input" #set up PC trigger to start pulse output AND acquisition self.dwf.FDwfAnalogOutTriggerSourceSet(hdwf, c_int(0), trigsrcPC) self.dwf.FDwfDigitalOutTriggerSourceSet(hdwf, trigsrcPC) self.dwf.FDwfAnalogOutTriggerSlopeSet(hdwf, c_int(0), c_int(0)) # set channel 1 to trigger on rising edge self.dwf.FDwfDigitalOutTriggerSlopeSet(hdwf, c_int(0)) self.dwf.FDwfDigitalInTriggerSourceSet(hdwf, trigsrcPC) self.dwf.FDwfDigitalInTriggerSlopeSet(hdwf, c_int(0)) #rising edge self.dwf.FDwfAnalogInTriggerSourceSet(hdwf, trigsrcPC) # self.dwf.FDwfAnalogInTriggerSlopeSet(hdwf,) #this command doesn't exist for analogin! print "set up triggers" #configure everything to wait for trigger self.dwf.FDwfAnalogOutConfigure(hdwf, c_int(0), c_bool(True)) # start master, slave will follow self.dwf.FDwfDigitalOutConfigure(hdwf, c_int(1)) self.dwf.FDwfDigitalInConfigure(hdwf, c_bool(0), c_bool(1)) self.dwf.FDwfAnalogInConfigure(hdwf, c_int(1), c_int(1)) # starts both analog in pins (hdwf, bool-reconfigure, bool-start) print "initialized pins" #send the trigger self.dwf.FDwfDeviceTriggerPC(hdwf) print "PC trigger pulse sent" #plot the things sts = c_int() while True: #data acquisition status should == 5 - filling buffer self.dwf.FDwfDigitalInStatus(hdwf, c_int(1), byref(sts)) sts1 = sts.value self.dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts)) print ("analog status = " + str(sts.value)) print ("digital status = " +str(sts1)) if sts.value == DwfStateDone.value : #status ==2 = done print "acquisition complete" break When I run this, this is my printout:
  6. I am sending synchronized, phase-shifted pulses with the AWG on both AnalogOut channels on the Discovery2, using a custom application I'm writing in python. I am feeding the AnalogOut directly back to the AnalogIn with no additional hardware involved. I am trying to read the two AWG signals using the AnalogIn channels, but I can't get Channel 2 to report the signal. Instead, both signals are adding together and displaying as coming from channel 1, with the expected channel 2 signal showing up as negative voltages on channel 1. How do I separate the two signals? This is the chunk of code I am using to record samples and plot (mostly copied from the provided code samples): #configure analog in self.dwf.FDwfAnalogInFrequencySet(hdwf, c_double(int(hzSys.value/(100*self.xRate)))) self.dwf.FDwfAnalogInBufferSizeSet(hdwf, c_int(4000)) self.dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(0), c_bool(True)) self.dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(0), c_double(5)) self.dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(1), c_bool(True)) self.dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(1), c_double(5)) #begin acquisition self.dwf.FDwfAnalogInConfigure(hdwf, c_int(1), c_int(1)) #collect data sts = c_int() while True: self.dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts)) if sts.value == DwfStateDone.value : break time.sleep(0.1) #read data rg1 = (c_double*1000)() #rg = pointer to allocated buffer to copy the acquisition data rg2 = (c_double*1000)() #rg = pointer to allocated buffer to copy the acquisition data self.dwf.FDwfAnalogInStatusData(hdwf, c_int(0), rg1, len(rg1)) # get channel 1 data self.dwf.FDwfAnalogInStatusData(hdwf, c_int(1), rg2, len(rg2)) # get channel 2 data #set up plot self.canvasX.figure.clear() plt1 = self.canvasX.figure.add_subplot(211) plt2 = self.canvasX.figure.add_subplot(212) #plot data rgpy1=[0.0]*len(rg1) rgpy2=[0.0]*len(rg2) for i in range(0,len(rgpy1)): rgpy1=rg1 rgpy2=rg2 plt1.plot(rgpy1, 'b') plt2.plot(rgpy2, 'r') self.canvasX.draw()
  7. Is there a way to execute "Defined Measurement" functions on an analog input stream from inside a custom Waveforms SDK program? I'm particularly interested in running a frequency measurement from my custom application (but ideally all of the factory defined measurement functions would be available). Judging by the SDK documentation, it seems that the only way to accomplish such a feat is to re-implement the calculation by hand such that it runs against an appropriate buffer of acquired samples. I don't want to duplicate this effort unless it's absolutely necessary. Even being able to see how these functions are implemented for the internal Waveforms functionality would be helpful if they can't be made available via the SDK API (apparently these implementations are kept secret; they are not visible in the measurement "Edit" window). UPDATE: I've established that the measurement functions are available from the Javascript API. Is it possible to boot a headless Waveforms and immediately execute a Waveforms "Script"? It doesn't seem to be possible execute a Waveforms "Script" from the normal Waveforms SDK; this would be really useful. But something along the lines of this would be great: /usr/bin/waveforms --run /path/to/MyCoolCustomScript.js where the script file is just a normal Waveforms "Script" like what you would run from the Script device.