{
"cells": [
{
"cell_type": "markdown",
"id": "baa7659c-bba6-4e0a-a22d-ff58adc493c4",
"metadata": {},
"source": [
"# Power Supply Examples"
]
},
{
"cell_type": "markdown",
"id": "39faa5ee-85f1-4330-9d16-f18d247cbe29",
"metadata": {},
"source": [
"## Initial Setup\n",
"Import the power supply class from `inspy.instrument.powersupply`. The device connection can be managed by using the `connect()` and `disconnect()` methods. However, the use of context managers (see example below) is recommended."
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "f0fd4906-7bbb-43b4-aef6-f30504e7813e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ID of the instrument:\n",
"Keysight Technologies,E36312A,MY61004144,2.1.0-1.0.4-1.12\n"
]
}
],
"source": [
"from inspy.instrument.powersupply import PsuKeysightE36312A\n",
"\n",
"ADDRESS = \"USB0::10893::4354::MY61004144::0::INSTR\"\n",
"psu: PsuKeysightE36312A = PsuKeysightE36312A(ADDRESS)\n",
"psu.connect()\n",
"\n",
"# Get the ID of the instrument\n",
"print(\"ID of the instrument:\")\n",
"print(psu.get_id())"
]
},
{
"cell_type": "markdown",
"id": "f3acbcb8-fa3f-4edc-9328-37b84d36b728",
"metadata": {},
"source": [
"## Simple Settings\n",
"Various settings can be set and fetched using the setter/getter methods."
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "a7528ba6-4ee6-4723-90b3-ca045c6670e3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Setting channel 1 to 2V and 0.1A:\n",
"Done setting channel 1 to 2V and 0.1A\n",
"Getting voltage and current of channel 1:\n",
"State: True\n",
"Voltage: 1.998844 V\n",
"Current: -2.6e-05 A\n",
"Setting channel 2 to 5V and 0.2A:\n",
"Done setting channel 2 to 5V and 0.2A\n",
"Getting voltage and current of channel 2:\n",
"True\n",
"Voltage: 4.99975 V\n",
"Current: 1.7e-05 A\n"
]
}
],
"source": [
"import logging\n",
"\n",
"# By default it will log all the commands and responses to the console\n",
"# You can disable it by the following command\n",
"logging.getLogger(\"PsuKeysightE36312A\").setLevel(logging.WARNING)\n",
"\n",
"# Set the channel 1 to 2V and 0.1A\n",
"print(\"Setting channel 1 to 2V and 0.1A:\")\n",
"psu.set_channel_state(enable=True, channel=1)\n",
"psu.set_voltage(voltage=2, channel=1)\n",
"psu.set_current(current=0.1, channel=1)\n",
"print(\"Done setting channel 1 to 2V and 0.1A\")\n",
"\n",
"# Get the voltage and current of channel 1\n",
"print(\"Getting voltage and current of channel 1:\")\n",
"print(f\"State: {psu.get_channel_state(channel=1)}\")\n",
"# get_voltage/get_current return the last value you set (echoes the setpoint),\n",
"# while measure_voltage/measure_current query the instrument for the actual\n",
"# live reading\n",
"print(f\"Voltage: {psu.measure_voltage(channel=1)} V\")\n",
"print(f\"Current: {psu.measure_current(channel=1)} A\")\n",
"\n",
"# Set the channel 2 to 5V and 0.2A\n",
"print(\"Setting channel 2 to 5V and 0.2A:\")\n",
"psu.set_channel_state(enable=True, channel=2)\n",
"psu.set_voltage(voltage=5, channel=2)\n",
"psu.set_current(current=0.2, channel=2)\n",
"print(\"Done setting channel 2 to 5V and 0.2A\")\n",
"\n",
"# Get the voltage and current of channel 2\n",
"print(\"Getting voltage and current of channel 2:\")\n",
"print(psu.get_channel_state(channel=2))\n",
"print(f\"Voltage: {psu.measure_voltage(channel=2)} V\")\n",
"print(f\"Current: {psu.measure_current(channel=2)} A\")\n",
"\n",
"psu.disconnect()"
]
},
{
"cell_type": "markdown",
"id": "740d35f3",
"metadata": {},
"source": [
"## Configuring Protection Limits \n",
"Before enabling a channel, it's good practice to set the current range and protection trip points that will guard your device under test."
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "d7fe04a4",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Voltage trip point: 5.5 V\n",
"Current limit: 0.5 A\n",
"Current protection enabled: True\n"
]
}
],
"source": [
"# Demonstrating connecting using a context manager\n",
"with PsuKeysightE36312A(ADDRESS) as psu:\n",
" # Current range must be set while the channel is disabled\n",
" psu.set_channel_state(enable=False, channel=1)\n",
" # Set OVP trip point and current limit/protection to protect the device under test\n",
" psu.set_output_voltage_trip_point(voltage=5.5, channel=1)\n",
" psu.set_current(current=0.5, channel=1)\n",
" # Trip the output if that limit is hit\n",
" psu.set_current_protection_state(enable=True, channel=1)\n",
"\n",
" # Wait for the PSU to apply the settings before trusting a read back\n",
" psu.await_completion()\n",
"\n",
" print(f\"Voltage trip point: {psu.get_output_voltage_trip_point(channel=1)} V\")\n",
" print(f\"Current limit: {psu.get_current(channel=1)} A\")\n",
" print(f\"Current protection enabled: {psu.get_current_protection_state(channel=1)}\")\n",
"\n",
" # Now safe to enable and use the channel\n",
" psu.set_channel_state(enable=True, channel=1)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "cc-inspy (3.10.0.final.0)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}