From 4c50d6325dccfaf94b9cb1763f5d006000473339 Mon Sep 17 00:00:00 2001 From: Jude-Osems Date: Mon, 27 Jan 2025 17:00:37 +0000 Subject: [PATCH] ADF5611:test:Add test file for ADF5611 Added pytest file for adf5611, modified index.rst file to include device, correct attribute name error in adf5611_examples.py Signed-off-by: Jude Osemene --- adi/adf5611.py | 22 +++++++++-------- doc/source/devices/index.rst | 1 + examples/adf5611_example.py | 26 ++++++++++--------- test/test_adf5611.py | 48 ++++++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 22 deletions(-) create mode 100644 test/test_adf5611.py diff --git a/adi/adf5611.py b/adi/adf5611.py index 13caddccc..dbfc863a6 100644 --- a/adi/adf5611.py +++ b/adi/adf5611.py @@ -1,4 +1,4 @@ -# Copyright (C) 2021-2024 Analog Devices, Inc. +# Copyright (C) 2021-2025 Analog Devices, Inc. # # SPDX short identifier: ADIBSD @@ -33,7 +33,7 @@ class adf5611(attribute, context_manager): "3.000000", "3.200000", ) - + _rfoutdiv_divider_options = ( "1", "2", @@ -65,8 +65,10 @@ def rfout_frequency(self): @rfout_frequency.setter def rfout_frequency(self, value): """Get/Set the rfout frequency in Hz""" - self._set_iio_attr("altvoltage0", "rfout_frequency", True, int(value), self._ctrl) - + self._set_iio_attr( + "altvoltage0", "rfout_frequency", True, int(value), self._ctrl + ) + @property def altvolt0_rfout_power(self): return self._get_iio_attr("altvoltage0", "rfout_power", True, self._ctrl) @@ -76,7 +78,7 @@ def altvolt0_rfout_power(self, value): self._set_iio_attr_int( "altvoltage0", "rfout_power", True, int(value), self._ctrl ) - + @property def reference_frequency(self): return self._get_iio_dev_attr("reference_frequency", self._ctrl) @@ -84,7 +86,7 @@ def reference_frequency(self): @reference_frequency.setter def reference_frequency(self, value): self._set_iio_dev_attr("reference_frequency", value, self._ctrl) - + @property def reference_divider(self): return self._get_iio_dev_attr("reference_divider", self._ctrl) @@ -92,7 +94,7 @@ def reference_divider(self): @reference_divider.setter def reference_divider(self, value): self._set_iio_dev_attr("reference_divider", value, self._ctrl) - + @property def charge_pump_current(self): return self._get_iio_dev_attr("charge_pump_current", self._ctrl) @@ -106,7 +108,7 @@ def charge_pump_current(self, value): ) self._set_iio_dev_attr("charge_pump_current", value, self._ctrl) - + @property def rfoutdiv_power(self): return self._get_iio_dev_attr("rfoutdiv_power", self._ctrl) @@ -114,7 +116,7 @@ def rfoutdiv_power(self): @rfoutdiv_power.setter def rfoutdiv_power(self, value): self._set_iio_dev_attr("rfoutdiv_power", value, self._ctrl) - + @property def rfoutdiv_divider(self): return self._get_iio_dev_attr("rfoutdiv_divider", self._ctrl) @@ -128,7 +130,7 @@ def rfoutdiv_divider(self, value): ) self._set_iio_dev_attr("rfoutdiv_divider", value, self._ctrl) - + @property def en_rfoutdiv(self): return self._get_iio_dev_attr("en_rfoutdiv", self._ctrl) diff --git a/doc/source/devices/index.rst b/doc/source/devices/index.rst index 1856b5aba..9308e196b 100644 --- a/doc/source/devices/index.rst +++ b/doc/source/devices/index.rst @@ -66,6 +66,7 @@ Supported Devices adi.adf4355 adi.adf4371 adi.adf5610 + adi.adf5611 adi.adg2128 adi.adis16375 adi.adis16460 diff --git a/examples/adf5611_example.py b/examples/adf5611_example.py index cb3080058..42779c4a4 100644 --- a/examples/adf5611_example.py +++ b/examples/adf5611_example.py @@ -5,20 +5,22 @@ import adi # Create a new AD5611 device Serial port connection instance -pll = adi.adf5611(uri="serial:/dev/ttyACM0,230400,8n1n") # Change URI to your specific serial port +pll = adi.adf5611( + uri="serial:/dev/ttyACM0,230400,8n1n" +) # Change URI to your specific serial port # Configure pll attributes -pll.reference_frequency = 122880000 # Set reference frequency to 122.88 MHz -pll.rfout_frequency = 12000000000 # Set RF output frequency to 12 GHz -pll.altvolt0_rfout_power = 3 # Set RF output power to 3 dBm -pll.reference_divider = 2 # Set reference divider to 1 -pll.charge_pump_current = "3.200000" # Set charge pump current to 3.2 mA +pll.reference_frequency = 122880000 # Set reference frequency to 122.88 MHz +pll.rfout_frequency = 12000000000 # Set RF output frequency to 12 GHz +pll.altvolt0_rfout_power = 3 # Set RF output power to 3 dBm +pll.reference_divider = 2 # Set reference divider to 1 +pll.charge_pump_current = "3.200000" # Set charge pump current to 3.2 mA # Configure RfoutDiv Divider Output -pll.rfoutdiv_divider = 0 # Set RfoutDiv Divider to 2 -pll.rfoutdiv_divider = "1" # Set RfoutDiv Divider to 1 -pll.en_rfoutdiv = 1 # Enable RfoutDiv Divider +pll.rfoutdiv_power = 0 # Set RfoutDiv Power to 0 dBm +pll.rfoutdiv_divider = "1" # Set RfoutDiv Divider to 1 +pll.en_rfoutdiv = 1 # Enable RfoutDiv Divider -pll.reg_write(0x0A, 0x5A) # Write to register 0x0A with value 0x5A -val = pll.reg_read(0x0A) # Read register 0x0A -print(hex(int(val))) # Print the value of register 0x0A +pll.reg_write(0x0A, 0x5A) # Write to register 0x0A with value 0x5A +val = pll.reg_read(0x0A) # Read register 0x0A +print(hex(int(val))) # Print the value of register 0x0A diff --git a/test/test_adf5611.py b/test/test_adf5611.py new file mode 100644 index 000000000..3f704dd63 --- /dev/null +++ b/test/test_adf5611.py @@ -0,0 +1,48 @@ +import pytest + +# This hardware is not yet supported for emulation +# Will run this by someone soon +hardware = ["adf5611"] +classname = "adi.adf5611" + + +######################################### +@pytest.mark.iio_hardware(hardware) +@pytest.mark.parametrize("classname", [classname]) +@pytest.mark.parametrize( + "attr, start, stop, step, tol, repeats", + [ + ("altvolt0_rfout_power", 1, 3, 1, 0, 2), + ("rfoutdiv_power", 1, 3, 1, 0, 2), + ("reference_divider", 1, 16383, 2, 0, 1), + ("rfout_frequency", 8000000000, 12000000000, 100000000, 0, 1), + + ], +) +def test_adf5611_attrs( + test_attribute_single_value, + iio_uri, + classname, + attr, + start, + stop, + step, + tol, + repeats, +): + test_attribute_single_value( + iio_uri, classname, attr, start, stop, step, tol, repeats + ) + + +######################################### +@pytest.mark.iio_hardware(hardware) +@pytest.mark.parametrize("classname", [(classname)]) +@pytest.mark.parametrize( + "attr, value", + [("en_rfoutdiv", 0), ("en_rfoutdiv", 1)], +) +def test_adf5611_attrs_bool( + test_attribute_single_value_boolean, iio_uri, classname, attr, value, +): + test_attribute_single_value_boolean(iio_uri, classname, attr, value)