Commit 488c3cb3 authored by David Cussans's avatar David Cussans

debugging and improvments on readout scripts

parent 447f1b96
......@@ -26,7 +26,7 @@ ThrCount3R 0x0000004c 0xffffffff 1 0
PostVetoTriggersR 0x00000068 0xffffffff 1 0
PreVetoTriggersR 0x00000069 0xffffffff 1 0
InternalTriggerIntervalW 0x00000062 0xffffffff 1 1
InternalTriggerIntervalR 0x0000006A 0xffffffff 1 1
InternalTriggerIntervalR 0x0000006A 0xffffffff 1 0
TriggerPatternW 0x00000063 0xffffffff 0 1
TriggerPatternR 0x0000006B 0xffffffff 1 0
TriggerVetoW 0x00000064 0xffffffff 0 1
......
......@@ -36,7 +36,15 @@ def startTLU( uhalDevice , pychipsBoard , writeTimestamps):
print "TLU is running"
def initTLU( uhalDevice , pychipsBoard , listenForTelescopeShutter , pulseDelay , pulseStretch , DUTMask , triggerInterval , thresholdVoltage ):
def stopTLU( uhalDevice , pychipsBoard ):
print "Turning on software trigger veto"
pychipsBoard.write("TriggerVetoW",1)
print "TLU triggers are stopped"
def initTLU( uhalDevice , pychipsBoard , listenForTelescopeShutter , pulseDelay , pulseStretch , triggerPattern , DUTMask , ignoreDUTBusy , triggerInterval , thresholdVoltage ):
print "Setting up AIDA TLU \n"
......@@ -66,6 +74,7 @@ def initTLU( uhalDevice , pychipsBoard , listenForTelescopeShutter , pulseDelay
clockStatus = pychipsBoard.read("LogicClocksCSR")
print "Clock status ( should be 3 if all clocks locked ) = " , hex(clockStatus)
assert ( clockStatus == 3 ) , "Clocks in TLU FPGA are not locked. No point in continuing. Re-prgramme or power cycle board"
if resetClocks:
print "Resetting clocks"
......@@ -114,20 +123,27 @@ def initTLU( uhalDevice , pychipsBoard , listenForTelescopeShutter , pulseDelay
# Stop internal triggers until setup complete
pychipsBoard.write("InternalTriggerIntervalW",0)
print "Setting input trigger delay, units = 160MHz clock cycles"
pychipsBoard.write("PulseDelayW",pulseDelay)
pulseDelay = pychipsBoard.read("PulseDelayR")
print "Pulse delay was set to ", pulseDelay
print "Setting input coincidence window to ",pulseStretch,", units = 160MHz clock cycles , Four 5-bit values ( one per input ) packed in to 32-bit word"
pychipsBoard.write("PulseStretchW",int(pulseStretch))
pulseStretchR = pychipsBoard.read("PulseStretchR")
print "Pulse stretch was set to ", hex(pulseStretchR)
# assert (int(pulseStretch) == pulseStretchR) , "Pulse stretch read-back doesn't equal written value"
print "Setting input trigger delay to ",pulseDelay , ", units = 160MHz clock cycles , Four 5-bit values ( one per input ) packed in to 32-bit word"
pychipsBoard.write("PulseDelayW",int(pulseDelay))
pulseDelayR = pychipsBoard.read("PulseDelayR")
print "Pulse delay read back as ", hex(pulseDelayR)
print "Setting trigger pattern (for external triggers) to %08x . Two 16-bit patterns packed into 32 bit word " %(triggerPattern)
pychipsBoard.write("TriggerPatternW",int(triggerPattern))
triggerPatternR = pychipsBoard.read("TriggerPatternR")
print "Trigger pattern read back as %08x " % (triggerPatternR)
print "Setting input coincidence window, units = 160MHz clock cycles"
pychipsBoard.write("PulseStretchW",pulseStretch)
pulseDelay = pychipsBoard.read("PulseStretchR")
print "Pulse stretch was set to ", pulseStretch
print "Enabling DUT(s): Mask = " , DUTMask
pychipsBoard.write("DUTMaskW",DUTMask)
print "Enabling DUT(s): Mask = " , hex(DUTMask)
pychipsBoard.write("DUTMaskW",int(DUTMask))
DUTMaskR = pychipsBoard.read("DUTMaskR")
print "DUTMaskR = " , DUTMaskR
print "DUTMaskR = " , hex(DUTMaskR)
print "Set all DUT into AIDA mode"
pychipsBoard.write("DUTInterfaceModeW", 0xFF)
......@@ -148,12 +164,10 @@ def initTLU( uhalDevice , pychipsBoard , listenForTelescopeShutter , pulseDelay
IgnoreShutterVeto = pychipsBoard.read("IgnoreShutterVetoR")
print "IgnoreShutterVeto = " , IgnoreShutterVeto
#print "Ignore veto on DUT 0"
#pychipsBoard.write("IgnoreDUTBusyW",1)
print "Ignore veto by BUSY on all DUTs"
pychipsBoard.write("IgnoreDUTBusyW",0xF)
print "setting Ignore veto by DUT BUSY mask to " , hex(ignoreDUTBusy)
pychipsBoard.write("IgnoreDUTBusyW",int(ignoreDUTBusy))
IgnoreDUTBusy = pychipsBoard.read("IgnoreDUTBusyR")
print "IgnoreDUTBusyR = " , IgnoreDUTBusy
print "IgnoreDUTBusyR = " , hex(IgnoreDUTBusy)
#print "Enabling handshake: No-handshake"
#board.write("HandshakeTypeW",1)
......@@ -166,6 +180,6 @@ def initTLU( uhalDevice , pychipsBoard , listenForTelescopeShutter , pulseDelay
internalTriggerFreq = 160000.0/triggerInterval
print "Internal trigger frequency = " , internalTriggerFreq , " kHz"
pychipsBoard.write("InternalTriggerIntervalW",triggerInterval) #0->Internal pulse generator disabled. Any other value will generate pulses with a frequency of n*6.25ns
trigInterval = pychipsBoard.read("InternalTriggerIntervalR")
print "Trigger interval read back as ", trigInterval
trigIntervalR = pychipsBoard.read("InternalTriggerIntervalR")
print "Trigger interval read back as ", trigIntervalR
......@@ -12,7 +12,11 @@ import uhal
import sys
import time , datetime
import time
from datetime import datetime
from optparse import OptionParser
# For single character non-blocking input:
import select
......@@ -24,6 +28,35 @@ from initTLU import *
def isData():
return select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], [])
now = datetime.now().strftime('%Y-%m-%dT%H_%M_%S')
default_filename = '/data/tlu/tluData_' + now + '.txt.gz'
parser = OptionParser()
parser.add_option('-r','--rootFname',dest='rootFname',
default=default_filename,help='Path of output file')
parser.add_option('-o','--writeTimestamps',dest='writeTimestamps',
default=True,help='Set True to write timestamps to ROOT file')
parser.add_option('-p','--printTimestamps',dest='printTimestamps',
default=True,help='Set True to print timestamps to screen')
parser.add_option('-s','--listenForTelescopeShutter',dest='listenForTelescopeShutter',
default=False,help='Set True to veto triggers when shutter goes high')
parser.add_option('-d','--pulseDelay',dest='pulseDelay', type=int,
default=0x00,help='Delay added to input triggers. Four 5-bit numbers packed into 32-bt word, Units of 6.125ns')
parser.add_option('-w','--pulseStretch',dest='pulseStretch',type=int,
default=0x00,help='Width added to input triggers. Four 5-bit numbers packed into 32-bt word. Units of 6.125ns')
parser.add_option('-t','--triggerPattern',dest='triggerPattern',type=int,
default=0xFFFEFFFE,help='Pattern match to generate trigger. Two 16-bit words packed into 32-bit word.')
parser.add_option('-m','--DUTMask',dest='DUTMask',type=int,
default=0x01,help='Three-bit mask selecting which DUTs are active.')
parser.add_option('-y','--ignoreDUTBusy',dest='ignoreDUTBusy',type=int,
default=0x0F,help='Three-bit mask selecting which DUTs can veto triggers by setting BUSY high. Low = can veto, high = ignore busy.')
parser.add_option('-i','--triggerInterval',dest='triggerInterval',type=int,
default=0,help='Interval between internal trigers ( in units of 6.125ns ). Set to zero to turn off internal triggers')
parser.add_option('-v','--thresholdVoltage',dest='thresholdVoltage',
default=-0.2,help='Threshold voltage for TLU inputs ( units of volts)')
(options, args) = parser.parse_args(sys.argv[1:])
from ROOT import TFile, TTree
from ROOT import gROOT # , AddressOf
......@@ -56,22 +89,6 @@ tluEvtStruct = TLUEvtStruct()
print "Setting up AIDA TLU to supply clock and trigger to TORCH readout\n"
writeTimestamps = True
listenForTelescopeShutter = False
#TriggerInterval = 400000 # Units = 160MHz clock ticks.
#loopWait = 1.0 # polling interval ( seconds )
#TriggerInterval = 16000 # Units = 160MHz clock ticks.
#TriggerInterval = 4000 # Units = 160MHz clock ticks.
TriggerInterval = 0 # Units = 160MHz clock ticks.
loopWait = 0.05 # polling interval ( seconds )
pulseDelay = 0 # between 0 and 31 in units of 160MHz clock.
pulseStretch = 4 # between 0 and 31 in units of 160MHz clock.
DUTMask = 1 # bit mask to indicate with DUT are active
writeTimestamps = True
printTimestamps = False
rootFname = "/data/tlu/OutputData.root"
# Point to board in uHAL
manager = uhal.ConnectionManager("file://./connection.xml")
hw = manager.getDevice("minitlu")
......@@ -83,16 +100,17 @@ bAddrTab = AddressTable("./aida_mini_tlu_addr_map.txt")
board = ChipsBusUdp(bAddrTab,"192.168.200.32",50001)
# Open Root file
f = TFile( rootFname, 'RECREATE' )
print "Opening ROOT file ",options.rootFname
f = TFile( options.rootFname, 'RECREATE' )
tree = TTree( 'T', 'TLU Data' )
#tree.Branch( 'tluInts', tluEvtStruct, 'Bufpos/i:HighWord/l:LowWord/l:EvtNumber/i:TimeStamp/l:EvtType/i:TrigsFired/i' )
tree.Branch( 'tluInts', tluEvtStruct, 'Bufpos/l:HighWord/l:LowWord/l:EvtNumber/l:TimeStamp/l:EvtType/l:TrigsFired/l' )
# Initialize TLU registers
initTLU( uhalDevice = hw, pychipsBoard = board, listenForTelescopeShutter = listenForTelescopeShutter, pulseDelay = pulseDelay, pulseStretch = pulseStretch, DUTMask = DUTMask, triggerInterval = TriggerInterval, thresholdVoltage =-0.2 )
initTLU( uhalDevice = hw, pychipsBoard = board, listenForTelescopeShutter = options.listenForTelescopeShutter, pulseDelay = options.pulseDelay, pulseStretch = options.pulseStretch, triggerPattern = options.triggerPattern , DUTMask = options.DUTMask, ignoreDUTBusy = options.ignoreDUTBusy , triggerInterval = options.triggerInterval, thresholdVoltage = options.thresholdVoltage )
loopWait = 0.1
oldEvtNumber = 0
oldPreVetotriggerCount = board.read("PreVetoTriggersR")
......@@ -115,13 +133,18 @@ while loopRunning:
if isData():
c = sys.stdin.read(1)
print "Got input: ", c
if c == 'q':
if c == 't':
loopRunning = False
print "Terminating loop"
elif c == 'c':
runStarted = True
print "Starting Run"
startTLU( uhalDevice = hw, pychipsBoard = board, writeTimestamps = writeTimestamps )
startTLU( uhalDevice = hw, pychipsBoard = board, writeTimestamps = options.writeTimestamps )
elif c == 'f':
# runStarted = True
print "Stopping triggers "
stopTLU( uhalDevice = hw, pychipsBoard = board )
if runStarted:
......@@ -179,7 +202,7 @@ while loopRunning:
trigsFired = (timestampData[ (evt*4) + 0] >> 16) & 0xFFF
if printTimestamps:
if options.printTimestamps:
print "bufferPos, highWord , lowWord , event-number , timestamp , evtType = %x %016x %016x %08x %012x %01x %03x" % ( evt , highWord , lowWord, evtNumber , timeStamp , evtType , trigsFired)
tluEvtStruct.uBufpos = evt
......
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