Jump to content

UwerusCodus

Members
  • Posts

    3
  • Joined

  • Last visited

UwerusCodus's Achievements

Newbie

Newbie (1/4)

0

Reputation

  1. Ahhhh, this clears up the darkness by a lot, so the Analog in buffer is not as I thought before 16k per Channel, its more that the device has a shared memory, that gets allocated to the different instruments by the configuration you open it with. I figured the probelm was that I used PIN6 for both, MISO of SPI and as a Trigger, as the PLL gives back both on this pin. I couldn`t solve it with the FDwfDigitalInReset() function either. I first did all the SPI, then called dwf.FDwfDigitalInReset(hdwf) and then did the DigitalOUT Pin setup and the Tripper setup, but didn`t work... Guess I'll have to clone the signals on the hardware and use 2 different DIOs to get everything to work. Thanks again for the help! PS: The Config stuff would be nice to put in either the SDK or the manual, best both:) Greetings from germany, UwerusCodus!
  2. Hello @attila, thanks a lot for the answers. I got the code running already and figured out the dwf.FDwfDigitalInConfigure(...) myself late that night, although afterwards it was kind ob obvious. In order to get my final code running, I tested the basic modules (1. Setting some DIO pins for amplifiers/mux on the custom PCB, 2. Sending some SPI messages to configre the PLL on the custom PCB and 3. the code from above to trigger of the digital pin and log Ch1 and Ch2.) by themself, successfully. Hint: I know about the external trigger but by design I HAVE TO use DIO6 as the Trigger for the Analog Scope. Combining these 3 individual codes I faced a problem I could not solve by now: I most likely reduced the problem to be the: dwf.FDwfDeviceConfigOpen(...) function. In order to get SPI working, I need to open the device with Configuration 3: dwf.FDwfDeviceConfigOpen(c_int(-1), c_int(3), byref(hdwf)) and to get the Digital Trigger running I need to open the device with Config 1: dwf.FDwfDeviceConfigOpen(c_int(-1), c_int(1), byref(hdwf)) As I can obiously only open it with one of both, I can not perform SPI configuration and Digital Trigger for Scope in the same code, which I need to... The SDK nor the Samples, nor the user manual or the dwl.h give conclusion of what for the Configurations are or what registers they affect. Is there any deeper Documentation you can give me? Or at least tell me what de differences are so what parameters I have to set to get a Configuration which is basically dwf.FDwfDeviceConfigOpen(c_int(-1), c_int(1+3), byref(hdwf)) :) Thanks in advance, UwerusCodus Again if it helps, the complete code so far: """ FMCW Radar Author: ... Revision: 2022-02-09 Requires: Python 2.7, 3 Description: In order to build the FMCW Radar Demontrator based on the ... Perform one meassurement after trigger with user definded sample rate and length. Both analog channels are meassured, the Trigger is a Digital DIO pin. Meassurement is saved to the buffer on the device, so we can sample up to 100MHz and 2^14 (~16000) samples per channel. The acquisition is then stored in a .csv file and passed for signal proccessing. ToDo: -check if Analog Discovery 2 (AD2) USB-ADC is connected -set pins for the programmable amplifiers and the signal multiplexers -(read Hex values from .csv data) and programm PLL via SPI -setup analog and digital instruments of Analog Discovery 2 -activate analog instrument and wait for trigger signal of the PLL (chirp begin) -Loop: -get acquisition from both channels -> store in Array (and export as .csv) -pass on to signal processing - (Signal Processing in parallel Task) """ from ctypes import * from dwfconstants import * import math import time import matplotlib.pyplot as plt import sys import numpy as np ####### Load the DWF, which forms the API between Python ond the C based Waveforms SDK ####### ''' 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") ''' if sys.platform.startswith("win"): dwf = cdll.LoadLibrary("dwf.dll") elif sys.platform.startswith("darwin"): dwf = cdll.LoadLibrary("/Library/Frameworks/dwf.framework/dwf") else: dwf = cdll.LoadLibrary("libdwf.so") # get the DWF Version provided by Digilent as an API between Python and the C based Waveforms SDK ####### version = create_string_buffer(16) dwf.FDwfGetVersion(version) print("Digilent DWF (API) Version: " + str(version.value)) ######################################################################################### ########################## user definable parameters #################################### ######################################################################################### # acquisition AcqHz = 10e6 # acquisitionHz / samplerate of ADC, max. 100MHz Samples = 2**14 # samples to collect after triggering, max. 2^14 samples ChlRange = 5 # set the +- Voltage range of AnalogIN Channel TrgPin = 6 # set the DIO Pin for the Trigger # SPI communication FreqSPI = 1e3 # set the SPI CLK Frequency CLKspi = 4 # SPI CLK pin SSspi = 5 # SPI Slave Select pin MOSIspi = 3 # SPI MOSI pin MISOspi = 6 # SPI MISO pin, also used as MUX out of the PLL, for the chirp begin trigger # Register values to be sent to PLL, extracted from Analog Devices ADF4159 PLL Software # Register order: R7, R6 Ramp 1, R6 Ramp 2, R5 Ramp 1, .... , R0 TXspi = [0x000307D7,\ 0x00005DBE,\ 0x00800006,\ 0x000A8F9D,\ 0x00800005,\ 0x00780084,\ 0x00780144,\ 0x010300C3,\ 0x07020052,\ 0x00000001,\ 0xF8240000] # SPI registers for PLL # MUX and Amplifier setting # basically bit operations, no usefull parameters, see directly in code ######################################################################################### ######################################################################################### ####### variables ####### hdwf = c_int() # create datatype for hardware handle of AD2 sts = c_byte() # create datatype for later status request of acquisition nSamplesCh1 = (c_double * Samples)() # create array for samples to be stored in (Channel 1) nSamplesCh2 = (c_double * Samples)() # create array for samples to be stored in (Channel 2) # ##################################################################################################################### #1. -check if Analog Discovery 2 (AD2) USB-ADC is connected ####### opening the device ####### print("Opening first device") #dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf)) # 2nd configuration for Analog Discovery with 16k analog-in buffer: Up to 16k samples/channel buffer length: # Trigger Detectors and Trigger Distribution Networks are implemented in the FPGA. This allows real time triggering and cross- # triggering of different instruments within the Analog Discovery device. Using external Trigger inputs/outputs, cross-triggering # between multiple Analog Discovery devices is possible. #dwf.FDwfDeviceConfigOpen(c_int(-1), c_int(1), byref(hdwf)) # (DIO Trigger to Analog working) open the AD2 and retrieve the handle dwf.FDwfDeviceConfigOpen(c_int(-1), c_int(3), byref(hdwf)) # (SPI working) Opens a device identified by the enumeration index with the selected CONFIGURATION and retrieves a handle. #dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf)) # not working.. if hdwf.value == hdwfNone.value: # if no device is found or the device is already in use szError = create_string_buffer(512) dwf.FDwfGetLastErrorMsg(szError); print("failed to open device\n" + str(szError.value)) quit() # ##################################################################################################################### #2. -set pins for the programmable amplifiers and the signal multiplexers ''' The adapter board is designed to have programmable amplifiers for the RX channels. In order to do so you have to set the resistors connected to the amplifiers using some MUX: AMP channel I1/Q1: AMP_MUX1_1(D12) AMP_MUX1_0(D11) Amplification 0 0 x100 0 1 x50 1 0 x30 1 1 x10 AMP channel I2/Q2: AMP_MUX2_1(D14) AMP_MUX1_0(D13) Amplification same as above... To route the amplified signals towards tha Analog Discovery 2 ADC, there are two analog MUX in series, that have to be set as following: SEL_MUX1(D1) SEL_MUX(D0) Ch1 Scope Ch2 Scope 0 0 I1 Q1 0 1 I2 Q2 1 0 I3 Q3 1 1 I4 Q4 ''' # enable output/mask on the pins, that shall be used as outputs, LSB=D0 dwf.FDwfDigitalIOOutputEnableSet(hdwf, c_int(0x7803)) # 0b 0111 1000 0000 0011 define pins 0,1,11-14 as output pins # 5432 1098 7654 3210 DIO pin count, LSB = 0, MSB 15 # set state of enabled IO pins, set the corresponding pins either high 1 or low 0 dwf.FDwfDigitalIOOutputSet(hdwf, c_int(0x0000)) # 0x0000 :I1/Q1, x100 amplification dwf.FDwfDigitalIOOutputSet(hdwf, c_int(0x0803)) # 0x0803 :I4/Q4, x50 amplification # ##################################################################################################################### #3. -(read Hex values from .csv data) and programm PLL via SPI print("Configuring SPI...") ''' INITIALIZATION SEQUENCE from PLL datasheet: After powering up the ADF4159, initialize the part by programming the registers in the following sequence: 1. Delay register (R7). 2. Step register (R6). Load the step register twice, first with STEP SEL = 0 and then with STEP SEL = 1. 3. Deviation register (R5). Load the deviation register twice, first with DEV SEL = 0 and then with DEV SEL = 1. 4. Clock register (R4). Load the clock register twice, first with CLK DIV SEL = 0 and then with CLK DIV SEL = 1. 5. Function register (R3). 6. R divider register (R2). 7. LSB FRAC register (R1). 8. FRAC/INT register (R0). ''' dwf.FDwfDigitalSpiFrequencySet(hdwf, c_double(FreqSPI)) # Sets the SPI frequency. dwf.FDwfDigitalSpiClockSet(hdwf, c_int(CLKspi)) # Specifies the DIO channel to use for SPI clock. dwf.FDwfDigitalSpiDataSet(hdwf, c_int(0), c_int(MOSIspi)) # D_MOSI_SISO = DIO, specify data channel dwf.FDwfDigitalSpiDataSet(hdwf, c_int(1), c_int(MISOspi)) # D_MISO = DIO, specify data back channel dwf.FDwfDigitalSpiIdleSet(hdwf, c_int(0), c_int(MOSIspi)) # D_MOSI_SISO = DwfDigitalOutIdleZet, specify channel idle state # dwf.FDwfDigitalSpiIdleSet(hdwf, c_int(0), c_int(3)) # <-- this was in the example, but probably wrong, 2 instead of 3 dwf.FDwfDigitalSpiIdleSet(hdwf, c_int(1), c_int(MISOspi)) # D_MISO = DwfDigitalOutIdleSet, specify data channel idle state dwf.FDwfDigitalSpiModeSet(hdwf, c_int(0)) # Set the SPI Mode (see video of Ben Eater SPI) # iMode CPOL CPHA # 0 0 0 # 1 0 1 # 2 1 0 # 3 1 1 dwf.FDwfDigitalSpiOrderSet(hdwf, c_int(1)) # data word send order: 1 MSB first, 0 LSB first # DIO value: 0 low, 1 high, -1 high impedance dwf.FDwfDigitalSpiSelect(hdwf, c_int(SSspi), c_int(1)) # Set the Chip Select CS channel level: 0 low, 1 high, -1 high impedance time.sleep(2) # wait few seconds, why? maybe for SPI device that may be connected, or debugging Oszi to click single shot # TX THE DATA OVER SPI dwf.FDwfDigitalSpiSelect(hdwf, c_int(SSspi), c_int(0)) # ChipSelect CS DIO-0 low, start transmission for registers in TXspi: dwf.FDwfDigitalSpiSelect(hdwf, c_int(SSspi), c_int(0)) # ChipSelect CS DIO-0 low # FDwfDigitalSpiWriteOne(HDWF hdwf, int cDQ, int cBits, unsigned int vTX) dwf.FDwfDigitalSpiWriteOne(hdwf, c_int(1), c_int(32), registers) # write 1 byte to MOSI # cDQ: # cDQ Type Description # 0 SISO use only DQ0 for read and write # 1 MOSI/MISO use DQ0 for write and DQ1 to read data # 2 DUAL use DQ0 for even and DQ1 for odd bits # 3 QUAD use DQ0 for 0,4,8…, DQ1 for 1,5,9…, DQ2 for 2,6,10…, DQ3 for 3,7,11… data bits dwf.FDwfDigitalSpiSelect(hdwf, c_int(SSspi), c_int(1)) # ChipSelect CS DIO-0 high print("SPI sent: " + hex(registers)) # time.sleep(0.001) print("PLL - ADC SPI communication completed") # ##################################################################################################################### #4. -setup analog and digital instruments of Analog Discovery 2 ####### set up acquisition ####### dwf.FDwfAnalogInFrequencySet(hdwf, c_double(AcqHz)) # set acquisition frequency dwf.FDwfAnalogInBufferSizeSet(hdwf, c_int(Samples)) # set the buffer size for AnalogIn dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(0), c_bool(True)) # enable Analog Channel 1 dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(1), c_bool(True)) # enable Analog Channel 2 dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(0), c_double(ChlRange)) # set the Voltage range of AnalogIN Channel 1 dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(1), c_double(ChlRange)) # set the Voltage range of AnalogIN Channel 2 ####### explanation of trigger ####### ''' in order to better understand the code, here a quick overview of the Analog Discovery 2 Trigger System: The Analog meassurement and the Digital Decoder are two independent instruments, each with an own TriggerDetector controller. Both instruments are managed by the FPGA. The only "direct" connection is the so called "Trigger Bus". A bus where all, the Analog, Digital, External, PC, ..., trigger units are connected to. This way every instrument can send a trigger released message to any other instrument. Means we basically do these steps: 1. Deactivate Auto Trigger in Analog instrrument 2. Tell AnalogInstrument to listen to the bus and trigger off the DigitalTriggerDetector signal. 3. (shift the trigger position to the "left boundary of the data window", default: Trigger = mid of Data Array) -> Analog instrument armed 4. Now on the digital instrument, set the pin to trigger on and on which condition 5. Start and arm digital In instrument -> Digital Trigger running 6. Start Analog Instrument ''' ####### set up trigger for the analog channel to be the DigitalInDetector ####### dwf.FDwfAnalogInTriggerAutoTimeoutSet(hdwf, c_double(0)) # disable auto trigger at analog channel dwf.FDwfAnalogInTriggerSourceSet(hdwf, trigsrcDetectorDigitalIn) # set the triggger source for the analog channels to be the DigitalInTriggerDetector # move trigger to left boundary, otherwise the signal will start in the middle #dwf.FDwfAnalogInTriggerPositionSet(hdwf, c_double(Samples/(2*AcqHz)))# Configures the horizontal trigger position in seconds. dwf.FDwfAnalogInTriggerPositionSet(hdwf, c_double((Samples-10)/(2*AcqHz)))# Configures the horizontal trigger position in seconds. print("Trigger horizontal Position Set to: " +str(-Samples/(2*AcqHz)) + "sec. Left boundary of Buffer.") ####### settings for the trigger on digital channel ####### # set clock divider for digital in instrument (do I need this??) # they did it in the examples, although it seems to work without hzDI = c_double() dwf.FDwfDigitalInInternalClockInfo(hdwf, byref(hzDI)) print("DigitanIn base freq: "+str(hzDI.value/1e6)+"MHz") #sample rate = system frequency / divider dwf.FDwfDigitalInDividerSet(hdwf, c_int(int(hzDI.value/100e6))) ## Configures the digital in trigger detector. ## #The logic for the trigger bits is: Low and High and (Rise or Fall). Setting a bit in both rise and fall will trigger on any #edge, any transition. For instance FDwfDigitalInTriggerInfo(hdwf, 0b0001, 2, 4, 8) will generate trigger when DIO-0 is low #and DIO-1 is high and DIO-2 is rising or DIO-3 is falling. The bits of the arguments represent pins. # FDwfDigitalInTriggerSet(hdwf, uint fsLevelLow, uint fsLevelHigh, uint fsEdgeRise, uint fsEdgeFall) dwf.FDwfDigitalInTriggerSet(hdwf, c_int(0), c_int(0), c_int(0), c_int(1<<TrgPin)) # DIO6 falling edge - The bits of the arguments represent pins. # startup digitalIn insturment dwf.FDwfDigitalInConfigure(hdwf, c_bool(0), c_bool(1)) # Configures the instrument and start or stop the acquisition. To reset the Auto trigger timeout, set 3rd param. to TRUE. ''' ####### set up power supply if needed ####### dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(0), c_double(True)) # enable positive supply dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(1), c_double(3.3)) # set voltage to ... V dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(1), c_int(0), c_double(True)) # enable negative supply dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(1), c_int(1), c_double(-3.3)) # set voltage to -... V dwf.FDwfAnalogIOEnableSet(hdwf, c_int(True)) # master enable ''' ###### wait at least 2 seconds with Analog Discovery for the offset to stabilize, before the first reading after device open or offset/range change ##### time.sleep(2) # ##################################################################################################################### #5. -activate analog instrument and wait for trigger signal of the PLL (chirp begin) ####### get AnalogIN instrument in Ready state ####### print("Starting AnalogIN instrument. Waiting for trigger...") # FDwfAnalogInConfigure(hdwf, int fReconfigure, int fStart) dwf.FDwfAnalogInConfigure(hdwf, c_bool(False), c_bool(True)) # Configures the instrument and start or stop the acquisition. To reset the Auto trigger timeout, setfReconfigure to TRUE. # ##################################################################################################################### #6. -main Acquisition Loop: while True: ####### repeatedly check if acquisition has been made ####### while True: dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts)) if sts.value == DwfStateDone.value: # if so: acquisition completed, break while loop break time.sleep(0.001) # else: wait 1ms and check again # -get acquisition from both channels -> store in Array (and export as .csv) ####### get the Samples from the desired channel ####### dwf.FDwfAnalogInStatusData(hdwf, 0, nSamplesCh1, Samples) # get channel 1 data from buffer dwf.FDwfAnalogInStatusData(hdwf, 1, nSamplesCh2, Samples) # get channel 2 data from buffer print("Data collected from AnalogIN buffer.") # the instrument gets armed again after the data was gathered, so it will collect the next set in trigger condition. print("Waiting for next trigger condition...") # -pass on to signal processing ####### display data ####### ''' plt.plot(TimeVec, np.fromiter(nSamplesCh1, dtype=np.double), 'bo-') # plot(x,y,style) plt.xlabel('Zeit in us'); plt.ylabel('Spannung in Volt'); plt.title('Samples Kanal 1') plt.show() ''' TimeVec = np.linspace(start=0, stop=(Samples * 1e6 / AcqHz), num=Samples) # generate time vector for plot fig, axs = plt.subplots(1, 2) # create subfigures (called axes) fig.set_figwidth(12); fig.set_figheight(5) # figure window size fig.suptitle('Samples') axs[0].plot(TimeVec, np.fromiter(nSamplesCh1, dtype=np.double), 'bo-') # plot Ch1 (x,y,style) axs[1].plot(TimeVec, np.fromiter(nSamplesCh2, dtype=np.double), 'ro-') # plot Ch2 (x,y,style) axs[0].set_title('channel 1'); axs[0].set(xlabel='time [us]', ylabel='voltage [V]') axs[1].set_title('channel 2'); axs[1].set(xlabel='time [us]') plt.show() # - (Signal Processing in parallel Task) ####### close device and free handle ####### dwf.FDwfDeviceCloseAll() print("Device released.")
  3. Hello there, I need to log the 2 analog Channels simultaniously with a high Samplerate of ~6MS, everything triggered off the falling edge of DIO pin 6. (IQ channels of FMCW radar, triggered of the PLLs Chirp Start signal) I already managed to log Data on one channel using the 16k Buffer. Also Triggering on the second Channel as well as on the external Trigger worked. But I can not manage to trigger of an specific DIO pin. Everything in Python. 1. If I got the SDK right, I only need one hdwf device handle for the AD2, not one for the analog and one for the digital instrument? 2. Also with the Trigger Bus I should be able to trigger the Analog Instrument off the DigitalTriggerDetector? 3. So my understandig is that I set the AnalogIn Trigger Source to DetectorDigitalIn (Trigger Bus connection). All the settings for the Trigger itself condition/pin/PositionShift/... have then to be done under: FDwfDigitalInTrigger...() in the DigitalDtriggerDetectior, right? 4. If so I can not really see from the SDK and the Examples, what Fuctions I have to call to arm the DigitalTriggerDetector in Order to Trigger on the Falling Edge of DIO6. Please tell me the necessary functionsto do so!:) 5. And one more additional question: Does every Analog Channel have its own 16k buffer or is the buffer shared for both or even the Digial pins as well? And is there a more in depth documentation then the SDK and examples? Thanks in advance! I added the code below: from ctypes import * from dwfconstants import * import math import time import matplotlib.pyplot as plt import sys import numpy ####### Load the DWF, which forms the API between Python ond the C based Waveforms SDK ####### 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") ######################################################################################### ########################## user definable parameters #################################### ######################################################################################### AcqHz = 100e6 # acquisitionHz / samplerate of ADC, max. 100MHz Samples = 2**14 # samples to collect after triggering, max. 2^14 samples ChlRange = 3.3 # set the +- Voltage range of AnalogIN Channel TrgPin = 6 # set the DIO Pin for the Trigger TrgLvl = 1.1 # set the voltage for the Trigger ######################################################################################### ######################################################################################### hdwf = c_int() # create datatype for hardware handle of AD2 sts = c_byte() # create datatype for later status request of acquisition nSamples = (c_double * Samples)() # create array for samples to be stored in ####### get the DWF Version provided by Digilent as an API between Python and the C based Waveforms SDK ####### version = create_string_buffer(16) dwf.FDwfGetVersion(version) print("Digilent DWF (API) Version: " + str(version.value)) ####### opening the device ####### print("Opening first device") #dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf)) # 2nd configuration for Analog Discovery with 16k analog-in buffer dwf.FDwfDeviceConfigOpen(c_int(-1), c_int(1), byref(hdwf)) # open the AD2 and retrieve the handle if hdwf.value == hdwfNone.value: # if no device is found or the device is already in use szError = create_string_buffer(512) dwf.FDwfGetLastErrorMsg(szError); print("failed to open device\n" + str(szError.value)) quit() ####### set up acquisition ####### dwf.FDwfAnalogInFrequencySet(hdwf, c_double(AcqHz)) # set acquisition frequency dwf.FDwfAnalogInBufferSizeSet(hdwf, c_int(len(nSamples))) # set the buffer size for AnalogIn dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(0), c_bool(True)) dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(0), c_double(ChlRange)) # set the Voltage range of AnalogIN Channel ####### set up trigger for the analog channel to be the DigitalInDetector ####### dwf.FDwfAnalogInTriggerAutoTimeoutSet(hdwf, c_double(0)) # disable auto trigger at analog channel dwf.FDwfAnalogInTriggerSourceSet(hdwf, trigsrcDetectorDigitalIn) # set the triggger source for the analog channels to be the DigitalInTriggerDetector #dwf.FDwfAnalogInTriggerSourceSet(hdwf, trigsrcExternal1) # ExtTrg1 as Trigger Source ### settings for analogIn Trigger Detector ### ''' dwf.FDwfAnalogInTriggerTypeSet(hdwf, trigtypeEdge) dwf.FDwfAnalogInTriggerConditionSet(hdwf, trigcondFallingNegative) # <----------------- warum geht das nicht?? dwf.FDwfAnalogInTriggerChannelSet(hdwf, c_int(0)) # first channel dwf.FDwfAnalogInTriggerLevelSet(hdwf, c_double(TrgLvl)) # trigger level 0.5V dwf.FDwfAnalogInTriggerConditionSet(hdwf, trigcondRisingPositive) # move trigger to left boundary, otherwise the signal will start in the middle #dwf.FDwfAnalogInTriggerPositionSet(hdwf, c_double(Samples/(2*AcqHz)))# Configures the horizontal trigger position in seconds. #dwf.FDwfAnalogInTriggerPositionSet(hdwf, c_double(4000/(2*AcqHz)))# Configures the horizontal trigger position in seconds. print("Trigger horizontal Position Set to: " +str(-Samples/(2*AcqHz)) + "sec. Left boundary of Buffer.") ''' ####### settings for the trigger on digital channel ####### #dwf.FDwfDigitalInTriggerSourceSet(hdwf, c_ubyte(3)) # trigsrcDetectorDigitalIn - Sets the trigger source for the instrument. #dwf.FDwfDigitalInTriggerPositionSet(hdwf, c_int(int(cSamples/2-1))) # Sets the number of samples to acquire after trigger. ## Configures the digital in trigger detector. ## #The logic for the trigger bits is: Low and High and (Rise or Fall). Setting a bit in both rise and fall will trigger on any #edge, any transition. For instance FDwfDigitalInTriggerInfo(hdwf, 0b0001, 2, 4, 8) will generate trigger when DIO-0 is low #and DIO-1 is high and DIO-2 is rising or DIO-3 is falling. The bits of the arguments represent pins. # FDwfDigitalInTriggerSet(HDWF hdwf, uint fsLevelLow, uint fsLevelHigh, uint fsEdgeRise, uint fsEdgeFall) dwf.FDwfDigitalInTriggerSet(hdwf, c_int(0), c_int(0), c_int(0), c_int(1<<6)) # DIO6 falling edge - The bits of the arguments represent pins. ####### set up power supply ####### dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(0), c_double(True)) # enable positive supply dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(0), c_int(1), c_double(3.3)) # set voltage to ... V dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(1), c_int(0), c_double(True)) # enable negative supply dwf.FDwfAnalogIOChannelNodeSet(hdwf, c_int(1), c_int(1), c_double(-3.3)) # set voltage to -... V dwf.FDwfAnalogIOEnableSet(hdwf, c_int(True)) # master enable ###### wait at least 2 seconds with Analog Discovery for the offset to stabilize, before the first reading after device open or offset/range change ##### time.sleep(2) ####### get AnalogIN instrument in Ready state ####### print("Starting AnalogIN instrument. Waiting for trigger...") # FDwfAnalogInConfigure(hdwf, int fReconfigure, int fStart) dwf.FDwfAnalogInConfigure(hdwf, c_bool(False), c_bool(True)) # Configures the instrument and start or stop the acquisition. To reset the Auto trigger timeout, setfReconfigure to TRUE. ####### repeatedly check if acquisition has been made ####### while True: dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts)) if sts.value == DwfStateDone.value: # if so: acquisition completed, break while loop break time.sleep(0.001) # else: wait 1ms and check again ####### get the nSamples from the desired channel ####### dwf.FDwfAnalogInStatusData(hdwf, 0, nSamples, len(nSamples)) # get channel 1 data from buffer # dwf.FDwfAnalogInStatusData(hdwf, 1, nSamples, len(nSamples)) # get channel 2 data print("Data collected from AnalogIN buffer.") ####### close device and free handle ####### dwf.FDwfDeviceCloseAll() print("Device released.") ####### store data to .csv file ####### f = open("TriggeredRecord.csv", "w+") for value in nSamples: f.write("%s\n" % value) f.close() print("Data saved to .csv file.") ####### display data ####### plt.plot(numpy.fromiter(nSamples, dtype=numpy.double), 'bo-') # plot(x,y,style) plt.show()
×
×
  • Create New...