Jump to content

abadialali

Members
  • Posts

    3
  • Joined

  • Last visited

Everything posted by abadialali

  1. Thanks a lot for your quick reply. What I am interested in doing is letting the Analog In wait for the first generated sample from the Analog Out then start recording, but I am not able to get it to do that even with what you mentioned, I know it works for normal Analog In read but it doesn't seem to work for analog record for some reason and I always lose some values depending on the sampling rate I am operating at.
  2. Thanks! it is working great now, but I still don't seem to be able to trigger the Analog in with the Analog out. Does the trigger work for record or not? I am using the following code portion: dwf.FDwfAnalogInTriggerSourceSet(hdwf, trigsrcAnalogOut1) dwf.FDwfAnalogInTriggerAutoTimeoutSet(hdwf, c_double(10.0)) dwf.FDwfAnalogInTriggerTypeSet(hdwf, trigtypeTransition) dwf.FDwfAnalogInTriggerLevelSet(hdwf,c_double(0.0)) dwf.FDwfAnalogInTriggerConditionSet(hdwf, trigcondRisingPositive) It seems like the Scope always work before the wavegen and it records few samples that causes some phase shift between my generated values and read ones.
  3. Hi Guys, I am using the Analog discovery 2 board and I want to generate a custom signal with a sampling of 100 Hz. I have modified the record code provided in the SDK and it is working perfectly , but code isn't working with sampling frequencies (hzAcq) lower than 1 kHz, it simply doesn't go into acquisition and doesn't give anything. Could you pelase let me know what is the issue. Below is the code: #declare ctype variables hdwf = c_int() sts = c_byte() hzAcq =c_double(1000) #sampling freq nSamples = 4096 rgdSamples = (c_double*nSamples)() cAvailable = c_int() cLost = c_int() cCorrupted = c_int() fLost = 0 fCorrupted = 0 fs = hzAcq.value fl = 100 fu = 1000 N = nSamples t = np.linspace(0,N-1,N)/fs freqmod = np.linspace(fl,fu,N) signal = np.sin( 2*np.pi*(t)) X = signal # samples between -1 and +1 for i in range(0,len(rgdSamples)): rgdSamples[i] =float(X[i]) #open 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() # enable wavegen channel 1, set the waveform to sine, set the frequency to 1 Hz, the amplitude to 2v and start the wavegen dwf.FDwfAnalogOutNodeEnableSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_bool(True)) # dwf.FDwfAnalogOutNodeFunctionSet(hdwf, c_int(0), AnalogOutNodeCarrier, funcSine) dwf.FDwfAnalogOutNodeFunctionSet(hdwf, c_int(0), AnalogOutNodeCarrier, funcCustom) dwf.FDwfAnalogOutNodeDataSet(hdwf, c_int(0), AnalogOutNodeCarrier, rgdSamples, c_int(nSamples)) dwf.FDwfAnalogOutNodeFrequencySet(hdwf, c_int(0), AnalogOutNodeCarrier, c_double(hzAcq.value/nSamples)) dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_double(1)) # enable scope channel 1, set the input range to 5v, set acquisition mode to record, set the sample frequency to 100kHz and set the record length to 2 seconds 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 #wait at least 2 seconds for the offset to stabilize time.sleep(2) print("Starting oscilloscope") dwf.FDwfAnalogInConfigure(hdwf, c_int(0), c_int(1)) dwf.FDwfAnalogOutConfigure(hdwf, c_int(0), c_bool(True)) cSamples = 0 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 # get the number of samples available, lost & corrupted dwf.FDwfAnalogInStatusRecord(hdwf, byref(cAvailable), byref(cLost), byref(cCorrupted)) cSamples += cLost.value # set the lost & corrupted flags if cLost.value : fLost = 1 if cCorrupted.value : fCorrupted = 1 # skip reading samples if there aren't any if cAvailable.value==0 : print ("No Values") continue # cap the available samples if the buffer would overflow from what's really available if cSamples+cAvailable.value > nSamples : cAvailable = c_int(nSamples-cSamples) # Read channel 1's available samples into the buffer dwf.FDwfAnalogInStatusData(hdwf, c_int(0), byref(rgdSamples, sizeof(c_double)*cSamples), cAvailable) # get channel 1 data cSamples += cAvailable.value # reset wavegen to stop it, close the device dwf.FDwfAnalogOutReset(hdwf, c_int(0)) dwf.FDwfDeviceCloseAll() # generate a graph image from the samples, and store it in a bytes buffer # plt.plot(np.fromiter(rgdSamples, dtype = np.float)) # bio = BytesIO() # plt.savefig(bio, format="png") plot(t,X,np.fromiter(rgdSamples, dtype = np.float))
×
×
  • Create New...