]> jspc29.x-matter.uni-frankfurt.de Git - mimosis_chain.git/commitdiff
add reset of MON registers master
authorMaps <maps@ikf>
Thu, 2 Apr 2026 10:54:18 +0000 (12:54 +0200)
committerMaps <maps@ikf>
Thu, 2 Apr 2026 10:54:54 +0000 (12:54 +0200)
add fpga input select option and BB conversion

scripts/cli/mimosis
scripts/modules/Mimosis/lib/Mimosis.pm

index d1065c8e60d8ef08f7fae86730ea7011de629eb2..c337bb8789c03acee00c401e4c95415f85d08a72 100755 (executable)
@@ -112,6 +112,7 @@ GLOBAL OPTIONS are:
     vnc         Open a vncviewer with preconfigured setup.
     adc         Read value of --channel
     initsca     Reset & Activate SCA
+    select      Set FPGA registers for correct data input
 
 For every <command> a short description is accessible with the -h and --help options.
 END_MESSAGE
@@ -415,7 +416,17 @@ END_MESSAGE
     exit 0;
 }
 
+sub help_select {
+  my $message = <<'END_MESSAGE';
+
+usage: mimosis select
+Configures the Trb to accept data from the given --feb sensor.
+
+END_MESSAGE
 
+    print $message;
+    exit 0;
+}
 
 sub help_adc {
   my $message = <<'END_MESSAGE';
@@ -720,6 +731,13 @@ my $res = GetOptions (
                     handler => \&help_mux,
                 }
             },
+        },    
+        select => {
+            options => {
+                'help|h' => {
+                    handler => \&help_select,
+                }
+            },
         },         
         vnc => {
             options => {
@@ -759,6 +777,17 @@ if( $res->{subcommand}[0] eq 'initsca' ) {
     Mimosis::initSca();
 }
 
+if( $res->{subcommand}[0] eq 'select' ) {
+  my $sensorInfo = Mimosis::getSensorInfo();
+  my $fpga = Mimosis::get_fpga();
+  my $links;
+     $links = 0 if $sensorInfo->{links} == 8;
+     $links = 1 if $sensorInfo->{links} == 4;
+     $links = 2 if $sensorInfo->{links} == 2;
+     $links = 3 if $sensorInfo->{links} == 1;
+  trb_register_loadbit($fpga,0x9011,0x1f,$sensorInfo->{dat});
+  trb_register_loadbit($fpga,0x9100,0x30000,$links << 16);
+}
 
 if( $res->{subcommand}[0] eq 'load' ) {
 
@@ -893,10 +922,14 @@ if( $res->{subcommand}[0] eq 'load' ) {
     if ($adcmap->{type} eq "PT") {
         Mimosis::writeScaRegister(0xae,0x14,0x60,0);        
         $ret = ($ret - 100)/0.385;
-        print "$ret °C\n";
+        printf("%.2f °C\n",$ret);
+        }
+    elsif ($ARGV[-1] eq "BB") {    
+        $ret = ($ret - 0.607*1600)/0.0809;
+        printf("%.1f mV (correct by -7.5V/V for any deviation of VSCA from 1.6V)\n",$ret);
         }
     else {
-        print "$ret mV\n";       
+        printf("%.1f mV\n",$ret);       
         }
     }
     
index fdd7c5bfbecd23cfef26f9454096d9ad4cd1460d..8ca0838b10d29e5bd0fbe12a9a89f4448de20aa9 100755 (executable)
@@ -69,7 +69,7 @@ our $adcmapping = {
 
 my $fpga = 0xffff;
 my $chipid = 0x1;
-my $i2cchannel = 0;
+my $i2cchannel = -1;
 my $singleAccess = 0;
 my $sleepVal1 = 1000;
 my $sleepVal2 = 1000000;
@@ -164,6 +164,9 @@ sub set_feb {
   set_chipid(0x100 + ($sensorInfo->{i2c} << 4) + $sensorInfo->{id});
   }
 
+sub getSensorInfo {
+  return $sensorInfo;
+}
 
 sub set_mbsStream {
   $mbsStream = $_[0] if defined $_[0];
@@ -212,7 +215,7 @@ sub set_collect_i2c_errors {
 sub get_collect_i2c_errors { return $collect_i2c_errors; }
 
 
-my %DAC = (
+our %DAC = (
     IBIAS => { ADDR => 0x40, MONITOR => 0x25, MONVAL => 1, TYPE => 'CURRENT', RESET => 0x40, },
     ITHR  => { ADDR => 0x41, MONITOR => 0x25, MONVAL => 3, TYPE => 'CURRENT', RESET => 0x34, },
     IDB   => { ADDR => 0x42, MONITOR => 0x25, MONVAL => 2, TYPE => 'CURRENT', RESET => 0x1c, },
@@ -233,7 +236,7 @@ my %DAC = (
 sub writeScaRegister {
   my ($tid,$channel,$command,$value) = @_;
   trb_register_write_mem( $fpga, 0xd602, 0, [($command << 16) + ($channel << 8) + $tid, $value, 0x4], 3);
-  usleep(10000);
+  usleep(200);
   
 }
    
@@ -325,7 +328,6 @@ sub getMuxChannel {
      $val += 0x20 if ($p eq 'AGND');
   my $ret = {MONITOR => 0x2f, MONVAL => $val};
   return $ret;
-   #IBIAS => { ADDR => 0x40, MONITOR => 0x25, MONVAL => 1, TYPE => 'CURRENT', RESET => 0x40, },
 }
 
 sub getAdcMap {
@@ -514,7 +516,7 @@ sub mimosis_i2c_command {
 }
 
 sub getSCAStatus {
-  usleep(1000);
+  usleep(1000); #GbE is slow enough
   my $ret = trb_register_read_mem($fpga,0xd60a,0,3);
   $fpga = (keys %$ret)[0] if $fpga >= 0xfe00;
   $ret = $ret->{$fpga};
@@ -610,14 +612,15 @@ sub mimosis_register_read {
 sub mimosis_instr_write {
 
     my ( $cmd ) = @_;
+    my $addr = ($chipid << 4) +  0x1;
 
     # CHIPID???
-    trb_register_write_mem(
-      $fpga, $trbMimRegWrMem, 0,
-      [ 0x0, ( $cmd << 8 ) + ($chipid<< 5) + ( 0x1 << 1 ), 0x1 ],
-      3 );
-
-     usleep($sleepVal1);
+    trb_register_write_mem(
+      $fpga, $trbMimRegWrMem, 0,
+      [ 0x0, ( $cmd << 8 ) + ($chipid<< 5) + ( 0x1 << 1 ), 0x1 ],
+      3 );
+    mimosis_i2c_command($addr,0, $cmd, 0, 1, 0);
+     usleep($sleepVal1);
 }
 
 
@@ -641,7 +644,7 @@ sub mimosis_load_file {
             mimosis_register_write(
               @$i[0], @$i[1] );
 
-            if( $printall ) {
+            if( $printall && $i2cchannel == -1) {
 
 #               printf( "%x %x %x\n",
 #                       $fpga, @$i[0], @$i[1] );
@@ -662,7 +665,7 @@ sub mimosis_load_file {
         }
     }
 
-    if ( $printall || $printwrong ) {
+    if ($i2cchannel == -1 && ( $printall || $printwrong )) {
 
         foreach my $i (@config) {
 
@@ -724,6 +727,8 @@ sub mimosis_scan_single_dac {
     my $fName = $name . $dac . ".csv";
     open( FH, '>', $fName ) or die $!;
 
+    mimosis_register_write( 0x25, 0 );
+    mimosis_register_write( 0x26, 0 );
     mimosis_register_write( $Mimosis::DAC{$dac}{'MONITOR'}, $Mimosis::DAC{$dac}{'MONVAL'} );
 
     for( my $set = $start;
@@ -748,6 +753,8 @@ sub mimosis_scan_single_dac {
         $Mimosis::DAC{$dac}{'ADDR'},
         $Mimosis::DAC{$dac}{'RESET'}
        );
+    mimosis_register_write( 0x25, 0 );
+    mimosis_register_write( 0x26, 0 );
 
     close(FH);