Преглед на файлове

kalypso 2v5 GUI 1024 pixel version

Meghana преди 3 години
ревизия
2f58a89825
променени са 64 файла, в които са добавени 5855 реда и са изтрити 0 реда
  1. 98 0
      AXI_ReConf.sh
  2. 4 0
      AXI_conf.sh
  3. 13 0
      AXI_read.sh
  4. 147 0
      AXI_reset.sh
  5. 1560 0
      GUI.py
  6. 11 0
      G_ON.sh
  7. 258 0
      adc_config.sh
  8. 269 0
      adc_config_2_offset.sh
  9. 80 0
      adc_config_2_offset_old.sh
  10. 269 0
      adc_offset_at_0_delay.sh
  11. 269 0
      adc_offset_remove.sh
  12. 48 0
      align_clock.sh
  13. 47 0
      align_clock_b.sh
  14. 37 0
      align_clock_b_revertback_1ns.sh
  15. 29 0
      auto_offset_removal.sh
  16. BIN
      bench.out
  17. BIN
      bench_for_offset.out
  18. 10 0
      clk_shifter.sh
  19. 265 0
      digital_gain.sh
  20. 10 0
      digital_high_pass.sh
  21. 39 0
      dma.sh
  22. 4 0
      dumpFile.sh
  23. 169 0
      ext_trigger_readout.sh
  24. 85 0
      full_sequence.sh
  25. 88 0
      full_sequence_ex_rf.sh
  26. 8 0
      iodelay_set.sh
  27. 27 0
      jesd_cnt_test.sh
  28. 212 0
      kalypso_registers.json
  29. 9 0
      misc_scripts/Set_ADC_1_Delay.sh
  30. 13 0
      misc_scripts/Set_ADC_Delay.sh
  31. 81 0
      misc_scripts/full_sequence_pcbtest.sh
  32. 47 0
      misc_scripts/normal_acq_loop.sh
  33. 43 0
      misc_scripts/readout.sh
  34. 32 0
      misc_scripts/readout_GUI.sh
  35. 46 0
      misc_scripts/set_gotthard_0.sh
  36. 45 0
      misc_scripts/set_gotthard_1.sh
  37. 43 0
      misc_scripts/set_gotthard_5.sh
  38. 47 0
      misc_scripts/set_vb_col.sh
  39. 33 0
      misc_scripts/set_vin_cm.sh
  40. 72 0
      normal_acq.sh
  41. 252 0
      offset_value_gen.py
  42. 97 0
      pll_62_5_KARA.sh
  43. 8 0
      pll_sync.sh
  44. 10 0
      poweroff.sh
  45. 12 0
      read.sh
  46. 100 0
      read_data.py
  47. 16 0
      read_reg.sh
  48. 6 0
      read_status.sh
  49. 31 0
      reload.sh
  50. 84 0
      reset.sh
  51. 84 0
      reset_ex_rf.sh
  52. 84 0
      set_dac_left.sh
  53. 124 0
      set_dac_voltages_25.sh
  54. 11 0
      soft_reset.sh
  55. 6 0
      status.sh
  56. 175 0
      strip_data.py
  57. 13 0
      sync_adcs.sh
  58. 45 0
      timescan.sh
  59. 0 0
      timescan_data.out
  60. 38 0
      timescan_plot.py
  61. 15 0
      tx_trig_adcs.sh
  62. 15 0
      tx_trig_adcs_left.sh
  63. 15 0
      tx_trig_adcs_right.sh
  64. 47 0
      write_csv.py

+ 98 - 0
AXI_ReConf.sh

@@ -0,0 +1,98 @@
+#! /bin/bash
+
+echo "*** Re-configure the whole AXI MASTER ***"
+
+pci -w 0x9114 0x08
+sleep 0.01
+pci -w 0x9118 0x01
+sleep 0.01
+value=`pci -r 0x911C -s1`
+echo "Value = $value "
+sleep 0.1
+
+pci -w 0x9114 0x0C
+sleep 0.01
+pci -w 0x9118 0x00
+sleep 0.01
+value=`pci -r 0x911C -s1`
+echo "Value = $value "
+sleep 0.1
+
+pci -w 0x9114 0x10
+sleep 0.01
+pci -w 0x9118 0x01
+sleep 0.01
+value=`pci -r 0x911C -s1`
+echo "Value = $value "
+sleep 0.1
+
+pci -w 0x9114 0x18
+sleep 0.01
+pci -w 0x9118 0x00
+sleep 0.01
+value=`pci -r 0x911C -s1`
+echo "Value = $value "
+sleep 0.1
+
+pci -w 0x9114 0x20
+sleep 0.01
+pci -w 0x9118 0x07 # was 07
+sleep 0.01
+value=`pci -r 0x911C -s1`
+echo "Value = $value "
+sleep 0.1
+
+pci -w 0x9114 0x24
+sleep 0.01
+pci -w 0x9118 0x0F   # was F before
+sleep 0.01
+value=`pci -r 0x911C -s1`
+echo "Frame per mulfi-frame = $value "
+sleep 0.1
+
+
+pci -w 0x9114 0x2C
+sleep 0.01
+pci -w 0x9118 0x2
+sleep 0.01
+value=`pci -r 0x911C -s1`
+echo "Sub Class Value = $value "
+sleep 0.1
+
+pci -w 0x9114 0x30
+sleep 0.01
+pci -w 0x9118 0x01 # dummy writing operation #
+pci -w 0x9118 0x00
+sleep 0.01
+value=`pci -r 0x911C -s1`
+echo "Value = $value "
+sleep 0.1
+
+pci -w 0x9114 0x34
+sleep 0.01
+pci -w 0x9118 0x01 # dummy writing operation # y
+pci -w 0x9118 0x00
+sleep 0.01
+value=`pci -r 0x911C -s1`
+echo "Value = $value "
+sleep 0.1
+
+pci -w 0x9114 0x28
+sleep 0.01
+pci -w 0x9118 0xF
+sleep 0.01
+value=`pci -r 0x911C -s1`
+echo "Value = $value "
+sleep 0.1
+
+pci -w 0x9114 0x04
+sleep 0.01
+pci -w 0x9118 0x01
+sleep 0.01
+value=`pci -r 0x911C -s1`
+echo "Value = $value "
+sleep 0.1
+
+
+
+echo "DONE ..."

+ 4 - 0
AXI_conf.sh

@@ -0,0 +1,4 @@
+
+echo "KALYPSO: AXI Master de- reset "
+pci -w 0x9040 0x200000
+sleep 0.1

+ 13 - 0
AXI_read.sh

@@ -0,0 +1,13 @@
+#! /bin/bash
+
+echo "*** READ the whole JESD AXI CORE REGISTRs ***"
+
+for add in {1..40};
+  do
+    pci -w 0x9114 0x$add
+    value=`pci -r 0x911C -s1`
+    echo "address $add, value = $value "
+  done
+
+echo " ...DONE..."
+

+ 147 - 0
AXI_reset.sh

@@ -0,0 +1,147 @@
+#! /bin/bash
+export PCILIB_MODEL=ipedma
+
+#echo "ADC & GOT: Turning on power..."
+#pci -w 9048 f0
+#sleep 0.1
+
+#pci -w 9048 ff
+#sleep 0.1
+
+#echo "KALYPSO: reset internal PLL"
+#pci -w 904C f
+#sleep 0.1
+
+#echo "KALYPSO: enable internal clock (WARNING: ONLY FOR DEBUGGING!)"
+#pci -w 904C 0
+#sleep 0.1
+
+#echo "KALYPSO: enable external RF-CLK"
+#pci -w 904C 1
+
+
+
+#echo "*DMA: START"
+#pci --stop-dma dma0r
+#sleep 0.2
+
+#pci --start-dma dma0r
+#sleep 0.2
+
+echo "RESET of the KALYPSO"
+pci -w 9040 0x800f0  
+
+
+echo "DE-RESET of the KALYPSO"
+pci -w 9040 0x0  
+
+echo "KALYPSO: Total Orbits"
+pci -w 0x9020 0x400
+sleep 0.1
+
+pci -w 0x9024 0
+sleep 0.1
+
+echo "*ONBOARD TRIG GEN: ON"
+pci -w 0x9044 0x2E
+sleep 0.01
+
+echo "GOTT: Integration Period"
+pci -w 0x9000 0x1
+sleep 0.01
+
+echo "GOTT: Integration Delay"
+pci -w 0x9004 0x0
+sleep 0.01
+
+echo "GOTT: Gain"
+pci -w 0x9010 0x02
+sleep 0.01
+
+
+#echo "KALYPSO: AXI Master de- reset "
+# pci -w 0x9040 0x200000
+#sleep 0.1
+#pci -w 0x9040 0x000021 -- original for reset Gotthard control to be consider later 
+#sleep 0.1
+
+# only control reg [0] and reg [5] for reset
+
+#pci -w 9040 0x000000
+#sleep 0.1
+
+
+
+
+# internal receiver reset
+#pci -w 0x9040 0x00000000
+#sleep 0.01
+#pci -w 0x9040 0x00000010
+#sleep 0.01
+#pci -w 0x9040 0x00000000
+#sleep 0.01
+
+
+
+#echo "*KALYPSO: Reset errors"
+#pci -w 0x9050 0x01
+#sleep 0.01
+#pci -w 0x9050 0x00
+#sleep 0.01
+
+
+
+#./PLL_jesd.sh
+#sleep 0.1
+
+
+
+
+
+#echo "*KALYPSO: Reset ADC ADS52J90"
+# pci -w 9040 0x00001000
+# sleep 0.1
+
+# pci -w 9040 0x00000000
+# sleep 0.1
+
+# reset ADC SPI (hardware reset)
+#echo "*KALYPSO: ADC Hardware reset"
+# control_reg [13]
+#pci -w 0x9040 0x00022000
+#sleep 0.01
+#pci -w 0x9040 0x00000000
+#sleep 0.01
+
+
+
+
+#echo "*KALYPSO: Configure ADC ADS52J90"
+#./spi_configure.sh
+
+
+#echo "*DMA: START"
+#pci --stop-dma dma0r
+#sleep 0.2
+
+#pci --start-dma dma0r
+#sleep 0.2
+
+
+
+
+#echo "*KALYPSO: DDR3 Enable Read"
+# control_reg [10]
+#pci -w 0x9040 0x00000400
+#sleep 0.01
+#pci -w 0x9040 0x00000000
+#sleep 0.01
+
+
+#echo "*DMA: Reading data..."
+#pci -r dma0 --multipacket -o test_data.out --timeout=1000000
+
+echo "write the number of samples to be acquired"
+pci -w 9108 0x1000  
+
+./status.sh

+ 1560 - 0
GUI.py

@@ -0,0 +1,1560 @@
+#!/usr/bin/env python
+
+from PyQt4 import QtCore, QtGui
+from QLed import QLed
+from PyQt4.QtGui import QApplication, QWidget, QPainter, QGridLayout, QSizePolicy, QStyleOption
+from PyQt4.QtCore import pyqtSignal, Qt, QSize, QTimer, QByteArray, QRectF, pyqtProperty
+from PyQt4.QtSvg import QSvgRenderer
+
+
+import pyqtgraph as pg
+import numpy as np
+from pyqtgraph.Qt import QtCore, QtGui
+from pyqtgraph import PlotWidget
+import time
+import datetime
+import os
+import os.path
+import subprocess
+import timescan_plot
+import strip_data
+import csv
+import json
+
+
+##import elog_eosd
+
+### VALUES TO DISPLAY ##################
+NUMBER_PIXELS   = 1024
+OFFSET          = 0x0
+#########################################
+
+try:
+    _fromUtf8 = QtCore.QString.fromUtf8
+except AttributeError:
+    def _fromUtf8(s):
+        return s
+
+try:
+    _encoding = QtGui.QApplication.UnicodeUTF8
+    def _translate(context, text, disambig):
+        return QtGui.QApplication.translate(context, text, disambig, _encoding)
+except AttributeError:
+    def _translate(context, text, disambig):
+        return QtGui.QApplication.translate(context, text, disambig)
+
+class Ui_MainWindow(object):
+    def setupUi(self, MainWindow):
+        MainWindow.setObjectName(_fromUtf8("MainWindow"))
+        MainWindow.resize(995, 662)
+        self.centralwidget = QtGui.QWidget(MainWindow)
+        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
+        self.verticalLayout_3 = QtGui.QVBoxLayout(self.centralwidget)
+        self.verticalLayout_3.setObjectName(_fromUtf8("verticalLayout_3"))
+
+        self.verticalLayout = QtGui.QVBoxLayout()
+        self.verticalLayout.setSizeConstraint(QtGui.QLayout.SetMaximumSize)
+        self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
+
+        # Define TABS
+        self.tab_widget = QtGui.QTabWidget()
+        self.tab1 = QtGui.QWidget()
+        self.tab2 = QtGui.QWidget()
+
+        self.t1_vertical = QtGui.QVBoxLayout(self.tab1)
+        self.t2_vertical = QtGui.QVBoxLayout(self.tab2)
+
+        self.tab_widget.addTab(self.tab1, "1D")
+        self.tab_widget.addTab(self.tab2, "2D")
+
+        # TAB for live view
+        self.graphicsView = PlotWidget(background='k')
+        self.graphicsView.setGeometry(QtCore.QRect(10, 60, 800, 500))
+        self.graphicsView.setObjectName(_fromUtf8("graphicsView"))
+        self.t1_vertical.addWidget(self.graphicsView)
+
+        # TAB for modulation view
+        self.imView = pg.GraphicsLayoutWidget()
+        self.modplot = self.imView.addPlot()
+        self.img = pg.ImageItem()
+        self.modplot.addItem(self.img)
+
+        self.imView.nextColumn()
+        self.hist = pg.HistogramLUTItem()
+        self.hist.setImageItem(self.img)
+        self.hist.setHistogramRange(0,2.0)
+        self.imView.addItem(self.hist)
+
+        #self.img.setImage(data)
+        self.hist.setLevels(0, 2)
+        self.modplot.autoRange()
+
+        self.imView.setGeometry(QtCore.QRect(10, 60, 800, 500))
+        self.imView.setObjectName(_fromUtf8("imView"))
+        self.t2_vertical.addWidget(self.imView)
+        self.verticalLayout.addWidget(self.tab_widget)
+
+        ## Lower part
+        self.horizontalLayout = QtGui.QHBoxLayout()
+        self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
+
+        self.label_disp_settings = QtGui.QLabel(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.label_disp_settings.sizePolicy().hasHeightForWidth())
+        self.label_disp_settings.setSizePolicy(sizePolicy)
+        self.label_disp_settings.setObjectName(_fromUtf8("label_disp_settings"))
+        self.horizontalLayout.addWidget(self.label_disp_settings)
+
+
+        self.label_pix_min = QtGui.QLabel(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.label_pix_min.sizePolicy().hasHeightForWidth())
+        self.label_pix_min.setSizePolicy(sizePolicy)
+        self.label_pix_min.setObjectName(_fromUtf8("label_pix_min"))
+        self.horizontalLayout.addWidget(self.label_pix_min)
+
+        self.spinbox_pix_min = QtGui.QSpinBox(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.spinbox_pix_min.sizePolicy().hasHeightForWidth())
+        self.spinbox_pix_min.setSizePolicy(sizePolicy)
+        self.spinbox_pix_min.setMaximumSize(QtCore.QSize(300, 16777215))
+        self.spinbox_pix_min.setObjectName(_fromUtf8("pix_min"))
+        self.spinbox_pix_min.setMinimum(0)
+        self.spinbox_pix_min.setMaximum(1022)
+        self.horizontalLayout.addWidget(self.spinbox_pix_min)
+
+        self.spinbox_pix_max = QtGui.QSpinBox(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.spinbox_pix_max.sizePolicy().hasHeightForWidth())
+        self.spinbox_pix_max.setSizePolicy(sizePolicy)
+        self.spinbox_pix_max.setMaximumSize(QtCore.QSize(300, 16777215))
+        self.spinbox_pix_max.setObjectName(_fromUtf8("pix_max"))
+        self.spinbox_pix_max.setMinimum(1)
+        self.spinbox_pix_max.setMaximum(1023)
+        self.horizontalLayout.addWidget(self.spinbox_pix_max)
+
+        #self.checkBox_remove_back = QtGui.QCheckBox(self.centralwidget)
+        #sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        #sizePolicy.setHorizontalStretch(0)
+        #sizePolicy.setVerticalStretch(0)
+        #sizePolicy.setHeightForWidth(self.checkBox_remove_back.sizePolicy().hasHeightForWidth())
+        #self.checkBox_remove_back.setSizePolicy(sizePolicy)
+        #self.checkBox_remove_back.setObjectName(_fromUtf8("checkBox_remove_back"))
+        #self.horizontalLayout.addWidget(self.checkBox_remove_back)
+
+        #self.checkBox_average = QtGui.QCheckBox(self.centralwidget)
+        #sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        #sizePolicy.setHorizontalStretch(0)
+        #sizePolicy.setVerticalStretch(0)
+        #sizePolicy.setHeightForWidth(self.checkBox_remove_back.sizePolicy().hasHeightForWidth())
+        #self.checkBox_average.setSizePolicy(sizePolicy)
+        #self.checkBox_average.setObjectName(_fromUtf8("checkBox_average"))
+        #self.horizontalLayout.addWidget(self.checkBox_average)
+
+        #self.checkBox_calc_modul = QtGui.QCheckBox(self.centralwidget)
+        #sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        #sizePolicy.setHorizontalStretch(0)
+        #sizePolicy.setVerticalStretch(0)
+        #sizePolicy.setHeightForWidth(self.checkBox_calc_modul.sizePolicy().hasHeightForWidth())
+        #self.checkBox_calc_modul.setSizePolicy(sizePolicy)
+        #self.checkBox_calc_modul.setObjectName(_fromUtf8("checkBox_calc_modul"))
+        #self.horizontalLayout.addWidget(self.checkBox_calc_modul)
+
+        #########################################
+
+        self.verticalLayout.addLayout(self.horizontalLayout)
+        self.line = QtGui.QFrame(self.centralwidget)
+        self.line.setFrameShape(QtGui.QFrame.HLine)
+        self.line.setFrameShadow(QtGui.QFrame.Sunken)
+        self.line.setObjectName(_fromUtf8("line"))
+        self.verticalLayout.addWidget(self.line)
+        self.horizontalLayout_2 = QtGui.QHBoxLayout()
+        self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2"))
+
+        ## KALYPSO Operation part
+        self.verticalLayout_2 = QtGui.QVBoxLayout()
+        self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
+
+        self.label_controls = QtGui.QLabel(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.label_controls.sizePolicy().hasHeightForWidth())
+        self.label_controls.setSizePolicy(sizePolicy)
+        self.label_controls.setObjectName(_fromUtf8("label_controls"))
+        self.verticalLayout_2.addWidget(self.label_controls)
+
+        self.pushButton_init_board = QtGui.QPushButton(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.pushButton_init_board.sizePolicy().hasHeightForWidth())
+        self.pushButton_init_board.setSizePolicy(sizePolicy)
+        self.pushButton_init_board.setMaximumSize(QtCore.QSize(800, 16777215))
+        self.pushButton_init_board.setObjectName(_fromUtf8("pushButton_init_board"))
+        self.verticalLayout_2.addWidget(self.pushButton_init_board)
+
+############################## with external RF ##########################################################
+        self.pushButton_init_board_ex_rf = QtGui.QPushButton(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.pushButton_init_board_ex_rf.sizePolicy().hasHeightForWidth())
+        self.pushButton_init_board_ex_rf.setSizePolicy(sizePolicy)
+        self.pushButton_init_board_ex_rf.setMaximumSize(QtCore.QSize(800, 16777215))
+        self.pushButton_init_board_ex_rf.setObjectName(_fromUtf8("pushButton_init_board_ex_rf"))
+        self.verticalLayout_2.addWidget(self.pushButton_init_board_ex_rf)
+
+######################################################################################################
+
+        self.pushButton_timescan = QtGui.QPushButton(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.pushButton_timescan.sizePolicy().hasHeightForWidth())
+        self.pushButton_timescan.setSizePolicy(sizePolicy)
+        self.pushButton_timescan.setMaximumSize(QtCore.QSize(800, 16777215))
+        self.pushButton_timescan.setObjectName(_fromUtf8("pushButton_timescan"))
+        self.verticalLayout_2.addWidget(self.pushButton_timescan)
+
+        self.pushButton_poweroff = QtGui.QPushButton(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        self.pushButton_poweroff.setSizePolicy(sizePolicy)
+        self.pushButton_poweroff.setMaximumSize(QtCore.QSize(800, 16777215))
+        self.pushButton_poweroff.setObjectName(_fromUtf8("pushButton_poweroff"))
+        self.verticalLayout_2.addWidget(self.pushButton_poweroff)
+
+        ### Horizontal Line
+        self.line_0 = QtGui.QFrame(self.centralwidget)
+        self.line_0.setFrameShape(QtGui.QFrame.HLine)
+        self.line_0.setFrameShadow(QtGui.QFrame.Sunken)
+        self.line_0.setObjectName(_fromUtf8("line_0"))
+        self.verticalLayout_2.addWidget(self.line_0)
+
+        ### Load from file
+        self.label_loadfile = QtGui.QLabel(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.label_loadfile.sizePolicy().hasHeightForWidth())
+        self.label_loadfile.setSizePolicy(sizePolicy)
+        self.label_loadfile.setObjectName(_fromUtf8("label_loadfile"))
+        self.verticalLayout_2.addWidget(self.label_loadfile)
+
+        self.pushButton_background_file = QtGui.QPushButton(self.centralwidget)
+        self.pushButton_background_file.setSizePolicy(sizePolicy)
+        self.pushButton_background_file.setMaximumSize(QtCore.QSize(400, 16777215))
+        self.pushButton_background_file.setObjectName(_fromUtf8("pushButton_background_file"))
+        self.verticalLayout_2.addWidget(self.pushButton_background_file)
+
+        self.pushButton_unmodulated_file = QtGui.QPushButton(self.centralwidget)
+        self.pushButton_unmodulated_file.setSizePolicy(sizePolicy)
+        self.pushButton_unmodulated_file.setMaximumSize(QtCore.QSize(400, 16777215))
+        self.pushButton_unmodulated_file.setObjectName(_fromUtf8("pushButton_unmodulated_file"))
+        self.verticalLayout_2.addWidget(self.pushButton_unmodulated_file)
+
+
+        self.pushButton_modulated_file = QtGui.QPushButton(self.centralwidget)
+        self.pushButton_modulated_file.setSizePolicy(sizePolicy)
+        self.pushButton_modulated_file.setMaximumSize(QtCore.QSize(400, 16777215))
+        self.pushButton_modulated_file.setObjectName(_fromUtf8("pushButton_modulated_file"))
+        self.verticalLayout_2.addWidget(self.pushButton_modulated_file)
+
+        self.horizontalLayout_2.addLayout(self.verticalLayout_2)
+        self.line_6 = QtGui.QFrame(self.centralwidget)
+        self.line_6.setFrameShape(QtGui.QFrame.VLine)
+        self.line_6.setFrameShadow(QtGui.QFrame.Sunken)
+        self.line_6.setObjectName(_fromUtf8("line_5"))
+        self.horizontalLayout_2.addWidget(self.line_6)
+
+
+        #### SETTINGS part
+        self.gridLayout = QtGui.QGridLayout()
+        self.gridLayout.setSizeConstraint(QtGui.QLayout.SetMinimumSize)
+        self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
+
+        ## Integration time
+        self.label_settings = QtGui.QLabel(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.label_settings.sizePolicy().hasHeightForWidth())
+        self.label_settings.setSizePolicy(sizePolicy)
+        self.label_settings.setObjectName(_fromUtf8("label_settings"))
+        self.gridLayout.addWidget(self.label_settings, 0, 0, 1, 1)
+
+        self.pushButton_readsettings = QtGui.QPushButton(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.pushButton_readsettings.sizePolicy().hasHeightForWidth())
+        self.pushButton_readsettings.setSizePolicy(sizePolicy)
+        self.pushButton_readsettings.setMaximumSize(QtCore.QSize(800, 16777215))
+        self.pushButton_readsettings.setObjectName(_fromUtf8("pushButton_readsettings"))
+        self.gridLayout.addWidget(self.pushButton_readsettings, 1, 0, 1, 1)
+
+        self.label_int_time = QtGui.QLabel(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.label_int_time.sizePolicy().hasHeightForWidth())
+        self.label_int_time.setSizePolicy(sizePolicy)
+        self.label_int_time.setObjectName(_fromUtf8("label_int_time"))
+        self.gridLayout.addWidget(self.label_int_time, 2, 0, 1, 1)
+
+        self.spinBox_int_time = QtGui.QSpinBox(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.spinBox_int_time.sizePolicy().hasHeightForWidth())
+        self.spinBox_int_time.setSizePolicy(sizePolicy)
+        self.spinBox_int_time.setMaximumSize(QtCore.QSize(300, 16777215))
+        self.spinBox_int_time.setObjectName(_fromUtf8("spinBox_int_time"))
+        self.spinBox_int_time.setRange(0,1024)
+	self.spinBox_int_time.setSingleStep(1)
+        self.gridLayout.addWidget(self.spinBox_int_time, 2, 1, 1, 1)
+
+        ## Int. Delay
+        self.label_int_delay = QtGui.QLabel(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.label_int_delay.sizePolicy().hasHeightForWidth())
+        self.label_int_delay.setSizePolicy(sizePolicy)
+        self.label_int_delay.setObjectName(_fromUtf8("label_int_delay"))
+        self.gridLayout.addWidget(self.label_int_delay, 3, 0, 1, 1)
+        self.spinBox_int_delay = QtGui.QSpinBox(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.spinBox_int_delay.sizePolicy().hasHeightForWidth())
+        self.spinBox_int_delay.setSizePolicy(sizePolicy)
+        self.spinBox_int_delay.setMaximumSize(QtCore.QSize(300, 16777215))
+        self.spinBox_int_delay.setObjectName(_fromUtf8("spinBox_int_delay"))
+        self.spinBox_int_delay.setRange(1,1023)
+	self.spinBox_int_delay.setSingleStep(1)
+        self.gridLayout.addWidget(self.spinBox_int_delay, 3, 1, 1, 1)
+
+        ## GOTT gain
+        self.spinBox_gott_gain = QtGui.QSpinBox(self.centralwidget)
+        self.spinBox_gott_gain.setMaximum(2)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.spinBox_gott_gain.sizePolicy().hasHeightForWidth())
+        self.spinBox_gott_gain.setSizePolicy(sizePolicy)
+        self.spinBox_gott_gain.setMaximumSize(QtCore.QSize(300, 16777215))
+        self.spinBox_gott_gain.setObjectName(_fromUtf8("spinBox_gott_gain"))
+        self.spinBox_gott_gain.setMaximum(2)
+        self.gridLayout.addWidget(self.spinBox_gott_gain, 4, 1, 1, 1)
+        self.label_gott_gain = QtGui.QLabel(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.spinBox_gott_gain.sizePolicy().hasHeightForWidth())
+        self.label_gott_gain.setSizePolicy(sizePolicy)
+        self.label_gott_gain.setObjectName(_fromUtf8("label_gott_gain"))
+        self.gridLayout.addWidget(self.label_gott_gain, 4, 0, 1, 1)
+
+        ## Total samples
+        self.label_samples = QtGui.QLabel(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.label_samples.sizePolicy().hasHeightForWidth())
+        self.label_samples.setSizePolicy(sizePolicy)
+        self.label_samples.setObjectName(_fromUtf8("label_samples"))
+        self.gridLayout.addWidget(self.label_samples, 5, 0, 1, 1)
+        self.spinBox_total_samples = QtGui.QSpinBox(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.spinBox_total_samples.sizePolicy().hasHeightForWidth())
+        self.spinBox_total_samples.setSizePolicy(sizePolicy)
+        self.spinBox_total_samples.setMaximumSize(QtCore.QSize(300, 16777215))
+        self.spinBox_total_samples.setObjectName(_fromUtf8("spinBox_total_samples"))
+	self.spinBox_total_samples.setMinimum(8)
+        self.spinBox_total_samples.setMaximum(25000000)
+	self.spinBox_total_samples.setSingleStep(8)
+        self.gridLayout.addWidget(self.spinBox_total_samples, 5, 1, 1, 1)
+
+        ## Skip FT
+        self.spinBox_skip_samples = QtGui.QSpinBox(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.spinBox_skip_samples.sizePolicy().hasHeightForWidth())
+        self.spinBox_skip_samples.setSizePolicy(sizePolicy)
+        self.spinBox_skip_samples.setMaximumSize(QtCore.QSize(300, 16777215))
+        self.spinBox_skip_samples.setObjectName(_fromUtf8("spinBox_skip_samples"))
+        self.spinBox_skip_samples.setMaximum(10000000)
+        self.gridLayout.addWidget(self.spinBox_skip_samples, 6, 1, 1, 1)
+        self.label_skip_samples = QtGui.QLabel(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.label_skip_samples.sizePolicy().hasHeightForWidth())
+        self.label_skip_samples.setSizePolicy(sizePolicy)
+        self.label_skip_samples.setObjectName(_fromUtf8("label_skip_samples"))
+        self.gridLayout.addWidget(self.label_skip_samples, 6, 0, 1, 1)
+
+        ## Internal Trigger label
+        #self.label_int_trig_text = QtGui.QLabel(self.centralwidget)
+        #sizePolicy.setHeightForWidth(self.label_int_trig_text.sizePolicy().hasHeightForWidth())
+        #self.label_int_trig_text.setSizePolicy(sizePolicy)
+        #self.label_int_trig_text.setObjectName(_fromUtf8("label_int_trig_text"))
+        #self.gridLayout.addWidget(self.label_int_trig_text, 6, 0, 1, 1)
+
+        ## Internal Trigger
+        self.spinBox_int_trig= QtGui.QSpinBox(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.spinBox_int_trig.sizePolicy().hasHeightForWidth())
+        self.spinBox_int_trig.setSizePolicy(sizePolicy)
+        self.spinBox_int_trig.setMaximumSize(QtCore.QSize(300, 16777215))
+        self.spinBox_int_trig.setObjectName(_fromUtf8("spinBox_int_trig"))
+        self.spinBox_int_trig.setMaximum(4096)
+        self.gridLayout.addWidget(self.spinBox_int_trig, 8, 1, 1, 1)
+        self.label_int_trig = QtGui.QLabel(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.label_int_trig.sizePolicy().hasHeightForWidth())
+        self.label_int_trig.setSizePolicy(sizePolicy)
+        self.label_int_trig.setObjectName(_fromUtf8("label_int_trig"))
+        self.gridLayout.addWidget(self.label_int_trig, 8, 0, 1, 1)
+
+
+
+
+        ## End of layout
+        self.horizontalLayout_2.addLayout(self.gridLayout)
+        self.line_5 = QtGui.QFrame(self.centralwidget)
+        self.line_5.setFrameShape(QtGui.QFrame.VLine)
+        self.line_5.setFrameShadow(QtGui.QFrame.Sunken)
+        self.line_5.setObjectName(_fromUtf8("line_5"))
+        self.horizontalLayout_2.addWidget(self.line_5)
+
+        ########################################################################
+        ### Acquisition part
+        self.gridLayout_acq = QtGui.QGridLayout()
+        self.gridLayout_acq.setSizeConstraint(QtGui.QLayout.SetMinimumSize)
+        self.gridLayout_acq.setObjectName(_fromUtf8("gridLayout_acq"))
+
+        self.label_acq = QtGui.QLabel(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.label_pix_min.sizePolicy().hasHeightForWidth())
+        self.label_acq.setSizePolicy(sizePolicy)
+        self.label_acq.setObjectName(_fromUtf8("label_acq"))
+        self.gridLayout_acq.addWidget(self.label_acq, 1, 0, 1, 1)
+
+        self.pushButton_background = QtGui.QPushButton(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.pushButton_background.sizePolicy().hasHeightForWidth())
+        self.pushButton_background.setSizePolicy(sizePolicy)
+        self.pushButton_background.setMaximumSize(QtCore.QSize(800, 16777215))
+        self.pushButton_background.setObjectName(_fromUtf8("pushButton_background"))
+        self.gridLayout_acq.addWidget(self.pushButton_background, 2, 0, 1, 1)
+
+        self.checkBox_remove_back = QtGui.QCheckBox(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.checkBox_remove_back.sizePolicy().hasHeightForWidth())
+        self.checkBox_remove_back.setSizePolicy(sizePolicy)
+        self.checkBox_remove_back.setObjectName(_fromUtf8("checkBox_remove_back"))
+        self.gridLayout_acq.addWidget(self.checkBox_remove_back, 2, 1, 1, 1)
+
+
+        self.pushButton_unmodulated = QtGui.QPushButton(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.pushButton_background.sizePolicy().hasHeightForWidth())
+        self.pushButton_unmodulated.setSizePolicy(sizePolicy)
+        self.pushButton_unmodulated.setMaximumSize(QtCore.QSize(800, 16777215))
+        self.pushButton_unmodulated.setObjectName(_fromUtf8("pushButton_unmodulated"))
+        self.gridLayout_acq.addWidget(self.pushButton_unmodulated, 3, 0, 1, 1)
+
+        self.checkBox_average = QtGui.QCheckBox(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.checkBox_average.sizePolicy().hasHeightForWidth())
+        self.checkBox_average.setSizePolicy(sizePolicy)
+        self.checkBox_average.setObjectName(_fromUtf8("checkBox_average"))
+        self.gridLayout_acq.addWidget(self.checkBox_average, 3, 1, 1, 1)
+
+
+        self.pushButton_modulated = QtGui.QPushButton(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.pushButton_modulated.sizePolicy().hasHeightForWidth())
+        self.pushButton_modulated.setSizePolicy(sizePolicy)
+        self.pushButton_modulated.setMaximumSize(QtCore.QSize(800, 16777215))
+        self.pushButton_modulated.setObjectName(_fromUtf8("pushButton_modulated"))
+        self.gridLayout_acq.addWidget(self.pushButton_modulated, 4, 0, 1, 1)
+
+        self.checkBox_calc_modul = QtGui.QCheckBox(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.checkBox_calc_modul.sizePolicy().hasHeightForWidth())
+        self.checkBox_calc_modul.setSizePolicy(sizePolicy)
+        self.checkBox_calc_modul.setObjectName(_fromUtf8("checkBox_calc_modul"))
+        self.gridLayout_acq.addWidget(self.checkBox_calc_modul, 4, 1, 1, 1)
+
+
+        self.checkBox_savefile = QtGui.QCheckBox(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.checkBox_savefile.sizePolicy().hasHeightForWidth())
+        self.checkBox_savefile.setSizePolicy(sizePolicy)
+        self.checkBox_savefile.setObjectName(_fromUtf8("checkBox_savefile"))
+        self.gridLayout_acq.addWidget(self.checkBox_savefile, 5, 0, 1, 1)
+
+        # self.checkBox_ELOG = QtGui.QCheckBox(self.centralwidget)
+        # sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        # sizePolicy.setHorizontalStretch(0)
+        # sizePolicy.setVerticalStretch(0)
+        # sizePolicy.setHeightForWidth(self.checkBox_ELOG.sizePolicy().hasHeightForWidth())
+        # self.checkBox_ELOG.setSizePolicy(sizePolicy)
+        # self.checkBox_ELOG.setObjectName(_fromUtf8("checkBox_ELOG"))
+        # self.gridLayout_acq.addWidget(self.checkBox_ELOG, 5, 1, 1, 1)
+
+        self.pushButton_file_path = QtGui.QPushButton(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.pushButton_file_path.sizePolicy().hasHeightForWidth())
+        self.pushButton_file_path.setSizePolicy(sizePolicy)
+        self.pushButton_file_path.setMaximumSize(QtCore.QSize(800, 16777215))
+        self.pushButton_file_path.setObjectName(_fromUtf8("pushButton_file_path"))
+        self.gridLayout_acq.addWidget(self.pushButton_file_path, 6, 0, 1, 1)
+
+        self.lineEdit_file_path = QtGui.QLineEdit(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.lineEdit_file_path.sizePolicy().hasHeightForWidth())
+        self.lineEdit_file_path.setSizePolicy(sizePolicy)
+        self.lineEdit_file_path.setMaximumSize(QtCore.QSize(800, 16777215))
+        self.lineEdit_file_path.setObjectName(_fromUtf8("lineEdit_file_path"))
+        self.gridLayout_acq.addWidget(self.lineEdit_file_path, 6, 1, 1, 1)
+
+
+        self.fillnum_bar = QtGui.QStatusBar(self.centralwidget)
+        self.fillnum_bar.showMessage("Fill number:")
+        self.fillnum_bar.setSizeGripEnabled(0)
+        self.fillnum_bar.setMaximumSize(QtCore.QSize(900, 100))
+        self.fillnum_bar.setObjectName(_fromUtf8("detector_bar"))
+        self.gridLayout_acq.addWidget(self.fillnum_bar, 7, 0, 1, 1)
+
+        self.lineEdit_fillnum = QtGui.QLineEdit(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.lineEdit_fillnum.sizePolicy().hasHeightForWidth())
+        self.lineEdit_fillnum.setSizePolicy(sizePolicy)
+        self.lineEdit_fillnum.setMaximumSize(QtCore.QSize(800, 16777215))
+        self.lineEdit_fillnum.setObjectName(_fromUtf8("lineEdit_fillnum"))
+        self.lineEdit_fillnum.setInputMask("99999")
+        self.lineEdit_fillnum.setText("12345")
+
+        self.gridLayout_acq.addWidget(self.lineEdit_fillnum, 7, 1, 1, 1)
+
+
+        self.detector_bar = QtGui.QStatusBar(self.centralwidget)
+        self.detector_bar.showMessage("Detector:")
+        self.detector_bar.setSizeGripEnabled(0)
+        self.detector_bar.setMaximumSize(QtCore.QSize(900, 100))
+        self.detector_bar.setObjectName(_fromUtf8("detector_bar"))
+        self.gridLayout_acq.addWidget(self.detector_bar, 8, 0, 1, 1)
+
+        self.lineEdit_detector = QtGui.QLineEdit(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.lineEdit_detector.sizePolicy().hasHeightForWidth())
+        self.lineEdit_detector.setSizePolicy(sizePolicy)
+        self.lineEdit_detector.setMaximumSize(QtCore.QSize(800, 16777215))
+        self.lineEdit_detector.setObjectName(_fromUtf8("lineEdit_detector"))
+        self.lineEdit_detector.setInputMask("NNNN")
+        self.lineEdit_detector.setText("Si01")
+        self.gridLayout_acq.addWidget(self.lineEdit_detector, 8, 1, 1, 1)
+
+        self.comments_bar = QtGui.QStatusBar(self.centralwidget)
+        self.comments_bar.showMessage("Comments:")
+        self.comments_bar.setSizeGripEnabled(0)
+        self.comments_bar.setMaximumSize(QtCore.QSize(900, 100))
+        self.comments_bar.setObjectName(_fromUtf8("comments_bar"))
+        self.gridLayout_acq.addWidget(self.comments_bar, 9, 0, 1, 1)
+
+        self.lineEdit_comments = QtGui.QLineEdit(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.lineEdit_file_path.sizePolicy().hasHeightForWidth())
+        self.lineEdit_comments.setSizePolicy(sizePolicy)
+        self.lineEdit_comments.setMaximumSize(QtCore.QSize(800, 16777215))
+        self.lineEdit_comments.setObjectName(_fromUtf8("lineEdit_comments"))
+        self.gridLayout_acq.addWidget(self.lineEdit_comments, 9, 1, 1, 1)
+
+        self.horizontalLayout_2.addLayout(self.gridLayout_acq)
+
+        self.line_7 = QtGui.QFrame(self.centralwidget)
+        self.line_7.setFrameShape(QtGui.QFrame.VLine)
+        self.line_7.setFrameShadow(QtGui.QFrame.Sunken)
+        self.line_7.setObjectName(_fromUtf8("line_7"))
+        self.horizontalLayout_2.addWidget(self.line_7)
+
+
+        ## Log
+        self.verticalLayout_9 = QtGui.QVBoxLayout()
+        self.verticalLayout_9.setSizeConstraint(QtGui.QLayout.SetMaximumSize)
+        self.verticalLayout_9.setObjectName(_fromUtf8("verticalLayout_9"))
+        self.horizontalLayout_2.addLayout(self.verticalLayout_9)
+
+        self.label_log = QtGui.QLabel(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.label_log.sizePolicy().hasHeightForWidth())
+        self.label_log.setSizePolicy(sizePolicy)
+        self.label_log.setObjectName(_fromUtf8("label_log"))
+        self.verticalLayout_9.addWidget(self.label_log)
+
+        self.checkBox_cont_acq = QtGui.QCheckBox(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.checkBox_cont_acq.sizePolicy().hasHeightForWidth())
+        self.checkBox_cont_acq.setSizePolicy(sizePolicy)
+        self.checkBox_cont_acq.setObjectName(_fromUtf8("checkBox_cont_acq"))
+        self.verticalLayout_9.addWidget(self.checkBox_cont_acq)
+
+ 	self.pushButton_run = QtGui.QPushButton(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.pushButton_run.sizePolicy().hasHeightForWidth())
+        self.pushButton_run.setCheckable(True)
+        self.pushButton_run.setSizePolicy(sizePolicy)
+        self.pushButton_run.setMaximumSize(QtCore.QSize(800, 16777215))
+        self.pushButton_run.setObjectName(_fromUtf8("pushButton_background"))
+        self.verticalLayout_9.addWidget(self.pushButton_run)
+
+
+        self.status_bar = QtGui.QStatusBar(self.centralwidget)
+        self.status_bar.showMessage("System Status: GUI started")
+        self.status_bar.setSizeGripEnabled(0)
+        self.status_bar.setMaximumSize(QtCore.QSize(900, 100))
+        self.status_bar.setObjectName(_fromUtf8("status_bar"))
+        self.verticalLayout_9.addWidget(self.status_bar)
+
+        self.textEdit = QtGui.QTextEdit(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        self.textEdit.setMaximumSize(QtCore.QSize(1024, 900))
+        self.textEdit.setSizePolicy(sizePolicy)
+        self.textEdit.setReadOnly(True)
+        self.textEdit.setObjectName(_fromUtf8("textEdit"))
+        # self.textEdit.setStyleSheet("background-image: url(kit.png); background-attachment: fixed; background-position: bottom right; background-repeat: no-repeat")
+        self.verticalLayout_9.addWidget(self.textEdit)
+
+
+        #self.horizontalLayout_2.addLayout(self.gridLayout)
+        self.line_5 = QtGui.QFrame(self.centralwidget)
+        self.line_5.setFrameShape(QtGui.QFrame.VLine)
+        self.line_5.setFrameShadow(QtGui.QFrame.Sunken)
+        self.line_5.setObjectName(_fromUtf8("line_5"))
+        self.horizontalLayout_2.addWidget(self.line_5)
+
+
+###############################------------------------------------LED------------------------------------------#########################################################
+        self.gridLayout_led = QtGui.QGridLayout()
+        self.gridLayout_led.setSizeConstraint(QtGui.QLayout.SetMaximumSize)
+        self.gridLayout_led.setObjectName(_fromUtf8("gridLayout_led"))
+        self.horizontalLayout_2.addLayout(self.gridLayout_led)
+        self.verticalLayout_10 = QtGui.QVBoxLayout()
+        self.verticalLayout_10.setSizeConstraint(QtGui.QLayout.SetMaximumSize)
+        self.verticalLayout_10.setObjectName(_fromUtf8("verticalLayout_10"))
+        self.horizontalLayout_2.addLayout(self.verticalLayout_10)
+
+
+        self.led1=QLed(self.centralwidget, onColour=QLed.Red,offColour=QLed.Green, shape=QLed.Circle)
+        self.led1.setMaximumSize(QtCore.QSize(10, 100))
+        sizePolicy.setHeightForWidth(self.led1.sizePolicy().hasHeightForWidth())
+        self.led1.setSizePolicy(sizePolicy)
+        #self.led3.value=True
+        self.label_led1 = QtGui.QLabel(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.label_led1.sizePolicy().hasHeightForWidth())
+        self.label_led1.setSizePolicy(sizePolicy)
+        self.label_led1.setObjectName(_fromUtf8("led 1"))
+        self.label_led1.setAlignment(Qt.AlignCenter)
+        self.gridLayout_led.addWidget(self.label_led1,1,1,1,1)
+        self.led1.setObjectName(_fromUtf8("Led 1"))
+        self.gridLayout_led.addWidget(self.led1,1,0,1,1)
+
+
+        self.led2=QLed(self.centralwidget, onColour=QLed.Red,offColour=QLed.Green, shape=QLed.Circle)
+        self.led2.setMaximumSize(QtCore.QSize(10, 100))
+        sizePolicy.setHeightForWidth(self.led2.sizePolicy().hasHeightForWidth())
+        self.led2.setSizePolicy(sizePolicy)
+        #self.led2.value=True
+        self.label_led2 = QtGui.QLabel(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.label_led2.sizePolicy().hasHeightForWidth())
+        self.label_led2.setSizePolicy(sizePolicy)
+        self.label_led2.setObjectName(_fromUtf8("led 2"))
+        self.label_led2.setAlignment(Qt.AlignCenter)
+        self.gridLayout_led.addWidget(self.label_led2,2,1,1,1)
+        self.led2.setObjectName(_fromUtf8("Led 2"))
+        self.gridLayout_led.addWidget(self.led2,2,0,1,1)
+
+
+        self.led3=QLed(self.centralwidget, onColour=QLed.Red,offColour=QLed.Green, shape=QLed.Circle)
+        self.led3.setMaximumSize(QtCore.QSize(10, 100))
+        sizePolicy.setHeightForWidth(self.led3.sizePolicy().hasHeightForWidth())
+        self.led3.setSizePolicy(sizePolicy)
+        #self.led3.value=True
+        self.label_led3 = QtGui.QLabel(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.label_led3.sizePolicy().hasHeightForWidth())
+        self.label_led3.setSizePolicy(sizePolicy)
+        self.label_led3.setObjectName(_fromUtf8("led 3"))
+        self.label_led3.setAlignment(Qt.AlignCenter)
+        self.gridLayout_led.addWidget(self.label_led3,3,1,1,1)
+        self.led3.setObjectName(_fromUtf8("Led 3"))
+        self.gridLayout_led.addWidget(self.led3,3,0,1,1)
+
+
+        self.led4=QLed(self.centralwidget, onColour=QLed.Red,offColour=QLed.Green, shape=QLed.Circle)
+        self.led4.setMaximumSize(QtCore.QSize(10, 100))
+        sizePolicy.setHeightForWidth(self.led4.sizePolicy().hasHeightForWidth())
+        self.led4.setSizePolicy(sizePolicy)
+        #self.led4.value=True
+        self.label_led4 = QtGui.QLabel(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.label_led4.sizePolicy().hasHeightForWidth())
+        self.label_led4.setSizePolicy(sizePolicy)
+        self.label_led4.setAlignment(Qt.AlignCenter)
+        self.label_led4.setObjectName(_fromUtf8("led 4"))
+        self.gridLayout_led.addWidget(self.label_led4,4,1,1,1)
+        self.led4.setObjectName(_fromUtf8("Led 4"))
+        self.gridLayout_led.addWidget(self.led4,4,0,1,1)
+
+
+        self.led5=QLed(self.centralwidget, onColour=QLed.Red,offColour=QLed.Green, shape=QLed.Circle)
+        self.led5.setMaximumSize(QtCore.QSize(10, 100))
+        sizePolicy.setHeightForWidth(self.led5.sizePolicy().hasHeightForWidth())
+        self.led5.setSizePolicy(sizePolicy)
+        #self.led5.value=True
+        self.label_led5 = QtGui.QLabel(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.label_led5.sizePolicy().hasHeightForWidth())
+        self.label_led5.setSizePolicy(sizePolicy)
+        self.label_led5.setAlignment(Qt.AlignCenter)
+        self.label_led5.setObjectName(_fromUtf8("led 5"))
+        self.gridLayout_led.addWidget(self.label_led5,5,1,1,1)
+        self.led5.setObjectName(_fromUtf8("Led 5"))
+        self.gridLayout_led.addWidget(self.led5,5,0,1,1)
+
+
+        self.led6=QLed(self.centralwidget, onColour=QLed.Red,offColour=QLed.Green, shape=QLed.Circle)
+        self.led6.setMaximumSize(QtCore.QSize(10, 100))
+        sizePolicy.setHeightForWidth(self.led6.sizePolicy().hasHeightForWidth())
+        self.led6.setSizePolicy(sizePolicy)
+        #self.led6.value=True
+        self.label_led6 = QtGui.QLabel(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.label_led6.sizePolicy().hasHeightForWidth())
+        self.label_led6.setSizePolicy(sizePolicy)
+        self.label_led6.setAlignment(Qt.AlignCenter)
+        self.label_led6.setObjectName(_fromUtf8("led 6"))
+        self.gridLayout_led.addWidget(self.label_led6,6,1,1,1)
+        self.led6.setObjectName(_fromUtf8("Led 6"))
+        self.gridLayout_led.addWidget(self.led6,6,0,1,1)
+
+
+        self.led7=QLed(self.centralwidget, onColour=QLed.Red,offColour=QLed.Green, shape=QLed.Circle)
+        self.led7.setMaximumSize(QtCore.QSize(10, 100))
+        sizePolicy.setHeightForWidth(self.led7.sizePolicy().hasHeightForWidth())
+        self.led7.setSizePolicy(sizePolicy)
+        #self.led7.value=True
+        self.label_led7 = QtGui.QLabel(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.label_led7.sizePolicy().hasHeightForWidth())
+        self.label_led7.setSizePolicy(sizePolicy)
+        self.label_led7.setAlignment(Qt.AlignCenter)
+        self.label_led7.setObjectName(_fromUtf8("led 7"))
+        self.gridLayout_led.addWidget(self.label_led7,7,1,1,1)
+        self.led7.setObjectName(_fromUtf8("Led 7"))
+        self.gridLayout_led.addWidget(self.led7,7,0,1,1)
+
+
+        self.led8=QLed(self.centralwidget, onColour=QLed.Red,offColour=QLed.Green, shape=QLed.Circle)
+        self.led8.setMaximumSize(QtCore.QSize(10, 100))
+        sizePolicy.setHeightForWidth(self.led8.sizePolicy().hasHeightForWidth())
+        self.led8.setSizePolicy(sizePolicy)
+        #self.led8.value=True
+        self.label_led8 = QtGui.QLabel(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.label_led8.sizePolicy().hasHeightForWidth())
+        self.label_led8.setSizePolicy(sizePolicy)
+        self.label_led8.setAlignment(Qt.AlignCenter)
+        self.label_led8.setObjectName(_fromUtf8("led 8"))
+        self.gridLayout_led.addWidget(self.label_led8,8,1,1,1)
+        self.led8.setObjectName(_fromUtf8("Led 8"))
+        self.gridLayout_led.addWidget(self.led8,8,0,1,1)
+
+
+        self.led9=QLed(self.centralwidget, onColour=QLed.Red,offColour=QLed.Green, shape=QLed.Circle)
+        self.led9.setMaximumSize(QtCore.QSize(10, 100))
+        sizePolicy.setHeightForWidth(self.led9.sizePolicy().hasHeightForWidth())
+        self.led9.setSizePolicy(sizePolicy)
+        #self.led9.value=True
+        self.label_led9 = QtGui.QLabel(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.label_led9.sizePolicy().hasHeightForWidth())
+        self.label_led9.setSizePolicy(sizePolicy)
+        self.label_led9.setAlignment(Qt.AlignCenter)
+        self.label_led9.setObjectName(_fromUtf8("led 5"))
+        self.gridLayout_led.addWidget(self.label_led9,9,1,1,1)
+        self.led9.setObjectName(_fromUtf8("Led 5"))
+        self.gridLayout_led.addWidget(self.led9,9,0,1,1)
+
+
+        self.led10=QLed(self.centralwidget, onColour=QLed.Red,offColour=QLed.Green, shape=QLed.Circle)
+        self.led10.setMaximumSize(QtCore.QSize(10, 100))
+        sizePolicy.setHeightForWidth(self.led10.sizePolicy().hasHeightForWidth())
+        self.led10.setSizePolicy(sizePolicy)
+        #self.led10.value=True
+        self.label_led10 = QtGui.QLabel(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.label_led10.sizePolicy().hasHeightForWidth())
+        self.label_led10.setSizePolicy(sizePolicy)
+        self.label_led10.setAlignment(Qt.AlignCenter)
+        self.label_led10.setObjectName(_fromUtf8("led 6"))
+        self.gridLayout_led.addWidget(self.label_led10,10,1,1,1)
+        self.led10.setObjectName(_fromUtf8("Led 6"))
+        self.gridLayout_led.addWidget(self.led10,10,0,1,1)
+
+
+        self.led11=QLed(self.centralwidget, onColour=QLed.Red,offColour=QLed.Green, shape=QLed.Circle)
+        self.led11.setMaximumSize(QtCore.QSize(10, 100))
+        sizePolicy.setHeightForWidth(self.led11.sizePolicy().hasHeightForWidth())
+        self.led11.setSizePolicy(sizePolicy)
+        #self.led11.value=True
+        self.label_led11 = QtGui.QLabel(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.label_led11.sizePolicy().hasHeightForWidth())
+        self.label_led11.setSizePolicy(sizePolicy)
+        self.label_led11.setAlignment(Qt.AlignCenter)
+        self.label_led11.setObjectName(_fromUtf8("led 7"))
+        self.gridLayout_led.addWidget(self.label_led11,11,1,1,1)
+        self.led11.setObjectName(_fromUtf8("Led 7"))
+        self.gridLayout_led.addWidget(self.led11,11,0,1,1)
+
+
+        self.led12=QLed(self.centralwidget, onColour=QLed.Red,offColour=QLed.Green, shape=QLed.Circle)
+        self.led12.setMaximumSize(QtCore.QSize(10, 100))
+        sizePolicy.setHeightForWidth(self.led12.sizePolicy().hasHeightForWidth())
+        self.led12.setSizePolicy(sizePolicy)
+        #self.led12.value=True
+        self.label_led12 = QtGui.QLabel(self.centralwidget)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.label_led12.sizePolicy().hasHeightForWidth())
+        self.label_led12.setSizePolicy(sizePolicy)
+        self.label_led12.setAlignment(Qt.AlignCenter)
+        self.label_led12.setObjectName(_fromUtf8("led 8"))
+        self.gridLayout_led.addWidget(self.label_led12,12,1,1,1)
+        self.led12.setObjectName(_fromUtf8("Led 8"))
+        self.gridLayout_led.addWidget(self.led12,12,0,1,1)
+
+
+
+        #self.pushButton_custom_function_2 = QtGui.QPushButton(self.centralwidget)
+        #sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed)
+        #sizePolicy.setHorizontalStretch(0)
+        #sizePolicy.setVerticalStretch(0)
+        #sizePolicy.setHeightForWidth(self.pushButton_custom_function_2.sizePolicy().hasHeightForWidth())
+        #self.pushButton_custom_function_2.setSizePolicy(sizePolicy)
+        #self.pushButton_custom_function_2.setMaximumSize(QtCore.QSize(400, 10000))
+        #self.pushButton_custom_function_2.setObjectName(_fromUtf8("pushButton_custom_function_2"))
+        #self.verticalLayout_2.addWidget(self.pushButton_custom_function_2)
+
+        self.verticalLayout.addLayout(self.horizontalLayout_2)
+        self.verticalLayout_3.addLayout(self.verticalLayout)
+        MainWindow.setCentralWidget(self.centralwidget)
+
+        ######### PLOT  ######### ######### ######### ######### ######### #########
+        pw=self.graphicsView
+
+        pw.setWindowTitle('KALYPSO data viewer')
+        pw.setLabel('bottom', 'Pixel')
+        pw.setLabel('left', 'Signal', units='ADC Counts')
+        self.modplot.setLabel('bottom', 'Sample number')
+        self.modplot.setLabel('left', 'Pixel number')
+        pw.setXRange(0, NUMBER_PIXELS)
+        pw.setYRange(0, 2**14)
+        pw.showGrid(1,1)
+        pw.addLegend()
+        curve = pw.plot(pen='g', name='raw')
+        curve_bg = pw.plot(pen='r', alpha = '0.8', name='w/o bg')
+        curve_std_p = pw.plot(pen=pg.mkPen(200, 0, 50, 160),name='+/- std.')
+        curve_std_l = pw.plot(pen=pg.mkPen(200, 0, 50, 160))
+        curve_snr   = pw.plot(pen=pg.mkPen(0, 0, 250, 160), name='SNR')
+
+
+
+
+
+
+        def update_plots(data):
+            if (self.tab_widget.currentIndex()==0):
+                plot_1D(data)
+            elif (self.tab_widget.currentIndex()==1):
+                plot_2D(data)
+
+        # Plot Waveform
+        def plot_1D(data):
+            global background_data
+            global unmodulated_data
+
+            pix_std=np.std(data,axis = 0)
+
+            if self.checkBox_average.isChecked():
+                data = np.average(data, axis = 0)
+            else:
+                data = data[OFFSET,:]
+
+            ## Remove BG
+            if self.checkBox_calc_modul.isChecked():
+                modulation = (data - background_data) / (unmodulated_data - background_data)
+                curve_bg.setData(modulation)
+                curve_snr.clear()
+                curve_std_l.clear()
+                curve_std_p.clear()
+                curve.clear()
+            elif self.checkBox_remove_back.isChecked():
+                curve_bg.setData(data - background_data)
+                curve.clear()
+                curve_std_p.setData(data - background_data+pix_std)
+                curve_std_l.setData(data - background_data-pix_std)
+                curve_snr.setData((data - background_data)/pix_std)
+                # curve_snr.setData(pix_std)
+            else:
+                curve.setData(data.flatten())
+                curve_std_p.setData(data+pix_std)
+                curve_std_l.setData(data-pix_std)
+                curve_snr.clear()
+                curve_bg.clear()
+
+            pw.setXRange(int(self.spinbox_pix_min.text()), int(self.spinbox_pix_max.text()))
+            app.processEvents()
+
+
+        # Input data must be array, not filename!
+        def plot_2D(data):
+            global background_data
+            global unmodulated_data
+
+            samples , pix = np.shape(data)
+            if self.checkBox_calc_modul.isChecked():
+                data = (data - background_data) / (unmodulated_data - background_data)
+            else:
+                if self.checkBox_remove_back.isChecked():
+                    data = data - background_data
+                else:
+                    data = data
+
+            self.img.setImage(data, autoLevels=0, autoDownsample="True")
+            self.modplot.setXRange(0,samples)
+            self.modplot.setYRange(int(self.spinbox_pix_min.text()), int(self.spinbox_pix_max.text()))
+
+            #self.hist.setHistogramRange(0.5,1.5)
+            #self.hist.setLevels(0.5,1.5)
+
+        #def terminal_cmd_checkbox():
+        #    if self.checkBox_cont_acq.isChecked():
+        #        if(int(self.spinBox_total_samples.text()) < 1000000):
+        #            subprocess.call(['./normal_acq.sh'])
+        #        else:
+        #            self.textEdit.setText('Too many samples selected for "Live preview"')
+        #            self.checkBox_cont_acq.toggle()
+        #        output_file = 'temp.bin'
+        #        if os.path.isfile(output_file):
+        #            data , dc, orb  = strip_data.strip_data(output_file, NUMBER_PIXELS, 0)
+        #            if dc:
+        #                update_plots(data)
+        #            else:
+        #                self.textEdit.append(u'\u26A0' + ' Data consistency check failed!')
+        #        else:
+        #            self.textEdit.append(u'\u26A0' + ' Data file does not exist!')
+        #        check_status()
+
+
+
+        def terminal_cmd_checkbox():
+            if self.checkBox_cont_acq.isChecked():
+                if(int(self.spinBox_total_samples.text()) < 1000000):
+                    subprocess.call(['./normal_acq.sh'])
+                else:
+                    self.textEdit.setText('Too many samples selected for "Live preview"')
+                    self.checkBox_cont_acq.toggle()
+                output_file = 'temp.bin'
+                if os.path.isfile(output_file):
+                    data, orb  = strip_data.strip_data(output_file, NUMBER_PIXELS, 0)
+                    update_plots(data)
+                else:
+                    self.textEdit.append(u'\u26A0' + ' Data file does not exist!')
+                check_status()
+                led_update()
+
+
+
+        def terminal_cmd_run():
+            if self.pushButton_run.isChecked():
+               self.pushButton_run.setStyleSheet("background-color : red")
+               self.pushButton_run.setText(_translate("MainWindow", "STOP", None))
+               self.pushButton_run.setEnabled(True)
+               if(int(self.spinBox_total_samples.text()) < 1000000):
+                   subprocess.call(['./normal_acq.sh'])
+               else:
+                   self.textEdit.setText('Too many samples selected for "Live preview"')
+                   self.checkBox_cont_acq.toggle()
+               output_file = 'temp.bin'
+               if os.path.isfile(output_file):
+                   data, orb  = strip_data.strip_data(output_file, NUMBER_PIXELS, 0)
+                   update_plots(data)
+               else:
+                   self.textEdit.append(u'\u26A0' + ' Data file does not exist!')
+               check_status()
+               led_update()
+            else:
+                self.pushButton_run.setStyleSheet("background-color : green")
+                self.pushButton_run.setText(_translate("MainWindow", "RUN", None))
+
+
+
+
+
+
+
+
+        def rst_slow_trigger_samples():
+            subprocess.check_output(['pci', '-w', self.registers["ST_TO_ACQ"]["address"],'0'])
+
+        def init_board():
+            self.textEdit.clear()
+            if (read_register("PCIE_RESET",hex=True) != "14021700"):
+                self.status_bar.showMessage('Error!', 1000)
+                self.textEdit.insertPlainText(u'\u26A0' + ' Communication failed with FPGA board... Check FPGA, the PCI-Express connection and reboot')
+            else:
+                self.status_bar.showMessage('Initializing board...', 5000)
+                subprocess.call(['./full_sequence.sh'])
+                self.spinBox_int_time.setValue(2)
+                self.spinBox_int_delay.setValue(0)
+                self.spinBox_gott_gain.setValue(2)
+                self.spinBox_total_samples.setValue(1024)
+                self.spinBox_skip_samples.setValue(0)
+                self.spinBox_int_trig.setValue(252)
+                rst_slow_trigger_samples()
+                self.status_bar.showMessage('Board initialized', 1000)
+                self.textEdit.insertPlainText(subprocess.check_output(['./status.sh']))
+                check_status()
+                led_update()
+
+        def init_board_ex_rf():
+            self.textEdit.clear()
+            if (read_register("PCIE_RESET",hex=True) != "14021700"):
+                self.status_bar.showMessage('Error!', 1000)
+                self.textEdit.insertPlainText(u'\u26A0' + ' Communication failed with FPGA board... Check FPGA, the PCI-Express connection and reboot')
+            else:
+                self.status_bar.showMessage('Initializing board...', 5000)
+                subprocess.call(['./full_sequence_ex_rf.sh'])
+                self.spinBox_int_time.setValue(2)
+                self.spinBox_int_delay.setValue(0)
+                self.spinBox_gott_gain.setValue(2)
+                self.spinBox_total_samples.setValue(1024)
+                self.spinBox_skip_samples.setValue(0)
+                self.spinBox_int_trig.setValue(252)
+                rst_slow_trigger_samples()
+                self.status_bar.showMessage('Board initialized with external RF parameters', 1000)
+                self.textEdit.insertPlainText(subprocess.check_output(['./status.sh']))
+                check_status()
+                led_update()
+
+        def timescan():
+            self.textEdit.setText(timestamp())
+            if os.path.isfile('temp_bg.bin'):
+                os.system('pci -w 0x9020 0x80')
+                self.textEdit.insertPlainText(subprocess.check_output(['./timescan.sh']))
+                self.textEdit.append('Timescan complete')
+                timescan_plot.timescan_plot('timescan_data.out', 128 ,1023)
+                self.status_bar.showMessage('Timescan', 1000)
+                write_total_samples()
+            else:
+                self.textEdit.append(u'\u26A0' + ' Take background measurement first!')
+
+        def get_filename():
+            return str(self.lineEdit_file_path.text() + 'f' + self.lineEdit_fillnum.text() + '_' + filename_timestamp() + '_' + self.lineEdit_detector.text())
+
+        def readout_modulated():
+            self.checkBox_cont_acq.setCheckState(0)
+            if self.checkBox_savefile.isChecked():
+	            output_file = (get_filename() + '_m.bin')
+            else:
+		        output_file = 'temp.bin'
+            time.sleep(0.1)
+            self.textEdit.setText(timestamp())
+            subprocess.call(['./normal_acq.sh', '-f', output_file])
+            if os.path.isfile(output_file):
+                # if self.checkBox_ELOG.isChecked():
+                #     elog_eosd.elog_eosd(output_file, 'm')
+                #     print ('Creating ELOG entry...')
+                if self.checkBox_savefile.isChecked():
+    	            write_csv(output_file)
+                if (int(self.spinBox_total_samples.text()) < 1000000):
+                    data, orb  = strip_data.strip_data(output_file, NUMBER_PIXELS, 0)
+                    self.textEdit.setText('Acquired ' + str(orb) + ' samples in ' + output_file)
+                    update_plots(data)
+
+                else:
+                    self.textEdit.append('*** File too large to process in GUI...')
+            else:
+                self.textEdit.append(u'\u26A0' + ' Data file does not exist!')
+            check_status()
+            led_update()
+
+        def readout_background():
+            global background_data
+            self.checkBox_cont_acq.setCheckState(0)
+            if self.checkBox_savefile.isChecked():
+	            output_file = (get_filename() + '_b.bin')
+            else:
+		        output_file = 'temp_bg.bin'
+            time.sleep(0.1)
+            self.textEdit.setText(timestamp())
+            subprocess.call(['./normal_acq.sh', '-f', output_file])
+            if os.path.isfile(output_file):
+                # if self.checkBox_ELOG.isChecked():
+                    ##elog_eosd.elog_eosd(output_file, 'b')
+                    # print ('Creating ELOG entry...')
+                if self.checkBox_savefile.isChecked():
+    	            write_csv(output_file)
+                if (int(self.spinBox_total_samples.text()) < 1000000):
+                    data, orb  = strip_data.strip_data(output_file, NUMBER_PIXELS, 0)
+                    self.textEdit.setText('Acquired ' + str(orb) + ' background in ' + output_file)
+                    background_data = np.average(data,axis = 0)
+
+                else:
+                    self.textEdit.append('*** File too large to process in GUI...')
+            else:
+                self.textEdit.append(u'\u26A0' + ' Data file does not exist!')
+            check_status()
+            led_update()
+
+
+        def readout_unmodulated():
+            global unmodulated_data
+            self.checkBox_cont_acq.setCheckState(0)
+            if self.checkBox_savefile.isChecked():
+	            output_file = (get_filename() + '_u.bin')
+            else:
+		        output_file = 'temp_un.bin'
+            time.sleep(0.1)
+            self.textEdit.setText(timestamp())
+            subprocess.call(['./normal_acq.sh', '-f', output_file])
+            if os.path.isfile(output_file):
+                # if self.checkBox_ELOG.isChecked():
+                    # print ('Creating ELOG entry...')
+                    ##elog_eosd.elog_eosd(output_file, 'u')
+                if self.checkBox_savefile.isChecked():
+    	            write_csv(output_file)
+                if (int(self.spinBox_total_samples.text()) < 1000000):
+                    data, orb  = strip_data.strip_data(output_file, NUMBER_PIXELS, 0)
+                    self.textEdit.setText('Acquired ' + str(orb) + ' unmodulated in ' + output_file)
+                    unmodulated_data = np.average(data,axis = 0)
+
+                else:
+                    self.textEdit.append('*** File too large to process in GUI...')
+            else:
+                self.textEdit.append(u'\u26A0' + ' Data file does not exist!')
+            check_status()
+            led_update()
+
+        def poweroff():
+            self.textEdit.setText(timestamp())
+            self.textEdit.insertPlainText(subprocess.check_output(['./poweroff.sh']))
+
+        def timestamp():
+            return datetime.datetime.now().strftime("[%H:%M:%S] ")
+
+        def filename_timestamp():
+            return (time.strftime("%Y-%m-%dT%Hh%Mm%Ss"))
+
+        # Dialog to set path to save readout file
+        def getDir():
+            dialog = QtGui.QFileDialog()
+            dialog.setFileMode(QtGui.QFileDialog.Directory)
+            dialog.setOption(QtGui.QFileDialog.ShowDirsOnly)
+            self.lineEdit_file_path.setText(_translate("MainWindow", dialog.getExistingDirectory(None, 'Choose Directory') + '/', None))
+
+        # Dialog to get unmodulated data, load result into global var unmodulated_data
+        def get_unmodulated():
+            global unmodulated_data
+            self.textEdit.setText(timestamp())
+            dialog = QtGui.QFileDialog()
+            dialog.setFileMode(QtGui.QFileDialog.ExistingFile)
+            unmodulated_filename = (_translate("MainWindow", dialog.getOpenFileName(None, 'Choose unmodulated file...'), None))
+            unmodulated_data = calc_average_from_file(unmodulated_filename)
+            self.textEdit.append('Opening unmodulated file: ' + unmodulated_filename)
+
+        # Dialog to get background file, load result into global var background_data
+        def get_background():
+            global background_data
+            self.textEdit.setText(timestamp())
+            dialog = QtGui.QFileDialog()
+            dialog.setFileMode(QtGui.QFileDialog.ExistingFile)
+            background_filename = (_translate("MainWindow", dialog.getOpenFileName(None, 'Choose background file...'), None))
+            background_data = calc_average_from_file(background_filename)
+            self.textEdit.append('Opening background file: ' + background_filename)
+
+
+        # Dialog to get modulated file, plots are updated
+        def get_modulated():
+            dialog = QtGui.QFileDialog()
+            self.textEdit.setText(timestamp())
+            dialog.setFileMode(QtGui.QFileDialog.ExistingFile)
+            modulated_filename = (_translate("MainWindow", dialog.getOpenFileName(None, 'Choose modulated file...'), None))
+            data ,orb  = strip_data.strip_data(modulated_filename, NUMBER_PIXELS, 0)
+            self.textEdit.append('Opening ' + str(orb) + ' samples from modulated file: ' + modulated_filename)
+            update_plots(data)
+
+        def read_pcie_register(reg_number):
+	        ## Output is a string with (rubbish) + (8 chars for values, starting from [11])
+            try:
+                pcitool_string = subprocess.check_output(['./read_reg.sh', '-r', str(reg_number)])
+            except subprocess.CalledProcessError as e:
+                pcitool_string = '0'
+            #pcitool_string = subprocess.check_output(['./read_reg.sh', '-r', str(reg_number)])
+            value = pcitool_string[11:19]
+            ##value = '00011110'
+            return value
+
+        def read_register(reg_key, hex=False):
+	        ## Output from 'pci -r' function in terminal is a string with (rubbish)
+            ## + (8 chars for values, starting from [11])
+            pcitool_string = subprocess.check_output(['pci', '-r', self.registers[reg_key]["address"]])
+            if hex==True:
+                return pcitool_string[11:19]
+            else:
+                value = int(pcitool_string[11:19],16) & int(self.registers[reg_key]["mask"],16)
+                return value
+
+        def write_reg(reg_key,value):
+            subprocess.check_output(['pci', '-w', self.registers[reg_key]["address"],hex(int(value))])
+            name_of_reg_written = self.registers[reg_key]["name"]
+            self.status_bar.showMessage('Writing '+name_of_reg_written + ' : ' + value, 1000)
+
+        # Calculate average from filename, if DC is not correct returns 0
+        def calc_average_from_file(filename):
+            data, orb  = strip_data.strip_data(filename, NUMBER_PIXELS, 0)
+            average = np.average(data,axis = 0)
+            return average
+
+
+        # Function used to create .CSV with all the settings together with data file
+        def write_csv(output_file):
+            csvfile = output_file[:-3] + "csv"
+            with open(csvfile, "w") as output:
+                writer = csv.writer(output, lineterminator='\n')
+                entries = []
+                for key in self.log_conf["log_entries"]:
+                    entries.append([str(self.registers[key]["name"]),read_register(key)])
+                entries.append(["Timestamp",filename_timestamp()])
+                entries.append(["Fill number",self.lineEdit_fillnum.text()])
+                entries.append(["Detector",self.lineEdit_detector.text()])
+                entries.append(["Comments",self.lineEdit_comments.text()])
+                writer.writerows(entries)
+
+        # Read-back the settings from FPGA and saves them in the GUI
+        def readback_settings():
+            try:
+                if (read_register("PCIE_RESET",hex=True) != "14021700"):
+                    self.status_bar.showMessage('Error!', 1000)
+                    self.textEdit.insertPlainText(u'\u26A0' + ' Communication failed with FPGA board... Check FPGA, the PCI-Express connection and reboot')
+                else:
+                    self.spinBox_int_time.setValue(read_register("INTEG_DURATION"))
+                    self.spinBox_int_delay.setValue(read_register("INTEG_DELAY"))
+                    self.spinBox_gott_gain.setValue(read_register("GOTT_GAIN"))
+                    self.spinBox_total_samples.setValue(read_register("FT_TO_ACQ"))
+                    self.spinBox_skip_samples.setValue(read_register("FT_SKIP"))
+                    self.spinBox_int_trig.setValue(read_register("CLK_DIV"))
+            except:
+                self.status_bar.showMessage('Error!', 1000)
+                self.textEdit.insertPlainText(u'\u26A0' + ' Communication failed with FPGA board... Check FPGA, the PCI-Express connection and reboot')
+
+
+        # Check status and decode errors
+        def check_status():
+            status_1 = read_register("STATUS_1", hex=True)
+            status_1 = read_register("STATUS_1", hex=True)
+            status_1 = read_register("STATUS_1", hex=True)
+            status_1 = int(status_1,16)
+            status_1 = '{:032b}'.format(status_1)
+            if (status_1 == '0000000000000000000000000000000000000000'):
+                self.status_bar.showMessage(u'Status: \u2713', 5000)
+            else:
+                self.status_bar.showMessage(u'Status: \u26A0 error detected!', 5000)
+                self.textEdit.setTextColor(QtGui.QColor(255, 50, 0))
+                if (status_1[0] != '0'):
+                    self.textEdit.append(u'\u26A0' + ' Fast trigger is too fast or integration time is too high!')
+                if (status_1[6] != '0'):
+                    self.textEdit.append(u'\u26A0' + ' ADC fifos full! Problem with onboard DDR memory, turn on/off FPGA board and reboot the system.')
+                if (status_1[8] != '0'):
+                    self.textEdit.append(u'\u26A0' + ' DDR fifo is full during data readout! Re-init, check PCIe connection')
+                if (status_1[16] != '0'):
+                    self.textEdit.append(u'\u26A0' + ' Synchronization lost during operation! Check RF-CLK and re-init the system')
+
+            self.textEdit.setTextColor(QtGui.QColor(0, 0, 0))
+            return
+
+
+
+
+	def led_update():
+            status_led = read_register("STATUS_1", hex=True)
+            status_led = read_register("STATUS_1", hex=True)
+            status_led = int(status_led,16)
+            status_led = '{:032b}'.format(status_led)
+            #print(status_led)
+            if (status_led == '0000000000000000000000000000000000000000'):
+                self.led1.value=False
+                self.led2.value=False
+                self.led3.value=False
+                self.led4.value=False
+                self.led5.value=False
+                self.led6.value=False
+                self.led7.value=False
+                self.led8.value=False
+                self.led9.value=False
+                self.led10.value=False
+                self.led11.value=False
+                self.led12.value=False
+            else:
+                if (status_led[4] != '0'):
+                    self.led1.value=True
+                if (status_led[5] != '0'):
+                    self.led2.value=True
+                if (status_led[17] != '0'):
+                    self.led3.value=True
+                if (status_led[18] != '0'):
+                    self.led4.value=True
+                if (status_led[19] != '0'):
+                    self.led5.value=True
+                if (status_led[20] != '0'):
+                    self.led6.value=True
+                if (status_led[21] != '0'):
+                    self.led7.value=True
+                if (status_led[22] != '0'):
+                    self.led8.value=True
+                if (status_led[23] != '0'):
+                    self.led9.value=True
+                if (status_led[25] != '0'):
+                    self.led10.value=True
+                if (status_led[26] != '0'):
+                    self.led11.value=True
+                if (status_led[27] != '0'):
+                    self.led12.value=True
+            return
+
+
+
+        with open('kalypso_registers.json') as registers_file:
+            self.registers = json.load(registers_file)
+
+        with open('kalypso_log_conf.json') as log_conf_file:
+            self.log_conf = json.load(log_conf_file)
+
+        # BUTTONS ACTIONS
+        self.spinBox_int_time.valueChanged.connect(lambda: write_reg("INTEG_DURATION",self.spinBox_int_time.text()))
+        self.spinBox_int_delay.valueChanged.connect(lambda: write_reg("INTEG_DELAY",self.spinBox_int_delay.text()))
+        self.spinBox_gott_gain.valueChanged.connect(lambda: write_reg("GOTT_GAIN",self.spinBox_gott_gain.text()))
+        self.spinBox_total_samples.valueChanged.connect(lambda: write_reg("FT_TO_ACQ",self.spinBox_total_samples.text()))
+        self.spinBox_skip_samples.valueChanged.connect(lambda: write_reg("FT_SKIP",self.spinBox_skip_samples.text()))
+        self.spinBox_int_trig.valueChanged.connect(lambda: write_reg("CLK_DIV",self.spinBox_int_trig.text()))
+
+        self.pushButton_file_path.clicked.connect(getDir)
+        self.pushButton_background_file.clicked.connect(get_background)
+        self.pushButton_modulated_file.clicked.connect(get_modulated)
+        self.pushButton_unmodulated_file.clicked.connect(get_unmodulated)
+        self.pushButton_readsettings.clicked.connect(readback_settings)
+        self.pushButton_init_board.clicked.connect(init_board)
+        self.pushButton_init_board_ex_rf.clicked.connect(init_board_ex_rf)
+        self.pushButton_timescan.clicked.connect(timescan)
+        self.pushButton_poweroff.clicked.connect(poweroff)
+        self.pushButton_modulated.clicked.connect(readout_modulated)
+        self.pushButton_background.clicked.connect(readout_background)
+        self.pushButton_unmodulated.clicked.connect(readout_unmodulated)
+
+        #self.pushButton_custom_function_2.clicked.connect(custom_function_2)
+
+        #timer
+        self.timer = pg.QtCore.QTimer()
+        #self.timer.timeout.connect(plot_waveform)
+        self.timer.timeout.connect(terminal_cmd_run)
+        self.timer.timeout.connect(terminal_cmd_checkbox)
+        self.timer.start(10)
+
+        self.retranslateUi(MainWindow)
+        QtCore.QMetaObject.connectSlotsByName(MainWindow)
+
+        ## Readback settings from FPGA at beginning
+
+        try:
+            if (read_register("PCIE_RESET",hex=True) != "14021700"):
+                self.status_bar.showMessage('Error!', 1000)
+                self.textEdit.insertPlainText(u'\u26A0' + ' Communication failed with FPGA board... Check FPGA, the PCI-Express connection and reboot')
+            else:
+                readback_settings()
+        except:
+            self.status_bar.showMessage('Error!', 1000)
+            self.textEdit.insertPlainText(u'\u26A0' + ' Communication failed with FPGA board... Check FPGA, the PCI-Express connection and reboot')
+
+
+
+
+    def retranslateUi(self, MainWindow):
+        boldFont=QtGui.QFont()
+        boldFont.setBold(True)
+        MainWindow.setWindowTitle(_translate("MainWindow", "KALYPSO-v2 GUI", None))
+        #self.pushButton_custom_function_2.setText(_translate("MainWindow", "custom_function_2", None))
+        self.label_settings.setText(_translate("MainWindow", "KALYPSO settings", None))
+        self.pushButton_readsettings.setText(_translate("MainWindow", "Read-back", None))
+        self.label_settings.setFont(boldFont)
+        self.label_int_time.setText(_translate("MainWindow", "Integration Time (16 ns step)", None))
+        self.label_int_delay.setText(_translate("MainWindow", "Integration Delay (16 ns step)", None))
+        self.label_gott_gain.setText(_translate("MainWindow", "GOTTHARD Gain", None))
+        self.label_disp_settings.setText(_translate("MainWindow", "Display settings", None))
+        self.label_disp_settings.setFont(boldFont)
+        self.label_pix_min.setText(_translate("MainWindow", "Pixel Range", None))
+        self.label_samples.setText(_translate("MainWindow", "Total samples", None))
+        self.spinbox_pix_min.setValue(0)
+        self.spinbox_pix_max.setValue(1023)
+        self.label_skip_samples.setText(_translate("MainWindow", "Fast-trigger skip", None))
+        # self.label_int_trig_text.setText(_translate("MainWindow", "Internal trigger (0 = external trigger)", None))
+        # self.label_int_trig_text.setFont(boldFont)
+        self.label_int_trig.setText(_translate("MainWindow", "Internal trig. DIV (0 = ext)", None))
+        self.label_controls.setText(_translate("MainWindow", "KALYPSO operation", None))
+        self.label_controls.setFont(boldFont)
+        self.pushButton_init_board.setText(_translate("MainWindow", "Init Board", None))
+        self.pushButton_init_board_ex_rf.setText(_translate("MainWindow", "Init Board (Soleil)", None))
+
+
+        self.pushButton_timescan.setText(_translate("MainWindow", "Timescan", None))
+        self.pushButton_poweroff.setText(_translate("MainWindow", "Poweroff", None))
+        self.label_loadfile.setText(_translate("MainWindow", "Load from file", None))
+        self.label_loadfile.setFont(boldFont)
+        self.pushButton_background_file.setText(_translate("MainWindow", "Background", None))
+        self.pushButton_modulated_file.setText(_translate("MainWindow", "Modulated", None))
+        self.pushButton_unmodulated_file.setText(_translate("MainWindow", "Unmodulated", None))
+
+        self.label_acq.setText(_translate("MainWindow", "Acquire data", None))
+        self.label_acq.setFont(boldFont)
+        self.checkBox_cont_acq.setText(_translate("MainWindow", "Live preview", None))
+        # self.checkBox_ELOG.setText(_translate("MainWindow", "Create ELOG entry", None))
+        self.checkBox_savefile.setText(_translate("MainWindow", "Save File", None))
+        self.pushButton_modulated.setText(_translate("MainWindow", "Modulated", None))
+        self.pushButton_background.setText(_translate("MainWindow", "Background", None))
+        self.pushButton_unmodulated.setText(_translate("MainWindow", "Unmodulated", None))
+
+        self.checkBox_calc_modul.setText(_translate("MainWindow", "Calculate Mod.", None))
+        self.checkBox_remove_back.setText(_translate("MainWindow", "Remove background", None))
+        self.checkBox_average.setText(_translate("MainWindow", "Show average", None))
+        self.pushButton_file_path.setText(_translate("MainWindow", "File Path", None))
+        self.lineEdit_file_path.setText(_translate("MainWindow", "./temp/", None))
+
+
+
+	self.label_led1.setText(_translate("MainWindow", "DDR ready", None))
+        self.label_led1.setFont(boldFont)
+        self.label_led2.setText(_translate("MainWindow", "PCIe link", None))
+        self.label_led2.setFont(boldFont)
+        self.label_led3.setText(_translate("MainWindow", "PLL Gotthard TOP", None))
+        self.label_led3.setFont(boldFont)
+        self.label_led4.setText(_translate("MainWindow", "PLL Gotthard BOTTOM", None))
+        self.label_led4.setFont(boldFont)
+        self.label_led5.setText(_translate("MainWindow", "PLL Infrastructure FPGA", None))
+        self.label_led5.setFont(boldFont)
+        self.label_led6.setText(_translate("MainWindow", "PLL on-board Kalypso", None))
+        self.label_led6.setFont(boldFont)
+        self.label_led7.setText(_translate("MainWindow", "ADC TOP", None))
+        self.label_led7.setFont(boldFont)
+        self.label_led8.setText(_translate("MainWindow", "ADC BOTTOM", None))
+        self.label_led8.setFont(boldFont)
+        self.label_led9.setText(_translate("MainWindow", "JESD TOP", None))
+        self.label_led9.setFont(boldFont)
+        self.label_led10.setText(_translate("MainWindow", "JESD BOTTOM", None))
+        self.label_led10.setFont(boldFont)
+        self.label_led11.setText(_translate("MainWindow", "JESD TOP ERROR", None))
+        self.label_led11.setFont(boldFont)
+        self.label_led12.setText(_translate("MainWindow", "JESD BOTTOM ERROR", None))
+        self.label_led12.setFont(boldFont)
+
+        self.label_log.setText(_translate("MainWindow", "KALYPSO status", None))
+        self.label_log.setFont(boldFont)
+
+if __name__ == "__main__":
+    import sys
+    app = QtGui.QApplication(sys.argv)
+    MainWindow = QtGui.QMainWindow()
+    app.setStyle('cleanlooks')
+    ui = Ui_MainWindow()
+    ui.setupUi(MainWindow)
+
+    MainWindow.show()
+    sys.exit(app.exec_())

+ 11 - 0
G_ON.sh

@@ -0,0 +1,11 @@
+#!/bin/sh
+
+
+echo "GOT: Turning on power..."
+#pci -w 9048 f0
+#sleep 0.1
+
+pci -w 9048 ff
+sleep 0.1
+
+echo "....done!****"

+ 258 - 0
adc_config.sh

@@ -0,0 +1,258 @@
+#! /bin/bash
+
+echo "*** ADC  ADS52j90 ***"
+echo "*** Start Configuration of ADC #1 and #2 ***"
+echo "       Sub Class 2      "
+echo "*** Start INIT after Power-ON ***"
+
+
+
+#echo "ADC1: Soft Reset"
+pci -w 0x90A0 0x00000001
+pci -w 0x90A4 0x00000001
+sleep 0.1
+
+#echo "ADC1: enable write"
+#pci -w 0x90A0 0x00000000
+#pci -w 0x90A4 0x00000000
+#sleep 0.1
+
+
+pci -w 0x90A0 0x000A3000
+pci -w 0x90A4 0x000A3000
+sleep 0.1
+
+
+#for LMFC  INIT VALUE
+#pci -w 0x90A0 0x0078fc00
+#pci -w 0x90A4 0x0078fc00
+#sleep 0.1
+## sequences start here #
+
+#echo "ADC1: REG ADD 1 EN-JESD AND DIS-LVDS"
+pci -w 0x90A0 0x00010060
+pci -w 0x90A4 0x00010060
+sleep 0.1
+
+#echo "TEST PATTER IS 1234"
+#pci -w 0x90A0 0x00051234
+#pci -w 0x90A0 0x00051234   # all 1s test mode is 2, all 0s is 3
+#sleep 0.1
+
+#echo "ADC1: REG ADD 2 --> Normal MODE' "
+pci -w 0x90A0 0x00020000  # all 1s test mode is 2, all 0s is 3
+pci -w 0x90A4 0x00020000  # all 1s test mode is 2, all 0s is 3
+sleep 0.1
+
+# bit number 5 is enable the PRBS_EN
+#echo "ADC1: REG ADD 3"
+pci -w 0x90A0 0x00038020                 #01 is 14bit mode, 000 is 12x, 001 is 14x, 100 is 16x, 011 is 10x
+pci -w 0x90A4 0x00038020                 #01 is 14bit mode, 000 is 12x, 001 is 14x, 100 is 16x, 011 is 10x
+sleep 0.1
+
+
+#echo "ADC1: REG ADD 4"
+pci -w 0x90A0 0x00040001                 #01 is 14bit mode, 00 is 12 bit mode and 11 is 10bit
+pci -w 0x90A4 0x00040001                 #01 is 14bit mode, 00 is 12 bit mode and 11 is 10bit
+sleep 0.1
+
+###############ADDED NEW#####################
+
+#pci -w 0x90A0 0x00410002                 #01 is 14bit mode, 00 is 12 bit mode and 11 is 10bit
+#pci -w 0x90A4 0x00410002                 #01 is 14bit mode, 00 is 12 bit mode and 11 is 10bit
+#sleep 0.1
+###########################################
+
+
+
+echo "Start JESD settings ADC #1 and #2"
+
+ #####-------changing K value-----#####
+ # enable force K
+ # with frame alignment option #
+#echo "ADC: REG ADD 49 --> to force K value"
+#pci -w 0x90A0 0x00491804
+#sleep 0.1
+
+###############ADDED NEW####################
+#echo "ADC1: REG ADD 46 --> JESD_RESET1"
+pci -w 0x90A0 0x00460002
+pci -w 0x90A4 0x00460002
+sleep 0.1
+###########################################
+#echo "ADC1: REG ADD 49 --> without FRAME ALIG. to force K value"
+pci -w 0x90A0 0x00490004
+pci -w 0x90A4 0x00490004
+sleep 0.1
+
+###################ADDED NEW##################
+#echo "ADC1: REG ADD 4A --> JESD_RESET3"
+pci -w 0x90A0 0x004A0080
+pci -w 0x90A4 0x004A0080
+sleep 0.1
+############################################
+
+#echo "ADC1: REG ADD 4B"
+pci -w 0x90A0 0x004B0100
+pci -w 0x90A4 0x004B0100
+sleep 0.1
+
+
+#echo "ADC1: REG ADD 50 --> INC JESD VDD "
+pci -w 0x90A0 0x00500002
+pci -w 0x90A4 0x00500002
+sleep 0.1
+
+
+
+#  force K to 5+1 = 6
+#echo "ADC1: REG ADD 53 --> K value force to F"
+pci -w 0x90A0 0x0053000F    #was f
+pci -w 0x90A4 0x0053000F    #was f
+sleep 0.1
+
+#echo "ADC1: REG ADD 55 Sub Class 2 - here"
+pci -w 0x90A0 0x00554020
+pci -w 0x90A4 0x00554020
+sleep 0.1
+
+#echo "ADC1: REG ADD 73"
+pci -w 0x90A0 0x00730010
+pci -w 0x90A4 0x00730010
+sleep 0.1
+
+
+
+#echo "READ ALL CONFIG ... "
+
+#echo "ADC1: Read"
+#pci -w 0x90A0 0x00000002
+
+#for add in {1..5};
+#  do
+#    pci -w 0x90B0 0x$add
+#    pci -r 0x90B0
+#    value=`pci -r 0x90A8 -s1`
+#    echo "address $add, value = $value "
+#  done
+#
+#for add in {49..73};
+#  do
+#    pci -w 0x90B0 0x$add
+#    pci -r 0x90B0
+#    value=`pci -r 0x90A8 -s1`
+#    echo "address $add, value = $value "
+#  done
+./adc_offset_remove.sh
+#0000
+echo "ADC 1 & 2: CONFIG ...DONE..."
+
+
+#! /bin/bash
+
+#echo "*** ADC  ADS52j90 ***"
+#echo "*** Start Configuration of ADC # 2 ***"
+#echo "*** Start INIT after Power-ON ***"
+# pci -w 0x90A4 0x000A3000
+# sleep 0.1
+
+#echo "ADC2: Soft Reset"
+#pci -w 0x90A4 0x00000001
+#sleep 0.1
+
+#echo "ADC2: enable write"
+#pci -w 0x90A4 0x00000000
+#sleep 0.1
+## sequences start here #
+
+#echo "ADC2: REG ADD 1"
+#pci -w 0x90A4 0x00010074
+#sleep 0.1
+
+#echo "TEST PATTER IS 1234"
+#pci -w 0x90A4 0x00051234
+#pci -w 0x90A4 0x00050000   # all 1s test mode is 2, all 0s is 3
+#sleep 0.1
+
+#echo "ADC2: REG ADD 2 --> Normal MODE ' "
+#pci -w 0x90A4 0x00021000  # all 1s test mode is 2, all 0s is 3
+#sleep 0.1
+
+# bit number 5 is enable the PRBS_EN
+#echo "ADC2: REG ADD 3"
+#pci -w 0x90A4 0x00038020                 #01 is 14bit mode, 000 is 12x, 001 is 14x, 100 is 16x, 011 is 10x
+#sleep 0.1
+
+#echo "ADC2: REG ADD 4"
+#pci -w 0x90A4 0x00040001                 #01 is 14bit mode, 00 is 12 bit mode and 11 is 10bit
+#sleep 0.1
+
+#echo "Start JESD settings ADC # 2"
+
+ #####-------changing K value-----#####
+ # enable force K
+ # with frame alignment option #
+#echo "ADC: REG ADD 49 --> to force K value"
+#pci -w 0x90A4 0x00491804
+#sleep 0.1
+
+#echo "ADC2: REG ADD 49 --> without FRAME ALIG. to force K value"
+#pci -w 0x90A4 0x00490004
+#sleep 0.1
+
+#echo "ADC2: REG ADD 4B"
+#pci -w 0x90A4 0x004B0100
+#sleep 0.1
+
+#  force K to 5+1 = 6
+#echo "ADC2: REG ADD 53 --> K value force to F"
+#pci -w 0x90A4 0x0053000F
+#sleep 0.1
+
+#echo "ADC2: REG ADD 55 Sub Class 2 - here"
+#pci -w 0x90A4 0x00554020
+#sleep 0.1
+
+#echo "ADC2: REG ADD 73"
+#pci -w 0x90A4 0x00730010
+#sleep 0.1
+
+#echo "READ ALL CONFIG ... "
+
+#echo "ADC2: enable read"
+#pci -w 0x90A4 0x00000002
+#sleep 0.1
+
+#for add in {1..5};
+#  do
+#    pci -w 0x90B4 0x$add
+#    pci -r 0x90B4
+#    value=`pci -r 0x90AC -s1`
+#    echo "address $add, value = $value "
+#  done
+
+#for add in {49..73};
+#  do
+#    pci -w 0x90B4 0x$add
+#    pci -r 0x90B4
+#   value=`pci -r 0x90AC -s1`
+#   echo "address $add, value = $value "
+#  done
+
+##################################################
+# lines to be removed
+pci -w 0x9114 0x20
+sleep 0.01
+pci -w 0x9118 0x0F # was 07
+sleep 0.01
+value=`pci -r 0x911C -s1`
+echo "Value = $value "
+sleep 0.1
+# frame per multiframe setting doesn't solve the problem
+pci -w 0x9114 0x24
+sleep 0.01
+pci -w 0x9118 0x1F   # was F before
+sleep 0.01
+value=`pci -r 0x911C -s1`
+echo "Frame per mulfi-frame = $value "
+sleep 0.1

+ 269 - 0
adc_config_2_offset.sh

@@ -0,0 +1,269 @@
+#! /bin/bash
+echo "Removing ADC offset at 0 delay setting"
+# bit number 5 is enable the PRBS_EN
+#echo "ADC1: REG ADD 3"
+pci -w 0x90A0 0x00038120                 #01 is 14bit mode, 000 is 12x, 001 is 14x, 100 is 16x, 011 is 10x
+sleep 0.05
+
+#####################################################################################################################################
+
+#echo "ADC1: REG ADD D"
+pci -w 0x90A0 0x000D01b9               #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD E"
+pci -w 0x90A0 0x000E01e3               #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD F"
+pci -w 0x90A0 0x000F017a                #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 10"
+pci -w 0x90A0 0x001001d1                #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 11"
+pci -w 0x90A0 0x0011017e                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 12"
+pci -w 0x90A0 0x0012019e                #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 13"
+pci -w 0x90A0 0x001301b5                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 14"
+pci -w 0x90A0 0x001401a1                #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 19"
+pci -w 0x90A0 0x00190187              #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 1A"
+pci -w 0x90A0 0x001A01ae                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 1B"
+pci -w 0x90A0 0x001B0147                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 1C"
+pci -w 0x90A0 0x001C0180                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 1D"
+pci -w 0x90A0 0x001D0145                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 1E"
+pci -w 0x90A0 0x001E017e                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 1F"
+pci -w 0x90A0 0x001F0158                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 20"
+pci -w 0x90A0 0x002001bc                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 25"
+pci -w 0x90A0 0x00250140                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 26"
+pci -w 0x90A0 0x00260175                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 27"
+pci -w 0x90A0 0x00270141                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 28"
+pci -w 0x90A0 0x0028017b                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 29"
+pci -w 0x90A0 0x00290122
+sleep 0.05
+
+#echo "ADC1: REG ADD 2A"
+pci -w 0x90A0 0x002A0133                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 2B"
+pci -w 0x90A0 0x002B0118                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 2C"
+pci -w 0x90A0 0x002C01a5                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 31"
+pci -w 0x90A0 0x0031012f                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 32"
+pci -w 0x90A0 0x00320139                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 33"
+pci -w 0x90A0 0x00330130                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 34"
+pci -w 0x90A0 0x0034016e                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 35"
+pci -w 0x90A0 0x0035017c                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 36"
+pci -w 0x90A0 0x00360174                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 37"
+pci -w 0x90A0 0x00370115             #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 38"
+pci -w 0x90A0 0x00380157                 #Offset value
+sleep 0.05
+##########################################################################################################
+
+#####################################################################################################################################
+pci -w 0x90A4 0x00038120                 #01 is 14bit mode, 000 is 12x, 001 is 14x, 100 is 16x, 011 is 10x
+sleep 0.05
+
+#echo "ADC2: REG ADD D"
+pci -w 0x90A4 0x000D0156                #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD E"
+pci -w 0x90A4 0x000E0162                #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD F"
+pci -w 0x90A4 0x000F0152               #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 10"
+pci -w 0x90A4 0x00100157                #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 11"
+pci -w 0x90A4 0x00110150                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 12"
+pci -w 0x90A4 0x00120177                #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 13"
+pci -w 0x90A4 0x0013016d                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 14"
+pci -w 0x90A4 0x00140167                #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 19"
+pci -w 0x90A4 0x00190136              #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 1A"
+pci -w 0x90A4 0x001A0183                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 1B"
+pci -w 0x90A4 0x001B0156                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 1C"
+pci -w 0x90A4 0x001C0171                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 1D"
+pci -w 0x90A4 0x001D018b                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 1E"
+pci -w 0x90A4 0x001E0163                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 1F"
+pci -w 0x90A4 0x001F0176                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 20"
+pci -w 0x90A4 0x002001d4                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 25"
+pci -w 0x90A4 0x0025018f                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 26"
+pci -w 0x90A4 0x002601a5                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 27"
+pci -w 0x90A4 0x00270136                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 28"
+pci -w 0x90A4 0x0028015f                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 29"
+pci -w 0x90A4 0x00290158                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 2A"
+pci -w 0x90A4 0x002A0193                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 2B"
+pci -w 0x90A4 0x002B013c                #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 2C"
+pci -w 0x90A4 0x002C013e                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 31"
+pci -w 0x90A4 0x0031015e                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 32"
+pci -w 0x90A4 0x00320155                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 33"
+pci -w 0x90A4 0x00330150                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 34"
+pci -w 0x90A4 0x00340165                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 35"
+pci -w 0x90A4 0x00350179                #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 36"
+pci -w 0x90A4 0x0036017b                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 37"
+pci -w 0x90A4 0x00370162                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 38"
+pci -w 0x90A4 0x0038017e                 #Offset value
+sleep 0.05

+ 80 - 0
adc_config_2_offset_old.sh

@@ -0,0 +1,80 @@
+#! /bin/bash
+
+# bit number 5 is enable the PRBS_EN
+echo "ADC1: REG ADD 3"
+pci -w 0x90A0 0x00038120                 #01 is 14bit mode, 000 is 12x, 001 is 14x, 100 is 16x, 011 is 10x
+sleep 0.3
+
+pci -w 0x90B0 0x0003
+pci -r 0x90B0
+pci -r 0x90A8
+
+
+#####################################################################################################################################
+echo "ADC1: REG ADD D"
+pci -w 0x90A0 0x000D03FF                #Offset value
+sleep 0.3
+pci -w 0x90B0 0x000D
+pci -r 0x90B0
+pci -r 0x90A8
+
+echo "ADC1: REG ADD E"
+pci -w 0x90A0 0x000E03FF                #Offset value
+sleep 0.3
+
+echo "ADC1: REG ADD F"
+pci -w 0x90A0 0x000F03FF                 #Offset value
+sleep 0.3
+
+echo "ADC1: REG ADD 10"
+pci -w 0x90A0 0x001003FF                #Offset value
+sleep 0.3
+
+echo "ADC1: REG ADD 11"
+pci -w 0x90A0 0x001103FF                 #Offset value
+sleep 0.3
+
+echo "ADC1: REG ADD 12"
+pci -w 0x90A0 0x001203FF                #Offset value
+sleep 0.3
+
+echo "ADC1: REG ADD 13"
+pci -w 0x90A0 0x001303FF                 #Offset value
+sleep 0.3
+
+echo "ADC1: REG ADD 14"
+pci -w 0x90A0 0x001403FF                #Offset value
+sleep 0.3
+
+echo "ADC1: REG ADD 19"
+pci -w 0x90A0 0x001903FF              #Offset value
+sleep 0.3
+
+echo "ADC1: REG ADD 1A"
+pci -w 0x90A0 0x001A03FF                 #Offset value
+sleep 0.3
+
+echo "ADC1: REG ADD 1B"
+pci -w 0x90A0 0x001B03FF                 #Offset value
+sleep 0.3
+
+echo "ADC1: REG ADD 1C"
+pci -w 0x90A0 0x001C03FF                 #Offset value
+sleep 0.3
+
+echo "ADC1: REG ADD 1D"
+pci -w 0x90A0 0x001D03FF                 #Offset value
+sleep 0.3
+
+echo "ADC1: REG ADD 1E"
+pci -w 0x90A0 0x001E03FF                 #Offset value
+sleep 0.3
+
+echo "ADC1: REG ADD 1F"
+pci -w 0x90A0 0x001F03FF                 #Offset value
+sleep 0.3
+
+echo "ADC1: REG ADD 20"
+pci -w 0x90A0 0x002003FF                 #Offset value
+sleep 0.3
+##########################################################################################################

+ 269 - 0
adc_offset_at_0_delay.sh

@@ -0,0 +1,269 @@
+#! /bin/bash
+echo "Removing ADC offset at 0 delay setting"
+# bit number 5 is enable the PRBS_EN
+#echo "ADC1: REG ADD 3"
+pci -w 0x90A0 0x00038120                 #01 is 14bit mode, 000 is 12x, 001 is 14x, 100 is 16x, 011 is 10x
+sleep 0.05
+
+#####################################################################################################################################
+
+#echo "ADC1: REG ADD D"
+pci -w 0x90A0 0x000D0000                #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD E"
+pci -w 0x90A0 0x000E0000               #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD F"
+pci -w 0x90A0 0x000F0000                #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 10"
+pci -w 0x90A0 0x00100000                #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 11"
+pci -w 0x90A0 0x00110000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 12"
+pci -w 0x90A0 0x00120000                #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 13"
+pci -w 0x90A0 0x00130000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 14"
+pci -w 0x90A0 0x00140000                #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 19"
+pci -w 0x90A0 0x00190000              #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 1A"
+pci -w 0x90A0 0x001A0000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 1B"
+pci -w 0x90A0 0x001B0000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 1C"
+pci -w 0x90A0 0x001C0000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 1D"
+pci -w 0x90A0 0x001D0000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 1E"
+pci -w 0x90A0 0x001E0000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 1F"
+pci -w 0x90A0 0x001F0000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 20"
+pci -w 0x90A0 0x00200000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 25"
+pci -w 0x90A0 0x00250000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 26"
+pci -w 0x90A0 0x00260000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 27"
+pci -w 0x90A0 0x00270000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 28"
+pci -w 0x90A0 0x00280000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 29"
+pci -w 0x90A0 0x00290000
+sleep 0.05
+
+#echo "ADC1: REG ADD 2A"
+pci -w 0x90A0 0x002A0000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 2B"
+pci -w 0x90A0 0x002B0000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 2C"
+pci -w 0x90A0 0x002C0000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 31"
+pci -w 0x90A0 0x00310000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 32"
+pci -w 0x90A0 0x00320000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 33"
+pci -w 0x90A0 0x00330000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 34"
+pci -w 0x90A0 0x00340000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 35"
+pci -w 0x90A0 0x00350000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 36"
+pci -w 0x90A0 0x00360000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 37"
+pci -w 0x90A0 0x00370000               #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 38"
+pci -w 0x90A0 0x00380000                 #Offset value
+sleep 0.05
+##########################################################################################################
+
+#####################################################################################################################################
+pci -w 0x90A4 0x00038120                 #01 is 14bit mode, 000 is 12x, 001 is 14x, 100 is 16x, 011 is 10x
+sleep 0.05
+
+#echo "ADC2: REG ADD D"
+pci -w 0x90A4 0x000D0000                #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD E"
+pci -w 0x90A4 0x000E0000                #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD F"
+pci -w 0x90A4 0x000F0000               #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 10"
+pci -w 0x90A4 0x00100000                #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 11"
+pci -w 0x90A4 0x00110000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 12"
+pci -w 0x90A4 0x00120000                #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 13"
+pci -w 0x90A4 0x00130000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 14"
+pci -w 0x90A4 0x00140000                #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 19"
+pci -w 0x90A4 0x00190000              #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 1A"
+pci -w 0x90A4 0x001A0000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 1B"
+pci -w 0x90A4 0x001B0000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 1C"
+pci -w 0x90A4 0x001C0000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 1D"
+pci -w 0x90A4 0x001D0000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 1E"
+pci -w 0x90A4 0x001E0000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 1F"
+pci -w 0x90A4 0x001F0000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 20"
+pci -w 0x90A4 0x00200000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 25"
+pci -w 0x90A4 0x00250000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 26"
+pci -w 0x90A4 0x00260000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 27"
+pci -w 0x90A4 0x00270000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 28"
+pci -w 0x90A4 0x00280000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 29"
+pci -w 0x90A4 0x00290000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 2A"
+pci -w 0x90A4 0x002A0000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 2B"
+pci -w 0x90A4 0x002B0000                #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 2C"
+pci -w 0x90A4 0x002C0000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 31"
+pci -w 0x90A4 0x00310000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 32"
+pci -w 0x90A4 0x00320000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 33"
+pci -w 0x90A4 0x00330000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 34"
+pci -w 0x90A4 0x00340000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 35"
+pci -w 0x90A4 0x00350000                #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 36"
+pci -w 0x90A4 0x00360000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 37"
+pci -w 0x90A4 0x00370000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 38"
+pci -w 0x90A4 0x00380000                 #Offset value
+sleep 0.05

+ 269 - 0
adc_offset_remove.sh

@@ -0,0 +1,269 @@
+#! /bin/bash
+
+# bit number 5 is enable the PRBS_EN
+#echo "ADC1: REG ADD 3"
+pci -w 0x90A0 0x00038120                 #01 is 14bit mode, 000 is 12x, 001 is 14x, 100 is 16x, 011 is 10x
+sleep 0.05
+
+#####################################################################################################################################
+
+#echo "ADC1: REG ADD D"
+pci -w 0x90A0 0x000D0000                #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD E"
+pci -w 0x90A0 0x000E01ff               #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD F"
+pci -w 0x90A0 0x000F0000                #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 10"
+pci -w 0x90A0 0x00100000                #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 11"
+pci -w 0x90A0 0x00110000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 12"
+pci -w 0x90A0 0x00120000                #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 13"
+pci -w 0x90A0 0x00130000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 14"
+pci -w 0x90A0 0x00140000                #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 19"
+pci -w 0x90A0 0x00190000              #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 1A"
+pci -w 0x90A0 0x001A0000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 1B"
+pci -w 0x90A0 0x001B0000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 1C"
+pci -w 0x90A0 0x001C0000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 1D"
+pci -w 0x90A0 0x001D0000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 1E"
+pci -w 0x90A0 0x001E0000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 1F"
+pci -w 0x90A0 0x001F0000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 20"
+pci -w 0x90A0 0x00200000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 25"
+pci -w 0x90A0 0x00250000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 26"
+pci -w 0x90A0 0x00260000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 27"
+pci -w 0x90A0 0x00270000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 28"
+pci -w 0x90A0 0x00280000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 29"
+pci -w 0x90A0 0x00290000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 2A"
+pci -w 0x90A0 0x002A0000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 2B"
+pci -w 0x90A0 0x002B0000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 2C"
+pci -w 0x90A0 0x002C0000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 31"
+pci -w 0x90A0 0x00310000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 32"
+pci -w 0x90A0 0x00320000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 33"
+pci -w 0x90A0 0x00330000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 34"
+pci -w 0x90A0 0x00340000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 35"
+pci -w 0x90A0 0x00350000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 36"
+pci -w 0x90A0 0x00360000                 #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 37"
+pci -w 0x90A0 0x003701ff               #Offset value
+sleep 0.05
+
+#echo "ADC1: REG ADD 38"
+pci -w 0x90A0 0x00380000                #Offset value
+sleep 0.05
+##########################################################################################################
+
+#####################################################################################################################################
+pci -w 0x90A4 0x00038120                 #01 is 14bit mode, 000 is 12x, 001 is 14x, 100 is 16x, 011 is 10x
+sleep 0.05
+
+#echo "ADC2: REG ADD D"
+pci -w 0x90A4 0x000D01ff                #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD E"
+pci -w 0x90A4 0x000E01ff                #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD F"
+pci -w 0x90A4 0x000F0000               #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 10"
+pci -w 0x90A4 0x00100000                #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 11"
+pci -w 0x90A4 0x00110000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 12"
+pci -w 0x90A4 0x00120000                #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 13"
+pci -w 0x90A4 0x00130000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 14"
+pci -w 0x90A4 0x00140000                #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 19"
+pci -w 0x90A4 0x00190000              #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 1A"
+pci -w 0x90A4 0x001A0000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 1B"
+pci -w 0x90A4 0x001B0000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 1C"
+pci -w 0x90A4 0x001C0000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 1D"
+pci -w 0x90A4 0x001D0000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 1E"
+pci -w 0x90A4 0x001E0000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 1F"
+pci -w 0x90A4 0x001F0000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 20"
+pci -w 0x90A4 0x00200000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 25"
+pci -w 0x90A4 0x00250000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 26"
+pci -w 0x90A4 0x00260000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 27"
+pci -w 0x90A4 0x00270000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 28"
+pci -w 0x90A4 0x00280000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 29"
+pci -w 0x90A4 0x00290000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 2A"
+pci -w 0x90A4 0x002A0000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 2B"
+pci -w 0x90A4 0x002B0000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 2C"
+pci -w 0x90A4 0x002C0000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 31"
+pci -w 0x90A4 0x00310000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 32"
+pci -w 0x90A4 0x00320000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 33"
+pci -w 0x90A4 0x00330000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 34"
+pci -w 0x90A4 0x00340000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 35"
+pci -w 0x90A4 0x00350000                #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 36"
+pci -w 0x90A4 0x00360000                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 37"
+pci -w 0x90A4 0x003701ff                 #Offset value
+sleep 0.05
+
+#echo "ADC2: REG ADD 38"
+pci -w 0x90A4 0x003801ff                 #Offset value
+sleep 0.05

+ 48 - 0
align_clock.sh

@@ -0,0 +1,48 @@
+echo "*CLOCK: Alignment... 2 nsec per execution."
+
+#pci -w 9088 ff
+#sleep 0.05
+#pci -w 9088 0
+#sleep 0.05
+#pci -w 9088 ff
+#sleep 0.05
+#pci -w 9088 0
+#sleep 0.05
+#pci -w 9088 ff
+#sleep 0.05
+#pci -w 9088 0
+#sleep 0.05
+#pci -w 9088 ff
+#sleep 0.05
+#pci -w 9088 0
+#sleep 0.05
+#pci -w 9088 ff
+#sleep 0.05
+#pci -w 9088 0
+#sleep 0.05
+
+# pci -w 9088 ff
+# sleep 0.05
+# pci -w 9088 0
+# sleep 0.05
+# pci -w 9088 ff
+# sleep 0.05
+# pci -w 9088 0
+# sleep 0.05
+# pci -w 9088 ff
+# sleep 0.05
+#pci -w 9088 0
+#sleep 0.05
+
+
+pci -w 9040 10310f00
+sleep 0.05
+pci -w 9040 10210f00
+sleep 0.05
+
+pci -w 908C 5f0
+sleep 0.05
+
+
+
+echo "*CLOCK: Alignment done!"

+ 47 - 0
align_clock_b.sh

@@ -0,0 +1,47 @@
+echo "*CLOCK: Alignment... 2 nsec per execution."
+
+#pci -w 908C ff
+#sleep 0.05
+#pci -w 908C 0
+#sleep 0.05
+#pci -w 908C ff
+#sleep 0.05
+#pci -w 908C 0
+#sleep 0.05
+#pci -w 908C ff
+#sleep 0.05
+#pci -w 908C 0
+#sleep 0.05
+#pci -w 908C ff
+#sleep 0.05
+#pci -w 908C 0
+#sleep 0.05
+#pci -w 908C ff
+#sleep 0.05
+#pci -w 908C 0
+#sleep 0.05
+# pci -w 908C ff
+# sleep 0.05
+# pci -w 908C 0
+# sleep 0.05
+# pci -w 908C ff
+# sleep 0.05
+# pci -w 908C 0
+# sleep 0.05
+# pci -w 908C ff
+# sleep 0.05
+#pci -w 908C 0
+#sleep 0.05
+
+
+pci -w 9040 10310f00
+sleep 0.05
+pci -w 9040 10210f00
+sleep 0.05
+
+
+pci -w 908C 5f0
+sleep 0.05
+
+
+echo "*CLOCK: Alignment done!"

+ 37 - 0
align_clock_b_revertback_1ns.sh

@@ -0,0 +1,37 @@
+echo "*CLOCK: Alignment... 2 nsec per execution."
+
+pci -w 908C 7f
+sleep 0.05
+pci -w 908C 0
+sleep 0.05
+#pci -w 9088 ff
+#sleep 0.05
+#pci -w 9088 0
+#sleep 0.05
+#pci -w 9088 ff
+#sleep 0.05
+#pci -w 9088 0
+#sleep 0.05
+#pci -w 9088 ff
+#sleep 0.05
+#pci -w 9088 0
+#sleep 0.05
+#pci -w 9088 ff
+#sleep 0.05
+#pci -w 9088 0
+#sleep 0.05
+# pci -w 9088 ff
+# sleep 0.05
+# pci -w 9088 0
+# sleep 0.05
+# pci -w 9088 ff
+# sleep 0.05
+# pci -w 9088 0
+# sleep 0.05
+# pci -w 9088 ff
+# sleep 0.05
+#pci -w 9088 0
+#sleep 0.05
+
+
+echo "*CLOCK: Alignment done!"

+ 29 - 0
auto_offset_removal.sh

@@ -0,0 +1,29 @@
+#!/bin/sh
+
+
+echo "ADC1: REG ADD 4"
+pci -w 0x90A0 0x00038120                 #01 is 14bit mode, 000 is 12x, 001 is 14x, 100 is 16x, 011 is 10x
+sleep 0.1
+
+#pci -w 0x90A0 0x00048801                 #01 is 14bit mode, 00 is 12 bit mode and 11 is 10bit
+#sleep 0.1
+
+pci -w 0x90A0 0x0004A801
+sleep 0.1
+
+#pci -w 0x90A0 0x00048801                 #01 is 14bit mode, 00 is 12 bit mode and 11 is 10bit
+#sleep 0.1
+
+
+echo "ADC2: REG ADD 4"
+pci -w 0x90A0 0x00038120                 #01 is 14bit mode, 000 is 12x, 001 is 14x, 100 is 16x, 011 is 10x
+sleep 0.1
+
+#pci -w 0x90A4 0x00048801                 #01 is 14bit mode, 00 is 12 bit mode and 11 is 10bit
+#sleep 0.1
+
+pci -w 0x90A4 0x0004A801
+sleep 0.1
+
+#pci -w 0x90A4 0x00048801                 #01 is 14bit mode, 00 is 12 bit mode and 11 is 10bit
+#sleep 0.1

BIN
bench.out


BIN
bench_for_offset.out


+ 10 - 0
clk_shifter.sh

@@ -0,0 +1,10 @@
+#!/bin/bash
+for add in {1..9};
+  do
+    echo "CLK SHIFT $add"
+    pci -w 9088 FF
+    pci -r 9088 -s 1
+    sleep 0.1
+    pci -w 9088 FE
+    pci -r 9088 -s 1
+  done

+ 265 - 0
digital_gain.sh

@@ -0,0 +1,265 @@
+echo "ADC1: REG ADD 3"
+pci -w 0x90A0 0x00039120                 #9 - with digital gain en , 8 -without digital gain en
+sleep 0.1
+
+#####################################################################################################################################
+
+echo "ADC1: REG ADD D"
+pci -w 0x90A0 0x000D0000                #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD E"
+pci -w 0x90A0 0x000E0000               #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD F"
+pci -w 0x90A0 0x000F0000                #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD 10"
+pci -w 0x90A0 0x00100000                #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD 11"
+pci -w 0x90A0 0x00110000                 #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD 12"
+pci -w 0x90A0 0x00120000                #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD 13"
+pci -w 0x90A0 0x00130000                 #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD 14"
+pci -w 0x90A0 0x00140000                #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD 19"
+pci -w 0x90A0 0x00190000              #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD 1A"
+pci -w 0x90A0 0x001A0000                 #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD 1B"
+pci -w 0x90A0 0x001B0000                 #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD 1C"
+pci -w 0x90A0 0x001C0000                 #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD 1D"
+pci -w 0x90A0 0x001D0000                 #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD 1E"
+pci -w 0x90A0 0x001E0000                 #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD 1F"
+pci -w 0x90A0 0x001F0000                 #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD 20"
+pci -w 0x90A0 0x00200000                 #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD 25"
+pci -w 0x90A0 0x00250000                 #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD 26"
+pci -w 0x90A0 0x00260000                 #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD 27"
+pci -w 0x90A0 0x00270000                 #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD 28"
+pci -w 0x90A0 0x00280000                 #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD 29"
+pci -w 0x90A0 0x00290000
+
+echo "ADC1: REG ADD 2A"
+pci -w 0x90A0 0x002A0000                 #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD 2B"
+pci -w 0x90A0 0x002B0000                 #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD 2C"
+pci -w 0x90A0 0x002C0000                 #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD 31"
+pci -w 0x90A0 0x00310000                 #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD 32"
+pci -w 0x90A0 0x00320000                 #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD 33"
+pci -w 0x90A0 0x00330000                 #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD 34"
+pci -w 0x90A0 0x00340000                 #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD 35"
+pci -w 0x90A0 0x00350000                 #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD 36"
+pci -w 0x90A0 0x00360000                 #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD 37"
+pci -w 0x90A0 0x00370000               #Offset value
+sleep 0.05
+
+echo "ADC1: REG ADD 38"
+pci -w 0x90A0 0x00380000                 #Offset value
+sleep 0.05
+##########################################################################################################
+
+#####################################################################################################################################
+pci -w 0x90A4 0x00039120                 #01 is 14bit mode, 000 is 12x, 001 is 14x, 100 is 16x, 011 is 10x
+sleep 0.05
+
+echo "ADC2: REG ADD D"
+pci -w 0x90A4 0x000D0000                #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD E"
+pci -w 0x90A4 0x000E0000                #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD F"
+pci -w 0x90A4 0x000F0000               #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 10"
+pci -w 0x90A4 0x00100000                #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 11"
+pci -w 0x90A4 0x00110000                 #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 12"
+pci -w 0x90A4 0x00120000                #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 13"
+pci -w 0x90A4 0x00130000                 #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 14"
+pci -w 0x90A4 0x00140000                #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 19"
+pci -w 0x90A4 0x00190000              #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 1A"
+pci -w 0x90A4 0x001A0000                 #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 1B"
+pci -w 0x90A4 0x001B0000                 #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 1C"
+pci -w 0x90A4 0x001C0000                 #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 1D"
+pci -w 0x90A4 0x001D0000                 #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 1E"
+pci -w 0x90A4 0x001E0000                 #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 1F"
+pci -w 0x90A4 0x001F0000                 #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 20"
+pci -w 0x90A4 0x00200000                 #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 25"
+pci -w 0x90A4 0x00250000                 #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 26"
+pci -w 0x90A4 0x00260000                 #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 27"
+pci -w 0x90A4 0x00270000                 #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 28"
+pci -w 0x90A4 0x00280000                 #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 29"
+pci -w 0x90A4 0x00290000                 #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 2A"
+pci -w 0x90A4 0x002A0000                 #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 2B"
+pci -w 0x90A4 0x002B0000                #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 2C"
+pci -w 0x90A4 0x002C0000                 #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 31"
+pci -w 0x90A4 0x00310000                 #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 32"
+pci -w 0x90A4 0x00320000                 #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 33"
+pci -w 0x90A4 0x00330000                 #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 34"
+pci -w 0x90A4 0x00340000                 #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 35"
+pci -w 0x90A4 0x00350000                #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 36"
+pci -w 0x90A4 0x00360000                 #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 37"
+pci -w 0x90A4 0x00370000                 #Offset value
+sleep 0.05
+
+echo "ADC2: REG ADD 38"
+pci -w 0x90A4 0x00380000                 #Offset value
+sleep 0.05

+ 10 - 0
digital_high_pass.sh

@@ -0,0 +1,10 @@
+#! /bin/bash
+
+
+echo "ADC: REG ADD 2 --> Digital High pass filtering' "
+pci -w 0x90A0 0x00150205
+
+pci -w 0x90A0 0x00210005
+
+# all 1s test mode is 2, all 0s is 3
+sleep 0.1

+ 39 - 0
dma.sh

@@ -0,0 +1,39 @@
+#!/bin/bash
+# By Michele Caselle for KAPTURE-2
+echo "--------------------------------"
+echo "------  	R E S E T  	---"
+echo "------		D M A   	---"
+echo "--------------------------------"
+
+export PCILIB_MODEL=ipedma
+
+echo "---------- R E S E T ------------------"
+pci -w 9040 0x1 
+sleep 0.2
+
+echo "---------- S T O P   D M A ------------------"
+pci --stop-dma dma0r
+sleep 0.2
+
+echo "---------- S T A R T  D M A ------------------"
+pci --start-dma dma0r
+sleep 0.2
+
+echo "---------- LIST OF DMA ENGINES------------------"
+pci --list-dma-engines
+sleep 0.2
+
+echo "---------- LIST OF DMA BUFFER------------------"
+pci --list-dma-buffers dma0r
+sleep 0.2
+
+echo "---------- S T A T U S ------------------"
+pci -r 9000 -s 100
+
+sleep 0.2
+echo "---------- ENABLE R/W ------------------"
+pci -w 9040 0x400 
+
+echo "---------- S T A T U S ------------------"
+pci -r 9000 -s 100
+

+ 4 - 0
dumpFile.sh

@@ -0,0 +1,4 @@
+#!/bin/bash
+
+hexdump -e ' "0x%08_ax: " 4/4 " 0x%08x " "\n" ' $1 | less
+

+ 169 - 0
ext_trigger_readout.sh

@@ -0,0 +1,169 @@
+ #!/bin/bash
+usage="
+$(basename "$0") [-h] [-f NNNNN] [-d AAAA] [-a n] [-s n]
+-- script to acquire with KALYPSO with external trigger
+------------------------------------------------
+where:
+    -h  show this help text
+
+    -f  set the fill number (default: 12345)
+    -d  set the detector name (default: Si01)
+    -a  set the number of triggers to acquire (default: 8)
+    -s  set the skip value (default: 0)
+
+    Note: to stop acquisition, create a 'stop_aq' file in the running directory
+------------------------------------------------"
+
+# A POSIX variable
+OPTIND=1         # Reset in case getopts has been used previously in the shell.
+
+# Initialize our own variables:
+# fill_num="12345"
+# det_name="Si01"
+extension=".bin"
+acquisitions=1000
+skip=0
+div="_"
+fill_prefix="f"
+
+fill_numFlag=false
+det_nameFlag=false
+
+bg_delay=20
+sig_delay=49
+
+bum="m"
+
+while getopts 'hd:f:as' opt; do
+    case "$opt" in
+    h)  echo "$usage"
+        exit
+        ;;
+    a)  acquisitions=$OPTARG
+        ;;
+    s)  skip=$OPTARG
+        ;;
+    f)  fill_num=$OPTARG
+        fill_numFlag=true
+        ;;
+    d)  det_name=$OPTARG
+        det_nameFlag=true
+        ;;
+    esac
+done
+
+shift $((OPTIND-1))
+
+[ "$1" = "--" ] && shift
+
+if ! $fill_numFlag; then
+    echo "Error: please specify the fill number with -f option (e.g. -f 12345)" >&2
+    echo "Use $(basename "$0") -h for help" >&2
+    exit
+fi
+
+if ! $det_nameFlag; then
+    echo "Error: please specify the detector name with -d option (e.g. -d Si01)" >&2
+    echo "Use $(basename "$0") -h for help" >&2
+    exit
+fi
+
+if [ -e "stop_aq" ]; then
+    rm "stop_aq"
+fi
+
+echo "Data Reset ... "
+pci -w 0x9040 0x000fff01
+
+echo "Writing Acquisitions ($acquisitions) and Skip ($skip)"
+pci -w 9024 $acquisitions
+sleep 0.1
+pci -w 902C $skip
+sleep 0.1
+
+echo "System is ON, now waiting for External trigger..."
+pci -w 0x9040 000fff00
+sleep 1
+
+
+
+for (( i=1; i<=$acquisitions; i++ ))
+do
+    tmpfname=$output_file$i$extension
+    echo "Acquiring dataset $i of $acquisitions in $tmpfname..."
+
+    ## Wait until a new acquisition is acquired...
+    ACQ_NUM="$(pci -r 9034 | sed 's/.*[0-9]:  //';)"
+    ACQ_NUM="$((16#$ACQ_NUM))"
+    ACQ_NUM_TEMP="$(pci -r 9034 | sed 's/.*[0-9]:  //';)"
+    ACQ_NUM_TEMP="$((16#$ACQ_NUM_TEMP))"
+
+    while [ "$ACQ_NUM_TEMP" -eq "$ACQ_NUM" ]
+    do
+        ACQ_NUM_TEMP="$(pci -r 9034 | sed 's/.*[0-9]:  //';)"
+        ACQ_NUM_TEMP="$((16#$ACQ_NUM_TEMP))"
+        sleep 0.01
+        now=$(date +"%T")
+        echo -ne "$now : Waiting for new trigger..."\\r
+    done
+
+    pci -r dma0 --multipacket -o $tmpfname --timeout $(($(($skip+1))*15000000))
+
+    #echo "Acquired at: $now"
+    creationtime="$(date +"%Y-%m-%dT%Hh%Mm%Ss" -r $tmpfname)"
+
+    pci -w 0x9040 0x000fff01
+    sleep 0.01
+    pci -w 0x9040 0x000fff00
+
+    mv $tmpfname $fill_prefix${fill_num}_${creationtime}_${det_name}_$bum$extension
+    echo "Acquired at $now: $fill_prefix${fill_num}_${creationtime}_${det_name}_$bum$extension"
+    python write_csv.py -f $fill_prefix${fill_num}_${creationtime}_${det_name}_$bum$extension
+
+    sleep 0.1
+
+    MODUL="$(($i%12))"
+
+    if ((MODUL == 0)); then
+        echo "Moving to Background"
+        pci -w 9004 $(printf %x $bg_delay)
+        bum="bg"
+        pci -r 9004
+    else
+        echo "Moving to Signal"
+        pci -w 9004 $(printf %x $sig_delay)
+        bum="m"
+        pci -r 9004
+    fi
+
+    if [ -e "stop_aq" ]; then
+        echo "Found 'stop_aq' file, data taking will now stop."
+        break
+    fi
+
+done
+#
+#
+#
+#
+# for (( i=1; i<=$acquisitions; i++ ))
+# do
+#     echo "Acquiring dataset $i of $acquisitions..."
+#     pci -r dma0 --multipacket -o $i$extension --timeout $(($(($skip+1))*10000000))
+#     now=$(date +"%T")
+#     echo "Acquired at: $now"
+#     creationtime="$(date +"%Y-%m-%dT%Hh%Mm%Ss" -r $i$extension)"
+#     # creationtimeunix="$(date +"%s" -r $i$extension)"
+#     mv $i$extension $fill_prefix${fill_num}_${creationtime}_${det_name}$extension
+#     echo "Saved in $fill_prefix${fill_num}_${creationtime}_${det_name}$extension"
+#     sleep 0.1
+# done
+
+echo "Acquisition done!"
+pci -w 0x9040 400000ff
+sleep 0.1
+
+pci -w 9024 0
+sleep 0.1
+pci -w 902C 0
+sleep 0.1

+ 85 - 0
full_sequence.sh

@@ -0,0 +1,85 @@
+#! /bin/bash
+export PCILIB_MODEL=ipedma
+
+echo "GLOBAL RESET ... "
+./reset.sh
+sleep 0.5
+
+echo "PLL INIT/CONF for KARA 62.5 MHz ... "
+./pll_62_5_KARA.sh
+sleep 0.1
+
+./pll_sync.sh
+sleep 0.1
+
+#./set_dac_voltages_25.sh
+#sleep 0.1
+
+echo "AXI_MASTER on FPGA INIT ..."
+./AXI_conf.sh
+sleep 0.1
+
+echo "AXI_Reconfiguration for SubClass 2, frame per Multi-frame = 16"
+./AXI_ReConf.sh
+sleep 0.1
+
+echo "ADCs INIT/CONF SubClass 2, frame per Multi-frame = 16"
+./adc_config.sh
+sleep 0.1
+
+echo "SOFT RESET ..."
+./soft_reset.sh
+sleep 0.1
+
+echo "SEND TX_TRIG both ADCs ..."
+./tx_trig_adcs.sh
+sleep 0.1
+./tx_trig_adcs_left.sh
+sleep 0.1
+./tx_trig_adcs_right.sh
+sleep 0.1
+
+
+echo "Gotthard ON ... "
+./G_ON.sh
+sleep 0.1
+
+
+#./set_dac_voltages_25.sh
+#sleep 0.1
+
+echo "Number of acquisitions to acquire (Slow Trig.)= 1"
+pci -w 0x9024 0x1
+sleep 0.1
+pci -w 0x9024 0x0 # for internal slow Triger #
+sleep 0.1
+
+echo "Number of acquisitions to skip (Slow Trig.)= 0"
+pci -w 0x902C 0x0
+sleep 0.1
+
+echo "Number of frame to acquire (Fast Trig.)= 1024"
+pci -w 0x9020 0x400
+sleep 0.1
+
+echo "Number of frame to skip (Fast Trig.)... = 1"
+pci -w 0x9028 0x1
+sleep 0.1
+pci -w 0x9028 0x0
+sleep 0.1
+
+#echo "Gotthard ON ... "
+#./align_clock.sh
+#./align_clock_b.sh
+sleep 0.1
+
+
+pci -w 0x910C 0
+sleep 0.1
+./adc_offset_at_0_delay.sh
+./adc_config_2_offset.sh  # previous board
+#pci -w 0x910C e
+#sleep 0.1
+
+pci -w 0x910C 2f
+sleep 0.1

+ 88 - 0
full_sequence_ex_rf.sh

@@ -0,0 +1,88 @@
+#! /bin/bash
+export PCILIB_MODEL=ipedma
+
+echo "GLOBAL RESET ... "
+./reset_ex_rf.sh
+sleep 0.5
+
+echo "PLL INIT/CONF for KARA 62.5 MHz ... "
+./pll_62_5_KARA.sh
+sleep 0.1
+
+./pll_sync.sh
+sleep 0.1
+
+#./set_dac_voltages_25.sh
+#sleep 0.1
+
+echo "AXI_MASTER on FPGA INIT ..."
+./AXI_conf.sh
+sleep 0.1
+
+echo "AXI_Reconfiguration for SubClass 2, frame per Multi-frame = 16"
+./AXI_ReConf.sh
+sleep 0.1
+
+echo "ADCs INIT/CONF SubClass 2, frame per Multi-frame = 16"
+./adc_config.sh
+sleep 0.1
+
+echo "SOFT RESET ..."
+./soft_reset.sh
+sleep 0.1
+
+echo "SEND TX_TRIG both ADCs ..."
+./tx_trig_adcs.sh
+sleep 0.1
+./tx_trig_adcs_left.sh
+sleep 0.1
+./tx_trig_adcs_right.sh
+sleep 0.1
+
+
+echo "Gotthard ON ... "
+./G_ON.sh
+sleep 0.1
+
+
+#./set_dac_voltages_25.sh
+#sleep 0.1
+
+echo "Number of acquisitions to acquire (Slow Trig.)= 1"
+pci -w 0x9024 0x1
+sleep 0.1
+pci -w 0x9024 0x0 # for internal slow Triger #
+sleep 0.1
+
+echo "Number of acquisitions to skip (Slow Trig.)= 0"
+pci -w 0x902C 0x0
+sleep 0.1
+
+echo "Number of frame to acquire (Fast Trig.)= 1024"
+pci -w 0x9020 0x400
+sleep 0.1
+
+echo "Number of frame to skip (Fast Trig.)... = 1"
+pci -w 0x9028 0x1
+sleep 0.1
+pci -w 0x9028 0x0
+sleep 0.1
+
+#echo "Gotthard ON ... "
+./align_clock.sh
+./align_clock_b.sh
+sleep 0.1
+
+
+pci -w 0x910C 0
+sleep 0.1
+./adc_offset_at_0_delay.sh
+./adc_config_2_offset.sh  # previous board
+
+#pci -w 0x910C e
+#sleep 0.1
+
+pci -w 64 1ffff
+
+pci -w 0x910C 2f
+sleep 0.1

+ 8 - 0
iodelay_set.sh

@@ -0,0 +1,8 @@
+echo "*IODELAY: Set DATA IOdelay"
+echo "*IODELAY: Set ADC pipeline depth"
+
+
+pci -w 9080 0x10001007
+sleep 0.1
+pci -w 9080 0x00001007
+sleep 0.1

+ 27 - 0
jesd_cnt_test.sh

@@ -0,0 +1,27 @@
+#! /bin/bash
+export PCILIB_MODEL=ipedma
+
+echo "write the number of samples to be acquired"
+#pci -w 9108 0x1000
+
+pci -w 0x9040 0x10210f00
+sleep 1
+
+echo "Set the HEADER + ENABLE Readout to DDR"
+pci -w 0x9040 0x18310000
+sleep 0.01
+
+
+echo "ENABLE Test pattern and start the acquisition"
+pci -w 0x9040 0x18210F00
+echo "DISABLE Test pattern"
+pci -w 0x9040 0x10210F00
+sleep 0.01
+
+echo "*DMA: Reading data..."
+./read.sh
+#pci -r dma0 --multipacket -o test_data.out --timeout=1000000
+
+#./status.sh
+
+#./dumpFile.sh bench.out

+ 212 - 0
kalypso_registers.json

@@ -0,0 +1,212 @@
+{
+
+"INTEG_DURATION" : {
+    "name" : "Integration Duration",
+    "address" : "0x9000",
+    "mask" : "0x000003FF",
+    "notes": "GOTTHARD integration period (4ns step) 10 bits only"
+  },
+
+"INTEG_DELAY" : {
+    "name" : "Integration Delay",
+    "address" : "0x9004",
+    "mask" : "0x000003FF",
+    "notes": "GOTTHARD integration delay (4ns step) 10 bits only"
+  },
+
+"GOTT_GAIN" : {
+    "name" : "Front-end electronics gain setting",
+    "address" : "0x9010",
+    "mask" : "0x0000000F",
+    "notes": "Only 2 bits"
+  },
+
+"TIMESCAN" : {
+    "name" : "Timescan function",
+    "address" : "0x9014",
+    "mask" : "0x00000001",
+    "notes": "Timescan = EN"
+  },
+
+"GOTT_ODELAY_SET" : {
+    "name" : "Output delay for front-end electronics",
+    "address" : "0x9018",
+    "mask" : "0x000000FF",
+    "notes": "not used in this version"
+  },
+
+"FT_TO_ACQ" : {
+    "name" : "Number of fast-triggers to acquire",
+    "address": "0x9020",
+    "mask" : "0xFFFFFFFF",
+    "notes": ""
+  },
+
+"ST_TO_ACQ" : {
+    "name" : "Number of slow-triggers to acquire",
+    "address" : "0x9024",
+    "mask" : "0xFFFFFFFF",
+    "notes": ""
+  },
+
+"FT_SKIP" : {
+    "name" : "Number of Fast triggers to skip",
+    "address" : "0x9028",
+    "mask" : "0xFFFFFFFF",
+    "notes": ""
+  },
+
+"ST_SKIP" : {
+    "name" : "Number of Slow Triggers to skip",
+    "address" : "0x902C",
+    "mask" : "0xFFFFFFFF",
+    "notes": ""
+  },
+
+  "VERSION_REG" : {
+    "name" : "Firmware version",
+    "address" : "0x9030",
+    "mask" : "0xFFFFFFFF",
+    "notes": "Format 0xAAAA_BBBB where AAAA = KALYPSO version BBBB = firmware revision"
+  },
+
+  "ST_ACQ" : {
+    "name" : "Number of Slow-triggers acquired",
+    "address" : "0x9034",
+    "mask" : "0xFFFFFFFF",
+    "notes": ""
+  },
+
+  "FT_ACQ" : {
+    "name" : "Number of Fast Triggers acquired",
+    "address" : "0x9038",
+    "mask" : "0xFFFFFFFF",
+    "notes": ""
+  },
+
+  "CONTROL" : {
+    "name" : "Control Register",
+    "address" : "0x9040",
+    "mask" : "0xFFFFFFFF",
+    "notes": "Too many bits see User Manual!"
+  },
+
+  "CLK_DIV" : {
+    "name" : "Clock divider for internal fast trigger generation",
+    "address" : "0x9044",
+    "mask" : "0xFFFFFFFF",
+    "notes": "Divider of ADC CLK = 62.5 MHz. Set to 0 to enable external trigger."
+  },
+
+  "POWER" : {
+    "name" : "Power configuration",
+    "address" : "0x9048",
+    "mask" : "0xFFFFFFFF",
+    "notes": "Enables power supply chips on mezzanine card "
+  },
+
+  "KAL_CONF" : {
+    "name" : "Advanced configuration",
+    "address" : "0x904C",
+    "mask" : "0xFFFFFFFF",
+    "notes": "Advanced config. Used for testing and debugging..."
+  },
+
+  "STATUS_1" : {
+    "name" : "Status register 1",
+    "address" : "0x9050",
+    "mask" : "0xFFFFFFFF",
+    "notes": "See user manual for bit description"
+  },
+
+  "STATUS_2" : {
+    "name" : "Status register 1",
+    "address" : "0x9054",
+    "mask" : "0xFFFFFFFF",
+    "notes": "See user manual for bit description"
+  },
+
+  "STATUS_3" : {
+    "name" : "Status register 1",
+    "address" : "0x9058",
+    "mask" : "0xFFFFFFFF",
+    "notes": "See user manual for bit description"
+  },
+
+  "ADC_SPI" : {
+    "name" : "SPI interface to ADC",
+    "address" : "0x9060",
+    "mask" : "0xFFFFFFFF",
+    "notes": ""
+  },
+
+  "PLL_SPI" : {
+    "name" : "SPI interface to PLL",
+    "address" : "0x9064",
+    "mask" : "0xFFFFFFFF",
+    "notes": ""
+  },
+
+  "I2C_DAC_0" : {
+    "name" : "I2C interface to DAC0",
+    "address" : "0x9068",
+    "mask" : "0xFFFFFFFF",
+    "notes": ""
+  },
+
+  "I2C_DAC_1" : {
+    "name" : "I2C interface to DAC1",
+    "address" : "0x906C",
+    "mask" : "0xFFFFFFFF",
+    "notes": ""
+  },
+
+  "DDR_ADDR_WR" : {
+    "name" : "BBB",
+    "address" : "0x9074",
+    "mask" : "0xFFFFFFFF",
+    "notes": "Current WR Address in DDR"
+  },
+
+  "DDR_ADDR_RD_CUR" : {
+    "name" : "I2C interface",
+    "address" : "0x907C",
+    "mask" : "0xFFFFFFFF",
+    "notes": "Current RD Address in DDR"
+  },
+
+  "I2C_DAC_1" : {
+    "name" : "BBB",
+    "address" : "0x9078",
+    "mask" : "0xFFFFFFFF",
+    "notes": "Next WR Address in DDR"
+  },
+
+  "IDELAYS" : {
+    "name" : "Configuration of IDELAY stage",
+    "address" : "0x9080",
+    "mask" : "0xFFFFFFFF",
+    "notes": "Tuned by Lorenzo don't change!"
+  },
+
+  "ALIGN_ADC" : {
+    "name" : "Pattern to align ADC",
+    "address" : "0x9084",
+    "mask" : "0xFFFFFFFF",
+    "notes": "Align ADC pattern & Bits 13:0"
+  },
+
+  "CLOCK_PS" : {
+    "name" : "Phase shift for output clock",
+    "address" : "0x9088",
+    "mask" : "0xFFFFFFFF",
+    "notes": ""
+  },
+
+  "PCIE_RESET" : {
+      "name" : "PCIe Id register",
+      "address" : "0x0000",
+      "mask" : "0xFFFFFFFF",
+      "notes": "Register used to identify PCIe Board"
+    }
+}

+ 9 - 0
misc_scripts/Set_ADC_1_Delay.sh

@@ -0,0 +1,9 @@
+#!/bin/sh
+
+echo "Set delay on T/Hs signals... "
+
+upfix=000704
+fixed=3
+hex_val=$(printf "%01x\n" $1)
+echo "Set $hex_val --> Time picosecond = `expr $1 "*" 150`."
+pci -w 0x9064 $upfix$hex_val$fixed

+ 13 - 0
misc_scripts/Set_ADC_Delay.sh

@@ -0,0 +1,13 @@
+#!/bin/bash
+
+echo "Set clock ADC delay... "
+
+upfix=3
+divfix=00C 
+fixed=1
+
+    hex_val=$(printf "%03x\n" $(($1<<2)))
+    
+    echo "Set $hex_val --> Time value picosecond = `expr $1 "*" 156`."
+    echo "Write pci -w 9060 $upfix$hex_val$divfix$fixed"
+    pci -w 0x9060 $upfix$hex_val$divfix$fixed

+ 81 - 0
misc_scripts/full_sequence_pcbtest.sh

@@ -0,0 +1,81 @@
+#! /bin/bash
+export PCILIB_MODEL=ipedma
+echo "CONFIGURING BARE PCB TEST ... "
+
+echo "GLOBAL RESET ... "
+./reset.sh
+sleep 0.5
+
+echo "PLL INIT/CONF for KARA 62.5 MHz ... "
+./pll_62_5_KARA.sh
+sleep 0.1
+
+./pll_sync.sh
+sleep 0.1
+
+./set_dac_voltages_25.sh
+sleep 0.1
+
+echo "AXI_MASTER on FPGA INIT ..."
+./AXI_conf.sh
+sleep 0.1
+
+echo "AXI_Reconfiguration for SubClass 2, frame per Multi-frame = 16"
+./AXI_ReConf.sh
+sleep 0.1
+
+echo "ADCs INIT/CONF SubClass 2, frame per Multi-frame = 16"
+./adc_config.sh
+sleep 0.1
+
+echo "SOFT RESET ..."
+./soft_reset.sh
+sleep 0.1
+
+echo "SEND TX_TRIG both ADCs ..."
+./tx_trig_adcs.sh
+sleep 0.1
+./tx_trig_adcs_left.sh
+sleep 0.1
+./tx_trig_adcs_right.sh
+sleep 0.1
+
+echo "Gotthard ON ... "
+./G_ON.sh
+sleep 0.1
+
+echo "Number of acquisitions to acquire (Slow Trig.)= 1"
+pci -w 0x9024 0x1
+sleep 0.1
+pci -w 0x9024 0x0 # for internal slow Triger #
+sleep 0.1
+
+echo "Number of acquisitions to skip (Slow Trig.)= 0"
+pci -w 0x902C 0x0
+sleep 0.1
+
+echo "Number of frame to acquire (Fast Trig.)= 1024"
+pci -w 0x9020 0x400
+sleep 0.1
+
+echo "Number of frame to skip (Fast Trig.)... = 1"
+pci -w 0x9028 0x1
+sleep 0.1
+pci -w 0x9028 0x0
+sleep 0.1
+
+#echo "Gotthard ON ... "
+#./align_clock.sh
+#./align_clock_b.sh
+sleep 0.1
+
+
+pci -w 0x910C 0
+sleep 0.1
+./adc_offset_at_0_delay.sh
+./adc_config_2_offset.sh  # previous board
+#pci -w 0x910C e
+#sleep 0.1
+
+pci -w 0x910C 2f
+sleep 0.1

+ 47 - 0
misc_scripts/normal_acq_loop.sh

@@ -0,0 +1,47 @@
+#! /bin/bash
+export PCILIB_MODEL=ipedma
+
+echo "Gotthard ON ... "
+./G_ON.sh    
+sleep 0.1
+
+echo "Number of acquisitions to acquire (Slow Trig.)= 1"
+pci -w 0x9024 0x1
+sleep 0.1
+
+echo "Number of acquisitions to skip (Slow Trig.)= 0"
+pci -w 0x902C 0x0
+sleep 0.1
+
+echo "Number of frame to acquire (Fast Trig.)= 1024"
+pci -w 0x9020 0x400
+sleep 0.1
+
+echo "Number of frame to skip (Fast Trig.)... = 1"
+pci -w 0x9024 0x0       
+sleep 0.1
+
+echo "Start Normal acquisition + ENABLE Readout to DDR + HEADER"
+pci -w 0x9040 0x1021FF00
+
+
+
+for add in {1..10};
+  do
+    echo "Start Normal acquisition + ENABLE Readout to DDR + HEADER $add"
+    pci -w 0x9040 0x1021FF00
+    sleep 0.5
+    echo "IDLE"
+    pci -w 0x9040 0x10210F00
+  done
+
+#./status.sh 
+#sleep 0.1
+
+#echo "*DMA: Reading data..."
+#./read.sh
+#pci -r dma0 --multipacket -o test_data.out --timeout=1000000
+
+#./status.sh
+
+#./dumpFile.sh bench.out 

+ 43 - 0
misc_scripts/readout.sh

@@ -0,0 +1,43 @@
+#! /bin/bash
+
+echo "***** KALYPSO 2.0 ******"
+echo "***   READ sequence ****"
+
+rm test_data.out
+
+echo "*ADC & GOT: RST"
+pci -w 0x9040 0x000fff01
+sleep 0.1
+
+echo "*KALYPSO: Total Orbits"
+pci -w 0x9020 0x20
+sleep 0.1
+
+# echo "*ONBOARD TRIG GEN: ON"
+# pci -w 0x9044 0x0017
+# sleep 0.01
+
+echo "GOTT: Integration Period"
+pci -w 0x9000 0x10
+sleep 0.01
+
+echo "GOTT: Integration Delay"
+pci -w 0x9004 0x10
+sleep 0.01
+
+echo "GOTT: Gain"
+pci -w 0x9010 0x000002
+sleep 0.01
+
+echo "*KALYPSO: Enable Readout + DDR"
+pci -w 0x9040 0x000fff00
+
+echo "*DMA: Reading data..."
+pci -r dma0 --multipacket -o test_data.out --timeout=1000000
+
+./status.sh
+
+echo "KALYPSO: Enable Readout + DDR"
+pci -w 0x9040 0x000fff01
+
+#python plot_single.py -f test_data.out --orbits=0

+ 32 - 0
misc_scripts/readout_GUI.sh

@@ -0,0 +1,32 @@
+#!/bin/sh
+
+# A POSIX variable
+OPTIND=1         # Reset in case getopts has been used previously in the shell.
+
+# Initialize our own variables:
+output_file="temp.bin"
+
+while getopts "f:" opt; do
+    case "$opt" in
+    f)  output_file=$OPTARG
+        ;;
+    esac
+done
+
+shift $((OPTIND-1))
+
+[ "$1" = "--" ] && shift
+
+echo "output_file='$output_file'"
+
+rm $output_file
+
+echo "*KALYPSO: Enable Readout + DDR"
+pci -w 0x9040 0x000fff00
+
+echo "*DMA: Reading data..."
+pci -r dma0 --multipacket -o $output_file --timeout=1000000
+
+echo "*KALYPSO: RST GOTTHARD stage"
+pci -w 0x9040 0x000fff01
+sleep 0.01

+ 46 - 0
misc_scripts/set_gotthard_0.sh

@@ -0,0 +1,46 @@
+#!/bin/sh
+
+
+#echo "ADC & GOT: Turning on power..."
+#pci -w 9048 f0
+#sleep 0.1
+
+pci -w 9048 ff
+sleep 0.1
+
+
+echo "***Configuring DACs***"
+
+#I2C_DAC_0 = h9068
+#I2C_DAC_1 = h906C
+#I2C_DAC_2 = h9070
+#I2C_DAC_3 = h9074
+#I2C_DAC_4 = h9078
+#I2C_DAC_5 = h907C
+
+
+
+echo "DAC0: CH0 = VB_COLBUFFER 29uA"
+pci -w 9068 000800               #750 original
+sleep 0.1
+
+
+echo "DAC0: CH1 = IB_DS 28uA"
+pci -w 9068 010550               #550
+sleep 0.1
+
+#################### Common for gotthard 0 and 1 ######################
+
+
+
+echo "DAC2: CH0 = VOUT_CM "
+pci -w 9070 0005DC          #5DC
+sleep 0.1
+
+
+echo "DAC2: CH1 = VIN_CM 560mV"
+pci -w 9070 010460            #460
+sleep 0.1
+
+
+echo "....done!****"

+ 45 - 0
misc_scripts/set_gotthard_1.sh

@@ -0,0 +1,45 @@
+#!/bin/sh
+
+
+#echo "ADC & GOT: Turning on power..."
+#pci -w 9048 f0
+#sleep 0.1
+
+pci -w 9048 ff
+sleep 0.1
+
+
+echo "***Configuring DACs***"
+
+#I2C_DAC_0 = h9068
+#I2C_DAC_1 = h906C
+#I2C_DAC_2 = h9070
+#I2C_DAC_3 = h9074
+#I2C_DAC_4 = h9078
+#I2C_DAC_5 = h907C
+
+
+
+echo "DAC0: CH2 = VB_COLBUFFER 29uA"
+pci -w 9068 020800    #750
+sleep 0.1
+
+
+echo "DAC0: CH3 = IB_DS 28uA"
+pci -w 9068 030690   #550-original  #650-reduced_saw
+sleep 0.1
+
+#################### common for gotthard 0 and 1 ##############################
+
+echo "DAC2: CH0 = VOUT_CM "
+pci -w 9070 0005DC
+sleep 0.1
+
+
+echo "DAC2: CH1 = VIN_CM 560mV"
+pci -w 9070 010460
+sleep 0.1
+
+
+
+echo "....done!****"

+ 43 - 0
misc_scripts/set_gotthard_5.sh

@@ -0,0 +1,43 @@
+#!/bin/sh
+
+
+#echo "ADC & GOT: Turning on power..."
+#pci -w 9048 f0
+#sleep 0.1
+
+pci -w 9048 ff
+sleep 0.1
+
+
+echo "***Configuring DACs***"
+
+#I2C_DAC_0 = h9068
+#I2C_DAC_1 = h906C
+#I2C_DAC_2 = h9070
+#I2C_DAC_3 = h9074
+#I2C_DAC_4 = h9078
+#I2C_DAC_5 = h907C
+
+
+
+echo "DAC3: CH2 = VB_COLBUFFER 29uA"
+pci -w 9074 020800
+sleep 0.1
+
+echo "DAC3: CH4 = IB_DS 28uA"
+pci -w 9074 030690
+sleep 0.1
+
+################# common for gotthard 4 and 5 #############################
+
+
+echo "DAC5: CH0 = VOUT_CM "
+pci -w 907C 0005DC
+sleep 0.1
+
+echo "DAC5: CH1 = VIN_CM 560mV"
+pci -w 907C 010460
+sleep 0.1
+
+
+echo "....done!****"

+ 47 - 0
misc_scripts/set_vb_col.sh

@@ -0,0 +1,47 @@
+#!/bin/sh
+
+
+#echo "ADC & GOT: Turning on power..."
+#pci -w 9048 f0
+#sleep 0.1
+
+echo "***Configuring DACs***"
+
+#I2C_DAC_0 = h9068
+#I2C_DAC_1 = h906C
+#I2C_DAC_2 = h9070
+#I2C_DAC_3 = h9074
+#I2C_DAC_4 = h9078
+#I2C_DAC_5 = h907C
+
+echo "DAC0: CH0 = VB_COLBUFFER 29uA"
+pci -w 9068 000$1
+sleep 0.1
+
+echo "DAC0: CH2 = VB_COLBUFFER 29uA"
+pci -w 9068 020$1
+sleep 0.1
+
+echo "DAC1: CH0 = VB_COLBUFFER 29uA"
+pci -w 906C 000$1
+sleep 0.1
+
+echo "DAC1: CH2 = VB_COLBUFFER 29uA"
+pci -w 906C 020$1
+sleep 0.1
+
+echo "DAC3: CH0 = VB_COLBUFFER 29uA"
+pci -w 9074 000$1
+sleep 0.1
+
+echo "DAC3: CH2 = VB_COLBUFFER 29uA"
+pci -w 9074 020$1
+sleep 0.1
+
+echo "DAC4: CH0 = VB_COLBUFFER 29uA"
+pci -w 9078 000$1
+sleep 0.1
+
+echo "DAC4: CH2 = VB_COLBUFFER 29uA"
+pci -w 9078 020$1
+sleep 0.1

+ 33 - 0
misc_scripts/set_vin_cm.sh

@@ -0,0 +1,33 @@
+#!/bin/sh
+
+
+#echo "ADC & GOT: Turning on power..."
+#pci -w 9048 f0
+#sleep 0.1
+
+echo "***Configuring DACs***"
+
+#I2C_DAC_0 = h9068
+#I2C_DAC_1 = h906C
+#I2C_DAC_2 = h9070
+#I2C_DAC_3 = h9074
+#I2C_DAC_4 = h9078
+#I2C_DAC_5 = h907C
+
+
+
+echo "DAC2: CH1 = VIN_CM 560mV"
+pci -w 9070 010$1
+sleep 0.5
+
+echo "DAC2: CH3 = VIN_CM 560mV "
+pci -w 9070 030$1
+sleep 0.5
+
+echo "DAC5: CH1 = VIN_CM 560mV"
+pci -w 907C 010$1
+sleep 0.5
+
+echo "DAC5: CH3 = VIN_CM 560mV "
+pci -w 907C 030$1
+sleep 0.5

+ 72 - 0
normal_acq.sh

@@ -0,0 +1,72 @@
+#! /bin/bash
+export PCILIB_MODEL=ipedma
+#!/bin/sh
+# A POSIX variable
+OPTIND=1         # Reset in case getopts has been used previously in the shell.
+
+# Initialize our own variables:
+output_file="temp.bin"
+
+while getopts "f:" opt; do
+    case "$opt" in
+    f)  output_file=$OPTARG
+        ;;
+    esac
+done
+
+shift $((OPTIND-1))
+
+[ "$1" = "--" ] && shift
+
+echo "output_file='$output_file'"
+
+rm $output_file
+
+echo "Number of acquisitions to acquire (Slow Trig.)= 1"
+pci -w 0x9024 0x1
+sleep 0.001
+
+echo "Number of acquisitions to skip (Slow Trig.)= 0"
+pci -w 0x902C 0x0
+sleep 0.1
+#./tx_trig_adcs.sh #!/bin/sh
+#sleep 0.1
+
+#echo "Number of frame to acquire (Fast Trig.)= 1024"
+#pci -w 0x9020 0x800
+#sleep 0.0001
+
+
+echo "reset TOP/BOTTOM"
+pci -w 0x904C 0x2
+sleep 0.001
+pci -w 0x904C 0x0
+sleep 0.001
+pci -w 0x9024 0x0
+sleep 0.001
+
+echo "ADD Reset DDR"
+#pci -w 0x9040 0x10210F50  # was 0x10210F40
+pci -w 0x9040 0x10210F50
+sleep 0.01
+
+pci -w 0x9040 0x10210F00
+sleep 0.01
+
+echo "Start Normal acquisition + ENABLE Readout to DDR + HEADER"
+pci -w 0x9040 0x1021FF00
+sleep 0.5
+#./status.sh
+echo "IDLE"
+pci -w 0x9040 0x10210F00
+sleep 0.5
+#./status.sh
+echo $output_file
+echo "*DMA: Reading data..."
+pci -r dma0 --multipacket -o $output_file --timeout=1000000
+
+#pci -r dma0 --multipacket -o test_data.out --timeout=1000000
+
+#./status.sh
+
+#./dumpFile.sh bench.out

+ 252 - 0
offset_value_gen.py

@@ -0,0 +1,252 @@
+import numpy as np
+import sys
+import matplotlib.pyplot as plt
+import matplotlib as mpl
+from scipy import signal
+import scipy.integrate as spi
+from scipy import asarray as ar, exp, sqrt
+from scipy.optimize import curve_fit
+#from astropy import modeling
+
+
+pixels = 512*2
+TAIL = [0xba98,0xfedc]*16
+DEAD = [0xdea1,0xdead,0xdea2,0xdead,0xdea3,0xdead,0xdea4,0xdead,0xdea5,0xdead,0xdea6,0xdead,0xdea7,0xdead,0xdea8,0xdead]
+
+def strip_data(filename, number_pixels, orbits, offset = None):
+        global data
+
+        ###############----------Read data from memory----------############################################
+        np.set_printoptions(threshold='nan')
+        data = np.fromfile(str(filename), dtype=np.uint16)
+        #if offset is None:
+        # data = np.memmap( str(filename), dtype=np.dtype('<u2'), mode='r')
+        #else:
+        #    data = np.memmap( str(filename), dtype=np.dtype('<u2'), offset = (2*pixels*offset),mode='r')
+
+
+        ###############----------Remove Header----------####################################################
+
+        if (data[0] == 0x1111 and data[15] == 0xF888):
+            print ('Removing header .....')
+            data = data[16:]
+        else:
+            print ('No data header....')
+            data = data
+
+        ##############--------Search and remove for TAIL--------############################################
+        offset = 0
+        tailoffset = offset
+        while np.any((data[tailoffset : tailoffset + len(TAIL)] != TAIL)):
+            tailoffset += 8
+            if tailoffset + len(TAIL) > len(data):
+                print('Could not find tail')
+                sys.exit(-1)
+        print('Found tail at offset ' + str(tailoffset))
+
+        ##############--------Search and remove for DEAD filling--------##################################
+        deadcnt = 0
+        deadoffset = tailoffset
+        while np.any(data[deadoffset - len(DEAD) : deadoffset] == DEAD):
+            deadcnt +=1
+            deadoffset -= len(DEAD)
+
+        print('Removed %d bytes of DEAD' %(deadcnt))
+
+        ##############--------Set the pure data --------###################################################
+
+        data = np.frombuffer((data[offset:deadoffset]), dtype = np.uint16)
+
+        #dead = np.where(data == 0xdea1)
+        #loc = np.amin(dead)
+        #data = data[0:loc]
+
+        ############-------Swap the data bytes and change from 16 bit to 14 bit---------####################
+
+        data = data.byteswap()
+        data = data >> 2
+
+        #############---------Index decoder for the jesd data for 16 input mode----------###################
+        odd_inner_idx_1 = [23,22,7,6,21,20,5,4,19,18,3,2,17,16,1,0] # working one
+        odd_inner_idx_2 = [8,9,24,25,10,11,26,27,12,13,28,29,14,15,30,31]    # non interleaved
+
+        odd_index_1 = np.zeros([256], dtype=np.int64)
+        odd_index_2 = np.zeros([256], dtype=np.int64)
+        for i in range(16):
+            for j in range(16):
+                odd_index_1[i * 16 + j] = odd_inner_idx_1[i] +  j * 64
+
+        for i in range(16):
+            for j in range(16):
+                odd_index_2[i * 16 + j] = odd_inner_idx_2[i] +  j * 64
+
+
+        even_inner_idx_1 = [55,54,39,38,53,52,37,36,51,50,35,34,49,48,33,32] # working one
+        even_inner_idx_2 = [40,41,56,57,42,43,58,59,44,45,60,61,46,47,62,63]    # non interleaved
+
+        even_index_1 = np.zeros([256], dtype=np.int64)
+        even_index_2 = np.zeros([256], dtype=np.int64)
+        for i in range(16):
+            for j in range(16):
+                even_index_1[i * 16 + j] = even_inner_idx_1[i] +  j * 64
+
+        for i in range(16):
+            for j in range(16):
+                even_index_2[i * 16 + j] = even_inner_idx_2[i] +  j * 64
+
+
+        ################------working part---------###########################################################
+        #index_interleave = np.ravel(np.column_stack((index_1,index_2)))  #interleaving the pixels, NOTE: interchange index_1 & index_2 if the pixels are swapped
+        #k = 32
+        #pixel_map = []
+        #a = index_interleave
+
+        #for i in range(0, len(a), k):
+        #    pixel_map.extend((a[i:i + k])[::-1])
+        ######################################################################################################
+        l = 16
+        odd_adc_2 = []
+        odd_b = odd_index_2
+        for i in range(0, len(odd_b), l):
+            odd_adc_2.extend((odd_b[i:i + l])[::-1])
+
+        even_adc_2 = []
+        even_b = even_index_2
+        for i in range(0, len(even_b), l):
+            even_adc_2.extend((even_b[i:i + l])[::-1])
+
+        #index_interleave = np.concatenate((odd_index_1,odd_adc_2),axis = 0)    # for concatenated pixels
+        #odd_index_interleave = np.concatenate((odd_index_1,odd_adc_2),axis = 0)    # for concatenated pixels
+        #even_index_interleave = np.concatenate((even_index_1,even_adc_2),axis = 0)    # for concatenated pixels
+
+        #odd_index_interleave = np.ravel(np.column_stack((odd_index_1,odd_adc_2)))    # for interleaved pixels
+        #even_index_interleave = np.ravel(np.column_stack((even_index_1,even_adc_2)))    # for interleaved pixels
+
+        #splitting the even part of the ADC since on the sensor they belong to the outer 256 x 2
+        #even_index_interleave_left = even_index_interleave[0:256]
+        #even_index_interleave_right = even_index_interleave[256:512]
+
+        #splitting the even part of the ADC since on the sensor they belong to the outer 256 x 2
+        odd_left_1 = odd_index_1[0:128]
+        odd_right_1 = odd_index_1[128:256]
+
+        odd_left_2 = odd_adc_2[0:128]
+        odd_right_2 = odd_adc_2[128:256]
+
+        #final_1024_index = np.concatenate((even_index_interleave_left,odd_index_interleave,even_index_interleave_right),axis = 0)
+        #######################
+        final_1024_index = np.concatenate((odd_left_1,even_index_1,odd_right_1,odd_left_2,even_adc_2,odd_right_2),axis = 0)  # for concatenated pixels
+
+        ##############-------------Reshape the data as pixel x orbits-------------------###################
+        if (orbits):
+            data = data[0:orbits*512*2]
+
+        data = np.reshape(data,(-1,pixels))
+
+        data = data[:,final_1024_index]
+
+        orb, pix = np.shape(data)
+
+        return (data, orb)
+
+
+
+
+
+strip_data('f12345_2020-09-07T16h14m21s_Si01_m.bin',1024,1)
+np.set_printoptions(formatter={'int':hex})
+
+pixel_num = np.arange(1,513,1)
+modulated_data = data.astype(np.uint16)
+orbits, pixels = np.shape(modulated_data)
+ad = np.transpose(modulated_data)
+offset_to = ad - ad + 850
+offset_value = ad - offset_to
+
+x = 16
+
+print('ADC1 0x90A0')
+###########
+print('Register 38 is',offset_value[4,:])  #D/E
+print('Register 36 is',offset_value[4+x,:])  #F/10
+print('Register 34 is',offset_value[4+2*x,:])  #11/12
+print('Register 32 is',offset_value[4+3*x,:])  #13/14
+
+print('Register 2C is',offset_value[4+4*x,:])  #19/1A
+print('Register 2A is',offset_value[4+5*x,:])  #1B/1C
+print('Register 28 is',offset_value[4+6*x,:]) #1D/1E
+print('Register 26 is',offset_value[4+7*x,:]) #1F/20
+###########
+print('Register 37 is',offset_value[4+8*x,:])  #D/E
+print('Register 35 is',offset_value[4+9*x,:])  #F/10
+print('Register 33 is',offset_value[4+10*x,:])  #11/12
+print('Register 31 is',offset_value[4+11*x,:])  #13/14
+
+print('Register 2B is',offset_value[4+12*x,:])  #19/1A
+print('Register 29 is',offset_value[4+13*x,:])  #1B/1C
+print('Register 27 is',offset_value[4+14*x,:]) #1D/1E
+print('Register 25 is',offset_value[4+15*x,:]) #1F/20
+
+print('Register 1F is',offset_value[4+16*x,:]) #25/26
+print('Register 1D is',offset_value[4+17*x,:]) #27/28
+print('Register 1B is',offset_value[4+18*x,:]) #29/2A
+print('Register 19 is',offset_value[4+19*x,:]) #2B/2C
+
+print('Register 13 is',offset_value[4+20*x,:]) #31/32
+print('Register 11 is',offset_value[4+21*x,:]) #33/34
+print('Register F is' ,offset_value[4+22*x,:]) #35/36
+print('Register D is'  ,offset_value[4+23*x,:]) #37/38
+###########
+print('Register 20 is',offset_value[4+24*x,:]) #25/26
+print('Register 1E is',offset_value[4+25*x,:]) #27/28
+print('Register 1C is',offset_value[4+26*x,:]) #29/2A
+print('Register 1A is',offset_value[4+27*x,:]) #2B/2C
+
+print('Register 14 is',offset_value[4+28*x,:]) #31/32
+print('Register 12 is',offset_value[4+29*x,:]) #33/34
+print('Register 10 is' ,offset_value[4+30*x,:]) #35/36
+print('Register  E is'  ,offset_value[4+31*x,:]) #37/38
+###################################################################
+print('ADC2 0x90A4')
+
+print('Register E is'  ,offset_value[4+32*x,:]) #D/E
+print('Register 10 is' ,offset_value[4+33*x,:]) #F/10
+print('Register 12 is',offset_value[4+34*x,:]) #11/12
+print('Register 14 is',offset_value[4+35*x,:]) #13/14
+
+print('Register 1A is',offset_value[4+36*x,:]) #19/1A
+print('Register 1C is',offset_value[4+37*x,:]) #1B/1C
+print('Register 1E is',offset_value[4+38*x,:]) #1D/1E
+print('Register 20 is',offset_value[4+39*x,:]) #1F/20
+
+print('Register D is'  ,offset_value[4+40*x,:]) #D/E
+print('Register F is' ,offset_value[4+41*x,:]) #F/10
+print('Register 11 is',offset_value[4+42*x,:]) #11/12
+print('Register 13 is',offset_value[4+43*x,:]) #13/14
+
+print('Register 19 is',offset_value[4+44*x,:]) #19/1A
+print('Register 1B is',offset_value[4+45*x,:]) #1B/1C
+print('Register 1D is',offset_value[4+46*x,:]) #1D/1E
+print('Register 1F is',offset_value[4+47*x,:]) #1F/20
+
+print('Register 25 is',offset_value[4+48*x,:]) #25/26
+print('Register 27 is',offset_value[4+49*x,:]) #27/28
+print('Register 29 is',offset_value[4+50*x,:]) #29/2A
+print('Register 2B is',offset_value[4+51*x,:]) #2B/2C
+
+print('Register 31 is',offset_value[4+52*x,:]) #31/32
+print('Register 33 is',offset_value[4+53*x,:]) #33/34
+print('Register 35 is',offset_value[4+54*x,:]) #35/36
+print('Register 37 is',offset_value[4+55*x,:]) #37/38
+
+print('Register 26 is',offset_value[4+56*x,:]) #25/26
+print('Register 28 is',offset_value[4+57*x,:]) #27/28
+print('Register 2A is',offset_value[4+58*x,:]) #29/2A
+print('Register 2C is',offset_value[4+59*x,:]) #2B/2C
+
+print('Register 32 is',offset_value[4+60*x,:]) #31/32
+print('Register 34 is',offset_value[4+61*x,:]) #33/34
+print('Register 36 is',offset_value[4+62*x,:]) #35/36
+print('Register 38 is',offset_value[4+63*x,:]) #37/38
+
+plt.show()

+ 97 - 0
pll_62_5_KARA.sh

@@ -0,0 +1,97 @@
+#!/bin/bash
+
+#echo "Remove Board Reset ... "
+#pci -w 0x9040 0x00
+#sleep 0.5
+
+#while :
+#do
+
+echo "*PLL: calibration start ... "
+echo "*PLL: R0 Reset ... "
+
+pci -w 0x9064 0x80000000
+sleep 0.2
+
+
+#pci -w 0x9064 0x80000100
+#sleep 0.2
+
+
+#pci -w 0x9064 0x00030100
+#sleep 0.2
+
+
+# R0 (INIT)
+
+pci -w 0x9064 0x80000100 # OUTPUT 500MHZ FPGA
+sleep 0.2
+
+#echo "*PLL: R0 "
+pci -w 0x9064 0x00030100 # OUTPUT 500 MHZ FPGA
+sleep 0.2
+
+
+#echo "*PLL: R1 "
+#pci -w 0x9064 0x00005C01 # SYS_REF_2 before 0x00035C01
+#sleep 0.2
+
+#echo "*PLL: R2 "
+#pci -w 0x9064 0x00005C02 # SYS_REF_1
+#sleep 0.2
+
+#echo "*PLL: R3 "
+#pci -w 0x9064 0x00030403   #######original
+#sleep 0.2
+
+echo "*PLL: R3 "
+pci -w 0x9064 0x00070473   #was 8 before for delay     #####remove later # clk_ADC_2    working:0x000704b3
+sleep 0.2
+
+#echo "*PLL: R4 "
+#pci -w 0x9064 0x00030404
+#sleep 0.2
+
+echo "*PLL: R4 "
+pci -w 0x9064 0x00070474        #was 8 before for delay        # d0,d4,d8,db # clk_ADC_1  working:0x000704b3
+sleep 0.2
+
+echo "*PLL: R5 "
+pci -w 0x9064 0x00070205           # FPGA_GTHX_CLOCK_0
+sleep 0.2
+
+
+echo "*PLL: R6 "
+pci -w 0x9064 0x00070206            # FPGA_GTHX_CLOCK_1
+sleep 0.2
+
+
+#echo "*PLL: R7 "
+#pci -w 0x9064 0x00005C07            # FPGA_SYS_REF before 0x00035C07
+#sleep 0.2
+
+
+echo "*PLL: R8 "
+pci -w 0x9064 0x10000908
+sleep 0.2
+
+echo "*PLL: R9 "
+pci -w 0x9064 0xA0022A09
+sleep 0.2
+
+echo "*PLL: RB (R11)"
+pci -w 0x9064 0x0082000B
+sleep 0.2
+
+echo "*PLL: RD (R13)"
+pci -w 0x9064 0x028300AD
+sleep 0.2
+
+echo "*PLL: RE (R14)"
+pci -w 0x9064 0x08007D0E
+sleep 0.2
+
+
+echo "*PLL: RF (R15)"
+pci -w 0x9064 0xCC03E80F
+sleep 0.2

+ 8 - 0
pll_sync.sh

@@ -0,0 +1,8 @@
+#!/bin/bash
+
+echo "Send the PLL sync signals ... "
+
+pci -w 0x9040 0x11200F00
+sleep 1
+echo "Done .... "
+pci -w 0x9040 0x10200F00

+ 10 - 0
poweroff.sh

@@ -0,0 +1,10 @@
+#! /bin/bash
+
+
+echo "KALYPSO: Poweroff"
+
+pci -w 0x9040 0xff
+sleep 0.1
+
+pci -w 0x9048 0x00
+sleep 0.1

+ 12 - 0
read.sh

@@ -0,0 +1,12 @@
+#!/bin/bash
+export PCILIB_MODEL=ipedma
+rm bench.out
+echo "--------------------------------"
+echo "------  READ  D A T A 	---"
+echo "--------------------------------"
+pci -r dma0 --multipacket -o bench.out -t 1000000
+#pci -r dma0 -s 40960 -o bench.out -t 100000
+
+#pci -r dma0 -o bench.out
+#pci -r dma0 -s 40960 -o bench.out -t 100000
+# pci -r dma0 -s 40960 -o bench.out -t 100000

+ 100 - 0
read_data.py

@@ -0,0 +1,100 @@
+###### Read in data from KALYPSO
+#from docopt import docopt
+
+import numpy as np
+#import matplotlib.pyplot as plt
+#from mpl_toolkits.axes_grid1 import make_axes_locatable
+#import matplotlib as mpl
+#import strip_data
+import os
+
+NUMBER_PIXELS = 256
+DDR_FILLING   = [0xba98,0xfedc]
+HEADER_0      = 0xABBA
+short_pattern = [0,1,2,3,3,2,1,0]
+long_pattern = np.repeat(short_pattern, 32)
+
+
+
+#####################################################################################
+## strip_data (filename, number of pixels, orbits[opt.])
+## return: data_array_stripped,   data_consistency_is_ok,   orbits
+#####################################################################################
+
+#####################################################################################
+def strip_data(filename, number_pixels, orbits, offset = None):
+
+#    np.set_printoptions(threshold='nan')
+     # data = np.fromfile(str(filename), dtype=np.uint16)
+     if     offset is None:
+         data = np.memmap( str(filename), dtype=np.dtype('<u2'), mode='r')
+     else:
+         data = np.memmap( str(filename), dtype=np.dtype('<u2'), offset = (2*NUMBER_PIXELS*offset),mode='r')
+	
+     print(data.shape)
+
+
+     if (orbits):
+         data = data[0:orbits*number_pixels]
+          
+     print(data.shape)
+
+#####################################################################################
+     ### Remove Header
+#####################################################################################
+     if (data[0] == 43962):
+         print("Removing header...")
+         data = data[16:]
+         data = np.append(data,[DDR_FILLING,DDR_FILLING,DDR_FILLING,DDR_FILLING,DDR_FILLING,DDR_FILLING,DDR_FILLING,DDR_FILLING])
+
+#####################################################################################
+     ## Reshape list as an 256*whatever array
+#####################################################################################
+     data = np.reshape(data, (-1,NUMBER_PIXELS))
+     print(data.shape)
+     # data = data[0:-8,:]
+
+#####################################################################################
+     ### Remove Filling at the end
+#####################################################################################
+
+     lines_with_filling = 0
+
+     print("\n***********************")
+     print("Removing DDR filling...")
+     while (np.all(data[-1:]==DDR_FILLING) or np.all(data[-1:]==0x00000000)):
+         data = data[0:-1,:]
+         lines_with_filling += 1
+
+     print("Removed %d bytes with DDR filling" % (lines_with_filling*512))
+     print(data.shape)
+
+#####################################################################################
+     ### Data consistency check
+#####################################################################################
+     orbits, pixels = np.shape(data)
+
+     high = (data & 0xC000) >> 14
+     data = (data & 0x3fff)
+     #print (NUMBER_PIXELS)
+     #print (data)
+     print(data.shape)
+     print("\n***********************")
+     print("Checking data consistency on %d orbits: " % orbits)
+
+     if (not np.any(high - long_pattern)):
+         print("everything is ok!")
+         return (data, 1, orbits)
+     else:
+         print("error in data consistency!")
+         #sys.exit("Error in data Consistency!!")
+         #print (high - long_pattern)
+         #print (np.where((high - long_pattern) != 0)[0])
+         return (data, 1, orbits)
+
+
+
+
+
+strip_data('f12345_2020-02-12T11h45m01s_Si01_m.bin',256,1000)
+

+ 16 - 0
read_reg.sh

@@ -0,0 +1,16 @@
+#!/bin/sh
+
+# A POSIX variable
+OPTIND=1         # Reset in case getopts has been used previously in the shell.
+
+# Initialize our own variables:
+reg=0x9000
+
+while getopts "r:" opt; do
+    case "$opt" in
+    r)  reg=$OPTARG
+        ;;
+    esac
+done
+
+pci -r $reg

+ 6 - 0
read_status.sh

@@ -0,0 +1,6 @@
+#!/bin/sh
+
+#echo "    9040:  00345678"
+pci -r 9050
+
+

+ 31 - 0
reload.sh

@@ -0,0 +1,31 @@
+#! /bin/bash
+
+device=`lspci -vv | grep -m 1 Xilinx | awk '{print $1}'`
+if [ -z "$device" ]; then
+    echo "Xilinx device doesn't exist, rescanning..."
+    echo 1 > /sys/bus/pci/rescan
+    exit
+else
+    echo "Xilinx is located at: " $device
+fi
+echo "remove devices"
+echo  1 > /sys/bus/pci/devices/0000\:${device:0:2}\:${device:3:4}/remove
+sleep 1
+echo "rescan"
+echo 1 > /sys/bus/pci/rescan
+sleep 1
+echo "remove driver"
+rmmod pciDriver 
+sleep 1
+echo "instantiate driver"
+modprobe pciDriver
+sleep 1
+# for devices with different ID
+echo "10ee 6028" > /sys/bus/pci/drivers/pciDriver/new_id
+pci -i
+sleep .1
+#pci -r 9000
+echo "set bus master dma"
+dev=$device  
+echo Enabling bus mastering on device $dev
+setpci -s $dev 4.w=0x07

+ 84 - 0
reset.sh

@@ -0,0 +1,84 @@
+#! /bin/bash
+export PCILIB_MODEL=ipedma
+
+#echo "ADC & GOT: Turning on power..."
+#pci -w 9048 f0
+#sleep 0.1
+
+#pci -w 9048 ff
+#sleep 0.1
+###################################### For internal RF clock ##########################
+echo "KALYPSO: reset internal PLL"
+pci -w 904C 1
+sleep 0.1
+
+echo "KALYPSO: enable internal clock (WARNING: ONLY FOR DEBUGGING!)"
+pci -w 904C 0
+sleep 0.1
+
+echo "reset and synchronize TOP and BOTTOM"
+pci -w 904C 2
+sleep 0.1
+
+echo "SETTING FOR 0 for 1024 and 8 for 512 PIXELS"
+pci -w 904C 0
+sleep 0.1
+
+
+############## For external RF clock ############
+#echo "KALYPSO: #################################################"
+#echo "KALYPSO: setup enable external RF clock"
+#echo "KALYPSO: #################################################"
+
+#pci -w 904C 1
+#sleep 0.1
+
+#echo "reset and synchronize TOP and BOTTOM"
+#pci -w 904C 003
+#sleep 0.1
+
+#echo "SETTING FOR 1024 PIXELS"
+#pci -w 904C 001
+#sleep 0.1
+
+####################################################
+
+
+
+####################################################
+echo "RESET of the KALYPSO"
+#pci -w 9040 0x800ff  # enable internal clock
+pci -w 9040 800800ff # enable external clock
+sleep 0.1
+
+echo "DE-RESET of the KALYPSO"
+#pci -w 9040 0x0      # enable internal clock
+pci -w 9040 80000000 # enable external clock
+sleep 0.1
+
+
+######################################
+pci -w 0x9024 0
+sleep 0.1
+
+pci -w 0x9024 1
+sleep 0.1
+#########################################
+echo "*ONBOARD TRIG GEN: ON"
+pci -w 0x9044 0xb8   #2e was before
+sleep 0.1
+
+echo "GOTT: Integration Period"
+pci -w 0x9000 0x2
+sleep 0.1
+
+echo "GOTT: Integration Delay"
+pci -w 0x9004 0x0
+sleep 0.1
+
+echo "GOTT: Gain"
+pci -w 0x9010 0x02
+sleep 0.1
+
+echo "write the number of samples to be acquired"
+pci -w 9108 0x0400

+ 84 - 0
reset_ex_rf.sh

@@ -0,0 +1,84 @@
+#! /bin/bash
+export PCILIB_MODEL=ipedma
+
+#echo "ADC & GOT: Turning on power..."
+#pci -w 9048 f0
+#sleep 0.1
+
+#pci -w 9048 ff
+#sleep 0.1
+###################################### For internal RF clock ##########################
+#echo "KALYPSO: reset internal PLL"
+#pci -w 904C 1
+#sleep 0.1
+
+#echo "KALYPSO: enable internal clock (WARNING: ONLY FOR DEBUGGING!)"
+#pci -w 904C 0
+#sleep 0.1
+
+#echo "reset and synchronize TOP and BOTTOM"
+#pci -w 904C 2
+#sleep 0.1
+
+#echo "SETTING FOR 0 for 1024 and 8 for 512 PIXELS"
+#pci -w 904C 0
+#sleep 0.1
+
+
+############## For external RF clock ############
+#echo "KALYPSO: #################################################"
+#echo "KALYPSO: setup enable external RF clock"
+#echo "KALYPSO: #################################################"
+
+pci -w 904C 1
+sleep 0.1
+
+#echo "reset and synchronize TOP and BOTTOM"
+pci -w 904C 003
+sleep 0.1
+
+#echo "SETTING FOR 1024 PIXELS"
+pci -w 904C 001
+sleep 0.1
+
+####################################################
+
+
+
+####################################################
+echo "RESET of the KALYPSO"
+#pci -w 9040 0x800ff  # enable internal clock
+pci -w 9040 800800ff # enable external clock
+sleep 0.1
+
+echo "DE-RESET of the KALYPSO"
+#pci -w 9040 0x0      # enable internal clock
+pci -w 9040 80000000 # enable external clock
+sleep 0.1
+
+
+######################################
+pci -w 0x9024 0
+sleep 0.1
+
+pci -w 0x9024 1
+sleep 0.1
+#########################################
+echo "*ONBOARD TRIG GEN: ON"
+pci -w 0x9044 0xb8   #2e was before
+sleep 0.1
+
+echo "GOTT: Integration Period"
+pci -w 0x9000 0x2
+sleep 0.1
+
+echo "GOTT: Integration Delay"
+pci -w 0x9004 0x0
+sleep 0.1
+
+echo "GOTT: Gain"
+pci -w 0x9010 0x02
+sleep 0.1
+
+echo "write the number of samples to be acquired"
+pci -w 9108 0x0400

+ 84 - 0
set_dac_left.sh

@@ -0,0 +1,84 @@
+#!/bin/sh
+
+
+#echo "ADC & GOT: Turning on power..."
+#pci -w 9048 f0
+#sleep 0.5
+
+#pci -w 9048 ff
+#sleep 0.5
+
+
+echo "***Configuring DACs***"
+
+#VB_COLBUFFER 750
+#IB_DS 550
+#VIN_CM 5DC
+#VOUT_CM 460
+
+
+#I2C_DAC_0 = h9068
+#I2C_DAC_1 = h906C
+#I2C_DAC_2 = h9070
+#I2C_DAC_3 = h9074
+#I2C_DAC_4 = h9078
+#I2C_DAC_5 = h907C
+
+
+
+echo "DAC0: CH0 = VB_COLBUFFER 29uA"
+pci -w 9068 000900
+sleep 0.5
+
+echo "DAC0: CH2 = VB_COLBUFFER 29uA"
+pci -w 9068 020900
+sleep 0.5
+
+echo "DAC1: CH0 = VB_COLBUFFER 29uA"
+pci -w 906C 000900
+sleep 0.5
+
+echo "DAC1: CH2 = VB_COLBUFFER 29uA"
+pci -w 906C 020900
+sleep 0.5
+
+
+########################################################
+
+echo "DAC0: CH1 = IB_DS 28uA"
+pci -w 9068 0106d0
+sleep 0.5
+
+echo "DAC0: CH3 = IB_DS 28uA"
+pci -w 9068 0306d0    #699 now programmed
+sleep 0.5
+
+echo "DAC1: CH1 = IB_DS 28uA"
+pci -w 906C 0106d0
+sleep 0.5
+
+echo "DAC1: CH3 = IB_DS 28uA"
+pci -w 906C 0306d0
+sleep 0.5
+
+#########################################################
+
+echo "DAC2: CH0 = VOUT_CM 750mV=5DC "
+pci -w 9070 0005DC
+sleep 0.5
+
+echo "DAC2: CH2 = VOUT_CM "
+pci -w 9070 0205DC
+sleep 0.5
+
+######################################################
+
+echo "DAC2: CH1 = VIN_CM 560mV"
+pci -w 9070 010460
+sleep 0.5
+
+echo "DAC2: CH3 = VIN_CM 560mV "
+pci -w 9070 030460
+sleep 0.5
+
+echo "....done!****"

+ 124 - 0
set_dac_voltages_25.sh

@@ -0,0 +1,124 @@
+#!/bin/sh
+
+
+#echo "ADC & GOT: Turning on power..."
+#pci -w 9048 f0
+#sleep 0.5
+
+#pci -w 9048 ff
+#sleep 0.5
+
+
+echo "***Configuring DACs***"
+
+#I2C_DAC_0 = h9068
+#I2C_DAC_1 = h906C
+#I2C_DAC_2 = h9070
+#I2C_DAC_3 = h9074
+#I2C_DAC_4 = h9078
+#I2C_DAC_5 = h907C
+
+
+
+echo "DAC0: CH0 = VB_COLBUFFER 29uA"
+pci -w 9068 000750
+sleep 0.5
+
+echo "DAC0: CH2 = VB_COLBUFFER 29uA"
+pci -w 9068 020750
+sleep 0.5
+
+echo "DAC1: CH0 = VB_COLBUFFER 29uA"
+pci -w 906C 000750
+sleep 0.5
+
+echo "DAC1: CH2 = VB_COLBUFFER 29uA"
+pci -w 906C 020750
+sleep 0.5
+
+echo "DAC3: CH0 = VB_COLBUFFER 29uA"
+pci -w 9074 000750
+sleep 0.5
+
+echo "DAC3: CH2 = VB_COLBUFFER 29uA"
+pci -w 9074 020750
+sleep 0.5
+
+echo "DAC4: CH0 = VB_COLBUFFER 29uA"
+pci -w 9078 000750
+sleep 0.5
+
+echo "DAC4: CH2 = VB_COLBUFFER 29uA"
+pci -w 9078 020750
+sleep 0.5
+
+
+
+echo "DAC0: CH1 = IB_DS 28uA"
+pci -w 9068 010550
+sleep 0.5
+
+echo "DAC0: CH3 = IB_DS 28uA"
+pci -w 9068 030550    #699 now programmed
+sleep 0.5
+
+echo "DAC1: CH1 = IB_DS 28uA"
+pci -w 906C 010550
+sleep 0.5
+
+echo "DAC1: CH3 = IB_DS 28uA"
+pci -w 906C 030550
+sleep 0.5
+
+echo "DAC3: CH1 = IB_DS 28uA"
+pci -w 9074 010550
+sleep 0.5
+
+echo "DAC3: CH3 = IB_DS 28uA"
+pci -w 9074 030550
+sleep 0.5
+
+echo "DAC4: CH1 = IB_DS 28uA"
+pci -w 9078 010550
+sleep 0.5
+
+echo "DAC4: CH3 = IB_DS 28uA"
+pci -w 9078 030550
+sleep 0.5
+
+
+echo "DAC2: CH0 = VOUT_CM 750mV=5DC "
+pci -w 9070 0005DC
+sleep 0.5
+
+echo "DAC2: CH2 = VOUT_CM "
+pci -w 9070 0205DC
+sleep 0.5
+
+echo "DAC5: CH0 = VOUT_CM "
+pci -w 907C 0005DC
+sleep 0.5
+
+echo "DAC5: CH2 = VOUT_CM "
+pci -w 907C 0205DC
+sleep 0.5
+
+
+
+echo "DAC2: CH1 = VIN_CM 560mV"
+pci -w 9070 010460
+sleep 0.5
+
+echo "DAC2: CH3 = VIN_CM 560mV "
+pci -w 9070 030460
+sleep 0.5
+##
+echo "DAC5: CH1 = VIN_CM 560mV"
+pci -w 907C 010460
+sleep 0.5
+
+echo "DAC5: CH3 = VIN_CM 560mV "
+pci -w 907C 030460
+sleep 0.5
+
+echo "....done!****"

+ 11 - 0
soft_reset.sh

@@ -0,0 +1,11 @@
+#! /bin/bash
+export PCILIB_MODEL=ipedma
+
+echo "RESET of the KALYPSO"
+pci -w 9040 0x200010
+sleep 0.1
+
+echo "DE-RESET of the KALYPSO"
+pci -w 9040 0x200000
+sleep 0.1
+#./status.sh

+ 6 - 0
status.sh

@@ -0,0 +1,6 @@
+#! /bin/bash
+
+echo "*************************"
+echo "** KALYPSO STATUS "
+pci -r 0x9000 -s 120
+echo "*************************"

+ 175 - 0
strip_data.py

@@ -0,0 +1,175 @@
+import numpy as np
+import sys
+
+
+pixels = 512*2
+TAIL = [0xba98,0xfedc]*16
+DEAD = [0xdea1,0xdead,0xdea2,0xdead,0xdea3,0xdead,0xdea4,0xdead,0xdea5,0xdead,0xdea6,0xdead,0xdea7,0xdead,0xdea8,0xdead]
+
+def strip_data(filename, number_pixels, orbits, offset = None):
+
+        ###############----------Read data from memory----------############################################
+        np.set_printoptions(threshold='nan')
+        # data = np.fromfile(str(filename), dtype=np.uint16)
+        if 	offset is None:
+        	data = np.memmap( str(filename), dtype=np.dtype('<u2'), mode='r')
+        else:
+            data = np.memmap( str(filename), dtype=np.dtype('<u2'), offset = (2*pixels*offset),mode='r')
+
+
+        ###############----------Remove Header----------####################################################
+
+        if (data[0] == 0x1111 and data[15] == 0xF888):
+            print ('Removing header .....')
+            data = data[16:]
+        else:
+            print ('No data header....')
+            data = data
+
+        ##############--------Search and remove for TAIL--------############################################
+        offset = 0
+        tailoffset = offset
+        while np.any((data[tailoffset : tailoffset + len(TAIL)] != TAIL)):
+            tailoffset += 8
+            if tailoffset + len(TAIL) > len(data):
+                print('Could not find tail')
+                #sys.exit(-1)
+                data = data
+        print('Found tail at offset ' + str(tailoffset))
+
+        ##############--------Search and remove for DEAD filling--------##################################
+        deadcnt = 0
+        deadoffset = tailoffset
+        while np.any(data[deadoffset - len(DEAD) : deadoffset] == DEAD):
+            deadcnt +=1
+            deadoffset -= len(DEAD)
+
+        print('Removed %d bytes of DEAD' %(deadcnt))
+
+        ##############--------Set the pure data --------###################################################
+
+        data = np.frombuffer((data[offset:deadoffset]), dtype = np.uint16)
+
+        #dead = np.where(data == 0xdea1)
+        #loc = np.amin(dead)
+        #data = data[0:loc]
+
+        ############-------Swap the data bytes and change from 16 bit to 14 bit---------####################
+
+        data = data.byteswap()
+
+
+        #############---------Index decoder for the jesd data for 16 input mode----------###################
+        odd_inner_idx_1 = [23,22,7,6,21,20,5,4,19,18,3,2,17,16,1,0] # working one
+        odd_inner_idx_2 = [8,9,24,25,10,11,26,27,12,13,28,29,14,15,30,31]    # non interleaved
+
+        odd_index_1 = np.zeros([256], dtype=np.int64)
+        odd_index_2 = np.zeros([256], dtype=np.int64)
+        for i in range(16):
+            for j in range(16):
+                odd_index_1[i * 16 + j] = odd_inner_idx_1[i] +  j * 64
+
+        for i in range(16):
+            for j in range(16):
+                odd_index_2[i * 16 + j] = odd_inner_idx_2[i] +  j * 64
+
+
+        even_inner_idx_1 = [55,54,39,38,53,52,37,36,51,50,35,34,49,48,33,32] # working one
+        even_inner_idx_2 = [40,41,56,57,42,43,58,59,44,45,60,61,46,47,62,63]    # non interleaved
+
+        even_index_1 = np.zeros([256], dtype=np.int64)
+        even_index_2 = np.zeros([256], dtype=np.int64)
+        for i in range(16):
+            for j in range(16):
+                even_index_1[i * 16 + j] = even_inner_idx_1[i] +  j * 64
+
+        for i in range(16):
+            for j in range(16):
+                even_index_2[i * 16 + j] = even_inner_idx_2[i] +  j * 64
+
+
+        #temp = [even_index_1[i^1] for i in range(len(even_index_1))]
+        #even_index_1 = temp
+
+
+        #swap odd left adc pixels
+        #odd_index_1_t = odd_index_1 + 1
+        #odd_index_1_t[:,0::2], odd_index_1_t[:,1::2] = odd_index_1[:,1::2], odd_index_1[:,0::2]
+        #odd_index_1 = odd_index_1_t
+
+        #swap even left adc pixels
+        #even_index_1_t = even_index_1 + 1
+        #even_index_1_t[:,0::2], even_index_1_t[:,1::2] = even_index_1[:,1::2], even_index_1[:,0::2]
+        #even_index_1 = even_index_1_t
+
+
+        ################------working part---------###########################################################
+        #index_interleave = np.ravel(np.column_stack((index_1,index_2)))  #interleaving the pixels, NOTE: interchange index_1 & index_2 if the pixels are swapped
+        #k = 32
+        #pixel_map = []
+        #a = index_interleave
+
+        #for i in range(0, len(a), k):
+        #    pixel_map.extend((a[i:i + k])[::-1])
+        ######################################################################################################
+        l = 16
+        odd_adc_2 = []
+        odd_b = odd_index_2
+        for i in range(0, len(odd_b), l):
+            odd_adc_2.extend((odd_b[i:i + l])[::-1])
+
+        even_adc_2 = []
+        even_b = even_index_2
+        for i in range(0, len(even_b), l):
+            even_adc_2.extend((even_b[i:i + l])[::-1])
+
+        odd_index_interleave = np.concatenate((odd_index_1,odd_adc_2),axis = 0)    # for concatenated pixels
+        even_index_interleave = np.concatenate((even_index_1,even_adc_2),axis = 0)    # for concatenated pixels
+
+        #odd_index_interleave = np.ravel(np.column_stack((odd_index_1,odd_adc_2)))    # for interleaved pixels
+        #even_index_interleave = np.ravel(np.column_stack((even_index_1,even_adc_2)))    # for interleaved pixels
+
+        #splitting the even part of the ADC since on the sensor they belong to the outer 256 x 2
+        even_index_interleave_left = even_index_interleave[0:256]
+        even_index_interleave_right = even_index_interleave[256:512]
+
+
+
+
+
+        #splitting the even part of the ADC since on the sensor they belong to the outer 256 x 2
+        odd_left_1 = odd_index_1[0:128]
+        odd_right_1 = odd_index_1[128:256]
+
+        odd_left_2 = odd_adc_2[0:128]
+        odd_right_2 = odd_adc_2[128:256]
+
+
+        #temp = [odd_right_1[i^1] for i in range(len(odd_right_1))]
+        #odd_right_1 = temp
+
+        #temp1 = [even_index_1[i^1] for i in range(len(even_index_1))]
+        #even_index_1 = temp1
+
+
+        #final_1024_index = np.concatenate((even_index_interleave_left,odd_index_interleave,even_index_interleave_right),axis = 0)
+        #######################
+        final_1024_index_concatenated = np.concatenate((odd_left_1,even_index_1,odd_right_1,odd_left_2,even_adc_2,odd_right_2),axis = 0)  # for concatenated pixels
+        left =  np.concatenate((odd_left_1,even_index_1,odd_right_1),axis = 0)
+
+        right = np.concatenate((odd_left_2,even_adc_2,odd_right_2),axis = 0)
+
+        final_1024_index_interleaved = np.ravel(np.column_stack((left,right)))  #for interleaved pixels
+
+        ##############-------------Reshape the data as pixel x orbits-------------------###################
+        if (orbits):
+            data = data[0:orbits*512*2]
+
+        data = np.reshape(data,(-1,pixels))
+
+        data = data[:,final_1024_index_interleaved]
+        data = data >> 2
+        data = ss.savgol_filter(data, 51, 3) # window size 51, polynomial order 3
+        orb, pix = np.shape(data)
+
+        return (data, orb)

+ 13 - 0
sync_adcs.sh

@@ -0,0 +1,13 @@
+#! /bin/bash
+export PCILIB_MODEL=ipedma
+
+pci -w 9040 0x200000  
+
+echo "SYNC SENT ... "
+pci -w 9040 0x600000  
+
+sleep 0.1
+echo "Normal Operation"
+pci -w 9040 0x200000  
+
+./status.sh

+ 45 - 0
timescan.sh

@@ -0,0 +1,45 @@
+#!/bin/sh
+pci -w 9024 0x1
+sleep 0.001
+pci -w 9024 0x0
+# A POSIX variable
+OPTIND=1   # Reset in case getopts has been used previously in the shell.
+
+# Initialize our own variables:
+output_file="timescan_data.out"
+orbits=0x1
+
+while getopts "o:f:" opt; do
+    case "$opt" in
+    o)  orbits=$OPTARG
+        ;;
+    f)  output_file=$OPTARG
+        ;;
+    esac
+done
+
+shift $((OPTIND-1))
+
+[ "$1" = "--" ] && shift
+
+#echo "orbits=$orbits, output_file='$output_file'"
+
+rm $output_file
+
+pci -w 9014 1
+sleep 0.1
+
+echo "*KALYPSO: Enable Readout + DDR"
+pci -w 0x9040 0x1021FF00
+sleep 0.1
+
+#echo "*DMA: Reading data..."
+pci -r dma0 --multipacket -o $output_file --timeout=1000000
+
+#echo "*KALYPSO: RST GOTTHARD stage"
+pci -w 0x9040 0x10210F00
+sleep 0.1
+
+echo "TS: Disable time scan"
+pci -w 0x9014 0x0
+sleep 0.1

+ 0 - 0
timescan_data.out


+ 38 - 0
timescan_plot.py

@@ -0,0 +1,38 @@
+import numpy as np
+import matplotlib.pyplot as plt
+import strip_data
+import os
+import os.path
+
+NUMBER_PIXELS = 1024
+
+def timescan_plot(filename, orbits, settings):
+
+    data, orb  = strip_data.strip_data(filename, NUMBER_PIXELS, 0)
+
+    if os.path.isfile('temp_bg.bin'):
+        bg_data , orb_bg  = strip_data.strip_data('temp_bg.bin', NUMBER_PIXELS, 0)
+        if (dc_bg):
+            bg_avg = np.average(bg_data,axis = 0)
+            data = bg_avg - data
+        else:
+            data = data
+
+
+    data = np.reshape(data, (-1,orbits,NUMBER_PIXELS))
+    data = np.average(data, axis=1)
+
+    data = np.reshape(data, (-1,NUMBER_PIXELS))
+    data = data[1::4,:]
+
+
+    fig, ax = plt.subplots()
+    im = ax.imshow(data, cmap=plt.cm.hot, aspect=0.5, interpolation='none', extent=[0,NUMBER_PIXELS,settings,0])
+
+    fig.colorbar(im, ax=ax)
+    plt.ylabel('Delay setting')
+    plt.xlabel('Pixels')
+
+    plt.tight_layout()
+
+    plt.show(block=True)

+ 15 - 0
tx_trig_adcs.sh

@@ -0,0 +1,15 @@
+#! /bin/bash
+export PCILIB_MODEL=ipedma
+
+pci -w 9040 0x200000
+
+echo "TX_TRIG SENT ... "
+pci -w 9040 0x260000
+
+sleep 0.1
+
+echo "Normal Operation"
+pci -w 9040 0x200000
+sleep 0.1
+
+#./status.sh

+ 15 - 0
tx_trig_adcs_left.sh

@@ -0,0 +1,15 @@
+#! /bin/bash
+export PCILIB_MODEL=ipedma
+
+pci -w 9040 0x200000
+
+echo "TX_TRIG SENT ... "
+pci -w 9040 0x220000
+
+sleep 0.1
+
+echo "Normal Operation"
+pci -w 9040 0x200000
+sleep 0.1
+
+#./status.sh

+ 15 - 0
tx_trig_adcs_right.sh

@@ -0,0 +1,15 @@
+#! /bin/bash
+export PCILIB_MODEL=ipedma
+
+pci -w 9040 0x200000
+
+echo "TX_TRIG SENT ... "
+pci -w 9040 0x240000
+
+sleep 0.1
+
+echo "Normal Operation"
+pci -w 9040 0x200000
+sleep 0.1
+
+#./status.sh

+ 47 - 0
write_csv.py

@@ -0,0 +1,47 @@
+"""Usage: write_csv.py -f FILE
+
+Options:
+    -h --help Show this screen.
+"""
+#!/usr/bin/python2
+from docopt import docopt
+
+import numpy as np
+import csv
+import json
+import os
+import os.path
+import subprocess
+
+
+
+def write_csv(output_file):
+
+    with open('kalypso_registers.json') as registers_file:
+        registers = json.load(registers_file)
+
+    with open('kalypso_log_conf.json') as log_conf_file:
+        log_conf = json.load(log_conf_file)
+
+    def read_register(reg_key, hex=False):
+        ## Output from 'pci -r' function in terminal is a string with (rubbish)
+        ## + (8 chars for values, starting from [11])
+        pcitool_string = subprocess.check_output(['pci', '-r', registers[reg_key]["address"]])
+        if hex==True:
+            return pcitool_string[11:19]
+        else:
+            value = int(pcitool_string[11:19],16) & int(registers[reg_key]["mask"],16)
+            return value
+
+    csvfile = output_file[:-3] + "csv"
+    with open(csvfile, "w") as output:
+        writer = csv.writer(output, lineterminator='\n')
+        entries = []
+        for key in log_conf["log_entries"]:
+            entries.append([str(registers[key]["name"]),read_register(key,hex=True)])
+        writer.writerows(entries)
+
+if __name__ == "__main__":
+    arguments = docopt(__doc__, version="lor 0.2")
+    output_file = arguments["FILE"]
+    write_csv(output_file)