forked from M-Labs/artiq
almazny: port to NAC3
This commit is contained in:
parent
8fc0e5d3aa
commit
b7d35446e2
|
@ -191,6 +191,7 @@ class Mirny:
|
||||||
self.bus.write(data)
|
self.bus.write(data)
|
||||||
|
|
||||||
|
|
||||||
|
@nac3
|
||||||
class Almazny:
|
class Almazny:
|
||||||
"""
|
"""
|
||||||
Almazny (High frequency mezzanine board for Mirny)
|
Almazny (High frequency mezzanine board for Mirny)
|
||||||
|
@ -198,6 +199,12 @@ class Almazny:
|
||||||
:param host_mirny - Mirny device Almazny is connected to
|
:param host_mirny - Mirny device Almazny is connected to
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
core: KernelInvariant[Core]
|
||||||
|
mirny_cpld: KernelInvariant[Mirny]
|
||||||
|
att_mu: Kernel[list[int32]]
|
||||||
|
channel_sw: Kernel[list[int32]]
|
||||||
|
output_enable: Kernel[bool]
|
||||||
|
|
||||||
def __init__(self, dmgr, host_mirny):
|
def __init__(self, dmgr, host_mirny):
|
||||||
self.mirny_cpld = dmgr.get(host_mirny)
|
self.mirny_cpld = dmgr.get(host_mirny)
|
||||||
self.att_mu = [0x3f] * 4
|
self.att_mu = [0x3f] * 4
|
||||||
|
@ -209,7 +216,7 @@ class Almazny:
|
||||||
self.output_toggle(self.output_enable)
|
self.output_toggle(self.output_enable)
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def att_to_mu(self, att):
|
def att_to_mu(self, att: float) -> int32:
|
||||||
"""
|
"""
|
||||||
Convert an attenuator setting in dB to machine units.
|
Convert an attenuator setting in dB to machine units.
|
||||||
|
|
||||||
|
@ -222,17 +229,17 @@ class Almazny:
|
||||||
return mu
|
return mu
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def mu_to_att(self, att_mu):
|
def mu_to_att(self, att_mu: int32) -> float:
|
||||||
"""
|
"""
|
||||||
Convert a digital attenuator setting to dB.
|
Convert a digital attenuator setting to dB.
|
||||||
|
|
||||||
:param att_mu: attenuator setting in machine units
|
:param att_mu: attenuator setting in machine units
|
||||||
:return: attenuator setting in dB
|
:return: attenuator setting in dB
|
||||||
"""
|
"""
|
||||||
return att_mu / 2
|
return float(att_mu) / 2.
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def set_att(self, channel, att, rf_switch=True):
|
def set_att(self, channel: int32, att: float, rf_switch: bool = True):
|
||||||
"""
|
"""
|
||||||
Sets attenuators on chosen shift register (channel).
|
Sets attenuators on chosen shift register (channel).
|
||||||
:param channel - index of the register [0-3]
|
:param channel - index of the register [0-3]
|
||||||
|
@ -242,7 +249,7 @@ class Almazny:
|
||||||
self.set_att_mu(channel, self.att_to_mu(att), rf_switch)
|
self.set_att_mu(channel, self.att_to_mu(att), rf_switch)
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def set_att_mu(self, channel, att_mu, rf_switch=True):
|
def set_att_mu(self, channel: int32, att_mu: int32, rf_switch: bool = True):
|
||||||
"""
|
"""
|
||||||
Sets attenuators on chosen shift register (channel).
|
Sets attenuators on chosen shift register (channel).
|
||||||
:param channel - index of the register [0-3]
|
:param channel - index of the register [0-3]
|
||||||
|
@ -254,7 +261,7 @@ class Almazny:
|
||||||
self._update_register(channel)
|
self._update_register(channel)
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def output_toggle(self, oe):
|
def output_toggle(self, oe: bool):
|
||||||
"""
|
"""
|
||||||
Toggles output on all shift registers on or off.
|
Toggles output on all shift registers on or off.
|
||||||
:param oe - toggle output enable (bool)
|
:param oe - toggle output enable (bool)
|
||||||
|
@ -262,13 +269,13 @@ class Almazny:
|
||||||
self.output_enable = oe
|
self.output_enable = oe
|
||||||
cfg_reg = self.mirny_cpld.read_reg(1)
|
cfg_reg = self.mirny_cpld.read_reg(1)
|
||||||
en = 1 if self.output_enable else 0
|
en = 1 if self.output_enable else 0
|
||||||
delay(100 * us)
|
self.core.delay(100. * us)
|
||||||
new_reg = (en << ALMAZNY_OE_SHIFT) | (cfg_reg & 0x3FF)
|
new_reg = (en << ALMAZNY_OE_SHIFT) | (cfg_reg & 0x3FF)
|
||||||
self.mirny_cpld.write_reg(1, new_reg)
|
self.mirny_cpld.write_reg(1, new_reg)
|
||||||
delay(100 * us)
|
self.core.delay(100. * us)
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def _flip_mu_bits(self, mu):
|
def _flip_mu_bits(self, mu: int32) -> int32:
|
||||||
# in this form MSB is actually 0.5dB attenuator
|
# in this form MSB is actually 0.5dB attenuator
|
||||||
# unnatural for users, so we flip the six bits
|
# unnatural for users, so we flip the six bits
|
||||||
return (((mu & 0x01) << 5)
|
return (((mu & 0x01) << 5)
|
||||||
|
@ -279,16 +286,16 @@ class Almazny:
|
||||||
| ((mu & 0x20) >> 5))
|
| ((mu & 0x20) >> 5))
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def _update_register(self, ch):
|
def _update_register(self, ch: int32):
|
||||||
self.mirny_cpld.write_ext(
|
self.mirny_cpld.write_ext(
|
||||||
ALMAZNY_REG_BASE + ch,
|
ALMAZNY_REG_BASE + ch,
|
||||||
8,
|
8,
|
||||||
self._flip_mu_bits(self.att_mu[ch]) | (self.channel_sw[ch] << 6),
|
self._flip_mu_bits(self.att_mu[ch]) | (self.channel_sw[ch] << 6),
|
||||||
ALMAZNY_SPIT_WR
|
ALMAZNY_SPIT_WR
|
||||||
)
|
)
|
||||||
delay(100 * us)
|
self.core.delay(100. * us)
|
||||||
|
|
||||||
@kernel
|
@kernel
|
||||||
def _update_all_registers(self):
|
def _update_all_registers(self):
|
||||||
for i in range(4):
|
for i in range(4):
|
||||||
self._update_register(i)
|
self._update_register(i)
|
||||||
|
|
Loading…
Reference in New Issue