Skip to content

Commit

Permalink
ADF5611:test:Add test file for ADF5611
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Jude-Osems committed Jan 27, 2025
1 parent 4305730 commit 4c50d63
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 22 deletions.
22 changes: 12 additions & 10 deletions adi/adf5611.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2021-2024 Analog Devices, Inc.
# Copyright (C) 2021-2025 Analog Devices, Inc.
#
# SPDX short identifier: ADIBSD

Expand Down Expand Up @@ -33,7 +33,7 @@ class adf5611(attribute, context_manager):
"3.000000",
"3.200000",
)

_rfoutdiv_divider_options = (
"1",
"2",
Expand Down Expand Up @@ -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)
Expand All @@ -76,23 +78,23 @@ 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)

@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)

@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)
Expand All @@ -106,15 +108,15 @@ 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)

@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)
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions doc/source/devices/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Supported Devices
adi.adf4355
adi.adf4371
adi.adf5610
adi.adf5611
adi.adg2128
adi.adis16375
adi.adis16460
Expand Down
26 changes: 14 additions & 12 deletions examples/adf5611_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
48 changes: 48 additions & 0 deletions test/test_adf5611.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 4c50d63

Please sign in to comment.