devName = daq.GetDeviceList()[0] #find 1st IOtech device print "Connected to %s\n\n" % devName handle = daq.Open(devName) if handle == -1: print "Cannot conncet to device\n" print "Exit" sys.exit(handle) print "Setting up scan...\n" daq.AdcSetAcq(handle, DaamNShot, 0, SCANS) #Scan settings daq.AdcSetScan(handle, channels, gains, flags) #set scan rate daq.AdcSetFreq(handle, RATE) #Set buffer location, size and flag settings daq.AdcTransferSetBuffer(handle, buffer, SCANS, CHANCOUNT, DatmUpdateSingle + DatmCycleOff) #Set to trigger immediatly daq.SetTriggerEvent(handle, STARTSOURCE, DetsRisingEdge, channels[0], gains[0], flags[0], DaqTypeAnalogLocal, 0, 0, DaqStartEvent) #Set to stop when the requested number of scans is completed daq.SetTriggerEvent(handle, STOPSOURCE, DetsRisingEdge, channels[0], gains[0], flags[0], DaqTypeAnalogLocal, 0, 0, DaqStopEvent) #begin data acquisition print "Scanning...\n" daq.AdcTransferStart(handle) daq.AdcArm(handle)
def raster(self): minVolt = -10.0 maxVolt = 10.0 freq = 1 COUNT = 68 * 62 FREQ = freq * COUNT x = [] y = [] NS = freq * 1 i = 0 while i < 62: j = 0 while j < 62: x.append(j) y.append(i) j += 1 j = 61 if i is not 61: while j >= 10: j -= 10 x.append(j) y.append(i) if i is 61: # The scan now has 62+6 points in each line and when it reaches the last line, it uses the same 6 points to go to beginning point while j >= 10: # For the actual data that we are interested, we have to ignore 6 points after every 62 points j -= 10 i -= 10 x.append(j) y.append(i) i = 61 i += 1 cnt_x = ((((np.array(x) * 0.01 - minVolt) * 65535 / (maxVolt - minVolt)))).astype(np.uint16) cnt_y = ((((np.array(y) * 0.01 - minVolt) * 65535 / (maxVolt - minVolt)))).astype(np.uint16) daq.DacSetOutputMode(handle, daqh.DddtLocal, 1, daqh.DdomStaticWave) daq.DacWaveSetTrig(handle, daqh.DddtLocal, 1, daqh.DdtsImmediate, 0) daq.DacWaveSetClockSource(handle, daqh.DddtLocal, 1, daqh.DdcsAdcClock) daq.DacWaveSetFreq(handle, daqh.DddtLocal, 1, FREQ) daq.DacWaveSetMode(handle, daqh.DddtLocal, 1, daqh.DdwmNShot, NS * COUNT) daq.DacWaveSetBuffer(handle, daqh.DddtLocal, 1, cnt_x, COUNT, daqh.DdtmUserBuffer) daq.DacWaveSetUserWave(handle, daqh.DddtLocal, 1) daq.DacSetOutputMode(handle, daqh.DddtLocal, 2, daqh.DdomStaticWave) daq.DacWaveSetTrig(handle, daqh.DddtLocal, 2, daqh.DdtsImmediate, 0) daq.DacWaveSetClockSource(handle, daqh.DddtLocal, 2, daqh.DdcsAdcClock) daq.DacWaveSetFreq(handle, daqh.DddtLocal, 2, FREQ) daq.DacWaveSetMode(handle, daqh.DddtLocal, 2, daqh.DdwmNShot, NS * COUNT) daq.DacWaveSetBuffer(handle, daqh.DddtLocal, 2, cnt_y, COUNT, daqh.DdtmUserBuffer) daq.DacWaveSetUserWave(handle, daqh.DddtLocal, 2) self.rasterbuffer = np.ones(NS * COUNT, dtype=np.uint16) channels = [0] gains = [daqh.DgainDbd3kX1] flags = [daqh.DafCtr16] daq.AdcSetAcq(handle, daqh.DaamNShot, 0, NS * COUNT) daq.AdcSetScan(handle, channels, gains, flags) daq.AdcSetFreq(handle, FREQ) daq.SetOption( handle, 0, daqh.DcofChannel, daqh.DcotCounterEnhMeasurementMode, daqh.DcovCounterEnhMode_Counter + daqh.DcovCounterEnhCounter_ClearOnRead) daq.AdcTransferSetBuffer(handle, self.rasterbuffer, NS * COUNT, 1, daqh.DatmUpdateSingle + daqh.DatmCycleOff) daq.SetTriggerEvent(handle, daqh.DatsExternalTTL, daqh.DetsRisingEdge, 0, daqh.DgainDbd3kX1, daqh.DafCtr16, daqh.DaqTypeCounterLocal, 0, 0, daqh.DaqStartEvent) daq.SetTriggerEvent(handle, daqh.DatsScanCount, daqh.DetsRisingEdge, 0, daqh.DgainDbd3kX1, daqh.DafCtr16, daqh.DaqTypeCounterLocal, 0, 0, daqh.DaqStopEvent) daq.AdcTransferStart(handle) daq.AdcArm(handle) print "waiting for Scan trigger...\n" daq.DacWaveArm(handle, daqh.DddtLocal) tm.sleep(1) handle1.Ctrig() print("Scanning...\n") active, retCount = daq.DacTransferGetStat(handle, daqh.DddtLocal, 1) while active & daqh.DdafTransferActive: active, retCount = daq.DacTransferGetStat(handle, daqh.DddtLocal, 1) #print(active, retCount) tm.sleep( 0.1 ) # Sometimes Data Acquisition isn't finished yet even though the DAC output is complete. Don't know why??? (Update frequencies and # of data points are the same) daq.AdcDisarm(handle) daq.DacWaveDisarm(handle, daqh.DddtLocal) print(self.rasterbuffer, len(self.rasterbuffer)) imagedata = np.zeros((62, 62)) i = j = k = 0 while k < len(self.rasterbuffer): imagedata[j, i] = self.rasterbuffer[k] i += 1 if i % 62 is 0: k += 6 j += 1 i = 0 k += 1 print(imagedata) plt.clf() plt.imshow(imagedata, cmap=cm.Greys_r) plt.show()
bufx = np.tile(line, ysize) devName = daq.GetDeviceList()[0] print "Connecting to %s\n\n" % devName handle = daq.Open(devName) if handle == -1: print "Cannot conncet to device\n" print "Exit" sys.exit(handle) print "Setting up scan...\n" daq.AdcSetAcq(handle, daqh.DaamNShot, 0, SCANS) #Scan settings daq.AdcSetScan(handle, channels, gains, flags) #set scan rate daq.AdcSetFreq(handle, FREQ) #Setup Channel 0 for count mode daq.SetOption( handle, channels[0], daqh.DcofChannel, daqh.DcotCounterEnhMeasurementMode, daqh.DcovCounterEnhMode_Counter + daqh.DcovCounterEnhCounter_ClearOnRead) #Setup Channel 1 for count mode daq.SetOption( handle, channels[1], daqh.DcofChannel, daqh.DcotCounterEnhMeasurementMode, daqh.DcovCounterEnhMode_Counter + daqh.DcovCounterEnhCounter_ClearOnRead) #Set buffer location, size and flag settings daq.AdcTransferSetBuffer(handle, buffer, SCANS, CHANCOUNT, daqh.DatmUpdateSingle + daqh.DatmCycleOff) #Set to Trigger on software trigger daq.SetTriggerEvent(handle, STARTSOURCE, daqh.DetsRisingEdge, channels[0],
def setup(self): # DAC: # Use channel 0 for z-axis output # Use PortAB for digital output streaming (provide a sync pulse indicating the start of the scan) # run DAC output and ADC input (counters) synchronously at a low frequency (traditionally we used a binning frequency of 50000Hz/80 ~ 625Hz # dz/dV slope of piezo controller self.dz_dV = 15.0 # um/V (depends on controller and is an approximate value) self.z0 = 15.0 # um; z-offset (has to be positive to not damage the piezo) self.delz = 24.0 # um; typical travel of a z-scan self.T = float( input( "Enter the desired time, in seconds, for one complete zscan\n " )) # s; half period = time to complete an up (or down) ramp self.N = int( input("How many scans do you wish to perform in single run?\n")) self.Thalf = self.T / 2 self.resolution = 1 << 16 # =2**16 (shift bit to left); 16-bit DAC self.resolution_half = 1 << 15 # =2**15 self.Vrange = 20.0 # V; +-10V output range of DAC self.dV_DAC = self.Vrange / self.resolution self.vz = self.delz / self.Thalf # speed of the ramp um/s # calculate the minimum update rate of DAC to ensure that voltage changes of dV_DAC result in an output update self.delV = self.delz / self.dz_dV # voltage amplitude of ramp self.V0 = form.voltage # voltage offset self.freq_min = self.delV / self.dV_DAC / self.Thalf # minimum update frequency self.FREQ = max(1000, self.freq_min) # set a lower floor for freq of 1kHz # make sure the freq is compatible (commensurable) with the number of data point per scan self.nwavehalf = int( round(self.FREQ * self.Thalf)) # number of data points in half of waveform self.nwave = self.nwavehalf * 2 self.FREQ = self.nwavehalf / self.Thalf # generate scan waveform self.Vtup = (np.ones(self.nwavehalf).cumsum() - 1) / ( self.nwavehalf - 1) * self.delV # up-ramp voltage waveform self.Vtdown = np.fliplr([self.Vtup])[0] # down-ramp voltage waveform self.l = len( self.Vtup ) / 2 # facilitates to make a ramp that starts from middle rather than bottom or top self.Vtmid = self.Vtup[self.l] self.Vtadjust = self.V0 - self.Vtmid # facilitates the mid-ramp to start at the focus point set by piezo self.Vt = np.concatenate([ self.Vtup[self.l:] + self.Vtadjust, self.Vtdown + self.Vtadjust, self.Vtup[:self.l] + self.Vtadjust ]) self.Vt = np.tile(self.Vt, self.N) # convert Vt into DAC count waveform (-10V = 0, 0V = 32768, +9.99969482421875V = 65535) # ((65535 - 32768 - 65535) + count) * dV_DAC = (count - 32768)*dV_DAC self.DACwave = np.around(self.Vt / self.dV_DAC + self.resolution_half).astype('uint16') # prepare waveform for digital output; used to mark the start of the scan # Note: make sure that the output port is initialized to LOW before start of waveform self.COUNT = self.N * self.nwave # = SCANS self.bufSYNC = np.zeros(self.COUNT, dtype=np.uint16) self.bufSYNC[ 0] = 1 # |^|________ single pulse at start of digital waveform # to read SYNC connect A0 to CNT1 # prepare ADC readSCAN self.SCANS = self.N * self.nwave # = COUNT self.CHANCOUNT = 2 self.channels = [0, 1] # 16 bit counter, 16 bit counter self.gains = [daqh.DgainDbd3kX1, daqh.DgainDbd3kX1] # ignored self.flags = [daqh.DafCtr16, daqh.DafCtr16] # get read buffer for photoncounts and sync pulses self.readbuffer = np.ones((self.SCANS * self.CHANCOUNT, ), dtype=np.uint16) # set start and stop conditions of readSCAN self.STARTSOURCE = daqh.DatsExternalTTL self.STOPSOURCE = daqh.DatsScanCount print "Setting up ADC scan...\n" daq.AdcSetAcq(handle, daqh.DaamNShot, 0, self.SCANS) # Scan settings daq.AdcSetScan(handle, self.channels, self.gains, self.flags) # set scan rate daq.AdcSetFreq(handle, self.FREQ) # Setup Channel 0 (photon counts) for count mode 16 bit, clear on read daq.SetOption( handle, self.channels[0], daqh.DcofChannel, daqh.DcotCounterEnhMeasurementMode, daqh.DcovCounterEnhMode_Counter + daqh.DcovCounterEnhCounter_ClearOnRead) # Setup Channel 1 (SYNC pulse read) for count mode 16 bit, clear on read daq.SetOption( handle, self.channels[1], daqh.DcofChannel, daqh.DcotCounterEnhMeasurementMode, daqh.DcovCounterEnhMode_Counter + daqh.DcovCounterEnhCounter_ClearOnRead) # Set buffer location, size and flag settings daq.AdcTransferSetBuffer(handle, self.readbuffer, self.SCANS, self.CHANCOUNT, daqh.DatmUpdateSingle + daqh.DatmCycleOff) # Set to Trigger on hardware trigger daq.SetTriggerEvent(handle, self.STARTSOURCE, daqh.DetsRisingEdge, self.channels[0], self.gains[0], self.flags[0], daqh.DaqTypeCounterLocal, 0, 0, daqh.DaqStartEvent) # Set to Stop when the requested number of scans is completed daq.SetTriggerEvent(handle, self.STOPSOURCE, daqh.DetsRisingEdge, self.channels[0], self.gains[0], self.flags[0], daqh.DaqTypeCounterLocal, 0, 0, daqh.DaqStopEvent) print("Setup complete.\n")