Commit 0878b3d6 authored by Theodor-Adrian Stana's avatar Theodor-Adrian Stana

sw: Changed pulsetest.py to avoid unnecessary user input

Also added channel frequency in output file.
Signed-off-by: Theodor-Adrian Stana's avatarTheodor Stana <t.stana@cern.ch>
parent d117dd4c
#===============================================================================
# CERN (BE-CO-HT)
# EI2C global definitions file
#===============================================================================
# author: Theodor Stana (t.stana@cern.ch)
#
# date of creation: 2014-03-05
#
# version: 1.0
#
# description:
#
# This module defines some global constants that are used by other scripts in
# the software suite. The constants and their definitions are in the code
# below.
#
#===============================================================================
# GNU LESSER GENERAL PUBLIC LICENSE
#===============================================================================
# This source file is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation; either version 2.1 of the License, or (at your
# option) any later version. This source is distributed in the hope that it
# will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Lesser General Public License for more details. You should have
# received a copy of the GNU Lesser General Public License along with this
# source; if not, download it from http://www.gnu.org/licenses/lgpl-2.1.html
#===============================================================================
# last changes:
# 2014-03-05 Theodor Stana File created
#===============================================================================
# TODO: -
#===============================================================================
# Hostname, username and password
HNAME = ""
USER = ""
PWD = ""
# Boolean to tell the ei2c.py module whether to create a dump file for the ELMA
# command replies
DUMP = False
...@@ -9,31 +9,31 @@ To run, you first need a CONV-TTL-BLO with a pulsetest gateware. Then: ...@@ -9,31 +9,31 @@ To run, you first need a CONV-TTL-BLO with a pulsetest gateware. Then:
%> ./pulsetest.py %> ./pulsetest.py
Slot no.: <give the slot number of the pulsetest CONV-TTL-BLO> Slot no.: <give the slot number of the pulsetest CONV-TTL-BLO>
Enable channel 1? (y/n) y
freq (Hz): 1 CH1 freq (Hz): <pulse frequency, number >0; 0 disables the channel >
Enable channel 2? (y/n) n CH2 freq (Hz): <pulse frequency, number >0; 0 disables the channel >
Enable channel 3? (y/n) n CH3 freq (Hz): <pulse frequency, number >0; 0 disables the channel >
Enable channel 4? (y/n) y CH4 freq (Hz): <pulse frequency, number >0; 0 disables the channel >
freq (Hz): 2 CH5 freq (Hz): <pulse frequency, number >0; 0 disables the channel >
Enable channel 5? (y/n) n CH6 freq (Hz): <pulse frequency, number >0; 0 disables the channel >
Enable channel 6? (y/n) y
freq (Hz): 4
How long would you like to run the test? How long would you like to run the test?
hrs: <give the number of hours> hrs: <give the number of hours>
mins: <give the number of minutes> mins: <give the number of minutes>
secs: <give the number of seconds> secs: <give the number of seconds>
For each channel you want to enable, it writes the frequency value to the For each channel you set a frequency value greater than 0, the script writes the
appropriate register in the pulsetest gateware, then sets the appropriate bits frequency value to the appropriate register in the pulsetest gateware, then sets
in the control register to enable pulse generation. For more information on the appropriate bits to the control register to enable pulse generation. For
the pulsetest gateware and the registers the script is writing, see: more information on the pulsetest gateware and the registers the script is
writing, see:
http://www.ohwr.org/projects/conv-ttl-blo-gw/wiki/pulsetest http://www.ohwr.org/projects/conv-ttl-blo-gw/wiki/pulsetest
Note that the output frequency is limited to 166 kHz _in software_, to avoid Note that the output pulse frequency is limited to the MAXFREQ value in the script
damage to the output transformers. _in software_, to avoid damage to the output stage MOSFET. The gateware employs
no limitation on this value.
When the script finishes execution, it will store the output to a file it When the script finishes execution, the script stores the output to a file it
specifies at the end. The name of this file is based on the date and time specifies at the end. The name of this file is based on the date and time
the script started execution. the script started execution.
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
# #
# date of creation: # date of creation:
# #
# version: 1.0 # version: 1.1
# #
# description: # description:
# This script works in conjunction with the pulsetest (v15.15) FPGA gateware # This script works in conjunction with the pulsetest (v15.15) FPGA gateware
...@@ -27,8 +27,10 @@ ...@@ -27,8 +27,10 @@
# source; if not, download it from http://www.gnu.org/licenses/lgpl-2.1.html # source; if not, download it from http://www.gnu.org/licenses/lgpl-2.1.html
#=============================================================================== #===============================================================================
# last changes: # last changes:
# 2014-07-02 Theodor Stana Setting the frequency to 0 Hz does not
# enable the channel
#=============================================================================== #===============================================================================
# TODO: - # TODO: -
#=============================================================================== #===============================================================================
import time import time
import sys import sys
...@@ -78,255 +80,246 @@ CTB_CLK_PER = 50*(10**(-9)) ...@@ -78,255 +80,246 @@ CTB_CLK_PER = 50*(10**(-9))
MAXFREQ = 5000 MAXFREQ = 5000
if __name__ == "__main__": if __name__ == "__main__":
# Get the IP, user and password for the ELMA crate from ei2cdefine.py # Get the IP, user and password for the ELMA crate from ei2cdefine.py
ip = ei2cdefine.HNAME ip = ei2cdefine.HNAME
user = ei2cdefine.USER user = ei2cdefine.USER
pwd = ei2cdefine.PWD pwd = ei2cdefine.PWD
testelma = EI2C(ip, user, pwd) testelma = EI2C(ip, user, pwd)
testelma.open() testelma.open()
# Ask for slot number # Ask for slot number
while 1: while 1:
try: try:
slot = raw_input("Slot no.: ") slot = raw_input("Slot no.: ")
slot = int(slot) slot = int(slot)
break break
except TypeError as e: except TypeError as e:
print("Please input a decimal slot number.") print("Please input a decimal slot number.")
except SlotError as e: except SlotError as e:
print(e.strerror) print(e.strerror)
except KeyboardInterrupt: except KeyboardInterrupt:
sys.exit(); sys.exit();
except: except:
print("Unexpected error: ", sys.exc_info()[0]) print("Unexpected error: ", sys.exc_info()[0])
bloid = testelma.read(slot, 0x00) bloid = testelma.read(slot, 0x00)
fwvers = testelma.read(slot, 0x04) & 0xFF fwvers = testelma.read(slot, 0x04) & 0xFF
if ( bloid != 0x54424c4f ) or ( fwvers != 0xff ): if ( bloid != 0x54424c4f ) or ( fwvers != 0xff ):
print "Wrong version number (0x%02x)" % fwvers print("Wrong version number (0x%02x)" % fwvers)
sys.exit(1) sys.exit(1)
testelma.write(slot, CHENREG, 0x00); testelma.write(slot, CHENREG, 0x00);
testelma.write(slot, CNTRST, 1); testelma.write(slot, CNTRST, 1);
testelma.write(slot, CNTRST, 0); testelma.write(slot, CNTRST, 0);
# First, setup the channel enable variable # First, setup the channel enable variable
chen = 0x00; chen = 0x00;
# Setup channel output pulse widths to 1.2us # Setup channel output pulse widths to 1.2us
testelma.write(slot, C1WDTHREG, 1.2*(10**(-6))/CTB_CLK_PER) testelma.write(slot, C1WDTHREG, 1.2*(10**(-6))/CTB_CLK_PER)
testelma.write(slot, C2WDTHREG, 1.2*(10**(-6))/CTB_CLK_PER) testelma.write(slot, C2WDTHREG, 1.2*(10**(-6))/CTB_CLK_PER)
testelma.write(slot, C3WDTHREG, 1.2*(10**(-6))/CTB_CLK_PER) testelma.write(slot, C3WDTHREG, 1.2*(10**(-6))/CTB_CLK_PER)
testelma.write(slot, C4WDTHREG, 1.2*(10**(-6))/CTB_CLK_PER) testelma.write(slot, C4WDTHREG, 1.2*(10**(-6))/CTB_CLK_PER)
testelma.write(slot, C5WDTHREG, 1.2*(10**(-6))/CTB_CLK_PER) testelma.write(slot, C5WDTHREG, 1.2*(10**(-6))/CTB_CLK_PER)
testelma.write(slot, C6WDTHREG, 1.2*(10**(-6))/CTB_CLK_PER) testelma.write(slot, C6WDTHREG, 1.2*(10**(-6))/CTB_CLK_PER)
# Setup channel delays and frequencies # Setup channel delays and frequencies
farr = [0,0,0,0,0,0] farr = [0,0,0,0,0,0]
inp = "" print("")
while (inp != 'y') and (inp != 'n'):
inp = raw_input("Enable channel 1? (y/n) ") freq = input("CH1 freq (Hz): ")
if (freq == 0):
if (inp == 'y'): print(" CH1 not enabled")
chen |= (1 << 0); else:
freq = input(" freq (Hz): ") chen |= (1 << 0)
if (freq > MAXFREQ): if (freq > MAXFREQ):
freq = MAXFREQ freq = MAXFREQ
print "Automatically setting channel frequency to %d Hz" % MAXFREQ print(" Automatically setting channel frequency to %d Hz" % MAXFREQ)
farr[0] = freq farr[0] = freq
freq = 1/(freq * CTB_CLK_PER) freq = 1/(freq * CTB_CLK_PER)
testelma.write(slot, C1FREQREG, int(freq)) testelma.write(slot, C1FREQREG, int(freq))
#print freq #print(freq)
#print hex(int(freq)) #print(hex(int(freq)))
inp = "" freq = input("CH2 freq (Hz): ")
while (inp != 'y') and (inp != 'n'): if (freq == 0):
inp = raw_input("Enable channel 2? (y/n) ") print(" CH2 not enabled")
else:
if (inp == 'y'): chen |= (1 << 1)
chen |= (1 << 1); if (freq > MAXFREQ):
freq = input(" freq (Hz): ") freq = MAXFREQ
if (freq > MAXFREQ): print(" Automatically setting channel frequency to %d Hz" % MAXFREQ)
freq = MAXFREQ farr[1] = freq
print "Automatically setting channel frequency to %d Hz" % MAXFREQ freq = 1/(freq * CTB_CLK_PER)
farr[1] = freq testelma.write(slot, C2FREQREG, int(freq))
freq = 1/(freq * CTB_CLK_PER) #print(freq)
testelma.write(slot, C2FREQREG, int(freq)) #print(hex(int(freq)))
#print freq
#print hex(int(freq)) freq = input("CH3 freq (Hz): ")
if (freq == 0):
inp = "" print(" CH3 not enabled")
while (inp != 'y') and (inp != 'n'): else:
inp = raw_input("Enable channel 3? (y/n) ") chen |= (1 << 2)
if (freq > MAXFREQ):
if (inp == 'y'): freq = MAXFREQ
chen |= (1 << 2); print(" Automatically setting channel frequency to %d Hz" % MAXFREQ)
freq = input(" freq (Hz): ") farr[2] = freq
if (freq > MAXFREQ): freq = 1/(freq * CTB_CLK_PER)
freq = MAXFREQ testelma.write(slot, C3FREQREG, int(freq))
print "Automatically setting channel frequency to %d Hz" % MAXFREQ #print(freq)
farr[2] = freq #print(hex(int(freq)))
freq = 1/(freq * CTB_CLK_PER)
testelma.write(slot, C3FREQREG, int(freq)) freq = input("CH4 freq (Hz): ")
#print freq if (freq == 0):
#print hex(int(freq)) print(" CH4 not enabled")
else:
inp = "" chen |= (1 << 3)
while (inp != 'y') and (inp != 'n'): if (freq > MAXFREQ):
inp = raw_input("Enable channel 4? (y/n) ") freq = MAXFREQ
print(" Automatically setting channel frequency to %d Hz" % MAXFREQ)
if (inp == 'y'): farr[3] = freq
chen |= (1 << 3); freq = 1/(freq * CTB_CLK_PER)
freq = input(" freq (Hz): ") testelma.write(slot, C4FREQREG, int(freq))
if (freq > MAXFREQ): #print(freq)
freq = MAXFREQ #print(hex(int(freq)))
print "Automatically setting channel frequency to %d Hz" % MAXFREQ
farr[3] = freq freq = input("CH5 freq (Hz): ")
freq = 1/(freq * CTB_CLK_PER) if (freq == 0):
testelma.write(slot, C4FREQREG, int(freq)) print(" CH5 not enabled")
#print freq else:
#print hex(int(freq)) chen |= (1 << 4);
if (freq > MAXFREQ):
inp = "" freq = MAXFREQ
while (inp != 'y') and (inp != 'n'): print(" Automatically setting channel frequency to %d Hz" % MAXFREQ)
inp = raw_input("Enable channel 5? (y/n) ") farr[4] = freq
freq = 1/(freq * CTB_CLK_PER)
if (inp == 'y'): testelma.write(slot, C5FREQREG, int(freq))
chen |= (1 << 4); #print(freq)
freq = input(" freq (Hz): ") #print(hex(int(freq)))
if (freq > MAXFREQ):
freq = MAXFREQ freq = input("CH6 freq (Hz): ")
print "Automatically setting channel frequency to %d Hz" % MAXFREQ if (freq == 0):
farr[4] = freq print(" CH6 not enabled")
freq = 1/(freq * CTB_CLK_PER) else:
testelma.write(slot, C5FREQREG, int(freq)) chen |= (1 << 5);
#print freq if (freq > MAXFREQ):
#print hex(int(freq)) freq = MAXFREQ
print(" Automatically setting channel frequency to %d Hz" % MAXFREQ)
inp = "" farr[5] = freq
while (inp != 'y') and (inp != 'n'): freq = 1/(freq * CTB_CLK_PER)
inp = raw_input("Enable channel 6? (y/n) ") testelma.write(slot, C6FREQREG, int(freq))
#print(freq)
if (inp == 'y'): #print(hex(int(freq)))
chen |= (1 << 5);
freq = input(" freq (Hz): ") # Ask how long to run the test
if (freq > MAXFREQ): print("")
freq = MAXFREQ print("How long would you like to run the test?")
print "Automatically setting channel frequency to %d" % MAXFREQ while 1:
farr[5] = freq try:
freq = 1/(freq * CTB_CLK_PER) hrs = raw_input(" hrs: ")
testelma.write(slot, C6FREQREG, int(freq)) hrs = int(hrs)
#print freq if (hrs < 0):
#print hex(int(freq)) raise Exception
break
# Ask how long to run the test except KeyboardInterrupt:
print "How long would you like to run the test?" sys.exit()
while 1: except:
try: print(" Hours must be a decimal number >= 0!")
hrs = raw_input(" hrs: ")
hrs = int(hrs) while 1:
if (hrs < 0): try:
raise Exception mins = raw_input(" mins: ")
break mins = int(mins)
except KeyboardInterrupt: if (mins < 0):
sys.exit() raise Exception
except: break
print " Hours must be a decimal number >= 0!" except KeyboardInterrupt:
sys.exit()
while 1: except:
try: print(" Minutes must be a decimal number >= 0!")
mins = raw_input(" mins: ")
mins = int(mins) while 1:
if (mins < 0): try:
raise Exception secs = raw_input(" secs: ")
break secs = int(secs)
except KeyboardInterrupt: if (secs < 0):
sys.exit() raise Exception
except: break
print " Minutes must be a decimal number >= 0!" except KeyboardInterrupt:
sys.exit()
while 1: except:
try: print(" Seconds must be a decimal number >= 0!")
secs = raw_input(" secs: ")
secs = int(secs) # Compute test end time according to current time
if (secs < 0): #
raise Exception # time.time() returns time since start of epoch
break # in seconds, so add secs, mins and hrs to that
except KeyboardInterrupt: start_time = time.time()
sys.exit() end_time = start_time + secs + 60*mins + 3600*hrs
except:
print " Seconds must be a decimal number >= 0!" # Generate output file named according to current time
fname = time.strftime("p-%Y-%m-%d-%Hh%M", time.localtime()) + ".txt"
# Compute test end time according to current time f = open(fname, "w")
#
# time.time() returns time since start of epoch # Write current time and start of test to output file
# in seconds, so add secs, mins and hrs to that f.write("------------------------------------------------------------\n")
start_time = time.time() f.write("%s: starting test\n" % time.strftime("%Y-%m-%d-%Hh%Mm%Ss", time.localtime()))
end_time = start_time + secs + 60*mins + 3600*hrs print("%s: starting test" % time.strftime("%Y-%m-%d-%Hh%Mm%Ss", time.localtime()))
f.write("------------------------------------------------------------\n")
# Generate output file named according to current time
fname = time.strftime("p-%Y-%m-%d-%Hh%M", time.localtime()) + ".txt" # Enable the needed channels and start generating pulses
f = open(fname, "w") testelma.write(slot, CHENREG, chen)
# Write current time and start of test to output file # Run test loop for the specified time
f.write("------------------------------------------------------------\r\n") while time.time() < end_time:
f.write("%s: starting test\n" % time.strftime("%Y-%m-%d-%Hh%Mm%Ss", time.localtime())) pass
print "%s: starting test" % time.strftime("%Y-%m-%d-%Hh%Mm%Ss", time.localtime())
f.write("------------------------------------------------------------\r\n") # Disable all channels
while (testelma.read(slot, CHENREG) != 0x00):
# Enable the needed channels and start generating pulses testelma.write(slot, CHENREG, 0x00)
testelma.write(slot, CHENREG, chen)
# Run test loop for the specified time f.write("%s: ending test\n" % time.strftime("%Y-%m-%d-%Hh%Mm%Ss", time.localtime()))
while time.time() < end_time: print("%s: ending test" % time.strftime("%Y-%m-%d-%Hh%Mm%Ss", time.localtime()))
pass f.write("------------------------------------------------------------\n")
secs = int(end_time - start_time)
# Disable all channels f.write("pulses sent and received:\n")
while (testelma.read(slot, CHENREG) != 0x00):
testelma.write(slot, CHENREG, 0x00) # Read counter registers
i = testelma.read(slot, C1IREG)
o = testelma.read(slot, C1OREG)
f.write("%s: ending test\n" % time.strftime("%Y-%m-%d-%Hh%Mm%Ss", time.localtime())) f.write("ch %d (f = %d) / i: %d / o: %d\n" % (1, farr[0], i, o))
print "%s: ending test" % time.strftime("%Y-%m-%d-%Hh%Mm%Ss", time.localtime())
f.write("------------------------------------------------------------\r\n") i = testelma.read(slot, C2IREG)
secs = int(end_time - start_time) o = testelma.read(slot, C2OREG)
f.write("pulses sent and received:\n") f.write("ch %d (f = %d) / i: %d / o: %d\n" % (2, farr[1], i, o))
# Read counter registers i = testelma.read(slot, C3IREG)
i = testelma.read(slot, C1IREG) o = testelma.read(slot, C3OREG)
o = testelma.read(slot, C1OREG) f.write("ch %d (f = %d) / i: %d / o: %d\n" % (3, farr[2], i, o))
f.write("ch %d / i: %d / o: %d\n" % (1, i, o))
i = testelma.read(slot, C4IREG)
i = testelma.read(slot, C2IREG) o = testelma.read(slot, C4OREG)
o = testelma.read(slot, C2OREG) f.write("ch %d (f = %d) / i: %d / o: %d\n" % (4, farr[3], i, o))
f.write("ch %d / i: %d / o: %d\n" % (2, i, o))
i = testelma.read(slot, C5IREG)
i = testelma.read(slot, C3IREG) o = testelma.read(slot, C5OREG)
o = testelma.read(slot, C3OREG) f.write("ch %d (f = %d) / i: %d / o: %d\n" % (5, farr[4], i, o))
f.write("ch %d / i: %d / o: %d\n" % (3, i, o))
i = testelma.read(slot, C6IREG)
i = testelma.read(slot, C4IREG) o = testelma.read(slot, C6OREG)
o = testelma.read(slot, C4OREG) f.write("ch %d (f = %d) / i: %d / o: %d\n" % (6, farr[5], i, o))
f.write("ch %d / i: %d / o: %d\n" % (4, i, o))
testelma.close()
i = testelma.read(slot, C5IREG)
o = testelma.read(slot, C5OREG) f.write("------------------------------------------------------------\n")
f.write("ch %d / i: %d / o: %d\n" % (5, i, o))
# Close output file
i = testelma.read(slot, C6IREG) f.close()
o = testelma.read(slot, C6OREG)
f.write("ch %d / i: %d / o: %d\n" % (6, i, o)) # Print output file name
print("")
testelma.close() print("Test results can be found in " + fname)
f.write("------------------------------------------------------------\r\n")
# Close output file
f.close()
# Print output file name
print
print "Test results can be found in " + fname
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