Skip to content

Hardware Link (caen.hvps)

caen.hvps

High-Voltage Power Supply (HVPS) control and monitoring for CAEN DT5780.

ToolHV

Controller for a single DT5780 High-Voltage Power Supply channel.

Maps physical parameters (voltage, current, ramp rates) to channel-specific HVPS registers (base offset 0x1220 + ch << 8) using hardware-dependent scaling factors detected by :class:caen.comm.TheBoard.

Attributes:

Name Type Description
HVPS dict[str, dict]

Register map with addresses, access flags, units, and limits.

Floats tuple[str, ...]

Names of analog HVPS parameters.

Status tuple[str, ...]

Bit-ordered labels for the 16-bit HVPS status register.

doubles dict[str, list]

Latest [value, unit] readings for analog parameters.

boolean dict[str, bool]

Decoded boolean flags from the HVPS status register.

Source code in caen/hvps.py
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 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
class ToolHV:
    """Controller for a single DT5780 High-Voltage Power Supply channel.

    Maps physical parameters (voltage, current, ramp rates) to channel-specific
    HVPS registers (base offset ``0x1220`` + ``ch << 8``) using hardware-dependent
    scaling factors detected by :class:`caen.comm.TheBoard`.

    Attributes:
        HVPS (dict[str, dict]): Register map with addresses, access flags, units, and limits.
        Floats (tuple[str, ...]): Names of analog HVPS parameters.
        Status (tuple[str, ...]): Bit-ordered labels for the 16-bit HVPS status register.
        doubles (dict[str, list]): Latest ``[value, unit]`` readings for analog parameters.
        boolean (dict[str, bool]): Decoded boolean flags from the HVPS status register.
    """
    HVPS = {
        "V set": {"addr": 0x1220, "w": 1, "unit": [1e-2, "V"], "max": 0xC350},
        "I set": {"addr": 0x1224, "w": 1, "unit": [5e-2, "μA"], "max": 0xF230},
        "Ramp Up": {"addr": 0x1228, "w": 1, "unit": [1e0, "V/s"], "max": 0xFF},
        "Ramp Down": {"addr": 0x122C, "w": 1, "unit": [1e0, "V/s"], "max": 0xFF},
        "V max": {"addr": 0x1230, "w": 1, "unit": [2e0, "V"], "max": 0xFF},
        "Control": {"addr": 0x1234, "w": 1, "unit": [1, ""]},
        "Status": {"addr": 0x1238, "w": 0, "unit": [1, ""]},
        "V mon": {"addr": 0x1240, "w": 0, "unit": [1e-2, "V"]},
        "I mon": {"addr": 0x1244, "w": 0, "unit": [5e-2, "μA"]},
    }
    Floats = tuple(e for e in HVPS.keys() if e != "Control" and e != "Status")
    Status = (
        "Power",
        "Ramp Up",
        "Ramp Down",
        "Imon > Iset",
        "Vmon > Vset",
        "Vmon < Vset",
        "Vset > Vmax",
        "IMon > Imax",
        "T > 80℃",
        "T > 125℃",
        "HV Inhibit",
        "Calibration err",
        "Alarm reset",
        "Shutting Down",
        "Power Limit",
        "Fan Speed",
    )

    """ the following is used as prefixes and suffixes for SpinBoxes: """
    pfx_and_sfx = {k: v["unit"][1] for k, v in HVPS.items() if v["w"] and v["unit"][1]}

    #    CLED   = {status[i]:('#00FF00' if i in (0,1,2,13) else '#FF0000') for i in range(len(status))}

    def __init__(self, device, ch, ramp=True, exts=False):
        """Initialize HVPS scaling factors and control flags for a channel.

        Args:
            device (TheBoard): Connected digitizer communication instance.
            ch (int): Channel index (``0`` or ``1``).
            ramp (bool): Use controlled ramp-up/ramp-down when switching HV on/off.
            exts (bool): Measure external analog signals instead of internal V/I monitors.
        """
        self.device, self.ch = device, ch
        self.HVPS["V max"]["unit"][0] = self.device.HV_Vmax
        self.HVPS["V set"]["unit"][0] = self.device.HV_Vset
        self.HVPS["I set"]["unit"][0] = self.device.HV_Iset
        self.HVPS["V mon"]["unit"][0] = self.device.HV_Vset
        self.HVPS["I mon"]["unit"][0] = self.device.HV_Iset
        """ the following is used as steps and ranges for SpinBoxes: """
        self.maximums = {}
        for k in self.pfx_and_sfx.keys():
            self.maximums[k] = int(self.HVPS[k]["max"] * self.HVPS[k]["unit"][0])
        self.hvc = (int(ramp) << 1) | (int(exts) << 7)
        self.doubles = dict.fromkeys(self.Floats)
        self.boolean = dict.fromkeys(self.Status)
        self.ON = staticmethod(lambda: self.WriteOne("Control", self.hvc | 1))
        self.OFF = staticmethod(lambda: self.WriteOne("Control", self.hvc | 0))

    def ReadAll(self):
        """Read all HVPS registers and update ``doubles`` and ``boolean`` dictionaries."""
        for k, T in self.HVPS.items():
            v, u = self.ReadOne(k), T["unit"][1]
            if k == "Status":
                for b in range(16):
                    self.boolean[self.Status[b]] = bool(v & (1 << b))
            elif k != "Control":
                self.doubles[k] = [v, u]

    def Get_Status(self):
        """Poll the 16-bit HVPS status register and update ``boolean`` flags."""
        v = self.ReadOne("Status")
        for b in range(16):
            self.boolean[self.Status[b]] = bool(v & (1 << b))

    def ReadOne(self, k) -> float:
        """Read a single HVPS parameter and convert it to physical units.

        Args:
            k (str): Parameter key from ``HVPS`` (e.g., ``'V mon'``, ``'I mon'``, ``'Status'``).

        Returns:
            Scaled parameter value in physical units (``V``, ``uA``, ``V/s``, or raw status word).
        """
        T = self.HVPS[k]
        return self.device.Reg32(self.ch << 8 | T["addr"]) * T["unit"][0]

    def WriteOne(self, k, v) -> int:
        """Convert a physical value to raw counts and write it to a writable HVPS register.

        Args:
            k (str): Writable parameter key from ``HVPS`` (e.g., ``'V set'``, ``'Ramp Up'``).
            v (float): Target value in physical units.

        Returns:
            Status code returned by ``CAENComm_Write32``.

        Raises:
            SystemExit: If the target parameter is read-only.
        """
        T = self.HVPS[k]
        if T["w"]:
            return self.device.Reg32(self.ch << 8 | T["addr"], int(v / T["unit"][0]))
        else:
            raise SystemExit(f"read-only register {T['addr']}")

Status = ('Power', 'Ramp Up', 'Ramp Down', 'Imon > Iset', 'Vmon > Vset', 'Vmon < Vset', 'Vset > Vmax', 'IMon > Imax', 'T > 80℃', 'T > 125℃', 'HV Inhibit', 'Calibration err', 'Alarm reset', 'Shutting Down', 'Power Limit', 'Fan Speed') class-attribute instance-attribute

the following is used as prefixes and suffixes for SpinBoxes:

Get_Status()

Poll the 16-bit HVPS status register and update boolean flags.

Source code in caen/hvps.py
89
90
91
92
93
def Get_Status(self):
    """Poll the 16-bit HVPS status register and update ``boolean`` flags."""
    v = self.ReadOne("Status")
    for b in range(16):
        self.boolean[self.Status[b]] = bool(v & (1 << b))

ReadAll()

Read all HVPS registers and update doubles and boolean dictionaries.

Source code in caen/hvps.py
79
80
81
82
83
84
85
86
87
def ReadAll(self):
    """Read all HVPS registers and update ``doubles`` and ``boolean`` dictionaries."""
    for k, T in self.HVPS.items():
        v, u = self.ReadOne(k), T["unit"][1]
        if k == "Status":
            for b in range(16):
                self.boolean[self.Status[b]] = bool(v & (1 << b))
        elif k != "Control":
            self.doubles[k] = [v, u]

ReadOne(k)

Read a single HVPS parameter and convert it to physical units.

Parameters:

Name Type Description Default
k str

Parameter key from HVPS (e.g., 'V mon', 'I mon', 'Status').

required

Returns:

Type Description
float

Scaled parameter value in physical units (V, uA, V/s, or raw status word).

Source code in caen/hvps.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
def ReadOne(self, k) -> float:
    """Read a single HVPS parameter and convert it to physical units.

    Args:
        k (str): Parameter key from ``HVPS`` (e.g., ``'V mon'``, ``'I mon'``, ``'Status'``).

    Returns:
        Scaled parameter value in physical units (``V``, ``uA``, ``V/s``, or raw status word).
    """
    T = self.HVPS[k]
    return self.device.Reg32(self.ch << 8 | T["addr"]) * T["unit"][0]

WriteOne(k, v)

Convert a physical value to raw counts and write it to a writable HVPS register.

Parameters:

Name Type Description Default
k str

Writable parameter key from HVPS (e.g., 'V set', 'Ramp Up').

required
v float

Target value in physical units.

required

Returns:

Type Description
int

Status code returned by CAENComm_Write32.

Raises:

Type Description
SystemExit

If the target parameter is read-only.

Source code in caen/hvps.py
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
def WriteOne(self, k, v) -> int:
    """Convert a physical value to raw counts and write it to a writable HVPS register.

    Args:
        k (str): Writable parameter key from ``HVPS`` (e.g., ``'V set'``, ``'Ramp Up'``).
        v (float): Target value in physical units.

    Returns:
        Status code returned by ``CAENComm_Write32``.

    Raises:
        SystemExit: If the target parameter is read-only.
    """
    T = self.HVPS[k]
    if T["w"]:
        return self.device.Reg32(self.ch << 8 | T["addr"], int(v / T["unit"][0]))
    else:
        raise SystemExit(f"read-only register {T['addr']}")

__init__(device, ch, ramp=True, exts=False)

Initialize HVPS scaling factors and control flags for a channel.

Parameters:

Name Type Description Default
device TheBoard

Connected digitizer communication instance.

required
ch int

Channel index (0 or 1).

required
ramp bool

Use controlled ramp-up/ramp-down when switching HV on/off.

True
exts bool

Measure external analog signals instead of internal V/I monitors.

False
Source code in caen/hvps.py
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
def __init__(self, device, ch, ramp=True, exts=False):
    """Initialize HVPS scaling factors and control flags for a channel.

    Args:
        device (TheBoard): Connected digitizer communication instance.
        ch (int): Channel index (``0`` or ``1``).
        ramp (bool): Use controlled ramp-up/ramp-down when switching HV on/off.
        exts (bool): Measure external analog signals instead of internal V/I monitors.
    """
    self.device, self.ch = device, ch
    self.HVPS["V max"]["unit"][0] = self.device.HV_Vmax
    self.HVPS["V set"]["unit"][0] = self.device.HV_Vset
    self.HVPS["I set"]["unit"][0] = self.device.HV_Iset
    self.HVPS["V mon"]["unit"][0] = self.device.HV_Vset
    self.HVPS["I mon"]["unit"][0] = self.device.HV_Iset
    """ the following is used as steps and ranges for SpinBoxes: """
    self.maximums = {}
    for k in self.pfx_and_sfx.keys():
        self.maximums[k] = int(self.HVPS[k]["max"] * self.HVPS[k]["unit"][0])
    self.hvc = (int(ramp) << 1) | (int(exts) << 7)
    self.doubles = dict.fromkeys(self.Floats)
    self.boolean = dict.fromkeys(self.Status)
    self.ON = staticmethod(lambda: self.WriteOne("Control", self.hvc | 1))
    self.OFF = staticmethod(lambda: self.WriteOne("Control", self.hvc | 0))