From 8f41cc6499ca92a1581405dd0d5e312ebc22fc64 Mon Sep 17 00:00:00 2001 From: AndyOesmer Date: Wed, 20 Sep 2023 10:11:22 +0800 Subject: [PATCH 1/4] Added CN0556 Support --- adi/__init__.py | 1 + adi/cn0556.py | 598 +++++++++++++++++++++++++++++++++++++++++++++ supported_parts.md | 1 + 3 files changed, 600 insertions(+) create mode 100644 adi/cn0556.py diff --git a/adi/__init__.py b/adi/__init__.py index 57ead3e42..19612dce1 100644 --- a/adi/__init__.py +++ b/adi/__init__.py @@ -77,6 +77,7 @@ from adi.cn0511 import cn0511 from adi.cn0532 import cn0532 from adi.cn0554 import cn0554 +from adi.cn0556 import cn0556 from adi.cn0565 import cn0565 from adi.cn0566 import CN0566 from adi.cn0575 import cn0575 diff --git a/adi/cn0556.py b/adi/cn0556.py new file mode 100644 index 000000000..47d35d7b4 --- /dev/null +++ b/adi/cn0556.py @@ -0,0 +1,598 @@ +# Copyright (C) 2024 Analog Devices, Inc. +# +# SPDX short identifier: ADIBSD +import adi + + +class cn0556(adi.cn0554): + + """The CN0556 class inherits features from the CN0554 (providing full + control and monitoring of the input and output voltages and currents) + and the one_bit_adc_dac (sets the mode of the regulator to either Buck + or Boost and enables and disables the LT8228). These combined + functionalities are utilized for a Programmable High Current and + Voltage Source/Sink Power Supply. + + parameters: + uri: type=string + URI of the platform + """ + + _board_config = { + "buck_input_current_limit": { + "scale": -1.2174 / 1000.0, + "offset": 11.345, + "min": 0.07, + "max": 10.0, + "unit": "A" + # I1P = 11.345-1.1274*ISET1P_CTL + }, + "buck_output_current_limit": { + "scale": -4.0108 / 1000.0, + "offset": 39.623, + "min": 0.0, + "max": 35.0, + "unit": "A" + # I2P = 39.623-4.0108*ISET2P_CTL + }, + "buck_input_undervoltage": { + "scale": -5.1281 / 1000.0, + "offset": 60.415, + "min": 12.0, + "max": 54.0, + "unit": "V" + # VUV1 = 60.415-5.1281*UV1_CTL + }, + "buck_target_output_voltage": { + "scale": -1.4666 / 1000.0, + "offset": 15.685, + "min": 2.0, + "max": 14.0, + "unit": "V" + # V2D = 15.685-1.4666*FB2_CTL + }, + "boost_input_current_limit": { + "scale": -4.0108 / 1000.0, + "offset": 39.623, + "min": 0.0, + "max": 35.0, + "unit": "A" + # I2N = 39.623-4.0108*ISET2N_CTL + }, + "boost_output_current_limit": { + "scale": -1.1274 / 1000.0, + "offset": 11.345, + "min": 0.07, + "max": 10.0, + "unit": "A" + # I1N = 11.345-1.1274*ISET1N_CTL + }, + "boost_input_undervoltage": { + "scale": -1.2195 / 1000.0, + "offset": 13.386, + "min": 8.0, + "max": 12.0, + "unit": "V" + # VUV2 = 13.386-1.2195*UV2_CTL + }, + "boost_target_output_voltage": { + "scale": -4.859 / 1000.0, + "offset": 61.995, + "min": 14.0, + "max": 56.0, + "unit": "V" + # V2D = 61.995-4.859*FB1_CTL + }, + # Measurements + "buck_input_voltage": { + "scale": 243.0 / 1000.0, + "offset": 0.0, + # V1 = V1_ADC*(243k/10k) + }, + "buck_input_current": { + "scale": 4.0 / 100.0, + "offset": 0.0, + # IV1 = 4*VMON1 + }, + "buck_output_current": { + "scale": 14.0 / 100.0, + "offset": 0.0, + # IV2 = 14*VMON1 + }, + "buck_output_voltage": { + "scale": 51.0 / 1000.0, + "offset": 0.0, + # V2 = V2_ADC*(51k/10k) + }, + "boost_input_voltage": { + "scale": 51.0 / 1000.0, + "offset": 0.0, + # V2 = V2_ADC*(51k/10k) + }, + "boost_input_current": { + "scale": 14.0 / 100.0, + "offset": 0.0, + # IV2 = 14*VMON1 + }, + "boost_output_current": { + "scale": 4.0 / 100.0, + "offset": 0.0, + # IV1 = 4*VMON1 + }, + "boost_output_voltage": { + "scale": 243.0 / 1000.0, + "offset": 0.0, + # V1 = V1_ADC*(243k/10k) + }, + "intvcc_voltage": {"scale": 1 / 100.0, "offset": 0.0}, + "share_voltage": {"scale": 1 / 100.0, "offset": 0.0}, + } + + def __init__(self, uri="ip:analog.local"): + adi.cn0554.__init__(self, uri=uri) + self.gpio = adi.one_bit_adc_dac(uri=uri) + + # Enable ADC Channels for reading Voltage and Current Monitoring, INTVCC, SHARE + self.rx_enabled_channels = [0, 4, 8, 10, 12, 14] + self.adc_scale = self.adc.channel[0].scale + + @property + def drxn(self): + """drxn: operating mode of the board. Returns '1' if in Buck Mode and '0' if in Boost Mode""" + return self.gpio.gpio_drxn + + @drxn.setter + def drxn(self, value): + """drxn: Buck or Boost Mode Setter. Options are: 1 (Buck Mode), 0 (Boost Mode).""" + if value != 1 and value != 0: + raise Exception( + "Invalid Input. Valid values are '1' for Buck Mode and '0' for Boost Mode" + ) + + self.gpio.gpio_drxn = value + + @property + def enable(self): + """enable the LT8228 device when True. + When set to false, device is disabled, DAC outputs set to 0, and sets the DRXN to boost mode.""" + return self.gpio.gpio_en + + @enable.setter + def enable(self, value): + if value: + self.gpio.gpio_en = 1 + else: + self.dac.voltage0.volt = 0 + self.dac.voltage2.volt = 0 + self.dac.voltage4.volt = 0 + self.dac.voltage6.volt = 0 + self.dac.voltage8.volt = 0 + self.dac.voltage10.volt = 0 + self.dac.voltage12.volt = 0 + self.dac.voltage14.volt = 0 + self.gpio.gpio_en = 0 + self.drxn = 0 + + @property + def intvcc_voltage(self): + """Return voltage at INTVCC pin in volts (V)""" + return self.read_value( + self.adc.channel[10], + "raw", + self._board_config["intvcc_voltage"]["scale"] * self.adc_scale, + self._board_config["intvcc_voltage"]["offset"], + ) + + @property + def share_voltage(self): + """Return voltage at SHARE pin in volts (V)""" + return self.read_value( + self.adc.channel[12], + "raw", + self._board_config["share_voltage"]["scale"] * self.adc_scale, + self._board_config["share_voltage"]["offset"], + ) + + @property + def report(self): + """Check if REPORT is triggered. Returns True if REPORT pin is HIGH.""" + return self.gpio.gpio_report + + @property + def fault(self): + """fault: checks if a fault is present. Returns True if a fault occurred.""" + return self.gpio.gpio_fault + + @property + def buck_output_voltage(self): + """Read buck output voltage at V2 terminals. Convert ADC data using scale and offset factors based on resistor divider network.""" + return self.read_value( + self.adc.channel[4], + "raw", + self._board_config["buck_output_voltage"]["scale"] * self.adc_scale, + self._board_config["buck_output_voltage"]["offset"], + ) + + @property + def buck_target_output_voltage(self): + """ + Compute for the target buck output voltage set at V2 side + using DAC data and scale and offset factors based on resistor divider network at FB2 node. + + returns buck target output voltage and DAC output voltage in volts (V) + return type: (float, float) + + """ + return ( + self.read_value( + self.dac.voltage2, + "volt", + self._board_config["buck_target_output_voltage"]["scale"], + self._board_config["buck_target_output_voltage"]["offset"], + ), + self.dac.voltage2.volt / 1000, + ) + + @buck_target_output_voltage.setter + def buck_target_output_voltage(self, value): + """Set buck output voltage at V2 side. Valid values are 2 to 14.""" + try: + self.set_value( + value, + self.dac.voltage2, + "volt", + self._board_config["buck_target_output_voltage"]["scale"], + self._board_config["buck_target_output_voltage"]["offset"], + self._board_config["buck_target_output_voltage"]["min"], + self._board_config["buck_target_output_voltage"]["max"], + self._board_config["buck_target_output_voltage"]["unit"], + ) + except Exception as e: + raise e + + @property + def buck_input_voltage(self): + """Read buck input voltage at V1 terminals. Convert ADC data using scale and offset factors based on a resistor divider network.""" + return self.read_value( + self.adc.channel[14], + "raw", + self._board_config["buck_input_voltage"]["scale"] * self.adc_scale, + self._board_config["buck_input_voltage"]["offset"], + ) + + @property + def buck_output_current(self): + """Read buck output current at V2 terminals. Convert ADC data using scale and offset factors based on resistor divider at IMON2 node.""" + return self.read_value( + self.adc.channel[8], + "raw", + self._board_config["buck_output_current"]["scale"] * self.adc_scale, + self._board_config["buck_output_current"]["offset"], + ) + + @property + def buck_input_current(self): + """Read buck input current at V1 terminals. Convert ADC data using scale and offset factors based on resistor divider at IMON1 node.""" + return self.read_value( + self.adc.channel[0], + "raw", + self._board_config["buck_input_current"]["scale"] * self.adc_scale, + self._board_config["buck_input_current"]["offset"], + ) + + @property + def buck_input_undervoltage(self): + """ + Compute for the buck input undervoltage set at V1 side + using DAC data and scale and offset factors based on resistor divider network at UV1 node. + + returns buck input undervoltage and DAC output voltage in volts (V) + return type: (float, float) + + """ + + return ( + self.read_value( + self.dac.voltage4, + "volt", + self._board_config["buck_input_undervoltage"]["scale"], + self._board_config["buck_input_undervoltage"]["offset"], + ), + self.dac.voltage4.volt / 1000, + ) + + @buck_input_undervoltage.setter + def buck_input_undervoltage(self, value): + """Set buck input undervoltage V1 side. Valid values are 12 to 54.""" + try: + self.set_value( + value, + self.dac.voltage4, + "volt", + self._board_config["buck_input_undervoltage"]["scale"], + self._board_config["buck_input_undervoltage"]["offset"], + self._board_config["buck_input_undervoltage"]["min"], + self._board_config["buck_input_undervoltage"]["max"], + self._board_config["buck_input_undervoltage"]["unit"], + ) + except Exception as e: + raise e + + @property + def buck_input_current_limit(self): + """ + Compute for the target buck input current limit set + using DAC data and scale and offset factors based on resistor divider network at ISET1P node. + + returns buck target input current limit and DAC output voltage in volts (V) + return type: (float, float) + + """ + return ( + self.read_value( + self.dac.voltage8, + "volt", + self._board_config["buck_input_current_limit"]["scale"], + self._board_config["buck_input_current_limit"]["offset"], + ), + self.dac.voltage8.volt / 1000, + ) + + @buck_input_current_limit.setter + def buck_input_current_limit(self, value): + """Set buck input current limit V1 side. Valid values are 0.07 to 10.""" + try: + self.set_value( + value, + self.dac.voltage8, + "volt", + self._board_config["buck_input_current_limit"]["scale"], + self._board_config["buck_input_current_limit"]["offset"], + self._board_config["buck_input_current_limit"]["min"], + self._board_config["buck_input_current_limit"]["max"], + self._board_config["buck_input_current_limit"]["unit"], + ) + except Exception as e: + raise e + + @property + def buck_output_current_limit(self): + """ + Compute for the target buck output current limit set + using DAC data and scale and offset factors based on resistor divider network at ISET2P node. + + returns buck target output current limit and DAC output voltage in volts (V) + return type: (float, float) + + """ + return ( + self.read_value( + self.dac.voltage12, + "volt", + self._board_config["buck_output_current_limit"]["scale"], + self._board_config["buck_output_current_limit"]["offset"], + ), + self.dac.voltage12.volt / 1000, + ) + + @buck_output_current_limit.setter + def buck_output_current_limit(self, value): + """Set buck output current limit V2 side. Valid values are 0 to 35.""" + try: + self.set_value( + value, + self.dac.voltage12, + "volt", + self._board_config["buck_output_current_limit"]["scale"], + self._board_config["buck_output_current_limit"]["offset"], + self._board_config["buck_output_current_limit"]["min"], + self._board_config["buck_output_current_limit"]["max"], + self._board_config["buck_output_current_limit"]["unit"], + ) + except Exception as e: + raise e + + @property + def boost_output_voltage(self): + """Read boost output voltage at V1 terminals. Convert ADC data using scale and offset factors based on resistor divider network.""" + return self.read_value( + self.adc.channel[14], + "raw", + self._board_config["boost_output_voltage"]["scale"] * self.adc_scale, + self._board_config["boost_output_voltage"]["offset"], + ) + + @property + def boost_target_output_voltage(self): + """ + Compute for the target boost output voltage set at V1 side + using DAC data and scale and offset factors based on resistor divider network at FB1 node. + + returns boost target output voltage and DAC output voltage in volts (V) + return type: (float, float) + + """ + return ( + self.read_value( + self.dac.voltage0, + "volt", + self._board_config["boost_target_output_voltage"]["scale"], + self._board_config["boost_target_output_voltage"]["offset"], + ), + self.dac.voltage0.volt / 1000, + ) + + @boost_target_output_voltage.setter + def boost_target_output_voltage(self, value): + """Set boost output voltage at V1 side. Valid values are 14 to 56.""" + try: + self.set_value( + value, + self.dac.voltage0, + "volt", + self._board_config["boost_target_output_voltage"]["scale"], + self._board_config["boost_target_output_voltage"]["offset"], + self._board_config["boost_target_output_voltage"]["min"], + self._board_config["boost_target_output_voltage"]["max"], + self._board_config["boost_target_output_voltage"]["unit"], + ) + except Exception as e: + raise e + + @property + def boost_input_voltage(self): + """Read boost input voltage at V2 terminals. Convert ADC data using scale and offset factors based on resistor divider network.""" + return self.read_value( + self.adc.channel[4], + "raw", + self._board_config["boost_input_voltage"]["scale"] * self.adc_scale, + self._board_config["boost_input_voltage"]["offset"], + ) + + @property + def boost_output_current(self): + """Read boost output current at V1 terminals. Convert ADC data using scale and offset factors based on resistor divider at IMON1 node.""" + return self.read_value( + self.adc.channel[0], + "raw", + self._board_config["boost_output_current"]["scale"] * self.adc_scale, + self._board_config["boost_output_current"]["offset"], + ) + + @property + def boost_input_current(self): + """Read boost input current at V2 terminals. Convert ADC data using scale and offset factors based on resistor divider at IMON2 node.""" + return self.read_value( + self.adc.channel[8], + "raw", + self._board_config["boost_input_current"]["scale"] * self.adc_scale, + self._board_config["boost_input_current"]["offset"], + ) + + @property + def boost_input_undervoltage(self): + """ + Compute for the boost input undervoltage set at V2 side + using DAC data and scale and offset factors based on resistor divider network at UV2 node. + + returns boost input undervoltage and DAC output voltage in volts (V) + return type: (float, float) + + """ + return ( + self.read_value( + self.dac.voltage6, + "volt", + self._board_config["boost_input_undervoltage"]["scale"], + self._board_config["boost_input_undervoltage"]["offset"], + ), + self.dac.voltage6.volt / 1000, + ) + + @boost_input_undervoltage.setter + def boost_input_undervoltage(self, value): + """Set boost input undervoltage V2 side. Valid values are 8 to 12.""" + try: + self.set_value( + value, + self.dac.voltage6, + "volt", + self._board_config["boost_input_undervoltage"]["scale"], + self._board_config["boost_input_undervoltage"]["offset"], + self._board_config["boost_input_undervoltage"]["min"], + self._board_config["boost_input_undervoltage"]["max"], + self._board_config["boost_input_undervoltage"]["unit"], + ) + except Exception as e: + raise e + + @property + def boost_input_current_limit(self): + """ + Compute for the target boost input current limit set + using DAC data and scale and offset factors based on resistor divider network at ISET2N node. + + returns boost target input current limit and DAC output voltage in volts (V) + return type: (float, float) + + """ + return ( + self.read_value( + self.dac.voltage14, + "volt", + self._board_config["boost_input_current_limit"]["scale"], + self._board_config["boost_input_current_limit"]["offset"], + ), + self.dac.voltage14.volt / 1000, + ) + + @boost_input_current_limit.setter + def boost_input_current_limit(self, value): + """Set boost input current limit V2 side. Valid values are 0 to 35.""" + try: + self.set_value( + value, + self.dac.voltage14, + "volt", + self._board_config["boost_input_current_limit"]["scale"], + self._board_config["boost_input_current_limit"]["offset"], + self._board_config["boost_input_current_limit"]["min"], + self._board_config["boost_input_current_limit"]["max"], + self._board_config["boost_input_current_limit"]["unit"], + ) + except Exception as e: + raise e + + @property + def boost_output_current_limit(self): + """ + Compute for the target boost output current limit set + using DAC data and scale and offset factors based on resistor divider network at ISET1N node. + + returns boost target output current limit and DAC output voltage in volts (V) + return type: (float, float) + + """ + return ( + self.read_value( + self.dac.voltage10, + "volt", + self._board_config["boost_output_current_limit"]["scale"], + self._board_config["boost_output_current_limit"]["offset"], + ), + self.dac.voltage10.volt / 1000, + ) + + @boost_output_current_limit.setter + def boost_output_current_limit(self, value): + """Set boost output current limit V1 side. Valid values are 0.07 to 10.""" + try: + self.set_value( + value, + self.dac.voltage10, + "volt", + self._board_config["boost_output_current_limit"]["scale"], + self._board_config["boost_output_current_limit"]["offset"], + self._board_config["boost_output_current_limit"]["min"], + self._board_config["boost_output_current_limit"]["max"], + self._board_config["boost_output_current_limit"]["unit"], + ) + except Exception as e: + raise e + + def read_value(self, ctrl, ctrl_name, scale, offset): + """Convert ADC data using the scale factor and offset based on simplified formulas derived and scaling + factors derived using the resistor divider networks at the feedback nodes.""" + return (getattr(ctrl, ctrl_name) * scale) + offset + + def set_value(self, value, ctrl, ctrl_name, scale, offset, val_min, val_max, unit): + """Convert user input value to equivalent DAC output voltage to control the output voltage and current limits + using the scale factor and offset based on simplified formulas derived using the resistor + divider networks at the feedback nodes.""" + if value < val_min or value > val_max: + raise Exception( + "Invalid value. Valid values for this property: {} to {} {}".format( + val_min, val_max, unit + ) + ) + setattr(ctrl, ctrl_name, (value - offset) / scale) diff --git a/supported_parts.md b/supported_parts.md index 0674ae8c1..c7f95fff5 100644 --- a/supported_parts.md +++ b/supported_parts.md @@ -140,6 +140,7 @@ - CN0532 - CN0540 - CN0554 +- CN0556 - CN0549 - CN0565 - CN0566 From b21b3c4d85f08b4fd3dd8068f5e8dc9a9465f49b Mon Sep 17 00:00:00 2001 From: AndyOesmer Date: Mon, 18 Dec 2023 18:03:55 +0800 Subject: [PATCH 2/4] Add documentation for cn0556 --- doc/source/devices/adi.cn0556.rst | 7 +++++++ doc/source/devices/index.rst | 1 + 2 files changed, 8 insertions(+) create mode 100644 doc/source/devices/adi.cn0556.rst diff --git a/doc/source/devices/adi.cn0556.rst b/doc/source/devices/adi.cn0556.rst new file mode 100644 index 000000000..5cc79d989 --- /dev/null +++ b/doc/source/devices/adi.cn0556.rst @@ -0,0 +1,7 @@ +cn0556 +================= + +.. automodule:: adi.cn0556 + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/source/devices/index.rst b/doc/source/devices/index.rst index 94d211097..e2a1c4fad 100644 --- a/doc/source/devices/index.rst +++ b/doc/source/devices/index.rst @@ -86,6 +86,7 @@ Supported Devices adi.cn0532 adi.cn0540 adi.cn0554 + adi.cn0556 adi.cn0565 adi.cn0566 adi.cn0575 From 73946c99e9d68680aed8cf85ebfad2ad0ce64b22 Mon Sep 17 00:00:00 2001 From: AndyOesmer Date: Wed, 20 Sep 2023 10:32:33 +0800 Subject: [PATCH 3/4] Added CN0556 pyadi-iio examples --- examples/cn0556/README.md | 16 ++ examples/cn0556/cn0556_example_boost.py | 109 ++++++++++++++ examples/cn0556/cn0556_example_buck.py | 125 ++++++++++++++++ examples/cn0556/cn0556_prod_tst_boost.py | 162 +++++++++++++++++++++ examples/cn0556/cn0556_prod_tst_buck.py | 177 +++++++++++++++++++++++ 5 files changed, 589 insertions(+) create mode 100644 examples/cn0556/README.md create mode 100644 examples/cn0556/cn0556_example_boost.py create mode 100644 examples/cn0556/cn0556_example_buck.py create mode 100644 examples/cn0556/cn0556_prod_tst_boost.py create mode 100644 examples/cn0556/cn0556_prod_tst_buck.py diff --git a/examples/cn0556/README.md b/examples/cn0556/README.md new file mode 100644 index 000000000..77e78258d --- /dev/null +++ b/examples/cn0556/README.md @@ -0,0 +1,16 @@ +# CN0556 + +## Run Example Scripts: +### Run CN0556 board in Buck Mode +This will perform an example of setting the CN0556 board in Buck Mode. +``` +python cn0556_example_buck.py +``` +By default, this script will produce a regulated voltage output of 14V at the V2 right side, when a voltage input of 54V-56V is connected to the V1 Buck Input side. + +### Run CN0556 board in Boost Mode +This will perform an example of setting the CN0556 board in Boost Mode. +``` +python cn0556_example_boost.py +``` +By default, this script will produce a regulated voltage output of 56V at the V1 left side, when a voltage input of 12V-14V is connected to the V2 Boost Input side. diff --git a/examples/cn0556/cn0556_example_boost.py b/examples/cn0556/cn0556_example_boost.py new file mode 100644 index 000000000..4730c3bc8 --- /dev/null +++ b/examples/cn0556/cn0556_example_boost.py @@ -0,0 +1,109 @@ +import sys +import time + +import adi + +# Optionally pass URI as command line argument, +# else use default context manager search +my_uri = sys.argv[1] if len(sys.argv) >= 2 else "ip:analog.local" +print("uri: " + str(my_uri)) + +my_cn0556 = adi.cn0556(uri=my_uri) + + +my_cn0556.drxn = 0 # Set to Boost Mode = 0 +drxn_status = my_cn0556.drxn +if drxn_status == 1: + print("Buck Mode") +elif drxn_status == 0: + print("Boost Mode") +else: + print("Unknown Mode") + +# Boost Mode Example: +UV2 = 12.0 +V1_Out = 56.0 +In_Current_Lim = 35.0 +Out_Current_Lim = 10.0 + +# Set Control Voltages from DAC: +my_cn0556.boost_input_undervoltage = UV2 +# my_cn0556.boost_input_undervoltage[0] - Gets the set Boost Input Undervoltage by the user +# my_cn0556.boost_input_undervoltage[1] - Gets the equivalent DAC Output Voltage to set the Boost Input Undervoltage +print( + "Boost Input Undervoltage set to: " + + str(my_cn0556.boost_input_undervoltage[0]) + + "V || UV2_CTL DAC Volt: " + + str(my_cn0556.boost_input_undervoltage[1]) +) + +my_cn0556.boost_target_output_voltage = V1_Out +# my_cn0556.boost_target_output_voltage[0] - Gets the set Boost Output Voltage by the user +# my_cn0556.boost_target_output_voltage[1] - Gets the equivalent DAC Output Voltage to set the Boost Output Voltage +print( + "Boost Output set to: " + + str(my_cn0556.boost_target_output_voltage[0]) + + "V || FB1_CTL DAC Volt: " + + str(my_cn0556.boost_target_output_voltage[1]) +) + +my_cn0556.boost_input_current_limit = In_Current_Lim +# my_cn0556.boost_input_current_limit[0] - Gets the set Boost Input Current Limit by the user +# my_cn0556.boost_input_current_limit[1] - Gets the equivalent DAC Output Voltage to set the Boost Input Current Limit +print( + "Boost Input Current Limit set to: " + + str(my_cn0556.boost_input_current_limit[0]) + + "V || ISET2N_CTL DAC Volt: " + + str(my_cn0556.boost_input_current_limit[1]) +) + +my_cn0556.boost_output_current_limit = Out_Current_Lim +# my_cn0556.boost_output_current_limit[0] - Gets the set Boost Output Current Limit by the user +# my_cn0556.boost_output_current_limit[1] - Gets the equivalent DAC Output Voltage to set the Boost Output Current Limit +print( + "Boost Output Current Limit set to: " + + str(my_cn0556.boost_output_current_limit[0]) + + "V || ISET1N_CTL DAC Volt: " + + str(my_cn0556.boost_output_current_limit[1]) +) + +print("\n...................................................") +print("Enable DC Voltage Source to V2 Boost In Terminals...") +print("...................................................") + +while True: + user_input = input( + "\nPress ENTER to ENABLE CN0556. To exit the program, input any key and then PRESS ENTER. " + ) + if user_input == "": + # Enable CN0556: + my_cn0556.enable = True + + time.sleep(1) + + print("ADC Readings: ") + print("Input Voltage: " + str(my_cn0556.boost_input_voltage) + "V") + print("Input Current: " + str(my_cn0556.boost_input_current) + "A") + print("Output Voltage: " + str(my_cn0556.boost_output_voltage) + "V") + print("Output Current: " + str(my_cn0556.boost_output_current) + "A") + + while True: + user_input = input( + "\nDo you want to continue? Enter 'N' to turn off CN0556. Enter 'Y' to leave the supply enabled. " + ) + if user_input == "Y": + break + elif user_input == "N": + # Disable CN0556: + my_cn0556.enable = False + print("=== End of Boost Mode Example ===") + break + else: + my_cn0556.enable = False + raise Exception("Enter the correct input.") + + else: + my_cn0556.enable = False + print("=== End of Boost Mode Example ===") + break + break diff --git a/examples/cn0556/cn0556_example_buck.py b/examples/cn0556/cn0556_example_buck.py new file mode 100644 index 000000000..05e04e0d4 --- /dev/null +++ b/examples/cn0556/cn0556_example_buck.py @@ -0,0 +1,125 @@ +import sys +import time + +import adi + +# Optionally pass URI as command line argument, +# else use default context manager search +my_uri = sys.argv[1] if len(sys.argv) >= 2 else "ip:analog.local" +print("uri: " + str(my_uri)) + +my_cn0556 = adi.cn0556(uri=my_uri) + +my_cn0556.drxn = 1 # Set to Buck Mode = 1 +drxn_status = my_cn0556.drxn +if drxn_status == 1: + print("Buck Mode") +elif drxn_status == 0: + print("Boost Mode") +else: + print("Unknown Mode") + +# Buck Mode Example: + +UV1 = 54.0 +V2_Out = 14.0 +In_Current_Lim = 10.0 +Out_Current_Lim = 35.0 + +# Set Control Voltages from DAC: + +my_cn0556.buck_input_undervoltage = UV1 +# my_cn0556.buck_input_undervoltage[0] - Gets the set Buck Input Undervoltage by the user +# my_cn0556.buck_input_undervoltage[1] - Gets the equivalent DAC Output Voltage to set the Buck Input Undervoltage + +print( + "Buck Input Undervoltage set to: " + + str(my_cn0556.buck_input_undervoltage[0]) + + "V || UV1_CTL DAC Volt: " + + str(my_cn0556.buck_input_undervoltage[1]) +) + +my_cn0556.buck_target_output_voltage = V2_Out +# my_cn0556.buck_target_output_voltage[0] - Gets the set Buck Output Voltage by the user +# my_cn0556.buck_target_output_voltage[1] - Gets the equivalent DAC Output Voltage to set the Buck Output Voltage + +print( + "Buck Output set to: " + + str(my_cn0556.buck_target_output_voltage[0]) + + "V || FB2_CTL DAC Volt: " + + str(my_cn0556.buck_target_output_voltage[1]) +) + +my_cn0556.buck_input_current_limit = In_Current_Lim +# my_cn0556.buck_input_current_limit[0] - Gets the set Buck Input Current Limit by the user +# my_cn0556.buck_input_current_limit[1] - Gets the equivalent DAC Output Voltage to set the Buck Input Current Limit + +print( + "Buck Input Current Limit set to: " + + str(my_cn0556.buck_input_current_limit[0]) + + "V || ISET1P_CTL DAC Volt: " + + str(my_cn0556.buck_input_current_limit[1]) +) + +my_cn0556.buck_output_current_limit = Out_Current_Lim +# my_cn0556.buck_output_current_limit[0] - Gets the set Buck Output Current Limit by the user +# my_cn0556.buck_output_current_limit[1] - Gets the equivalent DAC Output Voltage to set the Buck Output Current Limit + +print( + "Buck Output Current Limit set to: " + + str(my_cn0556.buck_output_current_limit[0]) + + "V || ISET2P_CTL DAC Volt: " + + str(my_cn0556.buck_output_current_limit[1]) +) + +print("\n..........................................................") +print( + "Input Rating: Buck Input Undervoltage is set to " + + str(UV1) + + "V , " + + str(In_Current_Lim) + + "A" +) +print("Maximum Output Rating: " + str(V2_Out) + "V , " + str(Out_Current_Lim) + "A") +print("..........................................................") + +print("\n...................................................") +print("Enable DC Voltage Source to V1 Buck In Terminals...") +print("...................................................") + +while True: + user_input = input( + "\nPress ENTER to ENABLE CN0556. To exit the program, input any key and then PRESS ENTER. " + ) + if user_input == "": + # Enable CN0556: + my_cn0556.enable = True + + time.sleep(1) + + print("ADC Readings: ") + print("Input Voltage: " + str(my_cn0556.buck_input_voltage) + "V") + print("Input Current: " + str(my_cn0556.buck_input_current) + "A") + print("Output Voltage: " + str(my_cn0556.buck_output_voltage) + "V") + print("Output Current: " + str(my_cn0556.buck_output_current) + "A") + + while True: + user_input = input( + "\nDo you want to continue? Enter 'N' to turn off CN0556. Enter 'Y' to leave the supply enabled. " + ) + if user_input == "Y": + break + elif user_input == "N": + # Disable CN0556: + my_cn0556.enable = False + print("=== End of Buck Mode Example ===") + break + else: + my_cn0556.enable = False + raise Exception("Enter the correct input.") + + else: + my_cn0556.enable = False + print("=== End of Buck Mode Example ===") + break + break diff --git a/examples/cn0556/cn0556_prod_tst_boost.py b/examples/cn0556/cn0556_prod_tst_boost.py new file mode 100644 index 000000000..f30895ecb --- /dev/null +++ b/examples/cn0556/cn0556_prod_tst_boost.py @@ -0,0 +1,162 @@ +import sys +import time + +import adi +import numpy as np + +print("-----------------------------------------------------------------------") +print("| EVAL-CN0556-EBZ: Programmable High Current Source/Sink Power Supply |") +print("-----------------------------------------------------------------------") +print("\n") +print("General Reminders:") +print(" - This test will run the board in Boost Mode.") +print( + " - Double check that the connections of the power supply and the electronic load are for the Boost Mode Operation." +) +print( + " - Make sure that the power supply and the electronic load are turned off and or disabled at the start of this test program." +) +print( + "!! Warning: The following steps involve high DC voltages. \nFollow instructions carefully to prevent hot plugging which may damage the device by an overvoltage transient." +) +print(" - Double check the connections again!") + +print("\n") +print("Connecting to evaluation board...") +my_cn0556 = adi.cn0556(uri="ip:analog.local") +time.sleep(1) + +print("Starting Buck Mode Test...") + +# Boost Mode Default Values: +V2_In = 14 +UV2 = 12 + +V1_Out = 56 + +In_Current_Lim = 35 +Out_Current_Lim = 10 + +print("\n") +my_cn0556.gpio.gpio_drxn = 0 # Set to Boost Mode = 0 +print("Enable ON!") +print("Boost Mode ON!") +my_cn0556.gpio.gpio_en = 1 +print("\n") + +while True: + user_input = input( + "Test # 1: Default Configuration of CN0556. Press enter to continue." + ) + if user_input == "": + # Set Control Voltages from DAC: + my_cn0556.set_boost_input_volt(14) + my_cn0556.set_boost_input_undervolt(12) + + my_cn0556.set_boost_output_volt(56) + + my_cn0556.set_boost_input_current_lim(35) + my_cn0556.set_boost_output_current_lim(10) + break + else: + raise Exception("Press ENTER key.") + + +time.sleep(1) + +print("Maximum Input Rating: " + str(V2_In) + "V , " + str(In_Current_Lim) + "A") +print("Maximum Output Rating: " + str(V1_Out) + "V , " + str(Out_Current_Lim) + "A") + +print("\n") + +print("......................................................") +print("Turn ON DC Voltage Source to V2 Boost Input Terminals...") +print("......................................................") +time.sleep(2) + +while True: + user_input = input("Press ENTER if voltage source is turned on.") + + if user_input == "": + # Set Control Voltages from DAC: + my_cn0556.set_boost_input_volt(14) + my_cn0556.set_boost_input_undervolt(12) + + my_cn0556.set_boost_output_volt(56) + + my_cn0556.set_boost_input_current_lim(35) + my_cn0556.set_boost_output_current_lim(10) + break + +print("The output voltage must still be from 54-57V.") +print("Take note: PASS or FAIL") +print("......................................................") +print("\n") +print("\n") + +print("......................................................") +print("Test # 2: The output voltage will be set to 40V.") +print("\n") + +while True: + user_input = input( + "Press ENTER to set the output voltage to 40V. Do not turn off power source.\n" + ) + + if user_input == "": + print("The output voltage is set to 40V.\n") + my_cn0556.set_boost_output_volt(40) + break + + +print("The output voltage must still be from 54-57V.") +print("Take note: PASS or FAIL") +print("......................................................") +print("\n") +print("\n") + +print("......................................................") +print("Test # 3: The output current limit will be set to 2A.") + +while True: + user_input = input( + "Press ENTER to set the output current limit to 2A. Do not turn off power source." + ) + + if user_input == "": + my_cn0556.set_boost_output_current_lim(2) + break + + +print("------") +print("Instruction: Slowly increase the electronic load to 2A.") +print("The output voltage must drop upon nearing the 2A limit.") +print("Take note: PASS or FAIL") +print("\n") +print("......................................................") + +while True: + user_input = input("Press ENTER to end the test.") + + if user_input == "": + break + +print("\n") +print("Test Done!") + +print("Turning off the device.") + +my_cn0556.dac.voltage0.volt = 0 +my_cn0556.dac.voltage2.volt = 0 +my_cn0556.dac.voltage4.volt = 0 +my_cn0556.dac.voltage6.volt = 0 +my_cn0556.dac.voltage8.volt = 0 +my_cn0556.dac.voltage10.volt = 0 +my_cn0556.dac.voltage12.volt = 0 +my_cn0556.dac.voltage14.volt = 0 + +my_cn0556.gpio.gpio_en = 0 +my_cn0556.gpio.gpio_drxn = 0 + +print("OFF!\n\n") +print("Turn off power supply and electronic load!") diff --git a/examples/cn0556/cn0556_prod_tst_buck.py b/examples/cn0556/cn0556_prod_tst_buck.py new file mode 100644 index 000000000..f2b7863d7 --- /dev/null +++ b/examples/cn0556/cn0556_prod_tst_buck.py @@ -0,0 +1,177 @@ +import sys +import time + +import adi +import numpy as np + +print("-----------------------------------------------------------------------") +print("| EVAL-CN0556-EBZ: Programmable High Current Source/Sink Power Supply |") +print("-----------------------------------------------------------------------") +print("\n") +print("General Reminders:") +print(" - This test will run the board in Buck Mode.") +print( + " - Double check that the connections of the power supply and the electronic load are for the Buck Mode Operation." +) +print( + " - Make sure that the power supply and the electronic load are turned off and or disabled at the start of this test program." +) +print( + "!! Warning: The following steps involve high DC voltages. \nFollow instructions carefully to prevent hot plugging which may damage the device by an overvoltage transient." +) +print(" - Double check the connections again!") + +print("\n") +print("Connecting to evaluation board...") +my_cn0556 = adi.cn0556(uri="ip:analog.local") +time.sleep(1) + +print("Starting Buck Mode Test...") + +# Buck Mode Default Values: +V1_In = 56 +UV1 = 54 + +V2_Out = 14 + +In_Current_Lim = 10 +Out_Current_Lim = 35 + +print("\n") +my_cn0556.gpio.gpio_drxn = 1 # Set to Buck Mode = 1 +print("Enable ON!") +print("Buck Mode ON!") +my_cn0556.gpio.gpio_en = 1 +print("\n") + +while True: + user_input = input("Default Configuration of CN0556. Press enter to continue.") + if user_input == "": + # Set Control Voltages from DAC: + my_cn0556.set_buck_input_volt(V1_In) + my_cn0556.set_buck_input_undervolt(UV1) + + my_cn0556.set_buck_output_volt(V2_Out) + + my_cn0556.set_buck_input_current_lim(In_Current_Lim) + my_cn0556.set_buck_output_current_lim(Out_Current_Lim) + break + else: + raise Exception("Press ENTER key.") + + +time.sleep(1) + +print("Maximum Input Rating: " + str(V1_In) + "V , " + str(In_Current_Lim) + "A") +print("Maximum Output Rating: " + str(V2_Out) + "V , " + str(Out_Current_Lim) + "A") + +print("\n") + +print("......................................................") +print("Turn ON DC Voltage Source to V1 Buck Input Terminals...") +print("......................................................") +time.sleep(2) + +while True: + user_input = input("Press ENTER if voltage source is turned on.") + + if user_input == "": + my_cn0556.set_buck_input_volt(56) + my_cn0556.set_buck_input_undervolt(54) + + my_cn0556.set_buck_output_volt(14) + + my_cn0556.set_buck_input_current_lim(10) + my_cn0556.set_buck_output_current_lim(35) + break + +print("\n") +print("\n") + +print("......................................................") +print("Test # 1: The input undervoltage will be set to 40V.") +print("\n") + +while True: + user_input = input( + "Press ENTER to set the undervoltage to 40V. Do not turn off power source.\n" + ) + + if user_input == "": + print("The input undervoltage is set to 40V.\n") + my_cn0556.set_buck_input_undervolt(40) + break + +print("------") +print("Instruction: Slowly decrease the DC power supply to 40V.\n") +time.sleep(2) +print("The output voltage must still be from 13-15V.") +print("Take note: PASS or FAIL") +print("......................................................") +print("\n") +print("\n") + +print("......................................................") +print("Test # 2: The output voltage will be set to 10V.") + +while True: + user_input = input( + "Press ENTER to set the output voltage to 10V. Do not turn off power source." + ) + + if user_input == "": + my_cn0556.set_buck_output_volt(10) + break + +print("The measured output voltage must be 10V.") +print("Take note: PASS or FAIL") +print("......................................................") +print("\n") + + +print("......................................................") +print("Test # 3: The output load current will be set to 2A limit") +print("The output voltage must drop when reaching the limit") +print("\n") + +while True: + user_input = input( + "Press ENTER to set the output current limit to 2A. Do not turn off power source." + ) + + if user_input == "": + my_cn0556.set_buck_output_current_lim(2) + break + +print("------") +print("Instruction: Slowly increase the electronic load to 2A.") +print("The output voltage must drop upon nearing the 2A limit.") +print("Take note: PASS or FAIL") +print("\n") +print("......................................................") + +while True: + user_input = input("Press ENTER to end the test.") + + if user_input == "": + break + +print("\n") +print("Test Done!") + +print("Turning off the device.") + +my_cn0556.dac.voltage0.volt = 0 +my_cn0556.dac.voltage2.volt = 0 +my_cn0556.dac.voltage4.volt = 0 +my_cn0556.dac.voltage6.volt = 0 +my_cn0556.dac.voltage8.volt = 0 +my_cn0556.dac.voltage10.volt = 0 +my_cn0556.dac.voltage12.volt = 0 +my_cn0556.dac.voltage14.volt = 0 + +my_cn0556.gpio.gpio_en = 0 +my_cn0556.gpio.gpio_drxn = 0 + +print("OFF!\n\n") +print("Turn off power supply and electronic load!") From 9fe589c83acae043ebd00eba34e0037310c7eab2 Mon Sep 17 00:00:00 2001 From: AndyOesmer Date: Wed, 20 Dec 2023 11:32:29 +0800 Subject: [PATCH 4/4] Added test for CN0556 --- test/emu/devices/cn0556.xml | 1 + test/emu/hardware_map.yml | 13 +++++++++++- test/test_cn0556.py | 41 +++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 test/emu/devices/cn0556.xml create mode 100644 test/test_cn0556.py diff --git a/test/emu/devices/cn0556.xml b/test/emu/devices/cn0556.xml new file mode 100644 index 000000000..9b6fb8bda --- /dev/null +++ b/test/emu/devices/cn0556.xml @@ -0,0 +1 @@ +]> \ No newline at end of file diff --git a/test/emu/hardware_map.yml b/test/emu/hardware_map.yml index df43cdcc3..97a908444 100644 --- a/test/emu/hardware_map.yml +++ b/test/emu/hardware_map.yml @@ -176,7 +176,18 @@ cn0554: - data_devices: - iio:device0 - iio:device1 - +cn0556: + - ad7124-8 + - ltc2688 + - one-bit-adc-dac + - pyadi_iio_class_support: + - cn0556 + - emulate: + - filename: cn0556.xml + - data_devices: + - iio:device0 + - iio:device1 + - iio:device2 cn0565: - ad5940 - adg2128 diff --git a/test/test_cn0556.py b/test/test_cn0556.py new file mode 100644 index 000000000..037240a43 --- /dev/null +++ b/test/test_cn0556.py @@ -0,0 +1,41 @@ +import adi +import pytest + +hardware = "cn0556" +classname = "adi.cn0556" + + +######################################### +@pytest.mark.iio_hardware(hardware, True) +@pytest.mark.parametrize("classname", [(classname)]) +@pytest.mark.parametrize( + "attr, start, stop, step, tol", + [ + ("drxn", 0, 1, 1, 1), + ("enable", 0, 1, 1, 1), + ("buck_target_output_voltage", 2, 14, 1, 1), + ("buck_input_undervoltage", 12, 54, 1, 1), + ("buck_input_current_limit", 0.07, 10, 1, 0.01), + ("buck_output_current_limit", 0, 35, 1, 0.01), + ("boost_target_output_voltage", 14, 56, 1, 1), + ("boost_input_undervoltage", 12, 54, 1, 1), + ("boost_input_current_limit", 0, 35, 1, 0.01), + ("boost_output_current_limit", 1, 10, 1, 0.01), + ("report", 0, 1, 1, 1), + ("fault", 0, 1, 1, 1), + ("intvcc_voltage", 0, 4, 1, 0.01), + ("share_voltage", 0, 4, 1, 0.01), + ("buck_input_voltage", 14, 56, 1, 0.01), + ("buck_output_voltage", 2, 14, 1, 0.01), + ("buck_input_current", 1, 10, 1, 0.01), + ("buck_output_current", 1, 35, 1, 0.01), + ("boost_input_voltage", 8, 14, 1, 0.01), + ("boost_output_voltage", 14, 56, 1, 0.01), + ("boost_input_current", 0, 35, 1, 0.01), + ("boost_output_current", 1, 10, 1, 0.01), + ], +) +def test_cn0556_attr( + test_attribute_single_value, iio_uri, classname, attr, start, stop, step, tol, +): + test_attribute_single_value(iio_uri, classname, attr, start, stop, step, tol)