document and rearrange some stuff
This commit is contained in:
@ -128,7 +128,7 @@ class Charon:
|
|||||||
self.sdr.rx_hardwaregain_chan1 = 10
|
self.sdr.rx_hardwaregain_chan1 = 10
|
||||||
self.sdr.tx_hardwaregain_chan0 = -10
|
self.sdr.tx_hardwaregain_chan0 = -10
|
||||||
|
|
||||||
# # switch control
|
# switch control
|
||||||
ctx = iio.Context(uri)
|
ctx = iio.Context(uri)
|
||||||
self.ctrl = ctx.find_device("ad9361-phy")
|
self.ctrl = ctx.find_device("ad9361-phy")
|
||||||
# raw ad9361 register accesss:
|
# raw ad9361 register accesss:
|
||||||
@ -136,10 +136,13 @@ class Charon:
|
|||||||
# https://www.analog.com/media/cn/technical-documentation/user-guides/ad9364_register_map_reference_manual_ug-672.pdf # noqa: E501
|
# 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.EXTERNAL_LNA_CONTROL, 0x90) # bit 7: AuxDAC Manual, bit 4: GPO Manual
|
||||||
self.ctrl.reg_write(AD9361Register.AUXDAC_ENABLE_CONTROL, 0x3F)
|
self.ctrl.reg_write(AD9361Register.AUXDAC_ENABLE_CONTROL, 0x3F)
|
||||||
|
|
||||||
|
# initialize switch control outputs
|
||||||
self._set_gpo(0b0000)
|
self._set_gpo(0b0000)
|
||||||
self._set_dac_code(value=0, channel=1)
|
self._set_dac_code(value=0, channel=1)
|
||||||
self._set_dac_code(value=0, channel=2)
|
self._set_dac_code(value=0, channel=2)
|
||||||
|
|
||||||
|
# set default switch state
|
||||||
self.set_switches(a=0, b=0)
|
self.set_switches(a=0, b=0)
|
||||||
|
|
||||||
def get_config(self) -> Dict[str, Any]:
|
def get_config(self) -> Dict[str, Any]:
|
||||||
@ -170,20 +173,15 @@ class Charon:
|
|||||||
def _set_gpo(self, value: int) -> None:
|
def _set_gpo(self, value: int) -> None:
|
||||||
self.ctrl.reg_write(AD9361Register.GPO_FORCE_AND_INIT, (value & 0x0F) << 4) # bits 7-4: GPO3-0
|
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]):
|
def _get_dac_code(self, channel: Literal[1, 2]) -> Tuple[float, AD9361DacVref, AD9361DacStepFactor]:
|
||||||
raise NotImplementedError()
|
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):
|
value = (word << 2) + (config & 0x3)
|
||||||
if excitation is None:
|
vref = AD9361DacVref((config >> 2) & 0x3)
|
||||||
excitation = a
|
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
|
|
||||||
|
|
||||||
self._set_gpo(val)
|
|
||||||
|
|
||||||
def _set_dac_code(
|
def _set_dac_code(
|
||||||
self,
|
self,
|
||||||
@ -217,18 +215,17 @@ class Charon:
|
|||||||
(value & 0x3) | (vref.value << 2) | (step_factor << 4),
|
(value & 0x3) | (vref.value << 2) | (step_factor << 4),
|
||||||
)
|
)
|
||||||
|
|
||||||
def _get_dac_code(self, channel: Literal[1, 2]) -> Tuple[float, AD9361DacVref, AD9361DacStepFactor]:
|
def set_switches(self, b: int, a: int, excitation: int | None = None):
|
||||||
word = self.ctrl.reg_read(AD9361Register.__getitem__(f"AUXDAC{channel}_WORD"))
|
if excitation is None:
|
||||||
config = self.ctrl.reg_read(AD9361Register.__getitem__(f"AUXDAC{channel}_CONFIG"))
|
excitation = a
|
||||||
|
|
||||||
value = (word << 2) + (config & 0x3)
|
val = 0
|
||||||
vref = AD9361DacVref((config >> 2) & 0x3)
|
|
||||||
step_factor = AD9361DacStepFactor((config >> 4) & 0x1)
|
|
||||||
|
|
||||||
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:
|
self._set_gpo(val)
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
def set_output_power(self, power: float):
|
def set_output_power(self, power: float):
|
||||||
pout = xr.DataArray(
|
pout = xr.DataArray(
|
||||||
@ -320,7 +317,7 @@ class Charon:
|
|||||||
s.loc[dict(frequency=frequency)] = self.get_b_over_a(frequency=frequency)
|
s.loc[dict(frequency=frequency)] = self.get_b_over_a(frequency=frequency)
|
||||||
return s
|
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(
|
s = xr.DataArray(
|
||||||
np.empty(len(frequency), dtype=np.complex128),
|
np.empty(len(frequency), dtype=np.complex128),
|
||||||
dims=["frequency"],
|
dims=["frequency"],
|
||||||
|
Reference in New Issue
Block a user