{
    "ModuleConfig": {
        "ModuleMeta": {
            "displayName": "MDPP-32_QDC",
            "eventHeaderFilters": [
                {
                    "filter": "0100 XXX0 MMMM MMMM XXXX XXSS SSSS SSSS",
                    "description": "Event size filter for the classic, non-sampling mode."
                },
                {
                    "filter": "0100 XXX1 MMMM MMMM SSSS SSSS SSSS SSSS",
                    "description": "Event size filter with extended size bits for sampling mode."
                }
            ],
            "typeId": 13,
            "typeName": "mdpp32_qdc",
            "variables": [
            ],
            "vendorName": "mesytec",
            "vmeAddress": 0
        },
        "baseAddress": 0,
        "enabled": true,
        "id": "{fa9e11a3-f690-4f3d-88fa-6f61c4c965b5}",
        "initScripts": [
            {
                "enabled": true,
                "id": "{bb836d11-7a5c-485f-8fdc-38db18dd786c}",
                "name": "Module Init",
                "properties": {
                    "icon": ":/vme_script.png"
                },
                "variable_table": {
                    "name": "",
                    "variables": {
                    }
                },
                "vme_script": "## Parameters for MDPP-32_QDC\n\n# Operation Mode\n# ############################################################################\n# tdc_resolution\n0x6042  0           # 0 ->  24 ps = 25 ns / 1024\n                    # 1 ->  49 ps = 25 ns / 512\n                    # 2 ->  98 ps = 25 ns / 256\n                    # 3 -> 195 ps = 25 ns / 128\n                    # 4 -> 391 ps = 25 ns / 64\n                    # 5 -> 781 ps = 25 ns / 32\n\n# output_format\n0x6044  3           # 0 -> time and long integral\n                    # 1 -> long integral only (QDC-mode)\n                    # 2 -> time only (TDC mode)\n                    # 3 -> long integral, short integral and time\n\n# first_hit\n0x605C  1           # 0 -> transmit all hits per channel in the window\n                    # 1 -> only transmit first hit per channel in the window\n\n# Trigger Setup\n# ############################################################################\n# win_start\n0x6050  $(16384 - 100 / 1.56) # second term: offset in ns, positive or negative\n                    # Window of interest start time relative to trigger.\n                    # Window start   = 16384  + delay[ns] / 1.56;\n                    # Delay can be negative to register hits before the trigger.\n                    # Delay may be in the range [-25560 ns, +25560 ns].\n                    # < 0 -> window starts before trigger\n                    # > 0 -> window is delayed\n\n# win_width (14 bit value)\n0x6054  $(200 / 1.56)    # first term in ns;\n                    # win_width = (win_width[ns] / 25ns * 16)\n                    # max value 16383; (Hex notation: 0x3FFF)\n                    # Range: [0, 25560 ns]\n\n# trig_source\n# Defines the trigger which creates the window of interest.\n0x6058  0x300       # 0x001 -> trigger 0 input\n                    # 0x002 -> trigger 1 input\n                    # 0x300 -> bank 0 and 1 (self trigger; all channels)\n                    # single channel: trig_source = 128 + (chan * 4)\n                    #                 with channel in 0..31\n                    # +-------------+--------------------+---------+\n                    # | Whole bank  |     32_channels    |  trig   |\n                    # |   2 bits    |       6 bits       | 2 bits  |\n                    # +============================================|\n                    # |   B1   | B0 | active |   Chan    | T1 | T0 |\n                    # |        |    |        |   [4:0]   |    |    |\n                    # +--------+----+--------+---+-------+----+----+\n\n# trigger_output\n# NIM1 trigger output\n0x605E  0x300       # 0x300 -> bank 0 and 1 (OR of all channels)\n                    # single channel: trigger_output = 128 + (chan * 4)\n                    #                 with channel in 0..31\n                    # +-------------+--------------------+---------+\n                    # | Whole bank  |     32_channels    |  trig   |\n                    # |   2 bits    |       6 bits       | 2 bits  |\n                    # +============================================|\n                    # |   B1   | B0 | active |   Chan    | X  | X  |\n                    # |        |    |        |   [4:0]   |    |    |\n                    # +--------+----+--------+---+-------+----+----+\n\n\n# I/O\n# ############################################################################\n# Sorted from top to bottom, as on the front panel.\n\n# ECL3 input\n0x6060  0x00        # 0x00 -> off\n                    # 0x01 -> trig0, terminated\n                    # 0x11 -> trig0, unterminated\n# ECL2 input\n0x6062  0x00        # 0x00 -> off\n                    # 0x01 -> sync, terminated\n                    # 0x11 -> sync, unterminated\n                    # 0x02 -> trig1, terminated\n                    # 0x12 -> trig1, unterminated\n# ECL1 input\n0x6064  0x00        # 0x00 -> off\n                    # 0x01 -> reset, terminated\n                    # 0x11 -> reset, unterminated\n# ECL0 output\n0x6066  0x00        # 0x0 -> off\n                    # 0x4 -> busy\n                    # 0x8 -> data in buffer above threshold 0x6018 (= Data ready)\n                    # 0x9 -> events in buffer above threshold 0x601E\n\n# NIM4 input\n0x6068  1           # 0 -> off\n                    # 1 -> trig0_in\n\n# NIM3\n# Note: Front panel Monitor setting overrides this setting (becomes mon1\n# output).\n0x606A  0           # 0 -> off\n                    # 2 -> sync in (also set CTRA.ts_sources (0x6096)!)\n# NIM2\n# Note: Front panel Monitor setting overrides this setting (becomes mon0\n# output).\n0x606C  1           # 0 -> off\n                    # 1 -> trig1_in\n                    # 2 -> reset\n\n# NIM1 is always trigger output\n\n# NIM0\n0x6074  1           # 0 -> off\n                    # 1 -> CBus\n                    # 4 -> busy_out (== FIFO full or ACQ stopped)\n                    # 8 -> data in buffer above threshold 0x6018\n                    # 9 -> events in buffer above threshold 0x601E\n\n# Internal Test Pulser\n# ############################################################################\n# pulser_status\n0x6070  0           # 0 -> off, 1 -> on\n\n# pulser_amplitude\n0x6072  400         # maximum amplitude: 0xFFF = 4095\n\n# Timestamp/Event Counters: CTRA, CTRB\n# ############################################################################\n# ts_sources\n0x6096  0b00        # bit 0: frequency source (0 -> VME, 1 -> external)\n                    # bit 1: external reset enable\n\n# ts_divisor (16 bit value)\n0x6098  1           # timestamp = time / ts_divisor\n                    # 0 means division by 65536\n\n# stop_ctr\n#0x60AE  0b00       # bit 0: stop CTRB (time_0, time_1, time_2)\n                    # bit 1: stop CTRA (ts_counter_lo, ts_counter_hi)\n                    # with 0 -> run, 1 -> stop counter\n"
            },
            {
                "enabled": true,
                "id": "{6b1068d1-199d-447a-ab6f-10655edde2b8}",
                "name": "Frontend Settings",
                "properties": {
                    "icon": ":/vme_script.png"
                },
                "variable_table": {
                    "name": "",
                    "variables": {
                    }
                },
                "vme_script": "# Front end settings\n# ############################################################################\n# select_chan_pair\n0x6100  8       # 0 -> channel 0, 1, 2, 3\n                # 1 -> channel 4, 5, 6, 7\n                # ...\n                # 8 -> all channels (set to common values)\n\n# signal_width (10 bit value)\n0x6110  30      # FWHM in ns\n\n# input_amplitude (16 bit value)\n0x6112  1000    # maximum required input amplitude: 0 to peak in mV\n\n# jumper_range\n0x6114  2000    # range printed on jumper top in mV\n\n# integration_long\n0x6118  $(200 / 12.5)  # first term in ns\n\t\t\t\t# 2..508 in multiples of 12.5 ns\n\n# integration_short\n0x611A  $(25 / 12.5)  # first term in ns\n\t\t\t\t# 1..120 in multiples of 12.5 ns,\n                # must be < integration_long.\n\n# threshold0 (15 bit value for the 1st selected channel)\n0x611C  0x4FF   # 1..0xFFFF, example: 0x200 -> 0.8%\n\n# threshold1 (15 bit value for the 2nd selected channel)\n0x611E  0x4FF   # 1..0xFFFF, example: 0x200 -> 0.8%\n\n# threshold2 (15 bit value for the 3rd selected channel)\n0x6120  0x4FF   # 1..0xFFFF, example: 0x200 -> 0.8%\n\n# threshold3 (15 bit value for the 4th selected channel)\n0x6122  0x4FF   # 1..0xFFFF, example: 0x200 -> 0.8%\n\n\n### Expert settings, usually the default settings are fine ####\n# qdc_jumper\n#0x6116  0      # 0 -> no, 1 -> yes\n#\n\n# long_gain_correction\n#0x612A  1024   #  256 -> divide by 4\n                # 4096 -> multiply by 4\n                # 1024 -> neutral\n\n# short_gain_correction\n#0x612E  1024   #  256 -> divide by 4\n                # 4096 -> multiply by 4\n                # 1024 -> neutral\n\n# Channel / Channel Pair Front end settings\n# ############################################################################\n\n/*\n# channels (0, 1, 2, 3)\n0x6100       0\n0x6110      16    # signal_width\n0x6112    1024    # input_amplitude\n0x6114    3072    # jumper_range\n0x6116       0    # qdc_jumper\n0x6118      16    # integration_long\n0x611A       2    # integration_short\n0x611C  0x00ff    # threshold0\n0x611E  0x00ff    # threshold1\n0x6120  0x00ff    # threshold2\n0x6122  0x00ff    # threshold3\n0x6128      32    # reset_time\n0x612A    1024    # long_gain_correction\n0x612E    1024    # short_gain_correction\n\n# channels (4, 5, 6, 7)\n0x6100       1\n0x6110      16    # signal_width\n0x6112    1024    # input_amplitude\n0x6114    3072    # jumper_range\n0x6116       0    # qdc_jumper\n0x6118      16    # integration_long\n0x611A       2    # integration_short\n0x611C  0x00ff    # threshold4\n0x611E  0x00ff    # threshold5\n0x6120  0x00ff    # threshold6\n0x6122  0x00ff    # threshold7\n0x6128      32    # reset_time\n0x612A    1024    # long_gain_correction\n0x612E    1024    # short_gain_correction\n\n# channels (8, 9, 10, 11)\n0x6100       2\n0x6110      16    # signal_width\n0x6112    1024    # input_amplitude\n0x6114    3072    # jumper_range\n0x6116       0    # qdc_jumper\n0x6118      16    # integration_long\n0x611A       2    # integration_short\n0x611C  0x00ff    # threshold8\n0x611E  0x00ff    # threshold9\n0x6120  0x00ff    # threshold10\n0x6122  0x00ff    # threshold11\n0x6128      32    # reset_time\n0x612A    1024    # long_gain_correction\n0x612E    1024    # short_gain_correction\n\n# channels (12, 13, 14, 15)\n0x6100       3\n0x6110      16    # signal_width\n0x6112    1024    # input_amplitude\n0x6114    3072    # jumper_range\n0x6116       0    # qdc_jumper\n0x6118      16    # integration_long\n0x611A       2    # integration_short\n0x611C  0x00ff    # threshold12\n0x611E  0x00ff    # threshold13\n0x6120  0x00ff    # threshold14\n0x6122  0x00ff    # threshold15\n0x6128      32    # reset_time\n0x612A    1024    # long_gain_correction\n0x612E    1024    # short_gain_correction\n\n# channels (16, 17, 18, 19)\n0x6100       4\n0x6110      16    # signal_width\n0x6112    1024    # input_amplitude\n0x6114    3072    # jumper_range\n0x6116       0    # qdc_jumper\n0x6118      16    # integration_long\n0x611A       2    # integration_short\n0x611C  0x00ff    # threshold16\n0x611E  0x00ff    # threshold17\n0x6120  0x00ff    # threshold18\n0x6122  0x00ff    # threshold19\n0x6128      32    # reset_time\n0x612A    1024    # long_gain_correction\n0x612E    1024    # short_gain_correction\n\n# channels (20, 21, 22, 23)\n0x6100       5\n0x6110      16    # signal_width\n0x6112    1024    # input_amplitude\n0x6114    3072    # jumper_range\n0x6116       0    # qdc_jumper\n0x6118      16    # integration_long\n0x611A       2    # integration_short\n0x611C  0x00ff    # threshold20\n0x611E  0x00ff    # threshold21\n0x6120  0x00ff    # threshold22\n0x6122  0x00ff    # threshold23\n0x6128      32    # reset_time\n0x612A    1024    # long_gain_correction\n0x612E    1024    # short_gain_correction\n\n# channels (24, 25, 26, 27)\n0x6100       6\n0x6110      16    # signal_width\n0x6112    1024    # input_amplitude\n0x6114    3072    # jumper_range\n0x6116       0    # qdc_jumper\n0x6118      16    # integration_long\n0x611A       2    # integration_short\n0x611C  0x00ff    # threshold24\n0x611E  0x00ff    # threshold25\n0x6120  0x00ff    # threshold26\n0x6122  0x00ff    # threshold27\n0x6128      32    # reset_time\n0x612A    1024    # long_gain_correction\n0x612E    1024    # short_gain_correction\n\n# channels (28, 29, 30, 31)\n0x6100       7\n0x6110      16    # signal_width\n0x6112    1024    # input_amplitude\n0x6114    3072    # jumper_range\n0x6116       0    # qdc_jumper\n0x6118      16    # integration_long\n0x611A       2    # integration_short\n0x611C  0x00ff    # threshold28\n0x611E  0x00ff    # threshold29\n0x6120  0x00ff    # threshold30\n0x6122  0x00ff    # threshold31\n0x6128      32    # reset_time\n0x612A    1024    # long_gain_correction\n0x612E    1024    # short_gain_correction\n*/\n"
            },
            {
                "enabled": true,
                "id": "{6080f16b-f07d-4ef9-8c82-e96ad84f86ba}",
                "name": "VME Interface Settings",
                "properties": {
                    "icon": ":/vme_script.png"
                },
                "variable_table": {
                    "name": "",
                    "variables": {
                    }
                },
                "vme_script": "# Settings related to the readout loop\n# #####################################\n# Trigger output via IRQ-lines at Backplane; MDPP-32\n# Implemented since March 2021.\n# 0x6300 0b1111'1111'1111'1111  #IRQ 1 lower 16 channels\n# 0x6302 0b1111'1111'1111'1111  # upper 16 channels\n# 0x6304 0b1111'1111'1111'1111  #IRQ2 lower 16 channels\n# 0x6306 0b1111'1111'1111'1111  # upper 16 channels\n# 0x6308 0b1111'1111'1111'1111  #IRQ3 lower 16 channels\n# 0x630A 0b1111'1111'1111'1111  # upper 16 channels\n# 0x630C 0b1111'1111'1111'1111  #IRQ4 lower 16 channels\n# 0x630E 0b1111'1111'1111'1111  # upper 16 channels\n# 0x6310 0b1111'1111'1111'1111  #IRQ5 lower 16 channels\n# 0x6312 0b1111'1111'1111'1111  # upper 16 channels\n# 0x6314 0b1111'1111'1111'1111  #IRQ6 lower 16 channels\n# 0x6316 0b1111'1111'1111'1111  # upper 16 channels\n# 0x6318 0b1111'1111'1111'1111  # ** not supported by MVLC ** IRQ 7 lower 16 channels\n# 0x631A 0b1111'1111'1111'1111  #** not supported by MVLC ** upper 16 channels\n#######################################\n\n0x6010  ${sys_irq}                          # irq level\n\n# IRQ_source and thresholds\n#0x601C 1                                   # 1 -> specifies number of words\n#0x6018  100                                # IRQ-FIFO threshold, words\n0x601C 0                                    # 0 -> the following register specifies the number of events\n0x601E $(${mesy_readout_num_events} + 1)    # IRQ-FIFO threshold, events\n\n# marking_type\n0x6038 ${mesy_eoe_marker}                   # End Of Event marking\n                                            # 0 -> event counter\n                                            # 1 -> time stamp\n                                            # 3 -> extended time stamp\n\n# multi event mode:\n0x6036 0xb                                  # 0x0 -> single event\n                                            # 0x3 -> multi event, number of words\n                                            # 0xb -> multi event, transmits number of events specified\n\n# max_transfer_data\n0x601A ${mesy_readout_num_events}           # multi event mode == 0x3 -> Berr is emitted when more or equal the\n                                            #   specified number of words have been sent and \"End Of Event\" is detected.\n                                            # multi event mode == 0xb -> Berr is emitted when the specified number\n                                            #   of events has been transmitted.\n\n# Stop the module from accepting triggers and clear the readout FIFO.\n# Acquisition will be started simultaneously for all modules in the parent\n# event by the \"Multicast DAQ Start\" script.\n0x603a 0   # stop acq\n0x603c 1   # FIFO reset\n0x6034 1   # readout reset\n\n# MCST - Multicast Setup\n# #####################################\n0x6020 0x80                                 # Enable multicast\n0x6024 0x${mesy_mcst}                       # Set 8 high bits of MCST address\n"
            },
            {
                "enabled": true,
                "id": "{687b5ba9-054d-4f9d-b691-a712f37a5071}",
                "name": "Streaming and Sampling",
                "properties": {
                    "icon": ":/vme_script.png"
                },
                "variable_table": {
                    "name": "",
                    "variables": {
                    }
                },
                "vme_script": "# Streaming and Sampling Settings\n# ############################################################################\n\n#***** Sample output ********\nset sampling 0\t   \t\t# 0= no sample output, 1 = sampling.\n\n#***** Definition of sampling trails ******\nset sample_source 0 \t\t# 0 = from ADC, 1 = deconvoluted, 2 = timing filter, 3 = from shaper.\nset no_offset_correction 0 \t# 0 = offset correction; 1= no offset correction\nset no_resampling 0\t\t\t# 0 = resampling; 1 = no resampling\n\nset number_presamples 4 # 0 to 1000, number of samples before input edge appears with ADC source\nset number_samples\t12  # 2 to 1000, total number of samples required. Even number.\n\n\n\n#********************************************\n#**** From here experts only ****************\n#********************************************\n\n#***** output data format **********\nset output_format 0 \t# 0 = standard WOI format #only for experts:  4 = compact_streaming, 8 = standard_streaming\n\t\t\t\t\t\t#  Compact streaming does not support sampling\n\n#**** Firmware check *************\nread a32 d16 0x600E # firmware revision\naccu_mask_rotate 0x000000ff 32\naccu_test_warn gte 0x50 \"MDPP-32_QDC >= FW3050 required for Sampling mode\"\n\n# *** Use the variables defined above ***************\n\n# output_format register 0x6044\n# 0 (default)   -> window of interest, no samples\n# 4  -> Since SCP FW2050. Enables compact_streaming.\n# 8  -> Since SCP FW2050. Enables standard_streaming.\n# Individual bits: {sampling, standard_streaming, compact_streaming, 0,0}\n#\t\t\t\t\tdefault: window of interest: standard_streaming = 0, compact_streaming = 0\n\n0x6044 0x${sampling}${output_format}\n\n# Sampling parameter (can be set for all channels or per channel pair)\n0x6100 8\t\t\t\t\t\t# select_chan_pair, 8 = all channels\n0x6146 ${number_presamples}\t\t# number of pre-samples\n0x6148 ${number_samples}\t\t# total samples to output (even number required)\n\n# sampling source and settings [7:0]\n# bits [1:0]: sample source\n#   00 = from ADC\n#   01 = deconvoluted\n#   10 = timing filter\n#   11 = from shaper\n# settings [7:4]\n#   bit 7 set: no offset correction\n#   bit 6 set: no resampling\n0x614A $(${no_offset_correction}*128+${no_resampling}*64+${sample_source})\n"
            }
        ],
        "name": "mdpp32_qdc",
        "type": "mdpp32_qdc",
        "variable_table": {
            "name": "",
            "variables": {
            }
        },
        "vmeReadout": {
            "enabled": true,
            "id": "{adda680b-d7de-4024-84ed-36e5c4b46be2}",
            "name": "Module Readout",
            "properties": {
                "icon": ":/vme_script.png"
            },
            "variable_table": {
                "name": "",
                "variables": {
                }
            },
            "vme_script": "# BLT readout until BERR or number of transfers reached\nmbltfifo a32 0x0000 65535\n"
        },
        "vmeReset": {
            "enabled": true,
            "id": "{7d9e6013-9619-4774-a18a-584e8d341a90}",
            "name": "Module Reset",
            "properties": {
                "icon": ":/vme_script.png"
            },
            "variable_table": {
                "name": "",
                "variables": {
                }
            },
            "vme_script": "# Reset the module\n0x6008 1\nwait 500ms\n\n## Get Module ids for log file\nprint \"Hardware ID:\"\nread a32 d16 0x6008\t# hardware ID\naccu_mask_rotate 0x0000ffff 0\naccu_test eq 0x5007 \"MDPP-32 hardware id check\"\n\nprint \"Firmware Revision:\"\nread a32 d16 0x600E # firmware revision\naccu_mask_rotate 0x0000f000 20\naccu_test eq 3 \"QDC firmware check\"\n\n0x603a 0   # stop acq\n0x603c 1   # FIFO reset\n0x6034 1   # readout reset\n"
        }
    }
}
