Skip to content

Hardware Link (caen.dppp)

caen.dppp

High-level DPP-PHA parameter management, register programming, and acquisition modes.

DPP

Controller for CAEN DT5780 DPP-PHA board and channel configurations.

Manages parameter persistence (<SN>.cfg), unit-to-register scaling, bitfield read-modify-write updates, automatic trapezoidal gain/rescaling recalculation, and switching between oscilloscope and spectroscopy modes.

Attributes:

Name Type Description
TRT str

Parameter key for Trapezoid Rise Time.

IDT str

Parameter key for Input Decay Time.

SHF str

Parameter key for Trapezoid Rescaling shift.

DGN str

Parameter key for Digital Gain.

WorkShop dict

Auxiliary GUI and calibration settings stored alongside hardware state.

Clock float

ADC sampling clock period in nanoseconds.

Board dict

Board-level parameter definitions and current values.

Channel dict

Channel-level DPP-PHA parameter definitions and current values.

Mode str

Active operating mode ('ReadOut' or 'Monitor').

FineGainMax list[float]

Maximum achievable fine gain per channel for current shaping times.

Source code in caen/dppp.py
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
class DPP:
    """Controller for CAEN DT5780 DPP-PHA board and channel configurations.

    Manages parameter persistence (``<SN>.cfg``), unit-to-register scaling,
    bitfield read-modify-write updates, automatic trapezoidal gain/rescaling
    recalculation, and switching between oscilloscope and spectroscopy modes.

    Attributes:
        TRT (str): Parameter key for Trapezoid Rise Time.
        IDT (str): Parameter key for Input Decay Time.
        SHF (str): Parameter key for Trapezoid Rescaling shift.
        DGN (str): Parameter key for Digital Gain.
        WorkShop (dict): Auxiliary GUI and calibration settings stored alongside hardware state.
        Clock (float): ADC sampling clock period in nanoseconds.
        Board (dict): Board-level parameter definitions and current values.
        Channel (dict): Channel-level DPP-PHA parameter definitions and current values.
        Mode (str): Active operating mode (``'ReadOut'`` or ``'Monitor'``).
        FineGainMax (list[float]): Maximum achievable fine gain per channel for current shaping times.
    """
#    iofile = "DPP.cfg"
    TRT = "Trapezoid Rise Time"
    IDT = "Input Decay Time"
    SHF = "Trapezoid Rescaling"
    DGN = "Digital Gain"

    def __init__(self):
        super().__init__()
        self.WorkShop = {}  # Empty dict for additional software settings
        self.Clock = BOARD.clock    # ADC clock in ns
        self.Board = BOARD.cfg      # board settings
        self.Channel = CHANNEL.cfg  # channel settings
        self.Mode = "ReadOut"       # Default Mode
        self.FineGainMax = [1,1]

    def BoardSetUp(self, device, DEBUG = False):
        """Reset the digitizer, load saved configuration, and program all registers.

        Sets mandatory bits in register ``0x8000`` (including bit 24 to enable the
        ``FORMAT`` word in aggregate headers) and applies all board and channel presets.

        Args:
            device (TheBoard): Connected digitizer instance.
            DEBUG (bool): Print verbose register read/write logs during initialization.
        """
        self.device = device
        self.device.Reset()
        SN = device.BoardInfo["Serial Number"]
        self.iofile = f"{SN}.cfg"
        self.LoadParameters()
        R = 1<<4 | 1<<8 | 1<<24 # bit 24 enables the FORMAT word in the aggregate data.
        self.device.Reg32(0x8000, R) # write bits that "must be 1" into 0x8000 register
        for k,v in self.Board.items():
            if not ("mode" in v and v["mode"]=="w"):
                try:
                    self.SetBoardParameter(k, v["values"][0], DEBUG=DEBUG)
                except KeyError:
                    vdef = v["init"]
                    print(f"New sotware configuration key {k} is set to default value {vdef}")
                    self.Board[k]["values"] = [vdef]
        for k,v in self.Channel.items():
            if k not in (self.SHF, self.DGN):
                for ch in range(self.device.NChannels):
#                    print(v)
                    self.SetChannelParameter(k, ch, v["values"][ch], DEBUG=DEBUG)

    def LoadParameters(self):
        """Load board, channel, and GUI parameters from ``<SN>.cfg`` or create defaults."""
        # 1. Use default parameters
        NB, NC = 1, TheBoard.NChannels
        for v in self.Board.values():
            v["values"]=[v["init"]]*NB
        for v in self.Channel.values():
            v["values"]=[v["init"]]*NC
        # 2. Update parameters values from saved config
        try:
            with open(self.iofile, "rb") as fp:
                S = pickle.load(fp)
                if "A" in S.keys():
                    self.WorkShop = S["A"]
#                    with open("workshop.toml", "w", encoding="utf-8") as f:
#                        tomlkit.dump(self.WorkShop, f)
#                    print("READ:", self.WorkShop)

                for k,v in S["B"].items():
                    if k not in self.Board.keys():
                        print(f"Key {k} is obsolete")
                    else:
                        try:
                            self.Board[k]["values"] = v
                        except KeyError as text: 
                            print(f"Saved key doesn't match current software version: {text}")

                for k,v in S["C"].items():
                    if k not in self.Channel.keys():
                        print(f"Key {k} is obsolete")
                    else:
                        try:
                            self.Channel[k]["values"] = v
                        except KeyError as text: 
                            print(f"Saved key doesn't match current software version: {text}")
                            print(k,v)
                            input()
                print(f"DPP Parameters are loaded from {self.iofile}!")
        # 3. In case there's no config, create it with default presets
        except FileNotFoundError:
            self.SaveParameters()
            print(f"Default parameters are saved to {self.iofile}!")
            self.LoadParameters()

    def SaveParameters(self):
        """Disarm acquisition and serialize all current parameters to ``<SN>.cfg``."""
        S = {}
        self.Board["Start/Stop"]["values"][0] = "Stop (Disarm)" # ensure stop for save
        S["A"] = self.WorkShop
#        print("WRITE:", self.WorkShop)
#        for k,v in self.Board.items():
#            if "values" not in v.keys():
#                print(k,v)
        S["B"] = {k:v["values"] for k,v in self.Board.items()}
        S["C"] = {k:v["values"] for k,v in self.Channel.items()}
        try:
            with open(self.iofile, "wb") as fp:
                pickle.dump(S, fp)
            print(f"DPP parameters saved to {self.iofile}")
        except:
            print("Could not save DPP parameters!")

    def WriteParameter(self, P, CH=0, DEBUG = False):
        """Convert a parameter value to register counts and write it to the board.

        Performs read-modify-write masking for bitfield registers, waits for the
        channel SPI busy flag (bit 2 of ``0x1n88``) before updating ``DC Offset``,
        and recursively updates ``Trapezoid Rescaling`` and ``Digital Gain`` when
        shaping or decay times change.

        Args:
            P (str): Parameter name from ``Board`` or ``Channel``.
            CH (int): Channel index (``0`` or ``1``; ignored for board-level parameters).
            DEBUG (bool): Print register addresses, bitmasks, and raw values.
        """
        logs = lambda x: print(x) if DEBUG else 0

        if P in self.Board.keys():
            D, CH = self.Board[P], 0
            if "addr" in D:
                addr = D["addr"]
            else:
                return
        else:
            D = self.Channel[P]
            if "addr" in D:
                addr = D["addr"] | CH << 8
            else:
                return

        H = f"{P:>30}: {D['values'][CH]}"
        if "unit" in D.keys():
            logs(f"\n{H} [{D['unit'][1]}] ADDR:{hex(addr)}")
        else:
            logs(f"\n{H} ADDR:{hex(addr)}")

        pick = "pick" in D.keys()
        unit = "unit" in D.keys()
        bits = "bits" in D.keys()
        read = not (("mode" in D.keys()) and (not 'r' in D["mode"]))

        W = D["values"][CH] # stored value
        w = f"{W}" # write value for log
        if pick:
            W = D["pick"][W][0] # value to write
            w = f"{hex(W)}" # write value for log
        elif unit:
            W = int(W // D["unit"][0]) # value to write
        else:
            W = int(W)

        if read: # if not writeonly register
            R = self.device.Reg32(addr)
            if bits: # parameter do not occupy the register in whole
                shift, size = D["bits"]  # bit address, record size
                mask = ((1 << size) - 1) << shift
                W = R ^ ((R ^ (W << shift)) & mask)
                w = f"{bin(W)}" # write value for log
                r = f"{bin(R)}" # read value for log
            else:
                r = f"{R}" # read value for log
        else:
            r = "Writeonly Register"
        logs(f"{'Read':>30}: {r}\n{'Write':>30}: {w}")

        if P == "DC Offset": # Before writing this register, it is necessary to check that the channel is not in busy status!
            status_addr = 0x1088 | (CH << 8)
            for _ in range(100):
                if not ((self.device.Reg32(status_addr) >> 2) & 1):
                    break
                time.sleep(0.001)
        self.device.Reg32(addr, W)

        if P in (self.TRT, self.IDT):
            logs(f"{'- R E C U R S I O N -':>30}")
            self.SHGDGN(CH)
            self.WriteParameter(self.SHF, CH, DEBUG)
            self.WriteParameter(self.DGN, CH, DEBUG)

    def SHGDGN(self, CH): # Trapezoid Rescaling & Digital Gain
        """Recalculate ``Trapezoid Rescaling`` (``SHF``) and ``Digital Gain`` (``DGN``).

        Args:
            CH (int): Channel index (``0`` or ``1``).
        """
        kM  = self.Channel[self.TRT]["values"][CH] // self.Channel[self.TRT]["unit"][0]
        kM *= self.Channel[self.IDT]["values"][CH] // self.Channel[self.IDT]["unit"][0]
        SHF = int(log2(kM)) & 0x3F
        FineGain = self.Channel["Fine Gain"]["values"][CH] # desired physical fine gain
        dgg = int(FineGain * 0xFFFF/kM * 2**SHF) & 0xFFFF  # digital gain (16 bits)
        self.Channel[self.SHF]["values"][CH] = SHF
        self.Channel[self.DGN]["values"][CH] = dgg
        self.FineGainMax[CH] = kM/(1<<SHF)
#        print(f"CH {CH} max gain: {kM/2**SHF}")

    def SetBoardParameter(self, P, V, DEBUG = False):
        """Update a board-level parameter value in memory and write it to hardware.

        Args:
            P (str): Board parameter name.
            V (Any): New parameter value in physical or symbolic units.
            DEBUG (bool): Enable verbose register logging.
        """
        self.Board[P]["values"][0] = V
        self.WriteParameter(P, DEBUG=DEBUG)

    def SetChannelParameter(self, P, CH, V, DEBUG = False):
        """Update a channel-level parameter value and program the corresponding register(s).

        Args:
            P (str): Channel parameter name.
            CH (int): Channel index (``0`` or ``1``).
            V (Any): New parameter value.
            DEBUG (bool): Enable verbose register logging.
        """
        self.Channel[P]["values"][CH] = V
        if "addr" in self.Channel[P].keys():
            self.WriteParameter(P, CH, DEBUG=DEBUG)
        elif "fine" in self.Channel[P].keys(): # this is when FineGain is changed
            self.SHGDGN(CH)
            self.WriteParameter(self.DGN, CH, DEBUG)

    def MonitorMode(self, DEBUG = False):
        """Configure the digitizer for oscilloscope mode with waveform capture enabled.

        Args:
            DEBUG (bool): Enable verbose register logging.
        """
        self.Mode = "Monitor"
#        self.SetBoardParameter("Software Clear", 1)
        self.SetBoardParameter("Waveform",                  0x1,  DEBUG=DEBUG)
#        self.SetBoardParameter("Record Length",            4096, DEBUG=DEBUG)
        self.SetBoardParameter("Aggregates in all",         0x0,  DEBUG=DEBUG)
        self.SetBoardParameter("Aggregates per BLT",        2,    DEBUG=DEBUG)
        self.SetChannelParameter("Events per Aggregate", 0, 2,    DEBUG=DEBUG)
        self.SetChannelParameter("Events per Aggregate", 1, 2,    DEBUG=DEBUG)

    def ReadOutMode(self, DEBUG = False):
        """Configure the digitizer for high-throughput spectroscopy list/histogram readout.

        Args:
            DEBUG (bool): Enable verbose register logging.
        """
        self.Mode = "ReadOut"
#        self.SetBoardParameter("Software Clear", 1)
        self.SetBoardParameter("Waveform",                  0x0,  DEBUG=DEBUG)
#        self.SetBoardParameter("Record Length",             0,   DEBUG=DEBUG)
        self.SetBoardParameter("Aggregates in all",         0xA,  DEBUG=DEBUG)
        self.SetBoardParameter("Aggregates per BLT",        1024, DEBUG=DEBUG)
        self.SetChannelParameter("Events per Aggregate", 0, 0,    DEBUG=DEBUG)
        self.SetChannelParameter("Events per Aggregate", 1, 0,    DEBUG=DEBUG)

    def AcquisitionStatus(self) -> list[int]:
        """Read status flags from the Acquisition Status register (``0x8104``).

        Returns:
            List of 8 bit flags corresponding to bits ``(2, 3, 4, 5, 7, 8, 15, 16)``.
        """
        S = self.device.Reg32(0x8104)
        return [(S>>n & 0x1) for n in (2,3,4,5,7,8,15,16)]

    def StartAcquisition(self):
        """Arm the digitizer and start data acquisition."""
        self.SetBoardParameter("Start/Stop", "Start (Arm)")

    def StopAcquisition(self):
        """Disarm the digitizer and stop data acquisition."""
        self.SetBoardParameter("Start/Stop", "Stop (Disarm)")

AcquisitionStatus()

Read status flags from the Acquisition Status register (0x8104).

Returns:

Type Description
list[int]

List of 8 bit flags corresponding to bits (2, 3, 4, 5, 7, 8, 15, 16).

Source code in caen/dppp.py
296
297
298
299
300
301
302
303
def AcquisitionStatus(self) -> list[int]:
    """Read status flags from the Acquisition Status register (``0x8104``).

    Returns:
        List of 8 bit flags corresponding to bits ``(2, 3, 4, 5, 7, 8, 15, 16)``.
    """
    S = self.device.Reg32(0x8104)
    return [(S>>n & 0x1) for n in (2,3,4,5,7,8,15,16)]

BoardSetUp(device, DEBUG=False)

Reset the digitizer, load saved configuration, and program all registers.

Sets mandatory bits in register 0x8000 (including bit 24 to enable the FORMAT word in aggregate headers) and applies all board and channel presets.

Parameters:

Name Type Description Default
device TheBoard

Connected digitizer instance.

required
DEBUG bool

Print verbose register read/write logs during initialization.

False
Source code in caen/dppp.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
    def BoardSetUp(self, device, DEBUG = False):
        """Reset the digitizer, load saved configuration, and program all registers.

        Sets mandatory bits in register ``0x8000`` (including bit 24 to enable the
        ``FORMAT`` word in aggregate headers) and applies all board and channel presets.

        Args:
            device (TheBoard): Connected digitizer instance.
            DEBUG (bool): Print verbose register read/write logs during initialization.
        """
        self.device = device
        self.device.Reset()
        SN = device.BoardInfo["Serial Number"]
        self.iofile = f"{SN}.cfg"
        self.LoadParameters()
        R = 1<<4 | 1<<8 | 1<<24 # bit 24 enables the FORMAT word in the aggregate data.
        self.device.Reg32(0x8000, R) # write bits that "must be 1" into 0x8000 register
        for k,v in self.Board.items():
            if not ("mode" in v and v["mode"]=="w"):
                try:
                    self.SetBoardParameter(k, v["values"][0], DEBUG=DEBUG)
                except KeyError:
                    vdef = v["init"]
                    print(f"New sotware configuration key {k} is set to default value {vdef}")
                    self.Board[k]["values"] = [vdef]
        for k,v in self.Channel.items():
            if k not in (self.SHF, self.DGN):
                for ch in range(self.device.NChannels):
#                    print(v)
                    self.SetChannelParameter(k, ch, v["values"][ch], DEBUG=DEBUG)

LoadParameters()

Load board, channel, and GUI parameters from <SN>.cfg or create defaults.

Source code in caen/dppp.py
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
    def LoadParameters(self):
        """Load board, channel, and GUI parameters from ``<SN>.cfg`` or create defaults."""
        # 1. Use default parameters
        NB, NC = 1, TheBoard.NChannels
        for v in self.Board.values():
            v["values"]=[v["init"]]*NB
        for v in self.Channel.values():
            v["values"]=[v["init"]]*NC
        # 2. Update parameters values from saved config
        try:
            with open(self.iofile, "rb") as fp:
                S = pickle.load(fp)
                if "A" in S.keys():
                    self.WorkShop = S["A"]
#                    with open("workshop.toml", "w", encoding="utf-8") as f:
#                        tomlkit.dump(self.WorkShop, f)
#                    print("READ:", self.WorkShop)

                for k,v in S["B"].items():
                    if k not in self.Board.keys():
                        print(f"Key {k} is obsolete")
                    else:
                        try:
                            self.Board[k]["values"] = v
                        except KeyError as text: 
                            print(f"Saved key doesn't match current software version: {text}")

                for k,v in S["C"].items():
                    if k not in self.Channel.keys():
                        print(f"Key {k} is obsolete")
                    else:
                        try:
                            self.Channel[k]["values"] = v
                        except KeyError as text: 
                            print(f"Saved key doesn't match current software version: {text}")
                            print(k,v)
                            input()
                print(f"DPP Parameters are loaded from {self.iofile}!")
        # 3. In case there's no config, create it with default presets
        except FileNotFoundError:
            self.SaveParameters()
            print(f"Default parameters are saved to {self.iofile}!")
            self.LoadParameters()

MonitorMode(DEBUG=False)

Configure the digitizer for oscilloscope mode with waveform capture enabled.

Parameters:

Name Type Description Default
DEBUG bool

Enable verbose register logging.

False
Source code in caen/dppp.py
266
267
268
269
270
271
272
273
274
275
276
277
278
279
    def MonitorMode(self, DEBUG = False):
        """Configure the digitizer for oscilloscope mode with waveform capture enabled.

        Args:
            DEBUG (bool): Enable verbose register logging.
        """
        self.Mode = "Monitor"
#        self.SetBoardParameter("Software Clear", 1)
        self.SetBoardParameter("Waveform",                  0x1,  DEBUG=DEBUG)
#        self.SetBoardParameter("Record Length",            4096, DEBUG=DEBUG)
        self.SetBoardParameter("Aggregates in all",         0x0,  DEBUG=DEBUG)
        self.SetBoardParameter("Aggregates per BLT",        2,    DEBUG=DEBUG)
        self.SetChannelParameter("Events per Aggregate", 0, 2,    DEBUG=DEBUG)
        self.SetChannelParameter("Events per Aggregate", 1, 2,    DEBUG=DEBUG)

ReadOutMode(DEBUG=False)

Configure the digitizer for high-throughput spectroscopy list/histogram readout.

Parameters:

Name Type Description Default
DEBUG bool

Enable verbose register logging.

False
Source code in caen/dppp.py
281
282
283
284
285
286
287
288
289
290
291
292
293
294
    def ReadOutMode(self, DEBUG = False):
        """Configure the digitizer for high-throughput spectroscopy list/histogram readout.

        Args:
            DEBUG (bool): Enable verbose register logging.
        """
        self.Mode = "ReadOut"
#        self.SetBoardParameter("Software Clear", 1)
        self.SetBoardParameter("Waveform",                  0x0,  DEBUG=DEBUG)
#        self.SetBoardParameter("Record Length",             0,   DEBUG=DEBUG)
        self.SetBoardParameter("Aggregates in all",         0xA,  DEBUG=DEBUG)
        self.SetBoardParameter("Aggregates per BLT",        1024, DEBUG=DEBUG)
        self.SetChannelParameter("Events per Aggregate", 0, 0,    DEBUG=DEBUG)
        self.SetChannelParameter("Events per Aggregate", 1, 0,    DEBUG=DEBUG)

SHGDGN(CH)

Recalculate Trapezoid Rescaling (SHF) and Digital Gain (DGN).

Parameters:

Name Type Description Default
CH int

Channel index (0 or 1).

required
Source code in caen/dppp.py
223
224
225
226
227
228
229
230
231
232
233
234
235
236
def SHGDGN(self, CH): # Trapezoid Rescaling & Digital Gain
    """Recalculate ``Trapezoid Rescaling`` (``SHF``) and ``Digital Gain`` (``DGN``).

    Args:
        CH (int): Channel index (``0`` or ``1``).
    """
    kM  = self.Channel[self.TRT]["values"][CH] // self.Channel[self.TRT]["unit"][0]
    kM *= self.Channel[self.IDT]["values"][CH] // self.Channel[self.IDT]["unit"][0]
    SHF = int(log2(kM)) & 0x3F
    FineGain = self.Channel["Fine Gain"]["values"][CH] # desired physical fine gain
    dgg = int(FineGain * 0xFFFF/kM * 2**SHF) & 0xFFFF  # digital gain (16 bits)
    self.Channel[self.SHF]["values"][CH] = SHF
    self.Channel[self.DGN]["values"][CH] = dgg
    self.FineGainMax[CH] = kM/(1<<SHF)

SaveParameters()

Disarm acquisition and serialize all current parameters to <SN>.cfg.

Source code in caen/dppp.py
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
    def SaveParameters(self):
        """Disarm acquisition and serialize all current parameters to ``<SN>.cfg``."""
        S = {}
        self.Board["Start/Stop"]["values"][0] = "Stop (Disarm)" # ensure stop for save
        S["A"] = self.WorkShop
#        print("WRITE:", self.WorkShop)
#        for k,v in self.Board.items():
#            if "values" not in v.keys():
#                print(k,v)
        S["B"] = {k:v["values"] for k,v in self.Board.items()}
        S["C"] = {k:v["values"] for k,v in self.Channel.items()}
        try:
            with open(self.iofile, "wb") as fp:
                pickle.dump(S, fp)
            print(f"DPP parameters saved to {self.iofile}")
        except:
            print("Could not save DPP parameters!")

SetBoardParameter(P, V, DEBUG=False)

Update a board-level parameter value in memory and write it to hardware.

Parameters:

Name Type Description Default
P str

Board parameter name.

required
V Any

New parameter value in physical or symbolic units.

required
DEBUG bool

Enable verbose register logging.

False
Source code in caen/dppp.py
239
240
241
242
243
244
245
246
247
248
def SetBoardParameter(self, P, V, DEBUG = False):
    """Update a board-level parameter value in memory and write it to hardware.

    Args:
        P (str): Board parameter name.
        V (Any): New parameter value in physical or symbolic units.
        DEBUG (bool): Enable verbose register logging.
    """
    self.Board[P]["values"][0] = V
    self.WriteParameter(P, DEBUG=DEBUG)

SetChannelParameter(P, CH, V, DEBUG=False)

Update a channel-level parameter value and program the corresponding register(s).

Parameters:

Name Type Description Default
P str

Channel parameter name.

required
CH int

Channel index (0 or 1).

required
V Any

New parameter value.

required
DEBUG bool

Enable verbose register logging.

False
Source code in caen/dppp.py
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
def SetChannelParameter(self, P, CH, V, DEBUG = False):
    """Update a channel-level parameter value and program the corresponding register(s).

    Args:
        P (str): Channel parameter name.
        CH (int): Channel index (``0`` or ``1``).
        V (Any): New parameter value.
        DEBUG (bool): Enable verbose register logging.
    """
    self.Channel[P]["values"][CH] = V
    if "addr" in self.Channel[P].keys():
        self.WriteParameter(P, CH, DEBUG=DEBUG)
    elif "fine" in self.Channel[P].keys(): # this is when FineGain is changed
        self.SHGDGN(CH)
        self.WriteParameter(self.DGN, CH, DEBUG)

StartAcquisition()

Arm the digitizer and start data acquisition.

Source code in caen/dppp.py
305
306
307
def StartAcquisition(self):
    """Arm the digitizer and start data acquisition."""
    self.SetBoardParameter("Start/Stop", "Start (Arm)")

StopAcquisition()

Disarm the digitizer and stop data acquisition.

Source code in caen/dppp.py
309
310
311
def StopAcquisition(self):
    """Disarm the digitizer and stop data acquisition."""
    self.SetBoardParameter("Start/Stop", "Stop (Disarm)")

WriteParameter(P, CH=0, DEBUG=False)

Convert a parameter value to register counts and write it to the board.

Performs read-modify-write masking for bitfield registers, waits for the channel SPI busy flag (bit 2 of 0x1n88) before updating DC Offset, and recursively updates Trapezoid Rescaling and Digital Gain when shaping or decay times change.

Parameters:

Name Type Description Default
P str

Parameter name from Board or Channel.

required
CH int

Channel index (0 or 1; ignored for board-level parameters).

0
DEBUG bool

Print register addresses, bitmasks, and raw values.

False
Source code in caen/dppp.py
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
def WriteParameter(self, P, CH=0, DEBUG = False):
    """Convert a parameter value to register counts and write it to the board.

    Performs read-modify-write masking for bitfield registers, waits for the
    channel SPI busy flag (bit 2 of ``0x1n88``) before updating ``DC Offset``,
    and recursively updates ``Trapezoid Rescaling`` and ``Digital Gain`` when
    shaping or decay times change.

    Args:
        P (str): Parameter name from ``Board`` or ``Channel``.
        CH (int): Channel index (``0`` or ``1``; ignored for board-level parameters).
        DEBUG (bool): Print register addresses, bitmasks, and raw values.
    """
    logs = lambda x: print(x) if DEBUG else 0

    if P in self.Board.keys():
        D, CH = self.Board[P], 0
        if "addr" in D:
            addr = D["addr"]
        else:
            return
    else:
        D = self.Channel[P]
        if "addr" in D:
            addr = D["addr"] | CH << 8
        else:
            return

    H = f"{P:>30}: {D['values'][CH]}"
    if "unit" in D.keys():
        logs(f"\n{H} [{D['unit'][1]}] ADDR:{hex(addr)}")
    else:
        logs(f"\n{H} ADDR:{hex(addr)}")

    pick = "pick" in D.keys()
    unit = "unit" in D.keys()
    bits = "bits" in D.keys()
    read = not (("mode" in D.keys()) and (not 'r' in D["mode"]))

    W = D["values"][CH] # stored value
    w = f"{W}" # write value for log
    if pick:
        W = D["pick"][W][0] # value to write
        w = f"{hex(W)}" # write value for log
    elif unit:
        W = int(W // D["unit"][0]) # value to write
    else:
        W = int(W)

    if read: # if not writeonly register
        R = self.device.Reg32(addr)
        if bits: # parameter do not occupy the register in whole
            shift, size = D["bits"]  # bit address, record size
            mask = ((1 << size) - 1) << shift
            W = R ^ ((R ^ (W << shift)) & mask)
            w = f"{bin(W)}" # write value for log
            r = f"{bin(R)}" # read value for log
        else:
            r = f"{R}" # read value for log
    else:
        r = "Writeonly Register"
    logs(f"{'Read':>30}: {r}\n{'Write':>30}: {w}")

    if P == "DC Offset": # Before writing this register, it is necessary to check that the channel is not in busy status!
        status_addr = 0x1088 | (CH << 8)
        for _ in range(100):
            if not ((self.device.Reg32(status_addr) >> 2) & 1):
                break
            time.sleep(0.001)
    self.device.Reg32(addr, W)

    if P in (self.TRT, self.IDT):
        logs(f"{'- R E C U R S I O N -':>30}")
        self.SHGDGN(CH)
        self.WriteParameter(self.SHF, CH, DEBUG)
        self.WriteParameter(self.DGN, CH, DEBUG)