hgriffin

Members
  • Content Count

    11
  • Joined

  • Last visited

Everything posted by hgriffin

  1. Hello, I have a python script to output a signal while recording from both input channels at the same time. I want to incorporate using a second analog discovery for two additional channels of data acquisition. From the device_enumerate.py, I see that both devices can be recognized in the same script, but how do I actually specify which device to record the data from? For example, here are some current (relevant) code snippets where I acquire data from both channels of one device. How would I specify the second device channels. ... "Opening first device..." dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf)) if hdwf.value == hdwfNone.value: print "failed to open device" quit() ... #set up acquisition dwf.FDwfAnalogInFrequencySet(hdwf, c_double(20000000.0)) dwf.FDwfAnalogInBufferSizeSet(hdwf, c_int(4096)) dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(0), c_bool(True)) dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(0), c_double(10)) dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(1), c_bool(True)) dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(1), c_double(10)) ... dwf.FDwfAnalogOutConfigure(hdwf, channel1, c_bool(True)) # starts the waveform while True: dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts)) if sts.value == DwfStateDone.value : break time.sleep(0.001) time.sleep(0.1) while (j < pulses + 1): try: print j dwf.FDwfAnalogOutConfigure(hdwf, channel1, c_bool(True)) # starts the waveform #begin acquisition while True: dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts)) if sts.value == DwfStateDone.value : break time.sleep(0.001) time.sleep(0.1) print "Acquisition finished" dwf.FDwfAnalogInStatusData(hdwf, 0, rgdSamples1, 4096) # get channel 1 data dwf.FDwfAnalogInStatusData(hdwf, 1, rgdSamples2, 4096) # get channel 2 data Any help or example code would be greatly appreciated! Cheers! Harry
  2. Hello, I was looking at the AnalogIn_Acquisition.py example. This is a good base for what I want. The goal is to iterate through a list, and average the output (rgpy in example) at each iteration, and store this in a list. However, I when I try nesting the functions inside lists, it doesn't appear to be reacquiring data. How do the AnalogInConfigure and Status work, and how could I acquire data in a loop? Thanks! for ii in range(0,5): #set up acquisition dwf.FDwfAnalogInFrequencySet(hdwf, c_double(20000000.0)) dwf.FDwfAnalogInBufferSizeSet(hdwf, c_int(4000)) dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(0), c_bool(True)) dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(0), c_double(5)) #wait at least 2 seconds for the offset to stabilize time.sleep(2) #begin acquisition dwf.FDwfAnalogInConfigure(hdwf, c_bool(False), c_bool(True)) print " waiting to finish" while True: dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts)) print "STS VAL: " + str(sts.value) + "STS DONE: " + str(DwfStateDone.value) if sts.value == DwfStateDone.value : break time.sleep(0.1) print "Acquisition finished" dwf.FDwfAnalogInStatusData(hdwf, 0, rgdSamples, 4000) # get channel 1 data #dwf.FDwfAnalogInStatusData(hdwf, 1, rgdSamples, 4000) # get channel 2 data dwf.FDwfDeviceCloseAll() #plot window dc = sum(rgdSamples)/len(rgdSamples) print "DC: "+str(dc)+"V" rgpy=[0.0]*len(rgdSamples) for i in range(0,len(rgpy)): rgpy[i]=rgdSamples[i] rg_slice = rgpy buffer = len(rg_slice) / 4 del rg_slice[buffer*4 - buffer:buffer*4] del rg_slice[0:buffer] voltage = sum(rg_slice) / len(rg_slice) print voltage
  3. Hi atilla, it turns out my scope wasn't sensitive enough to see the quick pulses. It looks like it is working okay now though! Is there any way to use the scope feature of the Analog Discovery while controlling it via python. Based on what I've seen you can only interface with it one way at a time, but I was wondering if there are any work arounds to use the GUI scope feature while running python scripts? Thanks for all the help and timely responses.
  4. I want to iterate through this single pulse, so I have tried various loops. However, I can't generate anything after the initial pulse. Does the device have to be opened and closed between each? I've tried looping the whole set up, and just the configure function, but no luck. Any suggestions? for j in range(1,4): #Setting up the parameters for waveform print "Generating custom waveform..." dwf.FDwfAnalogOutNodeEnableSet(hdwf, channel, AnalogOutNodeCarrier, c_bool(True)) dwf.FDwfAnalogOutNodeFunctionSet(hdwf, channel, AnalogOutNodeCarrier, funcCustom) #Define custom waveform; funcCustom dwf.FDwfAnalogOutNodeDataSet(hdwf, channel, AnalogOutNodeCarrier, rgdSamples, c_int(cSamples)) dwf.FDwfAnalogOutNodeFrequencySet(hdwf, channel, AnalogOutNodeCarrier, c_double(hzFreq)) #Set frequency attribute in Hz dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, channel, AnalogOutNodeCarrier, c_double(4.0)) #Set amplitude attribute in Volts dwf.FDwfAnalogOutRunSet(hdwf, channel, c_double(1.0/hzFreq)) # run for 1 periods dwf.FDwfAnalogOutWaitSet(hdwf, channel, c_double(1.0/hzFreq)) # wait one pulse time dwf.FDwfAnalogOutRepeatSet(hdwf, channel, c_int(1)) # repeat 1 times print 'Generating pulse in:' for k in range(1, 4): print 4-k time.sleep(k) print 'pulse no. ' + str(j) dwf.FDwfAnalogOutConfigure(hdwf, channel, c_bool(True)) time.sleep(1) print "done." dwf.FDwfDeviceCloseAll()
  5. Hi Attila, this works perfectly! Exactly what I was looking for. One quick question, in the FunctionSet function, where/how do we define "funcCustom" ? This sawtooth is what I want, but just so I know for future reference. Thanks so much! Harry
  6. Follow up, running the AnalogOut_Custom.py I am not able to see any waveforms. I see the voltage spikes when the device is initialized, but nothing else. Thanks so much for quick and helpful responses!
  7. Thanks for the information, and no problem. I keep getting this asymptotic increase to the offset voltage, as shown in the image in the above post. Even if I change the function, and try Sine, I get the identical behavior. Any thoughts on why this is happening? If I change the offsets to 0, then I don't seem to get any signal. Thanks!
  8. Hello, thanks for the response! I finally seem to be getting some signal. The waiting time seems to work. However, it isn't the ramp I'm expecting. I have a couple of further questions though. I actually don't want an offset. I want the starting voltage to be 0V, ramp up to 1V, then drop back down to 0V. It's easy enough to change the offset in the FDwfAnalogOutNodeOffsetSet function, but I was wondering how the function FDwfAnalogOutIdleSet works, and how it would change if I change the offset or amplitude? Also, to get it to go back to 0 V after the ramp, we could perhaps run to periods, but I don't see any change in behavior when I change the FDwfAnalogOutRunSet. Here is my current code: #defining parameters for wave dwf.FDwfAnalogOutNodeFunctionSet(hdwf, channel, AnalogOutNodeCarrier, funcRampUp) dwf.FDwfAnalogOutNodeSymmetrySet(hdwf, channel, AnalogOutNodeCarrier, c_double(100.0)) # 100% sawtooth dwf.FDwfAnalogOutNodeFrequencySet(hdwf, channel, AnalogOutNodeCarrier, c_double(50000.0)) dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, channel, AnalogOutNodeCarrier, c_double(1.0)) dwf.FDwfAnalogOutNodeOffsetSet(hdwf, channel, AnalogOutNodeCarrier, c_double(1)) dwf.FDwfAnalogOutIdleSet(hdwf, channel, c_int(2)) # 2 = DwfAnalogOutIdleInitial, 1V offset - 1V of ramp amplitude = 0V dwf.FDwfAnalogOutRunSet(hdwf, channel, AnalogOutNodeCarrier, c_double(1/50000.0)) # for 2 pulses set 2/frequency # this will run once: dwf.FDwfAnalogOutRepeatSet(hdwf, channel, AnalogOutNodeCarrier, c_int(1)) # repeat once dwf.FDwfAnalogOutConfigure(hdwf, channel, c_bool(True)) print 'closing...' for i in range(1, 4): print i time.sleep(1) dwf.FDwfDeviceClose(hdwf) Thanks so much for the timely responses, this is helping a lot!
  9. Hi Attila! Thanks for such a quick response! This is the code I am running right now. Trying to get one pulse. from ctypes import * import time from dwfconstants import * 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") #declare ctype variables hdwf = c_int() channel = c_int(0) #print DWF version version = create_string_buffer(16) dwf.FDwfGetVersion(version) print "DWF Version: "+version.value #open device print "Opening first device..." dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf)) if hdwf.value == hdwfNone.value: print "failed to open device" quit() dwf.FDwfAnalogOutNodeFunctionSet(hdwf, channel, AnalogOutNodeCarrier, funcRampUp) #dwf.FDwfAnalogOutNodeSymmetrySet(hdwf, channel, c_double(100.0) # 100% sawtooth dwf.FDwfAnalogOutNodeFrequencySet(hdwf, channel, AnalogOutNodeCarrier, c_double(50000.0)) dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, channel, AnalogOutNodeCarrier, c_double(1.0)) dwf.FDwfAnalogOutNodeOffsetSet(hdwf, channel, AnalogOutNodeCarrier, c_double(1.0)) dwf.FDwfAnalogOutIdleSet(hdwf, channel, c_int(2)) # 2 = DwfAnalogOutIdleInitial, 1V offset - 1V of ramp amplitude = 0V dwf.FDwfAnalogOutRunSet(hdwf, channel, AnalogOutNodeCarrier, c_double(1.0/50000.0)) # for 2 pulses set 2/frequency # this will run once: dwf.FDwfAnalogOutRepeatSet(hdwf, channel, AnalogOutNodeCarrier, c_int(1)) # repeat once dwf.FDwfDeviceClose(hdwf) Firstly, the FDwfAnalogOutNodeSymmetrySet throws a syntax error, unsure why. Also the pulse seems strange. Attached is an image from the oscilloscope I'm using to monitor it. Any thoughts? Cheers, Harry
  10. Hi! My goal is to use the Analog Digital 2 in order to move a piezoelectric via stick slip motion. I want to program this into a python script so that I can move the stage one step, record data for x amount of time, move the stage one step, record data, etc. In order to do this, I want to output a specific number of sawtooth wave periods (one to two) at a certain frequency. From these posts (https://forum.digilentinc.com/topic/4084-analog-discovery-2-waveform-generator/ , https://forum.digilentinc.com/topic/2609-how-to-create-one-pulse-via-sdk/#comment-9014), I have figured out how to do this through the GUI. I have also followed the example scripts and can output standing wave forms, just not pulses. So now, I am looking for some guidance in putting these together. Can you give me some suggestions, advice, or code snippets that might allow me to accomplish this? Are there any functions in the dwf module that might work? Any help is welcome and appreciated! Thanks, Harry digilentScreenCap