|
|
|
@@ -82,7 +82,7 @@ class AD9361DacStepFactor(IntEnum):
|
|
|
|
|
|
|
|
|
|
class Charon:
|
|
|
|
|
FREQUENCY_OFFSET = 1e6
|
|
|
|
|
DEFAULT_IP = "192.168.2.1"
|
|
|
|
|
DEFAULT_IP = "192.168.3.1"
|
|
|
|
|
|
|
|
|
|
calibration: rf.calibration.Calibration | None = None
|
|
|
|
|
|
|
|
|
@@ -90,8 +90,11 @@ class Charon:
|
|
|
|
|
self,
|
|
|
|
|
ip: str = DEFAULT_IP,
|
|
|
|
|
frequency: npt.ArrayLike = np.linspace(1e9, 2e9, 3),
|
|
|
|
|
ports: Tuple[int] = (1,),
|
|
|
|
|
ports: Tuple[int] | int = 1,
|
|
|
|
|
):
|
|
|
|
|
if isinstance(ports, int):
|
|
|
|
|
ports = (np.arange(ports) + 1).tolist()
|
|
|
|
|
ports = tuple(ports)
|
|
|
|
|
self.ports = ports
|
|
|
|
|
self.frequency = frequency
|
|
|
|
|
|
|
|
|
@@ -128,7 +131,7 @@ class Charon:
|
|
|
|
|
self.sdr.rx_hardwaregain_chan1 = 10
|
|
|
|
|
self.sdr.tx_hardwaregain_chan0 = -10
|
|
|
|
|
|
|
|
|
|
# # switch control
|
|
|
|
|
# switch control
|
|
|
|
|
ctx = iio.Context(uri)
|
|
|
|
|
self.ctrl = ctx.find_device("ad9361-phy")
|
|
|
|
|
# raw ad9361 register accesss:
|
|
|
|
@@ -136,11 +139,14 @@ class Charon:
|
|
|
|
|
# https://www.analog.com/media/cn/technical-documentation/user-guides/ad9364_register_map_reference_manual_ug-672.pdf # noqa: E501
|
|
|
|
|
self.ctrl.reg_write(AD9361Register.EXTERNAL_LNA_CONTROL, 0x90) # bit 7: AuxDAC Manual, bit 4: GPO Manual
|
|
|
|
|
self.ctrl.reg_write(AD9361Register.AUXDAC_ENABLE_CONTROL, 0x3F)
|
|
|
|
|
|
|
|
|
|
# initialize switch control outputs
|
|
|
|
|
self._set_gpo(0b0000)
|
|
|
|
|
self._set_dac_code(value=0, channel=1)
|
|
|
|
|
self._set_dac_code(value=0, channel=2)
|
|
|
|
|
|
|
|
|
|
self.set_switches(a=0, b=0)
|
|
|
|
|
# set default switch state
|
|
|
|
|
self.set_switches(a=self.ports[0] - 1, b=self.ports[0] - 1)
|
|
|
|
|
|
|
|
|
|
def get_config(self) -> Dict[str, Any]:
|
|
|
|
|
config = dict()
|
|
|
|
@@ -170,20 +176,15 @@ class Charon:
|
|
|
|
|
def _set_gpo(self, value: int) -> None:
|
|
|
|
|
self.ctrl.reg_write(AD9361Register.GPO_FORCE_AND_INIT, (value & 0x0F) << 4) # bits 7-4: GPO3-0
|
|
|
|
|
|
|
|
|
|
def _set_dac_voltage(self, voltage: float, channel: Literal[1, 2]):
|
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
def _get_dac_code(self, channel: Literal[1, 2]) -> Tuple[float, AD9361DacVref, AD9361DacStepFactor]:
|
|
|
|
|
word = self.ctrl.reg_read(AD9361Register.__getitem__(f"AUXDAC{channel}_WORD"))
|
|
|
|
|
config = self.ctrl.reg_read(AD9361Register.__getitem__(f"AUXDAC{channel}_CONFIG"))
|
|
|
|
|
|
|
|
|
|
def set_switches(self, a: int, b: int, excitation: int | None = None):
|
|
|
|
|
if excitation is None:
|
|
|
|
|
excitation = a
|
|
|
|
|
value = (word << 2) + (config & 0x3)
|
|
|
|
|
vref = AD9361DacVref((config >> 2) & 0x3)
|
|
|
|
|
step_factor = AD9361DacStepFactor((config >> 4) & 0x1)
|
|
|
|
|
|
|
|
|
|
val = 0
|
|
|
|
|
|
|
|
|
|
val |= int(bool(excitation)) << 0 # exc = GPO0
|
|
|
|
|
val |= int(bool(a)) << 2 # a = GPO2
|
|
|
|
|
val |= int(bool(b)) << 1 # b = GPO1
|
|
|
|
|
|
|
|
|
|
self._set_gpo(val)
|
|
|
|
|
return (value, vref, step_factor)
|
|
|
|
|
|
|
|
|
|
def _set_dac_code(
|
|
|
|
|
self,
|
|
|
|
@@ -217,18 +218,17 @@ class Charon:
|
|
|
|
|
(value & 0x3) | (vref.value << 2) | (step_factor << 4),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def _get_dac_code(self, channel: Literal[1, 2]) -> Tuple[float, AD9361DacVref, AD9361DacStepFactor]:
|
|
|
|
|
word = self.ctrl.reg_read(AD9361Register.__getitem__(f"AUXDAC{channel}_WORD"))
|
|
|
|
|
config = self.ctrl.reg_read(AD9361Register.__getitem__(f"AUXDAC{channel}_CONFIG"))
|
|
|
|
|
def set_switches(self, b: int, a: int, excitation: int | None = None):
|
|
|
|
|
if excitation is None:
|
|
|
|
|
excitation = a
|
|
|
|
|
|
|
|
|
|
value = (word << 2) + (config & 0x3)
|
|
|
|
|
vref = AD9361DacVref((config >> 2) & 0x3)
|
|
|
|
|
step_factor = AD9361DacStepFactor((config >> 4) & 0x1)
|
|
|
|
|
val = 0
|
|
|
|
|
|
|
|
|
|
return (value, vref, step_factor)
|
|
|
|
|
val |= int(bool(excitation)) << 0 # exc = GPO0
|
|
|
|
|
val |= int(bool(a)) << 2 # a = GPO2
|
|
|
|
|
val |= int(bool(b)) << 1 # b = GPO1
|
|
|
|
|
|
|
|
|
|
def _get_dac_voltage(self) -> float:
|
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
self._set_gpo(val)
|
|
|
|
|
|
|
|
|
|
def set_output_power(self, power: float):
|
|
|
|
|
pout = xr.DataArray(
|
|
|
|
@@ -305,22 +305,26 @@ class Charon:
|
|
|
|
|
|
|
|
|
|
return np.mean(data[1] / data[0])
|
|
|
|
|
|
|
|
|
|
def sweep_b_over_a(self):
|
|
|
|
|
def sweep_b_over_a(self, **kwargs):
|
|
|
|
|
s = xr.DataArray(
|
|
|
|
|
np.zeros(
|
|
|
|
|
len(self.frequency),
|
|
|
|
|
[len(self.frequency), len(self.ports), len(self.ports)],
|
|
|
|
|
dtype=np.complex128,
|
|
|
|
|
),
|
|
|
|
|
dims=["frequency"],
|
|
|
|
|
dims=["frequency", "m", "n"],
|
|
|
|
|
coords=dict(
|
|
|
|
|
frequency=self.frequency,
|
|
|
|
|
m=list(self.ports),
|
|
|
|
|
n=list(self.ports),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
for frequency in self.frequency:
|
|
|
|
|
s.loc[dict(frequency=frequency)] = self.get_b_over_a(frequency=frequency)
|
|
|
|
|
for m in s.m.data:
|
|
|
|
|
for n in s.n.data:
|
|
|
|
|
self.set_switches(b=m - 1, a=n - 1)
|
|
|
|
|
s.loc[dict(m=m, n=n)] = self.vna_capture(frequency=self.frequency, **kwargs)
|
|
|
|
|
return s
|
|
|
|
|
|
|
|
|
|
def vna_capture(self, frequency: npt.ArrayLike, callback: Callable[int, int] | None):
|
|
|
|
|
def vna_capture(self, frequency: npt.ArrayLike, callback: Callable[int, int] | None = None):
|
|
|
|
|
s = xr.DataArray(
|
|
|
|
|
np.empty(len(frequency), dtype=np.complex128),
|
|
|
|
|
dims=["frequency"],
|
|
|
|
|