Here is a lightly edited version of your code:
local _startV -- Used by script to track the starting voltage
local _srcRate = 4000 -- Source Update Rate used by the script Sets the source update rate (pts/sec) used by the script.
--Do not set higher than 8,000 if your waveform will have polarity changes 0V crossings)
function SetupAWG(startV, rangeV, limitI, wfrmTbl, remoteSense, trigLineIn)
-- Do some parameter checks
--=========================
if startV == nil then startV = 0 end
if remoteSense ~= true then remoteSense = false end
if type(trigLineIn) == "number" then
trigLineIn = math.floor(trigLineIn)
if trigLineIn < 0 or trigLineIn > 14 then
return true, "Error: Selected trigger line is not valid. trigLineIn must be a number between 0 and 14 or nil."
end
elseif trigLineIn ~= nil then
return true,"Error: Invalid parameter trigLineIn. trigLineIn must be a number between 0 and 14 or nil."
end
_startV = startV
--wfrmTbl = {0.078459,0.156434,0.233445,0.309017,0.382683,0.45399,0.522499,0.587785,0.649448,0.707107,0.760406,0.809017,0.85264,0.891007,0.92388,0.951057,0.97237,0.987688,0.996917,1,0.996917,0.987688,0.97237,0.951057,0.92388,0.891007,0.85264,0.809017,0.760406,0.707107,0.649448,0.587785,0.522499,0.45399,0.382683,0.309017,0.233445,0.156434,0.078459,0,-0.078459,-0.156434,-0.233445,-0.309017,-0.382683,-0.45399,-0.522499,-0.587785,-0.649448,-0.707107,-0.760406,-0.809017,-0.85264,-0.891007,-0.92388,-0.951057,-0.97237,-0.987688,-0.996917,-1,-0.996917,-0.987688,-0.97237,-0.951057,-0.92388,-0.891007,-0.85264,-0.809017,-0.760406,-0.707107,-0.649448,-0.587785,-0.522499,-0.45399,-0.382683,-0.309017,-0.233445,-0.156434,-0.078459,0}
-- compute the sine wave
pts_per_cycle = 72
wfrmTbl = {}
for i=1, pts_per_cycle do
wfrmTbl[i] = 1 * math.sin(i * 2 * math.pi/pts_per_cycle)
end
-- use some phase shift for smub sine wave
wfrmTbl_smub = {}
for i=1, pts_per_cycle do
wfrmTbl_smub[i] = 1 * math.sin(i * 2 * math.pi/pts_per_cycle + math.rad(90))
end
-- Setup the SMU for arb waveform output
--======================================
reset()
smua.reset()
smub.reset()
-- digital output trigger for external equipment
-- configure digital IO line 1 to output a active LO/falling edge
-- pulse at start of each current pulse
digio.trigger[1].clear()
digio.trigger[1].mode = digio.TRIG_FALLING
digio.trigger[1].pulsewidth = 10e-6
digio.trigger[1].stimulus = trigger.timer[1].EVENT_ID
smua.source.func = smua.OUTPUT_DCVOLTS
smub.source.func = smub.OUTPUT_DCVOLTS
if remoteSense == true then
smua.sense = smua.SENSE_REMOTE
smub.sense = smub.SENSE_REMOTE
else
smua.sense = smua.SENSE_LOCAL
smub.sense = smub.SENSE_LOCAL
end
smua.source.autorangev = smua.AUTORANGE_OFF
smua.source.autorangei = smua.AUTORANGE_OFF
smua.source.rangev = rangeV
smua.source.levelv = startV
smua.source.limiti = limitI
smua.source.delay = 0
smua.source.settling = smua.SETTLE_FAST_POLARITY
smub.source.autorangev = smub.AUTORANGE_OFF
smub.source.autorangei = smub.AUTORANGE_OFF
smub.source.rangev = rangeV
smub.source.levelv = startV
smub.source.limiti = limitI
smub.source.delay = 0
smub.source.settling = smub.SETTLE_FAST_POLARITY
-- Configure the Trigger Model
--============================
-- Timer 1 controls the time per point table phase A
trigger.timer[1].delay = 1 / _srcRate
trigger.timer[1].count = table.getn(wfrmTbl) > 1 and table.getn(wfrmTbl) - 1 or 1
if trigLineIn == nil then
-- Immediate
trigger.timer[1].stimulus = smua.trigger.ARMED_EVENT_ID
elseif trigLineIn == 0 then
-- Front panel TRIG button
display.trigger.clear()
trigger.timer[1].stimulus = display.trigger.EVENT_ID
else
-- Digio Trigger
digio.trigger[trigLineIn].clear()
digio.trigger[trigLineIn].mode = digio.TRIG_EITHER
trigger.timer[1].stimulus = digio.trigger[trigLineIn].EVENT_ID
end
trigger.timer[1].passthrough = true
-- Configure SMU Trigger Model for arb waveform output
smua.trigger.source.listv(wfrmTbl)
smua.trigger.source.limiti = limitI
smua.trigger.measure.action = smua.DISABLE
smua.trigger.endpulse.action = smua.SOURCE_HOLD
smua.trigger.endsweep.action = smua.SOURCE_HOLD
smua.trigger.count = table.getn(wfrmTbl)
smua.trigger.arm.count = 1
smua.trigger.arm.stimulus = 0
smua.trigger.source.stimulus = trigger.timer[1].EVENT_ID
smua.trigger.measure.stimulus = 0
smua.trigger.endpulse.stimulus = 0
smua.trigger.source.action = smua.ENABLE
smub.trigger.source.listv(wfrmTbl_smub)
smub.trigger.source.limiti = limitI
smub.trigger.measure.action = smub.DISABLE
smub.trigger.endpulse.action = smub.SOURCE_HOLD
smub.trigger.endsweep.action = smub.SOURCE_HOLD
smub.trigger.count = table.getn(wfrmTbl)
smub.trigger.arm.count = 1
smub.trigger.arm.stimulus = 0
smub.trigger.source.stimulus = trigger.timer[1].EVENT_ID -- ALC
smub.trigger.measure.stimulus = 0
smub.trigger.endpulse.stimulus = 0
smub.trigger.source.action = smub.ENABLE
--==============================
-- End Trigger Model Configuration
if errorqueue.count > 0 then
return true,"Error occured during setup. Please check that your parameters are valid."
else
return false,"No error."
end
end
function RunAWG(numCycles)
if numCycles == nil or numCycles < 0 then
numCycles = 1
end
-- Set the number of cycles to output
smua.trigger.arm.count = numCycles
smub.trigger.arm.count = numCycles
-- Turn output on
smua.source.output = smua.OUTPUT_ON
smub.source.output = smub.OUTPUT_ON
-- Start the trigger model execution
smub.trigger.initiate() -- start this first
smua.trigger.initiate()
if errorqueue.count > 0 then
return true,"Error occurred. See error queue for details."
else
return false,"No error."
end
end
--[[ Name: StopAWG()
Usage: err,msg = StopAWG()
Description:
This function stops the waveform output and turns the SMU
output off.
--]]
function StopAWG()
smua.abort()
smua.source.output = 0
smua.source.levelv = _startV
smub.abort()
smub.source.output = 0
smub.source.levelv = _startV
if errorqueue.count > 0 then
return true,"Error occured. See error queue for details."
else
return false,"No error."
end
end
To run it:
--SetupAWG(startV, rangeV, limitI, wfrmTbl, remoteSense, trigLineIn)
SetupAWG(0, 20, 0.1, wfrmC, false, nil)
--RunAWG(numCycles)
RunAWG(8)
See scope shot attached.