Пример #1
0
 def setTrackingMode(self, writechannel, trackingbyte, ppm_order):
     #inputs: channel to write data to, trackingbyte (byte that commands
     #modulator to enter tracking mode), and ppm order
     #outputs: terminal string
     print("Putting modulator into tracking mode for ppm order %d." %
           ppm_order)
     fl.flWriteChannel(self.handle, writechannel, bytearray([trackingbyte]))
Пример #2
0
    def measureSER(self, obslength=1.0):
        # Wait for DAC to settle
        time.sleep(0.1)

        # Reset cycle and error counters
        fl.flWriteChannel(self.handle, self.FIFO_ASYNC_WR, 0x00)

        # Wait for the observation time
        time.sleep(obslength)

        # TODO: combine commands below together
        # Latch cycle and error counters
        fl.flWriteChannel(self.handle, self.FIFO_ASYNC_WR, 0x01)

        # Request readback of cycle counter and error counter
        fl.flWriteChannel(self.handle, self.FIFO_ASYNC_WR,
                          0x03)  # cycle counter
        fl.flWriteChannel(self.handle, self.FIFO_ASYNC_WR,
                          0x04)  # error counter
        fl.flWriteChannel(self.handle, self.FIFO_ASYNC_WR,
                          0x05)  # ones counter

        # Readback counters (two counters, each 8 bytes)
        resp = fl.flReadChannel(self.handle, self.FIFO_ASYNC_RD, 24)
        if self.DEBUG: print "Length of response:", len(resp)
        if self.DEBUG: print[hex(a) for a in resp]
        (cycles, errors, ones) = struct.unpack(">QQQ", resp)
        ser = float(errors) / float(cycles)

        if self.DEBUG:
            print "0x%016X 0x%016X 0x%016X SER = %e" % (cycles, errors, ones,
                                                        ser)

        return cycles, errors, ones, ser
Пример #3
0
def findCenter(handle, init_only):

    laserInit(handle)
    thresholdInit(handle, 0, 15000)  #CHECK THE STARTING POINT HERE
    thresholdInit(handle, 1, 15000)
    thresholdInit(handle, 2, 15000)
    sleep(5)
    print("Initialization Complete")
    if (init_only):
        return
    while (fl.flReadChannel(handle, memMap.get_register('PDI')) < 1):

        #check starting temp
        MSB = fl.flReadChannel(handle, memMap.get_register('LTSa'))
        LSB = fl.flReadChannel(handle, memMap.get_register('LTSb'))

        value = MSB * 256 + LSB
        new_value = value + 1
        new_MSB = new_value / 256
        new_LSB = new_value % 256
        fl.flWriteChannel(handle, memMap.get_register('LTSa'), new_MSB)
        fl.flWriteChannel(handle, memMap.get_register('LTSb'), new_LSB)
        sleep(.15)
        if (new_value < 1100 or new_value > 1800):
            print("Center frequency was not matched")
            return
        reg64 = fl.flReadChannel(handle, memMap.get_register('PDI'))
        print(new_value, MSB, new_MSB, LSB, new_LSB, "Power level: ", reg64)
    print("matched center frequency")
Пример #4
0
    def FPGA_init(self):
        # SPI CS default to high
        fl.flWriteChannel(self.handle, self.FIFO_GPIO_WR, bytearray([0xFF]))
        time.sleep(0.1)

        self.initDAC()

        time.sleep(0.1)
Пример #5
0
def powerOff(handle, channelName):
    """
    Sends binary signal to a FPGA through specified channel to power off device at that location.
    Assumes communication has been opened.

    Args: 
        handle: An opaque reference to an internal structure representing the connection.
        channelName(string): Name of location to power off
    """

    fl.flWriteChannel(handle, mmap.KEY_TO_LOC[channelName], 0x0F)
Пример #6
0
def encrypt_and_write_bytes(handle, channel, numBytes, data):
    send = []
    p = encrypt(data)
    for i in range(numBytes):
        eight_bits = p & 0xff
        send.append(eight_bits)
        p = p >> 8

    for num in send:
        fl.flWriteChannel(handle, channel, num)
        fl.flSleep(50)
Пример #7
0
    def setPPM_M(self, M):
        #Depreciated command! Only use if using old FPGA image!
        self.M = M

        binval = struct.pack(">H", M)
        fl.flWriteChannel(self.handle, self.FIFO_ASYNC_WR,
                          bytearray([0x80, 0x00, binval[0]]))
        fl.flWriteChannel(self.handle, self.FIFO_ASYNC_WR,
                          bytearray([0x80, 0x01, binval[1]]))

        # Configure the PRBS bits-per-symbol, regardless of whether PRBS is active
        self.setBitsPerSymbol()
Пример #8
0
def update_SPI(handle, channels, byte_array):
    """
    Updates SPI

    Args:
        handle: An opaque reference to an internal structure representing the connection.
        channels(list): channles to be used as conduits
        byte_array(list): list of bytes
    """
    MSB_channel = channels[0]
    LSB_channel = channels[1]
    fl.flWriteChannel(handle, MSB_channel, byte_array[0])
    fl.flWriteChannel(handle, LSB_channel, byte_array[1])
Пример #9
0
    def usePRBS(self, turn_on_prbs=True):

        if turn_on_prbs:
            # First, we need to set the bits-per-symbol, this will be calculated from existing M
            self.setBitsPerSymbol()

            # Switch data source to PRBS
            fl.flWriteChannel(self.handle, self.FIFO_ASYNC_WR,
                              bytearray([0x80, 0x11, 0x01]))

        else:
            # Disable PRBS, causes modulator to send all "zero" symbols
            fl.flWriteChannel(self.handle, self.FIFO_ASYNC_WR,
                              bytearray([0x80, 0x11, 0x00]))
Пример #10
0
    def setLaserCurrent(self, comm_current):
        
        #Current Consumption
        #MSB_channel = 26    #LCCa
        MSB_channel = self.getMemMap().getAddress('LCCa')
        #LSB_channel = 27    #LCCb
        LSB_channel = self.getMemMap().getAddress('LCCb')

        #Convert commanded current to bytes
        code = comm_current/(4.096*1.1*((1/6.81)+(1/16500)))*4096
        first_byte, second_byte = self.code2bytes(code)

        fl.flWriteChannel(self.handle,MSB_channel,first_byte)      #writes bytes to channel
        fl.flWriteChannel(self.handle,LSB_channel,second_byte)
Пример #11
0
def setTemp(handle, code):

    MSB_channel = 1
    LSB_channel = 2

    #Convert uA to byte assignments
    code = setpoint  #finish equation
    first_byte = code / 256
    second_byte = code % 256

    fl.flWriteChannel(handle, MSB_channel,
                      first_byte)  #writes bytes to channel
    fl.flWriteChannel(handle, LSB_channel, second_byte)
    print("Temp set to : " + str(code))
Пример #12
0
    def setLaserCurrent(self, comm_current):
        
        #Current Consumption
        #MSB_channel = 3    #LBCa
        MSB_channel = self.getMemMap().getAddress('LBCa')
        #LSB_channel = 4    #LBCb
        LSB_channel = self.getMemMap().getAddress('LBCb')

        #Convert commanded current to bytes
	#What are the units of this calculation??	
        code = comm_current/(4.096*1.1*((1/6.81)+(1/16500)))*4096
        first_byte, second_byte = self.code2bytes(code)

        fl.flWriteChannel(self.handle,MSB_channel,first_byte)      #writes bytes to channel
        fl.flWriteChannel(self.handle,LSB_channel,second_byte)
Пример #13
0
 def setBitsPerSymbol(self, bps=None):
     """ Sets the number of PRBS bits per symbol. If not specified, calculate from M."""
     if bps == None:
         # Not specified, so calculate from M
         try:
             # Calculate number of bits per symbol, based on setting for M
             # ***floor*** is used to guarantee that there is an active slot in each symbol,
             # for non-power of 2 settings for M, this is desirable as it prevents empty slots
             bps = int(math.floor(math.log(self.M, 2)))
         except NameError:
             # If we get here, it means that M has not yet been configured
             raise "Configure M before enabling PRBS"
     if bps > 16 or bps < 2:
         raise "Bits per symbol invalue, must be in range 2-16"
     fl.flWriteChannel(self.handle, self.FIFO_ASYNC_WR,
                       bytearray([0x80, 0x12, bps]))
Пример #14
0
 def fill_fifo(self):
     count = 0
     end = 2048
     while (count != len(self.bytes)):
         fifo_space = 2048 - (
             (0x07 & fl.flReadChannel(
                 self.handle, self.memory.get_register('fff')) << 8) +
             fl.flReadChannel(self.handle, self.memory.get_register('dfp')))
         if (fifo_space > 0):
             end += fifo_space
             if (end > len(self.bytes)):
                 end = len(self.bytes)
             fl.flWriteChannel(self.handle, memMap.get_register('dat'),
                               bytearray(self.bytes[count:end]))
             print('Data FIFO Pointer = ' + str(
                 fl.flReadChannel(self.handle,
                                  self.memory.get_register('dfp'))))
             count = end
Пример #15
0
    def transfer(self, addr_in, is_write, values):

        # Prepare data
        iter_input = zip(addr_in, is_write, values)

        # Run transfer
        values_out = []
        for addr, w_f, val in iter_input:
            if w_f:
                fl.flWriteChannel(self.handle, addr, byte[num])
                values_out.append(None)
            else:
                values_out.append(fl.flReadChannel(self.handle, addr))

        #no error check for USB
        errors = [0] * len(addr_in)

        return errors, values_out
Пример #16
0
def enable_int_ref(handle):
    fl.flWriteChannel(handle, 5, 0x38)
    sleep(0.001)
    fl.flWriteChannel(handle, 6, 0)
    sleep(0.001)
    fl.flWriteChannel(handle, 7, 0x01)
    return
Пример #17
0
def reset(handle):
    fl.flWriteChannel(handle, 8, 0x28)
    sleep(0.001)
    fl.flWriteChannel(handle, 9, 0)
    sleep(0.001)
    fl.flWriteChannel(handle, 10, 0x01)
    return
Пример #18
0
def write_PD_dac(handle, addr, value):
    fl.flWriteChannel(handle, 5, addr & 0x7)
    sleep(0.001)
    fl.flWriteChannel(handle, 6, (value & 0xFF00) >> 8)
    sleep(0.001)
    fl.flWriteChannel(handle, 7, value & 0xFF)
    return
Пример #19
0
def enable_all_outputs(handle):
    fl.flWriteChannel(handle, 5, 0x20)
    sleep(0.001)
    fl.flWriteChannel(handle, 6, 0)
    sleep(0.001)
    fl.flWriteChannel(handle, 7, 0x0F)
    return
Пример #20
0
def update_PD_dac(handle):
    fl.flWriteChannel(handle, 5, 0x0F)
    sleep(0.001)
    fl.flWriteChannel(handle, 6, 0)
    sleep(0.001)
    fl.flWriteChannel(handle, 7, 0)
    return
Пример #21
0
def enable_int_ref(handle):
    fl.flWriteChannel(handle, 8, 0x38)
    sleep(0.001)
    fl.flWriteChannel(handle, 9, 0)
    sleep(0.001)
    fl.flWriteChannel(handle, 10, 0x01)
    return
Пример #22
0
def update_dac(handle):
    fl.flWriteChannel(handle, 8, 0x0F)
    sleep(0.001)
    fl.flWriteChannel(handle, 9, 0)
    sleep(0.001)
    fl.flWriteChannel(handle, 10, 0)
    return
Пример #23
0
def enable_all_dacs(handle):
    fl.flWriteChannel(handle, 8, 0x20)
    sleep(0.001)
    fl.flWriteChannel(handle, 9, 0)
    sleep(0.001)
    fl.flWriteChannel(handle, 10, 0x0F)
    return
Пример #24
0
def enable_sw_ldac(handle):
    fl.flWriteChannel(handle, 8, 0x30)
    sleep(0.001)
    fl.flWriteChannel(handle, 9, 0)
    sleep(0.001)
    fl.flWriteChannel(handle, 10, 0)
    return
Пример #25
0
def write_dac(handle, addr, value):
    fl.flWriteChannel(handle, 8, addr & 0x7)
    sleep(0.001)
    fl.flWriteChannel(handle, 9, (value & 0xFF00) >> 8)
    sleep(0.001)
    fl.flWriteChannel(handle, 10, value & 0xFF)
    return
Пример #26
0
    def test_write(self, channel, data):
        """
		Tests writing to a specified location in mem map using the channel and then checks the response of the board

		Args:
			channel(int): counduit channel to communicate to fpga board
			data(): data to be written to fpga board through specified channel
		Returns:
			(boolean): result from test_read
		"""

        fl.flWriteChannel(self.handle, channel, data)
        #not sure how to format data yet to test a read to loc that was written to
        #but the idea should be similar to this
        return self.test_read(channel, data)

    # def test(self, progConfig):
    # 	"""
    # 	Main function to test reading and writing data to and from various addresses on the FPGA board

    # 	Args:
    # 		progConfig(): file to configure FPGA board
    # 	Returns:
    # 		res(list): list containig reports of passed and failed tests
    # 	"""

    # 	res = []
    # 	ro = [(key, val[0]) for key in self.addresses for val in self.addresses[key] if val[1] == 'ro'] #creates tuples of read only locs with addr, (;NAME', addr)
    # 	rw = [(key, val[0]) for key in self.addresses for val in self.addresses[key] if val[1] == 'rw'] #creates tuples of read/write locs with addr, ('NAME', addr)

    # 	#fl.flLoadStandardFirmware(self.fpga.handle, progConfig)
    # 	if fl.IsFPGARunning(self.handle):
    # 		pass
    # 		#need to check all mem map locs and either test rw or ro
    # 		#then append ('P', 'Pass report'), or ('F', 'Fail report') to res
    # 	return res


# :d
Пример #27
0
    def setLaserTemp(self, comm_temp):
        
        #Temp Set Point
        #MSB_channel = 23    #LTSa
        MSB_channel = self.getMemMap().getAddress('LTSa')  
        #LSB_channel = 24    #LTSb
        LSB_channel = self.getMemMap().getAddress('LTSb')

        #TODO Constants are estimated; may need to verify with vendor
        R_known = 10000
        Vcc = 0.8
        B = 3900
        R_0 = 10000
        T_0 = 25 
        
        #converts input/commanded temp (comm_temp) to voltage
        V_set = Vcc/(((m.exp(B/comm_temp)*(R_0 * m.exp(-B/T_0)))/R_known)+1)
        V_code = self.voltage2code(V_set) #convert voltage to code
        fb, sb = self.code2byte(V_code) #convert code to bytes
        
        fl.flWriteChannel(self.handle,MSB_channel, fb)
        fl.flWriteChannel(self.handle,LSB_channel, sb)
Пример #28
0
def enable_int_ref(handle, dac):
    print(dac)
    fl.flWriteChannel(handle, dac[0], 0x38)
    sleep(0.1)
    fl.flWriteChannel(handle, dac[1], 0)
    sleep(0.1)
    fl.flWriteChannel(handle, dac[2], 0x01)
    return
Пример #29
0
def enable_all_dacs(handle, dac):
    print(dac)
    fl.flWriteChannel(handle, dac[0], 0x20)
    sleep(0.1)
    fl.flWriteChannel(handle, dac[1], 0)
    sleep(0.1)
    fl.flWriteChannel(handle, dac[2], 0x0F)
    return
Пример #30
0
def enable_sw_ldac(handle, dac):
    print(dac)
    fl.flWriteChannel(handle, dac[0], 0x30)
    sleep(0.1)
    fl.flWriteChannel(handle, dac[1], 0)
    sleep(0.1)
    fl.flWriteChannel(handle, dac[2], 0)
    return
Пример #31
0
            )

    if argList.p:
        progConfig = argList.p[0]
        print("Programming device with config {}...".format(progConfig))
        if isNeroCapable:
            fl.flProgram(handle, progConfig)
        else:
            raise fl.FLException("Device program requested but device at {} does not support NeroProg".format(vp))

    if argList.f and not (isCommCapable):
        raise fl.FLException("Data file load requested but device at {} does not support CommFPGA".format(vp))

    if isCommCapable and fl.flIsFPGARunning(handle):
        print("Zeroing R1 & R2...")
        fl.flWriteChannel(handle, 0x01, 0x00)
        fl.flWriteChannel(handle, 0x02, 0x00)
        if argList.f:
            dataFile = argList.f[0]
            print("Writing {} to FPGALink device {}...".format(dataFile, vp))
            for chunk in readFile(dataFile):
                fl.flWriteChannelAsync(handle, 0x00, chunk)

        print("Reading channel 0...")
        print("Got 0x{:02X}".format(fl.flReadChannel(handle, 0x00)))
        print("Reading channel 1...")
        print("Got 0x{:02X}".format(fl.flReadChannel(handle, 0x01)))
        print("Reading channel 2...")
        print("Got 0x{:02X}".format(fl.flReadChannel(handle, 0x02)))

except fl.FLException as ex:
Пример #32
0
        " ".join(["{:02X}".format(b) for b in bs])))
    fl.progClose(conn)

    print("jtagScanChain(): {")
    for idCode in fl.jtagScanChain(conn, PROG_CONFIG):
        print("  0x{:08X}".format(idCode))
    print("}")

    print("flProgram()...")
    fl.flProgram(conn, "J:{}:../../../../hdlmake/apps/makestuff/swled/cksum/vhdl/fpga.xsvf".format(PROG_CONFIG))
    print("...done.")

    fl.flSelectConduit(conn, CONDUIT)
    print("flIsFPGARunning(): {}".format(fl.flIsFPGARunning(conn)))

    fl.flWriteChannel(conn, 0, BYTE_ARRAY)

    bs = fl.flReadChannel(conn, 1, 16)
    print("flReadChannel(1, 16) got {} bytes: {{\n  {}\n}}".format(
        len(bs),
        " ".join(["{:02X}".format(b) for b in bs])))
    
    print("flReadChannel(2) got {:02X}".format(fl.flReadChannel(conn, 2)))

    fl.flReadChannelAsyncSubmit(conn, 0, 4)
    fl.flReadChannelAsyncSubmit(conn, 1, 8)
    fl.flReadChannelAsyncSubmit(conn, 2, 16)
    for i in range(3):
        bs = fl.flReadChannelAsyncAwait(conn)
        print("flReadChannelAsyncAwait() got {} bytes: {{\n  {}\n}}".format(
            len(bs),