Here is a Python sample for loading a custom waveform to the standard ARB mode.
It was targeting generation of double pulse test waveform type.
It is easy matter to save the EMEM memory to a tfwx file on the M: or U: drive for use in the SEQ.
'''
Create waveform and send to AFG31102
Double Pulse Test Waveform
--- A1---- ---A2---
| | | |
| | | |
-----------| |----------| |------------
<-- t1 -->|<--- t2 --->|<-----t3---->|<---t4---->|<---t5---->|
Pulse Heights, A1 and A2 , correspond to the Vgs applied to the FET
and therefore control the Ids current level.
rise/fall times = don't care yet
duration of other time segements = important
'''
import pyvisa
import numpy as np # for test wave
import matplotlib.pyplot as plt # for plotting, not required
#time durations for our waveform
t1 = 1e-6
t2 = 1e-6 #duration of A1
t3 = 1e-6 # off time in between two pulses
t4 = 1e-6 #duration of A2
t5 = 1e-6
#voltage amplitudes of the pulses
A1 = 1.25 #volts
A2 = 3 #volts
AFG_SampleRate = 250e6
total_time = t1 + t2 + t3 + t4 + t5
t_axis = np.arange(0, total_time, 1/AFG_SampleRate)
wave = np.multiply(0, t_axis) # populate with zeros
ARB_SRC_FREQ = int (AFG_SampleRate / len(t_axis))
print('********************')
print('ARB_SRC_FREQ: ' + str(ARB_SRC_FREQ))
print('without option, limit size of ARB to 131K entries')
print('Num Pts per ARB Waveform: ' + str(len(t_axis)))
print(len(wave))
#overwrite some of the zeros with our pulse height values
#first pulse
start_index=int(t1 * AFG_SampleRate)
stop_index = start_index + int(t2 * AFG_SampleRate)
print('start index pulse1: ' + str(start_index))
print('stop index pulse1: ' + str(stop_index))
for i in range(start_index, stop_index): #pulse top
wave[i] = A1
# second pulse
start_index=int((t1+ t2+ t3) * AFG_SampleRate)
stop_index = start_index + int(t4* AFG_SampleRate)
print('start index pulse2: ' + str(start_index))
print('stop index pulse2: ' + str(stop_index))
for i in range(start_index, stop_index): #pulse top
wave[i] = A2
#build normalized array
# normalize to dac values
m = 16382 / (wave.max() - wave.min())
b = -m * wave.min()
dac_values = (m * wave + b)
np.around(dac_values, out=dac_values)
dac_values = dac_values.astype(np.uint16)
# plot (optional)
plt.plot(dac_values)
plt.show()
#Get the this from NI-MAX
instrumentdescriptor = 'USB0::0x0699::0x035A::C013392::INSTR'
#instrumentdescriptor = 'GPIB0::11::INSTR'
print('****************************************')
debug = 0
if debug:
for item in wave:
print(item)
#Write the waveform to a text file
debug = 0
if debug:
fid = open('waveform.txt', 'w')
for j in wave:
fid.write(str(j) + '\n')
fid.close()
print('Sending waveform to AFG')
#Next sending to the AFG
resource_mgr = pyvisa.ResourceManager()
AFG = resource_mgr.open_resource(instrumentdescriptor)
AFG.read_termination = '\n'
AFG.encoding = 'latin_1'
def halt_on_msg():
e = int(AFG.query('*esr?'))
if e != 0:
raise Exception('non-zero esr')
print(AFG.query('*IDN?'))
#reset and clear the AFG status
AFG.write('*rst')
AFG.write('*cls')
#configure the channel to play arbitrary waveform, burst mode, .2ms timer
#on trigger, 0 - 5V output, 1 cycle of waveform per occurance.
AFG.write('source1:function ememory')
AFG.write('OUTP1:IMP INF') #MAX=10Kohms, INF is >10K, MIN=1ohm
AFG.write('source1:frequency ' + str(ARB_SRC_FREQ) )
AFG.write('source1:burst:mode trig')
AFG.write('source1:burst:ncycles 1')
AFG.write('source1:burst:state on')
AFG.write('trigger:sequence:timer 0.005')
AFG.write('source1:voltage:high ' + str(wave.max()))
AFG.write('source1:voltage:low ' + str(wave.min()))
#AFG.write('source1:voltage:offset 2.5')
# **************** send the ARB waveform ******************
halt_on_msg()
# datatype = "H" means unsigned short format
AFG.write_binary_values(':TRAC:DATA EMEM1,',
dac_values,
datatype='h',
is_big_endian=True)
halt_on_msg()
#finally, turn the output on
AFG.write('output1 on')