Arbitrary Waveform Generator Instrument

The Arbitrary Waveform Generator takes a time-series of voltage values, and generates the corresponding waveform at the DACs at a configurable rate.

The API for the AWG is made of two parts: write_lut defines the shape of the wave, while gen_waveform defines the speed and amplitude of the wave along with other parameters such as interpolation, dead time and so on.

You must call both functions at least once in order to generate a waveform.

Example Usage

The following example code and a wide range of other pymoku demo scripts can be found at the pymoku Github repository.

arbitrarywaveformgen_basic.py
#
# pymoku example: Arbitrary waveform generator
#
# This example demonstrates how you can generate and output arbitrary
# waveforms using Moku:AWG
#
# (c) 2019 Liquid Instruments Pty. Ltd.
#
from pymoku import Moku
from pymoku.instruments import ArbitraryWaveGen
import numpy as np

#generate a signal the the Arb Waveform Gen should generate on the output
t = np.linspace(0, 1, 100) # Evaluate our waveform at 100 points

# Simple square wave (can also use scipy.signal)
sq_wave = np.array([-1.0 if x < 0.5 else 1.0 for x in t])

# More interesting waveform. Note that we have to normalize this waveform
# to the range [-1, 1]
not_sq = np.zeros(len(t))
for h in np.arange(1, 15, 2):
    not_sq += (4 / (np.pi * h)) * np.cos(2 * np.pi * h * t)

not_sq = not_sq / max(not_sq)

# Connect to your Moku by its device name
# Alternatively, use Moku.get_by_serial('#####') or Moku('192.168.###.###')
m = Moku.get_by_name('Moku')

# Prepare the ArbitraryWaveGen instrument
i = m.deploy_or_connect(ArbitraryWaveGen)

try:
	# Load the waveforms to the device. This doesn't yet generate an output as we haven't
	# set the amplitude, frequency etc; this only defines the shape.
	i.write_lut(1, not_sq)
	i.write_lut(2, sq_wave)

	# We have configurable on-device linear interpolation between LUT points. Normally
	# interpolation is a good idea, but for sharp edges like square waves it will
	# improve jitter but reduce rise-time. Configure whatever's suitable for your application.
	i.gen_waveform(1, period=1e-6, amplitude=1, interpolation=True)
	i.gen_waveform(2, period=1e-6, amplitude=2, interpolation=False)
finally:
	m.close()

The ArbitraryWaveGen Class

class pymoku.instruments.ArbitraryWaveGen
WaveformGenerator.__init__()

Create a new WaveformGenerator instance, ready to be attached to a Moku.

enable_output(*args, **kwargs)

Enable or disable the ArbitraryWaveGen output(s).

If ch is None (the default), both channels will be acted upon, otherwise just the one specified by the argument.

Parameters:
  • ch (int; {1,2} or None) – Output channel, or both.
  • en (bool) – Enable the specified output channel(s).
Raises:

ValueError – Invalid parameters

gen_off(*args, **kwargs)

Warning

Method Deprecation: ‘gen_off’ has been deprecated, use ‘enable_output’ instead.

Turn ArbitraryWaveGen output(s) off.

The channel will be turned on when configuring the waveform type but can be turned off using this function. If ch is None (the default), both channels will be turned off, otherwise just the one specified by the argument.

Parameters:ch (int; {1,2} or None) – Channel to turn off, or both.
Raises:ValueError – Invalid parameters
gen_waveform(*args, **kwargs)

Configure and enable the Arbitrary Waveform on the given output channel.

The look-up table for this channel’s output waveform should have been loaded beforehand using write_lut.

The Arbitrary Waveform Generator has the ability to insert a deadtime between cycles of the look-up table. This time is specified in cycles of the waveform. During this time, the output will be held at the given dead_voltage. This allows the user to, for example, generate infrequent pulses without using space in the LUT to specify the time between, keeping the full LUT size to provide a high-resolution pulse shape.

Where the period and look-up table contents are set such that there isn’t exactly one LUT point per output sample, the AWG instrument can optionally provide a linear interpolation between LUT points.

This function enables the output channel by default. If you wish to enable the outputs simultaneously, you should set the en parameter to False and enable both when desired using enable_output.

Parameters:
  • ch (int; {1,2}) – Channel on which to generate the wave
  • period (float, [4e-9, 1];) – period of the signal in seconds
  • amplitude (float, [0.0,2.0] Vpp) – Waveform peak-to-peak amplitude
  • phase (float, [0-360] degrees) – Phase offset of the wave
  • offset (float, [-1.0,1.0] Volts) – DC offset applied to the waveform
  • interpolation (bool [True, False]) – Enable linear interpolation of LUT entries
  • dead_time (float [0, 2e18] cyc) – number of cycles which show the dead voltage. Use 0 for no dead time
  • dead_voltage (float [-2.0,2.0] V) – signal level during dead time in Volts
  • en (bool) – Enable output
Raises:
get_frequency(ch)

Returns the frequency of the output waveform on the selected channel.

Parameters:ch (int; {1,2}) – Output channel
Raises:ValueError – if the channel number is invalid
reset_phase(*args, **kwargs)

resets the channels phase accumulator to zero

Parameters:ch (int; {1,2}) – Channel on which the reset is performed
Raises:ValueError – if the channel number is invalid
set_defaults(*args, **kwargs)

Sets the Arbitrary Waveform Generator instrument to sane defaults

set_waveform_trigger(*args, **kwargs)

Specify what constitutes a trigger event for the given output channel. This takes effect only when the channel has triggered output mode enabled (see set_waveform_trigger_output ).

Parameters:
  • ch (int; {1,2}) – Output channel to set triggering on
  • source (string, {'in1','in2','ext'}) – Trigger source. May be either input channel, or the external ‘Trig’ back-panel connector allowing triggering from an externally-generated digital [LV]TTL or CMOS signal.
  • edge (string, {'rising','falling','both'}) – Which edge to trigger on. In ‘Pulse Width’ mode this specifies whether the pulse is positive (rising) or negative (falling), with the ‘both’ option being invalid.
  • level (float, [-5.0, 5.0] volts) – Trigger level. Ignored in ‘ext’ mode.
  • minwidth (float, seconds) – Minimum Pulse Width. 0 <= minwidth < (2^32/samplerate). Can’t be used with maxwidth.
  • maxwidth (float, seconds) – Maximum Pulse Width. 0 <= maxwidth < (2^32/samplerate). Can’t be used with minwidth.
  • hysteresis (bool) – Enable hysteresis around trigger point.
set_waveform_trigger_output(*args, **kwargs)

Enables triggered output mode on the specified channel and configures ‘how’ to output the set waveform on a trigger event.

Parameters:
  • ch (int; {1,2}) – Output channel to configure
  • trig_en (bool;) – Enables triggering mode on the specified output channel
  • single (bool;) – Enables single mode. Outputs a single waveform (vs continuous) per trigger event.
  • duration (float; [0.0, 1e11] seconds) – Total time that the triggered output should be generated (leave 0 for continuous). Note the duration resolution is 8ns.
  • hold_last (bool) – Hold the last value of the waveform for the duration of the triggered output.
sync_phase(*args, **kwargs)

Resets the phase accumulator of both output waveforms.

write_lut(ch, data, mode=None)

Writes the signal lookup table to memory in the Moku:Lab.

You can also choose the output rate of the AWG, which influences the maximum length of the look-up table as follows:

  • 1000MSPS: 8192 points per channel
  • 500MSPS: 16384 points per channel
  • 250MSPS: 32768 points per channel
  • 125MSPS: 65536 points per channel

If you don’t specify a mode, the fastest output rate for the given data length will be automatically chosen. This is correct in almost all circumstances.

If you specify a particular mode along with a data array too big for that mode, the behaviour is undefined.

To avoid unexpected output signals during write, disable the outputs by using the enable_output function.

Parameters:
  • ch (int; {1,2}) – Output channel to load the LUT to
  • data (float array;) – Lookup table coefficients normalised to range [-1.0, 1.0].
  • mode (int; {125, 250, 500, 1000} MSmps) – defines the output sample rate of the AWG.
Raises: