Skip to content

Commit

Permalink
Merge pull request #131 from folk-lab/TimJohann_Summer2022
Browse files Browse the repository at this point in the history
Tim Johann summer2022
  • Loading branch information
FolkLab authored Oct 19, 2022
2 parents 8508d90 + 2960ac5 commit 42217c7
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 65 deletions.
60 changes: 38 additions & 22 deletions Required/ScanController.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,16 @@ function/s scu_getDeviceChannels(instrID, channels, [adc_flag])
string channels

string new_channels = ""
variable real_channel_val
string sep = selectString(adc_flag, ",", ";")
variable i
for (i = 0; i<itemsinlist(channels, sep); i++)
new_channels = addlistItem(num2str(str2num(stringfromList(i, channels, sep)) - scf_getChannelStartNum(instrID, adc=adc_flag)), new_channels, sep, INF)
real_channel_val = str2num(stringfromList(i, channels, sep)) - scf_getChannelStartNum(instrID, adc=adc_flag)
if (real_channel_val < 0)
printf "ERROR: Channels passed were [%s]. After subtracting the start value for the device for the %d item in list, this resulted in a real value of %d which is not valid\r", channels, i, real_channel_val
abort "ERROR: Bad device channel given (see command history for more info)"
endif
new_channels = addlistItem(num2str(real_channel_val), new_channels, sep, INF)
endfor
if (strlen(new_channels) > 0 && cmpstr(channels[strlen(channels)-1], sep) != 0) // remove trailing ; or , if it WASN'T present initially
new_channels = new_channels[0,strlen(new_channels)-2]
Expand Down Expand Up @@ -1329,7 +1335,6 @@ function scs_checksweepstate()
// Pause sweep if button is pressed
do
if(sc_abortsweep)
// SaveWaves(msg="The scan was aborted during the execution.", save_experiment=0,fastdac=fastdac)
dowindow /k SweepControl
sc_abortsweep=0
sc_abortnosave=0
Expand Down Expand Up @@ -2640,31 +2645,42 @@ function scc_checkLimsFD(S)
endif

// Check that start/fin for each channel will stay within software limits
string softLimitPositive = "", softLimitNegative = "", expr = "(-?[[:digit:]]+)\\s*,\\s*([[:digit:]]+)", question
variable startval = 0, finval = 0
string buffer
for(i=0;i<itemsinlist(channels,",");i+=1)
splitstring/e=(expr) fdacvalstr[str2num(stringfromlist(i,channels,","))][2], softLimitNegative, softLimitPositive
if(!numtype(str2num(softLimitNegative)) == 0 || !numtype(str2num(softLimitPositive)) == 0)
sprintf buffer, "No Lower or Upper Limit found for Channel %s. Low limit = %s. High limit = %s, Limit string = %s\r", stringfromlist(i,channels,","), softLimitNegative, softLimitPositive, fdacvalstr[str2num(stringfromlist(i,channels,","))][2]
abort buffer
endif

startval = str2num(stringfromlist(i,starts,","))
finval = str2num(stringfromlist(i,fins,","))
if(startval < str2num(softLimitNegative) || startval > str2num(softLimitPositive) || finval < str2num(softLimitNegative) || finval > str2num(softLimitPositive))
// we are outside limits
sprintf question, "DAC channel %s will be ramped outside software limits. Continue?", stringfromlist(i,channels,",")
answer = ask_user(question, type=1)
if(answer == 2)
print("[ERROR] \"RecordValues\": User abort!")
dowindow/k SweepControl // kill scan control window
abort
endif
endif
scc_checkLimsSingleFD(stringfromlist(i,channels,","), str2num(stringfromlist(i,starts,",")), str2num(stringfromlist(i,fins,",")))
endfor
end

function scc_checkLimsSingleFD(channel, start, fin)
// Check the start/fin are within limits for channel of FastDAC
// TODO: This function can be fairly easily adapted for BabyDACs too
string channel // Single Channel str
variable start, fin // Single start, fin val for sweep

variable channel_num = str2num(scu_getChannelNumbers(channel, fastdac=1))

string softLimitPositive = "", softLimitNegative = "", expr = "(-?[[:digit:]]+)\\s*,\\s*([[:digit:]]+)", question, buffer
variable startval = 0, finval = 0, answer
wave/t fdacvalstr

splitstring/e=(expr) fdacvalstr[channel_num][2], softLimitNegative, softLimitPositive
if(!numtype(str2num(softLimitNegative)) == 0 || !numtype(str2num(softLimitPositive)) == 0)
sprintf buffer, "No Lower or Upper Limit found for Channel %s. Low limit = %s. High limit = %s, Limit string = %s\r", channel, softLimitNegative, softLimitPositive, fdacvalstr[channel_num][2]
abort buffer
endif

if(start < str2num(softLimitNegative) || start > str2num(softLimitPositive) || fin < str2num(softLimitNegative) || fin > str2num(softLimitPositive))
// we are outside limits
sprintf question, "DAC channel %s will be ramped outside software limits. Continue?", channel
answer = ask_user(question, type=1)
if(answer == 2)
print("[ERROR] \"RecordValues\": User abort!")
dowindow/k SweepControl // kill scan control window
abort
endif
endif

end

function scc_checkSameDeviceFD(S, [x_only, y_only])
// Checks all rampChs and ADCs (selected in fd_scancontroller window)
Expand Down
36 changes: 22 additions & 14 deletions Required/ScanController_INSTR.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -454,16 +454,24 @@ function listGPIBinstr()
variable instrID

// open resource manager
variable localRM
variable status = viOpenDefaultRM(localRM) // open local copy of resource manager
if(status < 0)
VISAerrormsg("[ERROR]: problem opening resource manager", localRM, status)
abort
nvar /z globalRM
if(!nvar_exists(globalRM))
openResourceManager()
nvar globalRM
endif


// variable localRM
// variable status = viOpenDefaultRM(localRM) // open local copy of resource manager
// if(status < 0)
// VISAerrormsg("[ERROR]: problem opening resource manager", localRM, status)
// abort
// endif
variable status

// print list of serial ports/instruments
status = viFindRsrc(localRM,"GPIB?*INSTR",findlist,instrcnt,instrDesc)
status = viFindRsrc(globalRM,"GPIB?*INSTR",findlist,instrcnt,instrDesc)
if(status < 0)
viStatusDesc(globalRM, status, error)
VISAerrormsg("listGPIBAddress -- OpenDefaultRM:", instrID, status)
return 0
elseif(instrcnt==0)
Expand Down Expand Up @@ -584,27 +592,27 @@ function setVISAoptions(instrID,options)
if(strlen(value)==0)
continue // if there is no value, move on
endif

status = 0
strswitch(key)
case "baudrate":
status = visaSetBaudRate(instrID, str2num(value))
continue
break
case "stopbits":
status = visaSetStopBits(instrID, str2num(value))
continue
break
case "databits":
status = visaSetDataBits(instrID, str2num(value))
continue
break
case "parity":
status = visaSetParity(instrID, str2num(value))
continue
break
case "timeout":
status = visaSetTimeout(instrID, str2num(value))
continue
break
endswitch

if(status<0)
VISAerrormsg("viSetAttribute", instrID, status)
VISAerrormsg("viSetAttribute "+key, instrID, status)
endif

endfor
Expand Down
100 changes: 86 additions & 14 deletions Required/Scans.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
// ScanBabyDACLS625Magnet2D
// ScanFastDACLS625Magenet2D
// ScanK2400LS625Magent2D
// ScanSRSFrequency

// Templates:
// ScanMultiVarTemplate -- Helpful template for running a scan inside multiple loops where other variables can change (i.e. up to 5D scans)
Expand Down Expand Up @@ -401,10 +402,10 @@ function ScanFastDAC(instrID, start, fin, channels, [numptsx, sweeprate, delay,
end


function ScanFastDacSlow(instrID, start, fin, channels, numpts, delay, ramprate, [starts, fins, y_label, until_checkwave, until_stop_val, until_operator, comments, nosave]) //Units: mV
function ScanFastDacSlow(instrID, start, fin, channels, numpts, delay, ramprate, [starts, fins, y_label, repeats, alternate, delayy, until_checkwave, until_stop_val, until_operator, comments, nosave]) //Units: mV
// sweep one or more FastDAC channels but in the ScanController way (not ScanControllerFastdac). I.e. ramp, measure, ramp, measure...
// channels should be a comma-separated string ex: "0, 4, 5"
variable instrID, start, fin, numpts, delay, ramprate, nosave, until_stop_val
variable instrID, start, fin, numpts, delay, ramprate, nosave, until_stop_val, repeats, alternate, delayy
string channels, y_label, comments, until_operator, until_checkwave
string starts, fins // For different start/finish points for each channel (must match length of channels if used)

Expand All @@ -417,6 +418,7 @@ function ScanFastDacSlow(instrID, start, fin, channels, numpts, delay, ramprate,
starts = selectstring(paramisdefault(starts), starts, "")
fins = selectstring(paramisdefault(fins), fins, "")
until_operator = selectstring(paramisdefault(until_operator), until_operator, "not_set")
delayy = ParamIsDefault(delayy) ? 5*delay : delayy

variable a
if (stringmatch(until_operator, "not_set") == 1)
Expand All @@ -440,7 +442,11 @@ function ScanFastDacSlow(instrID, start, fin, channels, numpts, delay, ramprate,

// Initialize ScanVars
struct ScanVars S // Note, more like a BD scan if going slow
initScanVarsFD(S, instrID, start, fin, channelsx=channels, numptsx=numpts, delayx=delay, rampratex=ramprate, startxs = starts, finxs = fins, comments=comments, y_label=y_label)
initScanVarsFD(S, instrID, start, fin, channelsx=channels, numptsx=numpts, delayx=delay, rampratex=ramprate, startxs = starts, finxs = fins, comments=comments, y_label=y_label,\
starty=1, finy=repeats, numptsy=repeats, alternate=alternate, delayy=delay)
if (s.is2d && strlen(S.y_label) == 0)
S.y_label = "Repeats"
endif
S.using_fastdac = 0 // Explicitly showing that this is not a normal fastDac scan
S.duration = numpts*max(0.05, delay) // At least 50ms per point is a good estimate
S.sweeprate = abs((fin-start)/S.duration) // Better estimate of sweeprate (Not really valid for a slow scan)
Expand All @@ -453,24 +459,42 @@ function ScanFastDacSlow(instrID, start, fin, channels, numpts, delay, ramprate,
RampStartFD(S, ignore_lims=1)

// Let gates settle
sc_sleep(delay*5)
sc_sleep(S.delayy)

// Make Waves and Display etc
InitializeScan(S)

// Main measurement loop
variable i=0
do
rampToNextSetpoint(S, i, fastdac=1, ignore_lims=1) // Ramp x to next setpoint
sc_sleep(S.delayx)
RecordValues(S, i, 0)
if (a!=0) // If running scan until condition is met
if (a*cw[i] - until_stop_val < 0)
break
variable i=0, j=0
variable d=1
for (j=0; j<S.numptsy; j++)
S.direction = d // Will determine direction of scan in fd_Record_Values

// Ramp to start of fast axis
RampStartFD(S, ignore_lims=1, x_only=1)
sc_sleep(S.delayy)
i = 0
do
rampToNextSetpoint(S, i, fastdac=1, ignore_lims=1) // Ramp x to next setpoint
sc_sleep(S.delayx)
if (s.is2d)
RecordValues(S, j, i)
else
RecordValues(S, i, 0)
endif
if (a!=0) // If running scan until condition is met
if (a*cw[i] - until_stop_val < 0)
break
endif
endif
i+=1
while (i<S.numptsx)

if (alternate!=0) // If want to alternate scan scandirection for next row
d = d*-1
endif
i+=1
while (i<S.numptsx)
endfor


// Save by default
if (nosave == 0)
Expand Down Expand Up @@ -1306,6 +1330,52 @@ function ScanK2400LS625Magnet2D(keithleyID, startx, finx, channelsx, numptsx, de
endif
end

function ScanSRSFrequency(instrID, startx, finx, numptsx, delayx, nosave)
variable instrID, startx, finx, numptsx, delayx, nosave
string channelsx, y_label, comments

// Reconnect instruments
sc_openinstrconnections(0)

// Set defaults
// comments = selectstring(paramisdefault(comments), comments, "")
// y_label = selectstring(paramisdefault(y_label), y_label, "")

// Initialize ScanVars
struct ScanVars S
initScanVars(S, instrIDx=instrID, startx=startx, finx=finx, numptsx=numptsx, delayx=delayx)

// Ramp to start without checks because checked above
SetSRSFrequency(S.instrIDx,startx)

// Let gates settle
sc_sleep(S.delayy*10)

// Make waves and graphs etc
initializeScan(S)

// Main measurement loop
variable i=0, setpointx
do
setpointx = S.startx + (i*(S.finx-S.startx)/(S.numptsx-1))
SetSRSFrequency(S.instrIDx,setpointx)
sc_sleep(S.delayx)
RecordValues(S, i, i)
i+=1
while (i<S.numptsx)

// Save by default
if (nosave == 0)
EndScan(S=S)
else
dowindow /k SweepControl
endif
//if repeated scans, it may be a good idea to reset the frequency here,
//SetSRSFrequency(S.instrIDx,startx)

end



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////// Useful Templates //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1399,3 +1469,5 @@ function StepTempScanSomething()
end




15 changes: 9 additions & 6 deletions Required/fastdac.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ function openFastDACconnection(instrID, visa_address, [verbose,numDACCh,numADCCh
sprintf comm, "name=FastDAC,instrID=%s,visa_address=%s" instrID, visa_address
string options
if(optical)
options = "baudrate=1750000,databits=8,stopbits=1,parity=0,test_query=*IDN?" // For Optical
options = "baudrate=1750000,databits=8,parity=0,test_query=*IDN?" // For Optical
else
options = "baudrate=57600,databits=8,stopbits=1,parity=0,test_query=*IDN?" // For USB
options = "baudrate=57600,databits=8,parity=0,test_query=*IDN?" // For USB
endif
openVISAinstr(comm, options=options, localRM=localRM, verbose=verbose)

Expand Down Expand Up @@ -682,7 +682,7 @@ function CalibrateFDAC(instrID)
endif

// ramp channel to 0V
fd_rampOutputFDAC(instrID,channel,0, 100000, ignore_lims=1)
fd_rampOutputFDAC(instrID,channel+scf_getChannelStartNum(instrID, adc=0),0, 100000, ignore_lims=1)
sprintf question, "Input value displayed by DMM in volts."
user_input = prompt_user("DAC offset calibration",question)
if(numtype(user_input) == 2)
Expand All @@ -700,7 +700,7 @@ function CalibrateFDAC(instrID)
print message

// ramp channel to -10V
fd_rampOutputFDAC(instrID,channel,-10000, 100000, ignore_lims=1)
fd_rampOutputFDAC(instrID,channel+scf_getChannelStartNum(instrID, adc=0),-10000, 100000, ignore_lims=1)
sprintf question, "Input value displayed by DMM in volts."
user_input = prompt_user("DAC gain calibration",question)
if(numtype(user_input) == 2)
Expand Down Expand Up @@ -777,7 +777,7 @@ function CalibrateFADC(instrID)
// turn result into key/value string
// response is formatted like this: "numCh0,zero,numCh1,zero,numCh0,full,numCh1,full,"
string result="", key_zero="", key_full=""
variable zeroIndex=0,fullIndex=0, calibrationFail = 0
variable zeroIndex=0,fullIndex=0, calibrationFail = 0, j=0
for(i=0;i<numADCCh;i+=1)
zeroIndex = whichlistitem("ch"+num2istr(i),response,",",0)+1
fullIndex = whichlistitem("ch"+num2istr(i),response,",",zeroIndex)+1
Expand All @@ -796,7 +796,10 @@ function CalibrateFADC(instrID)
response = sc_stripTermination(response,"\r\n")
if(scf_checkFDResponse(response,cmd,isString=1,expectedResponse="CALIBRATION_FINISHED") && calibrationFail == 0)
// all good, calibration complete
rampMultipleFDAC(instrID, "0,1,2,3", 0, ramprate=10000)
for(j=0;j<4;j++)
// rampMultipleFDAC(instrID, "0,1,2,3", 0, ramprate=10000)
fd_rampOutputFDAC(instrID, j+scf_getChannelStartNum(instrID, adc=0), 0, 100000)
endfor
fd_saveFadcCalibration(deviceAddress,deviceNum,numADCCh,result,adcSpeed)
ask_user("ADC calibration complete! Result has been written to file on \"config\" path.", type=0)
else
Expand Down
Loading

0 comments on commit 42217c7

Please sign in to comment.