Commit 607392e3 authored by David Cussans's avatar David Cussans

Checking in changes on branch before merging with trunk

parent b9c58117
...@@ -88,7 +88,7 @@ class FmcTluI2c: ...@@ -88,7 +88,7 @@ class FmcTluI2c:
################# #################
### set DAC value ### set DAC value
################# #################
def set_dac(self,channel,value): def set_dac(self,channel,value , vrefOn = 0 , i2cSlaveAddrDac = 0x1F):
if channel<0 or channel>7: if channel<0 or channel>7:
print "set_dac ERROR: channel",channel,"not in range 0-7 (bit mask)" print "set_dac ERROR: channel",channel,"not in range 0-7 (bit mask)"
return -1 return -1
...@@ -96,10 +96,17 @@ class FmcTluI2c: ...@@ -96,10 +96,17 @@ class FmcTluI2c:
print "set_dac ERROR: value",value,"not in range 0-0xFFFF" print "set_dac ERROR: value",value,"not in range 0-0xFFFF"
return -1 return -1
# AD5665R chip with A0,A1 tied to ground # AD5665R chip with A0,A1 tied to ground
i2cSlaveAddrDac = 0x1F # seven bit address, binary 00011111 #i2cSlaveAddrDac = 0x1F # seven bit address, binary 00011111
print "I2C address of DAC = " , hex(i2cSlaveAddrDac)
dac = RawI2cAccess(self.i2cBusProps, i2cSlaveAddrDac) dac = RawI2cAccess(self.i2cBusProps, i2cSlaveAddrDac)
# enter vref-on mode: # if we want to enable internal voltage reference:
dac.write([0x38,0x00,0x01]) if vrefOn:
# enter vref-on mode:
print "Turning internal reference ON"
dac.write([0x38,0x00,0x01])
else:
print "Turning internal reference OFF"
dac.write([0x38,0x00,0x00])
# now set the actual value # now set the actual value
sequence=[( 0x18 + ( channel &0x7 ) ) , (value/256)&0xff , value&0xff] sequence=[( 0x18 + ( channel &0x7 ) ) , (value/256)&0xff , value&0xff]
print sequence print sequence
...@@ -110,13 +117,20 @@ class FmcTluI2c: ...@@ -110,13 +117,20 @@ class FmcTluI2c:
################################################## ##################################################
### convert required threshold voltage to DAC code ### convert required threshold voltage to DAC code
################################################## ##################################################
# WARNING THIS CODE IS BUGGY. def convert_voltage_to_dac(self,desiredVoltage, Vref=1.300):
def convert_voltage_to_dac(self,desiredVoltage):
Vref = 2.50
Vdaq = ( desiredVoltage + Vref ) / 2 Vdaq = ( desiredVoltage + Vref ) / 2
dacCode = 0xFFFF * Vdaq / Vref dacCode = 0xFFFF * Vdaq / Vref
return int(dacCode) return int(dacCode)
##################################################
### calculate the DAC code required and set DAC
##################################################
def set_threshold_voltage(self, channel , voltage ):
dacCode = self.convert_voltage_to_dac(voltage)
print " requested voltage, calculated DAC code = " , voltage , dacCode
self.set_dac(channel , dacCode)
#!/bin/bash #!/bin/bash
# #
export PYTHONPATH=~/PyChips_1_4_3/src export PYTHONPATH=~/PyChips_1_5_0_pre2A/src
python test_aida_tlu.py python test_aida_tlu.py
...@@ -14,13 +14,22 @@ boardi2c = FmcTluI2c(board) ...@@ -14,13 +14,22 @@ boardi2c = FmcTluI2c(board)
boardFirmware = board.read("FirmwareId") boardFirmware = board.read("FirmwareId")
print "Firmware version = " , hex(boardFirmware) print "Firmware version = " , hex(boardFirmware)
#scanResults = boardi2c.i2c_scan() print "Scanning I2C bus:"
#print scanResults scanResults = boardi2c.i2c_scan()
print scanResults
boardId = boardi2c.get_serial_number() boardId = boardi2c.get_serial_number()
print "FMC-TLU serial number = " , boardId print "FMC-TLU serial number = " , boardId
# Set thresholds at about -0.1V ( with 1MOhm f/back resistors ) #dacValue = 0x4100
print "Setting Vthreshold to about -0.1V" dacValue = 0xFFFF
boardi2c.set_dac(7,0x4100) print "Setting Vthreshold for all DACs. Code = ", dacValue
boardi2c.set_dac(7,dacValue)
dacValue = 0x6000
print "Setting Vthreshold for DAC 0. Code = ", dacValue
boardi2c.set_dac(0,dacValue)
# set DACs to -5mV
#boardi2c.set_threshold_voltage(7, -0.005)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment