Jump to content

Thomas Lee

Members
  • Posts

    9
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Thomas Lee's Achievements

Newbie

Newbie (1/4)

0

Reputation

  1. Thanks Attila! I understood that the modes I am using for analog out and digital out do not capture high buffer size. I am wondering how could I know how much buffer storage I used for analog out or digital out in my selected mode (sinewave mode for analog out and counter mode for digital out)? For example, would that be OK if I increase the analog out time from 4 ms to 12 ms? Would that be OK if I double the time periods for digital out counter set? Also I am wondering which command would you recommend using to set the total runtime for the digital out counter? I also have a new purchased AD3, it is good to know AD3 has improved buffer size, I am wondering how could we adjust the buffer size for each section with commands? Best regards, Thomas
  2. Hi, I am using the analog out and digital out functions with the following settings: hzAcq=C_double(5e6) freq=180 impulsetime=4 ringdowntime=2 Analog out: dwf.FDwfAnalogOutTriggerSourceSet(hdwf,c_int(0),c_int(12)) dwf.FDwfAnalogOutNodeEnableSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_bool(True)) dwf.FDwfAnalogOutNodeFunctionSet(hdwf, c_int(0), AnalogOutNodeCarrier, funcSine) dwf.FDwfAnalogOutNodeFrequencySet(hdwf, c_int(0), AnalogOutNodeCarrier, c_double((freq/10.000)*hzAcq.value/500.000)) dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_double(excitation)) dwf.FDwfAnalogOutRunSet(hdwf,c_int(0), c_double((4/0.00002)/(hzAcq.value*10))) # run for 4 ms dwf.FDwfAnalogOutRepeatSet(hdwf, c_int(0), c_int(1)) Digital out pattern generator: dwf.FDwfDigitalOutDividerSet(hdwf, c_int(0), c_int(20)) dwf.FDwfDigitalOutDividerSet(hdwf, c_int(1), c_int(20)) dwf.FDwfDigitalOutDividerSet(hdwf, c_int(2), c_int(20)) dwf.FDwfDigitalOutDividerSet(hdwf, c_int(3), c_int(20)) dwf.FDwfDigitalOutCounterInitSet(hdwf, c_int(0), c_uint(0), c_uint(1)) dwf.FDwfDigitalOutCounterInitSet(hdwf, c_int(1), c_uint(1), c_uint(1)) dwf.FDwfDigitalOutCounterInitSet(hdwf, c_int(2), c_uint(0), c_uint(1)) dwf.FDwfDigitalOutCounterInitSet(hdwf, c_int(3), c_uint(1), c_uint(1)) dwf.FDwfDigitalOutEnableSet(hdwf, c_int(0), c_int(1)) dwf.FDwfDigitalOutCounterSet(hdwf, c_int(0), c_uint(int(ringdownTime*5000+650)), c_uint(int(impulseTime*5000+150))) dwf.FDwfDigitalOutEnableSet(hdwf, c_int(1), c_int(1)) dwf.FDwfDigitalOutCounterSet(hdwf, c_int(1), c_uint(int(impulseTime*5000+50)), c_uint(int(ringdownTime*5000+750))) dwf.FDwfDigitalOutEnableSet(hdwf, c_int(2), c_int(1)) dwf.FDwfDigitalOutCounterSet(hdwf, c_int(2), c_uint(int(impulseTime*5000+1050)), c_uint(int(ringdownTime*5000-250))) dwf.FDwfDigitalOutEnableSet(hdwf, c_int(3), c_int(1)) dwf.FDwfDigitalOutCounterSet(hdwf, c_int(3), c_uint(int(impulseTime*5000+100)), c_uint(int(ringdownTime*5000+700))) I used the default buffer size setting which is 4K for analog out and 1K for digital out. Since my analog out setting is 5 MHz sample frequency and run for 4 ms, the captured buffer size is 20 K which already exceeded the buffer size, however, the system seems still working in set time duration. For the digital out, I used 20 as divider and digitaloutcounterset to define the pattern, which would capture 30800 bits (impulseTime*5000+100+ringdownTime*5000+700) for one cycle, this seems also exceeded the 1K limit but still work. I am wondering is my calculation wrong or the setting I used does not require that much buffer size? Best regards, Thomas
  3. Hi, As the analog discover 2&3 is compatible with raspberry pi 3&4, I am wondering is that able to communicate with raspberry pi wirelessly utilizing a Bluetooth adaptor connected to the analog discover device through usb? Best regards, Thomas
  4. Hi, I am developing a system including the wavegen, digital out triggers and oscilloscope based on the analog discover 2 and programmed with the SDK python. The codes are shown as attached, currently the codes works well but I have three questions: 1. nSamples = int(8192), the datasheet shows the maximum record length is 16 k, however, when I increase the nSample to any value over 8192, the records went wrong. Since there are two analogIn channels, is that means the maximum record length for each channel is 8 k? 2. The time.sleep =3s issue, the python examples say the oscilloscope need 2 s to stabilize, I am wondering what is the minimum time interval between each time AnalogIn oscilloscope sampling? Since my application requires 500 times oscilloscope capture, decreasing the time interval helps a lot. 3. Currently I used one AnalogIn channel, and I am trying to use two AnalogIn channels and each channel triggered with rising edge of different digital out signal. However, I found that it seems like the two channels are triggered with only the first detected rising edge of the two trigger signals. I am wondering is there any solution to apply the two seperate triggers for the two oscillisope channels? Thanks! Zeyu hdwf = c_int() sts = c_byte() hzAcq = c_double(5e6) nSamples = int(8192) 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 for j in range(1,50, 1): print("Opening first device") dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf)) rgSamples1 = (c_int16*nSamples)() if hdwf.value == hdwfNone.value: szerr = create_string_buffer(512) dwf.FDwfGetLastErrorMsg(szerr) print(str(szerr.value)) print("failed to open device") quit() print("Generating sine wave...") # dwf.FDwfDigitalOutTriggerSourceSet(hdwf,c_int(0), c_int(8)) # dwf.FDwfDigitalOutTriggerSourceSet(hdwf,c_int(1), c_int(8)) dwf.FDwfDigitalOutDividerSet(hdwf, c_int(0), c_int(20)) dwf.FDwfDigitalOutDividerSet(hdwf, c_int(1), c_int(20)) dwf.FDwfDigitalOutDividerSet(hdwf, c_int(2), c_int(20)) dwf.FDwfDigitalOutDividerSet(hdwf, c_int(3), c_int(20)) # dwf.FDwfDigitalOutDividerSet(hdwf, c_int(4), c_int(20)) dwf.FDwfDigitalOutCounterInitSet(hdwf, c_int(0), c_uint(0), c_uint(1)) dwf.FDwfDigitalOutCounterInitSet(hdwf, c_int(1), c_uint(1), c_uint(1)) dwf.FDwfDigitalOutCounterInitSet(hdwf, c_int(2), c_uint(0), c_uint(1)) dwf.FDwfDigitalOutCounterInitSet(hdwf, c_int(3), c_uint(1), c_uint(1)) # dwf.FDwfDigitalOutCounterInitSet(hdwf, c_int(4), c_uint(1), c_uint(1)) dwf.FDwfDigitalOutEnableSet(hdwf, c_int(0), c_int(1)) # dwf.FDwfDigitalOutRunSet(hdwf, c_double(0.00005)) # 1ms run # dwf.FDwfDigitalOutWaitSet(hdwf, c_double(0)) # 1ms run # dwf.FDwfDigitalOutRepeatSet(hdwf, c_int(3)) dwf.FDwfDigitalOutCounterSet(hdwf, c_int(0), c_uint(4150), c_uint(27150)) # 100MHz base freq /(30+30) = 1.67 MHz dwf.FDwfDigitalOutEnableSet(hdwf, c_int(1), c_int(1)) dwf.FDwfDigitalOutCounterSet(hdwf, c_int(1), c_uint(27050), c_uint(4250)) # 100MHz base freq /(30+30) = 1.67 MHz # dwf.FDwfDigitalOutRunSet(hdwf, c_double(0.00005)) # 1ms run # dwf.FDwfDigitalOutWaitSet(hdwf, c_double(0)) # 1ms run # dwf.FDwfDigitalOutRepeatSet(hdwf, c_int(3)) # once dwf.FDwfDigitalOutEnableSet(hdwf, c_int(2), c_int(1)) dwf.FDwfDigitalOutCounterSet(hdwf, c_int(2), c_uint(28350), c_uint(2950)) dwf.FDwfDigitalOutEnableSet(hdwf, c_int(3), c_int(1)) dwf.FDwfDigitalOutCounterSet(hdwf, c_int(3), c_uint(27300), c_uint(4000)) # dwf.FDwfDigitalOutEnableSet(hdwf, c_int(4), c_int(1)) # dwf.FDwfDigitalOutCounterSet(hdwf, c_int(4), c_uint(27300), c_uint(4000)) dwf.FDwfAnalogOutTriggerSourceSet(hdwf,c_int(0),c_int(12)) # dwf.FDwfAnalogOutTriggerSlopeSet(hdwf,c_int(0), DwfTriggerSlopeRise) # dwf.FDwfAnalogInTriggerChannelSet(hdwf, 1) # 1st channel # dwf.FDwfAnalogOutTriggerLevelSet(hdwf, c_double(0.5)) # 0.5V dwf.FDwfAnalogOutNodeEnableSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_bool(True)) dwf.FDwfAnalogOutNodeFunctionSet(hdwf, c_int(0), AnalogOutNodeCarrier, funcSine) dwf.FDwfAnalogOutNodeFrequencySet(hdwf, c_int(0), AnalogOutNodeCarrier, c_double((16.8+j/50.000)*hzAcq.value/500.000)) dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_double(5)) dwf.FDwfAnalogOutRunSet(hdwf,c_int(0), c_double(270000/(hzAcq.value*10))) # run for 2 periods # dwf.FDwfAnalogOutWaitSet(hdwf, c_int(0), c_double(10000/hzAcq.value)) # wait one pulse time dwf.FDwfAnalogOutRepeatSet(hdwf, c_int(0), c_int(1)) # repeat 5 times 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 lengt dwf.FDwfAnalogInTriggerAutoTimeoutSet(hdwf, c_double(0)) #disable auto trigger dwf.FDwfAnalogInTriggerSourceSet(hdwf, 11) # dwf.FDwfAnalogInTriggerSourceSet(hdwf, 2) #one of the analog in channels dwf.FDwfAnalogInTriggerTypeSet(hdwf, trigtypeEdge) # dwf.FDwfAnalogInTriggerChannelSet(hdwf, 1) # 1st channel dwf.FDwfAnalogInTriggerLevelSet(hdwf, c_double(0.5)) # 0.5V # dwf.FDwfAnalogInTriggerHysteresisSet(hdwf, c_double(0.5)) dwf.FDwfAnalogInTriggerConditionSet(hdwf, trigcondRisingPositive) # dwf.FDwfAnalogInTriggerConditionSet(hdwf, trigcondFallingNegative) # dwf.FDwfAnalogInTriggerAutoTimeoutSet(hdwf, c_double(0)) #disable auto trigger dwf.FDwfAnalogInTriggerHoldOffSet(hdwf, c_double(0)) # dwf.FDwfAnalogInTriggerChannelInfo(hdwf, c_int(1), c_int(3)) print("Starting oscilloscope") dwf.FDwfAnalogInConfigure(hdwf, c_bool(False), c_bool(True)) dwf.FDwfAnalogOutConfigure(hdwf, c_int(0), c_bool(True)) dwf.FDwfDigitalOutConfigure(hdwf, c_int(1)) time.sleep(3) iSample = 0 while True: dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts)) dwf.FDwfAnalogInStatusRecord(hdwf, byref(cAvailable), byref(cLost), byref(cCorrupted)) iSample += cLost.value iSample %= nSamples if cLost.value : fLost = 1 if cCorrupted.value : fCorrupted = 1 iBuffer = 0 #wait at least 2 sec while cAvailable.value>0: cSamples = cAvailable.value # we are using circular sample buffer, make sure to not overflow if iSample+cAvailable.value > nSamples: cSamples = nSamples-iSample dwf.FDwfAnalogInStatusData16(hdwf, c_int(0), byref(rgSamples1, sizeof(c_int16)*iSample), c_int(iBuffer), c_int(cSamples)) # get channel 1 dat # dwf.FDwfAnalogInStatusData16(hdwf, c_int(1), byref(rgSamples2, sizeof(c_int16)*iSample), c_int(iBuffer), c_int(cSamples)) # get channel 2 dat iBuffer += cSamples cAvailable.value -= cSamples iSample += cSamples iSample %= nSamples if sts.value == DwfStateDone.value : # done break dwf.FDwfAnalogOutReset(hdwf, c_int(0)) dwf.FDwfDigitalOutReset(hdwf) dwf.FDwfDeviceCloseAll() # align recorded data if iSample != 0: rgSamples1 = rgSamples1[iSample:]+rgSamples1[:iSample] print("Recording done "+str(iSample)) if fLost: print("Samples were lost! Reduce frequency") if fCorrupted: print("Samples could be corrupted! Reduce frequency") List = [(16.8+j/50.000)*hzAcq.value/500.000] for v in rgSamples1: List.append(v) with open("liqtest2075m.csv", "a") as f_object: writer_object = writer(f_object) writer_object.writerow(List) f_object.close() AnalogIn_Record_Trigger_int16_si5m.py
  5. Hi Attila, I have tried with 1.5 V trigger but the system still can not recognize the trigger signal. I am wondering if it is possible to set up a meeting with you to see my setup? If we do the trigger with AD2 DIO, my project requires 2 square signals which have 20 us high time, 30 us low time and 15 us offset between each other. I am wondering if it is possible to generate the two signals like that. Best regards, zeyu
  6. Thanks for your reply, this method works well. In my project, I am using a square wave generated by raspberry pi as trigger signal and it is connected to the AnalogIn channel 2. The trigger signal still can not work with the updated codes. I am not sure what is wrong. A possible solution would be generate the square wave with the Analog Discovery wavegenerator. I am wondering whether we can generate 10 kHz suare wave with the analog discover2 and use this signal as trigger? Best regards, Zeyu
  7. Thanks for your reply, just wondering how did u set the trigger signal for this example? In the modified script, the trigger signal is set to be C2 which is also the sampled signal. May I know how to use the signal connected to another analog in channel to trigger the scope for the other channel?
  8. Hi Attila, Thanks for your reply. I have set the dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts)) to 1, however the system still cannot readout the trigger signal in AnalogIn (Channel 2). Do u have any suggestion? I just wondering whether any further setting for Analogin (Channel 2) is required (currently all the analogin settings are for channel 1). Best regards, Zeyu
  9. Hi, I am using Raspberry Pi 4 and Analog discovery 2 to building a sampling system. The trigger signal is generated by the raspberry pi and routed to the second analog input channel. The trigger signal has a voltage of 4 V and the trigger mode is set as Positive edge. From the lab oscilloscope, the trigger signal is observed while it is not read out by the analogIn channel of the Analog discovery 2 oscilloscope (it shows that the system stopped at Reading analog in status) . I am wondering whether there is anything wrong with my codes (shown as attached codes, especially in the trigger setting part), hope to have your advice. Best regards, Zeyu from time import sleep import RPi.GPIO as GPIO import signal from ctypes import * from dwfconstants import * import math import time import matplotlib.pyplot as plt import sys import numpy from csv import writer import pandas as pd 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(1e8) nSamples = int(1e4) 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 for j in range(1, 3, 1): print("Opening first device") dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf)) rgSamples1 = (c_int16*nSamples)() if hdwf.value == hdwfNone.value: szerr = create_string_buffer(512) dwf.FDwfGetLastErrorMsg(szerr) print(str(szerr.value)) print("failed to open device") quit() print("Generating sine wave...") dwf.FDwfAnalogOutNodeEnableSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_bool(True)) dwf.FDwfAnalogOutNodeFunctionSet(hdwf, c_int(0), AnalogOutNodeCarrier, funcSine) dwf.FDwfAnalogOutNodeFrequencySet(hdwf, c_int(0), AnalogOutNodeCarrier, c_double((90.0+j)*hzAcq.value/nSamples)) dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_double(5)) dwf.FDwfAnalogOutConfigure(hdwf, c_int(0), c_bool(True)) #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 def lopper(): for i in range(1,300): GPIO.output(7,0) sleep(0.001) GPIO.output(8,1) sleep(0.001) GPIO.output(8,0) GPIO.output(7,1) sleep(0.001) GPIO.output(7,0) GPIO.setmode(GPIO.BCM) GPIO.setup(7,GPIO.OUT) GPIO.setup(8,GPIO.OUT) lopper() dwf.FDwfAnalogInTriggerAutoTimeoutSet(hdwf, c_double(0)) #disable auto trigger dwf.FDwfAnalogInTriggerSourceSet(hdwf, trigsrcDetectorAnalogIn) #one of the analog in channels dwf.FDwfAnalogInTriggerTypeSet(hdwf, trigtypeEdge) dwf.FDwfAnalogInTriggerChannelSet(hdwf, 1) # first channel dwf.FDwfAnalogInTriggerLevelSet(hdwf, c_double(3.5)) # 0.5V dwf.FDwfAnalogInTriggerConditionSet(hdwf, trigcondRisingPositive) # dwf.FDwfAnalogInTriggerHoldOffSet(hdwf, c_double(0.01)) GPIO.cleanup() print("Starting dwf.FDwfAnalogInConfigure(hdwf, c_bool(False), c_bool(True)) dwf.FDwfAnalogOutConfigure(hdwf, c_int(0), c_bool(True)) dwf.FDwfAnalogOutReset(hdwf, c_int(0)) iSample = 0 while True: dwf.FDwfAnalogInStatus(hdwf, c_int(0), byref(sts)) dwf.FDwfAnalogInStatusRecord(hdwf, byref(cAvailable), byref(cLost), byref(cCorrupted)) iSample += cLost.value iSample %= nSamples if cLost.value : fLost = 1 if cCorrupted.value : fCorrupted = 1 iBuffer = 0 #wait at least 2 sec while cAvailable.value>0: cSamples = cAvailable.value # we are using circular sample buffer, make sure to not overflow if iSample+cAvailable.value > nSamples: cSamples = nSamples-iSample dwf.FDwfAnalogInStatusData16(hdwf, c_int(0), byref(rgSamples1, sizeof(c_int16)*iSample), c_int(iBuffer), c_int(cSamples)) # get channel 1 dat iBuffer += cSamples cAvailable.value -= cSamples iSample += cSamples iSample %= nSamples if sts.value == DwfStateDone.value : # done break dwf.FDwfDeviceCloseAll() if iSample != 0 : rgSamples1 = rgSamples1[iSample:]+rgSamples1[:iSample] print("Recording done "+str(iSample)) if fLost: print("Samples were lost! Reduce frequency") if fCorrupted: print("Samples could be corrupted! Reduce frequency") List = [] for v in rgSamples1: List.append(v) with open("record5.csv", "a") as f_object: writer_object = writer(f_object) writer_object.writerow(List) f_object.close() plt.plot(numpy.fromiter(rgSamples1, dtype = numpy.int16)) plt.show() file=open("record6.csv","w") df=pd.read_csv("record5.csv",header=None, low_memory=False) data=df.values data=list(map(list,zip(*data))) data=pd.DataFrame(data) data.to_csv(file,header=0,index=0) text = open("record6.csv", "r") text = ' '.join([i for i in text]) text = text.replace(",", " ") file = open('read.txt', 'w') file.write(text) file.close()
×
×
  • Create New...