예제 #1
0
def reset(readPort, writePort):
    Bcolors.printInfo("Resetting ... ")
    toggle_reset(writePort)
    time.sleep(0.1)
    toggle_reset(writePort)

    #before starting measurement, clearing the values from the FIFO
    clear_results(readPort)
예제 #2
0
def write_to_mem(addr, data, writePort):
    Bcolors.printInfo("Write " + str(data) + " to addr " + str(addr))
    instruction_addr = (instructions.spi_write << 29) | addr
    #Bcolors.printInfo("Instruction: " + "0x{:04x}".format(addr))
    writePort.sendInt(instruction_addr)
    instruction_data = (instructions.spi_write << 29) | data
    #Bcolors.printInfo("Instruction: " + "0x{:04x}".format(data))
    writePort.sendInt(instruction_data)
    def stop(self):
        Bcolors.printInfo("Rigol DP832A - Stop and close connection")
        self.rigol.outputOffAll()

        # return to LOCAL mode
        self.rigol.setLocal()

        self.rigol.close()
 def set_voltage(self, voltage, channel=1):
     Bcolors.printInfo("Rigol DP832A - Setting voltage on channel " +
                       str(channel) + " to " + str(voltage) + "V")
     if voltage <= 1 or channel == 2:
         self.rigol.setVoltage(voltage, channel)
     else:
         Bcolors.printInfo("Rigol DP832A - Voltage to high on channel " +
                           str(channel) + " for voltage " + str(voltage) +
                           "V")
         self.turn_off_all()
         exit()
	def setFrequency(self,frequency,writePort,verbose=False):
		## Set extra 8 divisor on or off +
		#if frequency < 5:
		#	extraDivOn = True
		#else:
		#	extraDivOn = False
		#
		##reset mmcm for configuration + set divider on/off
		#self.map.seek(0x0000,os.SEEK_SET)
		#if extraDivOn:
		#	self.map.write_byte(chr(0x03))
		#else:
		#	self.map.write_byte(chr(0x01))
		#
		## Set power register
		#self.map.seek(0x10A0,os.SEEK_SET)
		#self.map.write(struct.pack("I",0x0000FFFF))

		# Find nearest frequency, this frequency will be used
		#if extraDivOn:
		#	exactFrequency = self.findNearestFrequency(frequency*8,verbose)
		#else:
		#	exactFrequency = self.findNearestFrequency(frequency,verbose)
		instruction = (instructions.chip_setclk << 29) | (0x28 << 16) | (0xFFFF)
		writePort.sendInt(instruction)

		exactFrequency = self.findNearestFrequency(frequency,verbose)

		with open(cnst.PROJDIR + "/python/lookup_data/freq_" + "%.2f" % exactFrequency + ".csv","r") as lookUpFile:
			for i, line in enumerate(lookUpFile):
				if i != 0:
					regName, fakeAddr, value = line.split(",")
					if verbose:
						Bcolors.printInfo(regName + "address:" + str(Clock.drpAddressMap[regName[1:-1]]) + " value: " + hex(int(value,16)))
					addr = Clock.drpAddressMap[regName[1:-1]]
					instruction = (instructions.chip_setclk << 29) | (addr << 16) | int(value,16)
					writePort.sendInt(instruction)
					#self.map.seek(0x1000 + 4*Clock.drpAddressMap[regName[1:-1]],os.SEEK_SET)
					#self.map.write(struct.pack("I",int(value,16)))
					#time.sleep(0.001)

		#if verbose:
		#	self.printDRPRegisters()

		#self.map.seek(0x0000,os.SEEK_SET)
		#if extraDivOn:
		#	self.map.write_byte(chr(0x02))
		#	return exactFrequency/8
		#else:
		#	self.map.write_byte(chr(0x00))
		#	return exactFrequency
		return exactFrequency
	def openPort(self):
		self.portId = open(self.devfile, 'wb',0)
		if self.portId == 0:
			Bc.printError("Could not open " + devfile + " for write")
			return False
		else:
			#Bc.printInfo("Succesfully opened write port to " + self.devfile)

			if self.dummy:
				self.dummyId = open("./writeLog_" + str(WritePort.writePortCount), 'w')
				Bc.printInfo("Opened dummy port with id " + str(self.dummyId))

			return True
예제 #7
0
def read_addr(addr, writePort):
    instruction = (instructions.spi_write << 29) | addr
    Bcolors.printInfo("Reading addr " + str(addr))
    #Bcolors.printInfo("Instruction: " + "0x{:04x}".format(addr))
    writePort.sendInt(instruction)
예제 #8
0
def write_mem(n_addr, writePort):
    Bcolors.printInfo("Writing memory from 0 to {} ...".format(n_addr))
    instruction = (instructions.write_prog << 29) | n_addr
    #Bcolors.printInfo("Instruction: " + "0x{:04x}".format(instruction))
    writePort.sendInt(instruction)
예제 #9
0
def enable_exit_mode(writePort):
    Bcolors.printInfo("Enabling EXIT mode ...")
    data = (4095 << 4) | 3
    #Bcolors.printInfo("Instruction: " + "0x{:04x}".format(data))
    instruction = (instructions.spi_write << 29) | data
    writePort.sendInt(instruction)
예제 #10
0
def enable_read_mode(memory, writePort):
    Bcolors.printInfo("Enabling READ mode for memory " + str(memory) + " ...")
    data = (4095 << 4) | (memory << 2) | 0
    #Bcolors.printInfo("Instruction: " + "0x{:04x}".format(data))
    instruction = (instructions.spi_write << 29) | data
    writePort.sendInt(instruction)
예제 #11
0
def start(writePort):
    Bcolors.printInfo("Sending start pulse ...")
    instruction = (instructions.chip_start << 29)
    writePort.sendInt(instruction)
 def turn_on_all(self):
     Bcolors.printInfo("Rigol DP832A - Turning ON all channels")
     self.rigol.outputOnAll()
 def turn_on(self, channel=1):
     Bcolors.printInfo("Rigol DP832A - Turning ON channel " + str(channel))
     self.rigol.outputOn(channel)
 def turn_off_all(self):
     Bcolors.printInfo("Rigol DP832A - Turning OFF all channels")
     self.rigol.outputOffAll()
 def get_real_voltage(self, channel=1):
     Bcolors.printInfo("Rigol DP832A - Getting real voltage on channel " +
                       str(channel))
     return self.rigol.measureVoltage(channel)
	def findNearestFrequency(self, frequency, verbose=False):
		idx = (abs(self.frequencies-frequency)).argmin()
		if verbose:
			Bcolors.printInfo("Nearest frequency = " + str(self.frequencies[idx]) + " for requested frequency " + str(frequency))
		return self.frequencies[idx]