Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

Commit

Permalink
add afg31000 blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
dstrande committed Nov 29, 2023
1 parent f463ce2 commit 1cf855e
Show file tree
Hide file tree
Showing 46 changed files with 7,478 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from flojoy import flojoy, DataContainer, TextBlob, VisaConnection
from typing import Optional, Literal


@flojoy(inject_connection=True)
def ALIGN_PHASES_AFG31000(
connection: VisaConnection,
channel: Literal["1", "2"] = "1",
input: Optional[DataContainer] = None,
) -> TextBlob:
"""Run this block to align the phases for ch1 and ch2.
This block should also work with compatible Tektronix AFG31XXX instruments.
Parameters
----------
connection: VisaConnection
The VISA address (requires the CONNECTION_AFG31000 block).
channel: select, default=ch1
Which channel is the reference?
Returns
-------
TextBlob
Placeholder
"""

afg = connection.get_handle()

afg.write(f"SOURCE{channel}:PHASE:INIT")

return TextBlob(text_blob="Aligned channel phases")

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"docstring": {
"long_description": "This block should also work with compatible Tektronix AFG31XXX instruments.",
"short_description": "Run this block to align the phases for ch1 and ch2.",
"parameters": [
{
"name": "connection",
"type": "VisaConnection",
"description": "The VISA address (requires the CONNECTION_AFG31000 block)."
},
{
"name": "channel",
"type": "select, default=ch1",
"description": "Which channel is the reference?"
}
],
"returns": [
{
"name": null,
"type": "TextBlob",
"description": "Placeholder"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
In this example, an Tektronix AFG31000 is used to generate two waveforms.

First the necessary blocks were added:

- `CONNECT_AFG31000`
- `RESET_AFG31000`
- 2x `FUNCTION_AFG31000`
- `ALIGN_PHASES_AFG31000`
- `OUTPUT_AFG31000`
- `SAVE_STATE_AFG31000`

The instrument address was set for each `AFG31000` block. Ensure the `OUTPUT_AFG31000` block has both channels turn on.

The blocks were connected as shown and the app was run. The `SAVE_STATE_AFG31000` block can be used to save and recall the current state of the AFG. However, you must use a `OUTPUT_AFG31000` block to turn the outputs back on.

An oscilloscope was connected to the AFG31000 resulting in waveform:

![image](https://res.cloudinary.com/dhopxs1y3/image/upload/v1701277906/flojoy-docs/afg31000/afg31000_basic.png)
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from flojoy import flojoy, OrderedPair, TextBlob, VisaConnection, Vector
from typing import Literal
from numpy import max, min


@flojoy(inject_connection=True)
def ARBITRARY_AFG31000(
input: OrderedPair | Vector,
connection: VisaConnection,
memory_state: Literal["EMEM1", "EMEM2"] = "EMEM1",
source: Literal["1", "2"] = "1",
frequency: float = 1e6,
amplitude: float = 1,
offset: float = 0,
phase: float = 0,
) -> TextBlob:
"""Take the input waveform and use it as the arbitrary wavefunction.
This block should also work with compatible Tektronix AFG31XXX instruments.
Parameters
----------
connection: VisaConnection
The VISA address (requires the CONNECTION_AFG31000 block).
memory_state: select, default=EMEM1
Save the function in "Edit Memory" 1 or 2.
channel: select, default=1
Choose the channel to use with the waveform.
frequency: float, default=1e6
The voltage of the waveform to set, in Hz.
amplitude: float, default=1
The voltage of the waveform to set.
offset: float, default=0
The voltage offset to set the waveform to, in volts.
phase: float, default=0
The phase to set the waveform to, in degrees.
Returns
-------
TextBlob
Placeholder
"""

assert -180.0 <= phase <= 180.0, "The phase must be between -180 and 180 degrees."

afg = connection.get_handle()

match input:
case OrderedPair():
y = input.y
case Vector():
y = input.v

y -= min(y)
y /= max(y)
y *= 16383

afg.write_binary_values(
f"DATA:DATA {memory_state}, ", y, is_big_endian=True, datatype="h"
)
afg.write(f"SOURCE{source}:FUNCTION {memory_state}")

afg.write(f"SOURCE{source}:FREQUENCY {frequency}")
afg.write(f"SOURCE{source}:VOLTAGE:AMPLITUDE {amplitude}")
afg.write(f"SOURCE{source}:VOLTAGE:OFFSET {offset}")
afg.write(f"SOURCE{source}:PHASE:ADJUST {phase}DEG")

return TextBlob(text_blob="Set FG parameters")
Loading

0 comments on commit 1cf855e

Please sign in to comment.