use Getopt::Long;
use Data::Dumper;
use HADES::TrbNet;
+use Pod::Usage;
+
my $DEBUG = 0; #print debug messages
-my $LOAD_DIRECT = 1; #load settings and initialize
-my $WRITE_FILES = 1; #write configration files
+my $NO_LOAD_DIRECT = 0; #load settings and initialize
+my $NO_WRITE_FILES = 0; #write configration files
my @default_settings = (0x50010, #1:0 peaking 10ns, 3:2 gain 4mV, 4 internal bandgap
0x5011e, #2:0 tail1 R 27k, 5:3 tail1 C 10pF
my $addresses; #addr -> serial
my $settings; #addr -> @registers(0xa040-0xa07F)
+my $threshold = 0;
+my $help = 0;
+
+Getopt::Long::Configure(qw(gnu_getopt));
+GetOptions(
+ 'help|h' => \$help,
+ 'threshold|t=i' => \$threshold,
+ 'noload' => \$NO_LOAD_DIRECT,
+ 'nowrite' => \$NO_WRITE_FILES,
+ 'debug|d' => \$DEBUG,
+ ) ;
+pod2usage(1) if $help;
+
+$default_settings[3] = ($default_settings[3] & 0xfff00) + ($threshold & 0x7f);
+
+
###############################################################################
#Read baseline file and store values
###############################################################################
###############################################################################
#Load settings via trbcmd
###############################################################################
-if($LOAD_DIRECT) {
+if(! $NO_LOAD_DIRECT) {
foreach my $a (keys %$settings) {
trb_register_write_mem($a,0xa002,0,[0x4c504c40,0x4c704c60],2);#set register sets
trb_register_write_mem($a,0xa040,0,$settings->{$a},64); #write settings
###############################################################################
#Write configuration files
###############################################################################
-if($WRITE_FILES) {
+if(! $NO_WRITE_FILES) {
system("mkdir -p ../settings_tdc/auto");
system("rm ../settings_tdc/auto/????_10_pasttrec_settings.trbcmd");
foreach my $a (keys %$settings) {
}
+__END__
+
+=head1 NAME
+
+generate_pasttrec_settings.pl - Loads and configures Pasttrec settings, writes configuration files
+
+=head1 SYNOPSIS
+
+generate_pasttrec_settings.pl [options]
+
+ Options:
+ -h, --help brief help message
+ -t, --threshold N use threshold N
+ -d, --debug write debug messages
+ --noload don't load settings
+ --nowrite don't save settings
+
+=head1 OPTIONS
+
+=over 15
+
+=item B<-h | --help>
+
+Print a brief help message and exit.
+
+=item B<-t N | --threshold N>
+
+Use defined threshold (0..127) instead of default one
+
+=item B<--noload>
+
+Do not load settings to Pasttrec
+
+=item B<--nowrite>
+
+Do not write configuration files
+
+=item B<-d | --debug>
+
+Write debug messages
+
+=back
+
+=head1 DESCRIPTION
+
+
+=cut
use Getopt::Long;
use Data::Dumper;
use HADES::TrbNet;
+use Pod::Usage;
+use Time::HiRes qw(usleep);
my $DEBUG = 0; #print debug messages
-my $LOAD_DIRECT = 1; #load settings and initialize
-my $WRITE_FILES = 1; #write configration files
+
my @default_settings = (0x50010, #1:0 peaking 10ns, 3:2 gain 4mV, 4 internal bandgap
0x5011e, #2:0 tail1 R 27k, 5:3 tail1 C 10pF
0x50215, #2:0 tail1 R 23k, 5:3 tail1 C 0.9pF
- 0x50302, #6:0 global threshold 5=10mV
+ 0x50300, #6:0 global threshold 0
0x50400,0x50500,0x50600,0x50700,0x50800,0x50900,0x50a00,0x50b00,
0,0,0,0);
+my $counters;
+my $counters2;
+my $rates;
+my $baselines;
my $serials; #uid -> serial
my $addresses; #addr -> serial
my $settings; #addr -> @registers(0xa040-0xa07F)
+
+
+my $threshold = 0;
+my $help = 0;
+my $waittime = 1;
+Getopt::Long::Configure(qw(gnu_getopt));
+GetOptions(
+ 'help|h' => \$help,
+ 'threshold|t=i' => \$threshold,
+ 'debug|d' => \$DEBUG,
+ 'wait|w=f' => \$waittime,
+ ) ;
+pod2usage(1) if $help;
+
+$default_settings[3] = ($default_settings[3] & 0xfff00) + ($threshold & 0x7f);
+
trb_init_ports() or die trb_strerror();
+
+###############################################################################
+#Function to set pasttrec registers
+###############################################################################
sub init_pasttrecs {
- foreach my $a (keys %$addresses) {
- printf("board %04x found.\n",$a) if $DEBUG;
- trb_register_write_mem($a,0xa002,0,[0x4c304c30,0x4c304c30],2);#set register sets
- trb_register_write($a,0xaa00,1); #init Pasttrec
-
- foreach my $pt (0..3) {
- foreach my $i (0..11) {
- trb_register_write($a,0xa200+($pt << 4)+$i,$default_settings[$i]);
- }
+ trb_register_write_mem(0xfe91,0xa002,0,[0x4c304c30,0x4c304c30],2);#set register sets
+ trb_register_write(0xfe91,0xaa00,1); #init Pasttrec
+ trb_register_write_mem(0xfe91,0xa002,0,[0x4c704c60,0x4c504c40],2);#clean-up register sets
+
+ foreach my $pt (0..3) {
+ foreach my $i (0..11) {
+ trb_register_write(0xfe91,0xa200+($pt << 4)+$i,$default_settings[$i]);
}
}
}
sub set_baseline {
my $baseline = $_[0] // 0;
-
- foreach my $a (keys %$addresses) {
- printf("board %04x found.\n",$a) if $DEBUG;
- foreach my $pt (0..3) {
- foreach my $i (4..11) {
- trb_register_write($a,0xa200+($pt << 4)+$i,$default_settings[$i]+$baseline);
- }
+ foreach my $pt (0..3) {
+ foreach my $i (4..11) {
+ trb_register_write(0xfe91,0xa200+($pt << 4)+$i,$default_settings[$i]+$baseline);
}
}
}
}
}
- my $counters;
- my $counters2;
- my $rates;
- my $baselines;
###############################################################################
#Prepare Scan
###############################################################################
init_pasttrecs();
set_baseline(0);
+
+###############################################################################
+#Do Scan
+###############################################################################
foreach my $i (0..31) {
print("Set baseline $i\n");
set_baseline($i);
$counters = trb_register_read_mem(0xfe91,0xdfc0,0,32);
- sleep(1);
+ usleep($waittime*1E6);
$counters2 = trb_register_read_mem(0xfe91,0xdfc0,0,32);
foreach my $b (keys %{$counters}) {
}
}
-
+###############################################################################
+#Calculate means
+###############################################################################
foreach my $b (keys %{$rates}) {
foreach my $c (0..31) {
my $sum=0; my $tot=0;
if($tot==0) {$baselines->{$b}[$c]=0x63;}
}
}
-print Dumper $baselines;
+
+###############################################################################
+#Output Data
+###############################################################################
foreach my $b (sort keys %{$rates}) {
foreach my $p (0..3) {
printf(" %i\t%i\t%02i\t%02i\t%02i\t%02i\t%02i\t%02i\t%02i\t%02i\n",
}
}
+
+__END__
+
+=head1 NAME
+
+pasttrec_baseline_finder.pl - Scans baselines for all available Pasttrec chips
+
+=head1 SYNOPSIS
+
+pasttrec_baseline_finder.pl [options]
+
+ Options:
+ -h, --help brief help message
+ -t, --threshold N use threshold N
+ -d, --debug write debug messages
+
+=head1 OPTIONS
+
+=over 15
+
+=item B<-h | --help>
+
+Print a brief help message and exit.
+
+=item B<-t N | --threshold N>
+
+Use defined threshold (0..127) instead of default (0)
+
+=item B<-d | --debug>
+
+Write debug messages
+
+=item B<-w F| --wait F>
+
+Time to wait between two steps in seconds
+
+=back
+
+=head1 DESCRIPTION
+
+
+=cut