From 3e0a6326bd526afaa96fbbd388e4aecaf1c59e27 Mon Sep 17 00:00:00 2001 From: Ruiheng Su Date: Sat, 15 Jul 2023 12:50:08 -0700 Subject: [PATCH 1/5] some small changes, need to revise before merging --- Required/Scans.ipf | 64 +++--- Required/ls625_single_supply.ipf | 5 +- Required/srs830.ipf | 12 ++ Scan_n_D_Bxyz.ipf | 326 ++++++++++++++++++++++++++++++- 4 files changed, 379 insertions(+), 28 deletions(-) diff --git a/Required/Scans.ipf b/Required/Scans.ipf index 8cbfac5f..2568591e 100644 --- a/Required/Scans.ipf +++ b/Required/Scans.ipf @@ -459,7 +459,7 @@ function ScanFastDacSlow(instrID, start, fin, channels, numpts, delay, ramprate, RampStartFD(S, ignore_lims=1) // Let gates settle - sc_sleep(S.delayy) + sc_sleep(1) // Make Waves and Display etc InitializeScan(S) @@ -475,6 +475,7 @@ function ScanFastDacSlow(instrID, start, fin, channels, numpts, delay, ramprate, 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) @@ -663,8 +664,8 @@ function ScanFastDAC2D(fdID, startx, finx, channelsx, starty, finy, channelsy, n end -function Scank2400(instrID, startx, finx, channelsx, numptsx, delayx, rampratex, [y_label, comments, nosave]) //Units: mV - variable instrID, startx, finx, numptsx, delayx, rampratex, nosave +function Scank2400(instrID, startx, finx, channelsx, numptsx, delayx, rampratex, [y_label, comments, nosave, ramp]) //Units: mV + variable instrID, startx, finx, numptsx, delayx, rampratex, nosave, ramp string channelsx, y_label, comments //abort "WARNING: This scan has not been tested with an instrument connected. Remove this abort and test the behavior of the scan before running on a device!" @@ -684,10 +685,10 @@ function Scank2400(instrID, startx, finx, channelsx, numptsx, delayx, rampratex, // PreScanChecksKeithley(S) // Ramp to start without checks because checked above - rampK2400Voltage(S.instrIDx, startx) + rampK2400Voltage(S.instrIDx, startx, ramprate = rampratex) // Let gates settle - sc_sleep(S.delayy*20) + sc_sleep(2) // Make waves and graphs etc initializeScan(S) @@ -696,8 +697,11 @@ function Scank2400(instrID, startx, finx, channelsx, numptsx, delayx, rampratex, variable i=0, setpointx do setpointx = S.startx + (i*(S.finx-S.startx)/(S.numptsx-1)) -// rampK2400Voltage(S.instrIDx, setpointx, ramprate=S.rampratex) - setK2400Voltage(S.instrIDx, setpointx) + if (ramp ==1) + rampK2400Voltage(S.instrIDx, setpointx, ramprate=S.rampratex) + else + setK2400Voltage(S.instrIDx, setpointx) + endif sc_sleep(S.delayx) RecordValues(S, i, i) i+=1 @@ -734,11 +738,11 @@ function Scank24002D(instrIDx, startx, finx, numptsx, delayx, rampratex, instrID // PreScanChecksKeithley(S) // Ramp to start without checks because checked above - rampK2400Voltage(S.instrIDx, startx) - rampK2400Voltage(S.instrIDy, starty) + rampK2400Voltage(S.instrIDx, startx, ramprate = rampratex) + rampK2400Voltage(S.instrIDy, starty, ramprate = rampratex) // Let gates settle - sc_sleep(S.delayy*5) + sc_sleep(2) // Make waves and graphs etc initializeScan(S) @@ -750,7 +754,6 @@ function Scank24002D(instrIDx, startx, finx, numptsx, delayx, rampratex, instrID setpointy = S.starty + (i*(S.finy-S.starty)/(S.numptsy-1)) rampK2400Voltage(S.instrIDy, setpointy, ramprate=S.rampratey) rampK2400Voltage(S.instrIDx, setpointx, ramprate=S.rampratex) - sc_sleep(S.delayy) j=0 do @@ -1086,11 +1089,18 @@ function ScanMultipleK2400LS625Magnet2D(keithleyIDs, start, fin, numptsx, delayx end - -function ScanLS625Magnet(instrID, startx, finx, numptsx, delayx, [y_label, comments, nosave]) - variable instrID, startx, finx, numptsx, delayx, nosave +function ScanLS625Magnet(instrID, startx, finx, numptsx, delayx, [y_label, comments, nosave, fast]) //set fast=1 to run quickly + variable instrID, startx, finx, numptsx, delayx, nosave, fast string y_label, comments - //abort "WARNING: This scan has not been tested with an instrument connected. Remove this abort and test the behavior of the scan before running on a device!" + + + variable ramprate + + if(paramisdefault(fast)) + fast=0 + endif + + // Reconnect instruments sc_openinstrconnections(0) @@ -1099,14 +1109,17 @@ function ScanLS625Magnet(instrID, startx, finx, numptsx, delayx, [y_label, comme 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, \ - y_label=y_label, x_label = "Field /mT", comments=comments) + y_label=y_label, comments=comments) // Check software limits and ramprate limits // PreScanChecksMagnet(S) + ramprate = getLS625rate(S.instrIDx) // Ramp to start without checks because checked above setlS625fieldWait(S.instrIDx, S.startx) @@ -1121,8 +1134,13 @@ function ScanLS625Magnet(instrID, startx, finx, numptsx, delayx, [y_label, comme variable i=0, setpointx do setpointx = S.startx + (i*(S.finx-S.startx)/(S.numptsx-1)) - setlS625fieldWait(S.instrIDx, setpointx, short_wait = 1) // Mr Ray changed this on August 04 - sc_sleep(S.delayx) + if(fast==1) + setlS625field(S.instrIDx, setpointx) + sc_sleep(max(S.delayx, (S.delayx+60*abs(finx-startx)/numptsx/ramprate))) + else + setlS625fieldwait(S.instrIDx, setpointx) +// sc_sleep(S.delayx) + endif RecordValues(S, i, i) i+=1 while (i Date: Fri, 1 Sep 2023 12:41:56 -0700 Subject: [PATCH 2/5] Update Update --- Required/Scans.ipf | 11 +- Required/fastdac.ipf | 4 +- Required/keithley2400.ipf | 24 +++- Scan_n_D_Bxyz.ipf | 282 ++++++++++++++++++++++++++++++++------ ips120_single_supply.ipf | 1 - 5 files changed, 274 insertions(+), 48 deletions(-) diff --git a/Required/Scans.ipf b/Required/Scans.ipf index 2568591e..debb93d8 100644 --- a/Required/Scans.ipf +++ b/Required/Scans.ipf @@ -1295,6 +1295,7 @@ function ScanFastDacSlowLS625Magnet2D(instrIDx, startx, finx, channelsx, numptsx // Set defaults comments = selectstring(paramisdefault(comments), comments, "") y_label = selectstring(paramisdefault(y_label), y_label, "") + // Initialize ScanVars struct ScanVars S @@ -1315,7 +1316,7 @@ function ScanFastDacSlowLS625Magnet2D(instrIDx, startx, finx, channelsx, numptsx setlS625fieldWait(S.instrIDy, starty ) // Let gates settle - asleep(S.delayy*10) + asleep(S.delayy) // Make Waves and Display etc InitializeScan(S) @@ -1326,15 +1327,17 @@ function ScanFastDacSlowLS625Magnet2D(instrIDx, startx, finx, channelsx, numptsx do setpointx = S.startx setpointy = S.starty + (i*(S.finy-S.starty)/(S.numptsy-1)) - setlS625field(S.instrIDy, setpointy) - rampMultipleFDAC(S.instrIDx,channelsx,setpointx,ramprate=S.rampratex, ignore_lims=1) - setlS625fieldwait(S.instrIDy, setpointy, short_wait = 1) + rampMultipleFDAC(S.instrIDx,channelsx, setpointx, ramprate=S.rampratex, ignore_lims=1) + setlS625fieldwait(S.instrIDy, setpointy) sc_sleep(S.delayy) j=0 do setpointx = S.startx + (j*(S.finx-S.startx)/(S.numptsx-1)) rampMultipleFDAC(S.instrIDx,channelsx,setpointx,ramprate=S.rampratex, ignore_lims=1) sc_sleep(S.delayx) +// if (mod(j, 100) == 0) +// sc_sleep(S.delayx) +// endif RecordValues(S, i, j) j+=1 while (j inf, Vt and Vb can be regarded as ramping simultaneously along the const D line + string instrIDs + variable numpts, nDest + nvar k2400t,k2400b + variable VtopNow=getk2400voltage(k2400t) + variable VbtmNow=getk2400voltage(k2400b) + variable ConstD=ConvertVtVbToD(VtopNow,VbtmNow) + + variable VtopDest=ConvertnDToVt(nDest,ConstD) + variable VbtmDest=ConvertnDToVb(nDest,ConstD) + + string starts=num2str(VtopNow)+","+num2str(VbtmNow) + string fins=num2str(VtopDest)+","+num2str(VbtmDest) + + + variable i=1 + do + rampMultipleK2400s(instrIDs,i,numpts,starts,fins, ramprate = 2000) + i+=1 + while (i inf, Vt and Vb can be regarded as ramping simultaneously along the const D line + string instrIDs + variable numpts, nDest + nvar k2400t,k2400b + variable VtopNow=getk2400voltage(k2400t) + variable VbtmNow=getk2400voltage(k2400b) + variable ConstD=ConvertVtVbToD(VtopNow,VbtmNow) + + variable VtopDest=ConvertnDToVt(nDest,ConstD) + variable VbtmDest=ConvertnDToVb(nDest,ConstD) + + string starts=num2str(VtopNow)+","+num2str(VbtmNow) + string fins=num2str(VtopDest)+","+num2str(VbtmDest) + + + variable i=1 + do +// rampMultipleK2400s(instrIDs,i,numpts,starts,fins, ramprate = 2000) + setMultipleK2400s(instrIDs,i,numpts,starts,fins, 0.03) + i+=1 + while (i check || check > 5*val) +// autosrsSens(srs5) +// endif +// +// check = getsrssensitivity(srs3)/1e3 +// check = getsrssensitivity(srs3)/1e3 +// val = readsrsx(srs3) +// val = readsrsx(srs3) +// if (val > check || check > 5*val) +// autosrsSens(srs3) +// endif + RecordValues(S, i, 0) i+=1 while (i(B0,pi-theta,alpha+pi) in para space - variable magnetIDX,magnetIDY,magnetIDZ, BTranslateX, BTranslateY, BTranslateZ, thetafromY, alphafromX, startB, finB, numptsB, delayB, numptsN,delayN, ramprateB,nosave + variable magnetIDX,magnetIDY,magnetIDZ, BTranslateX, BTranslateY, BTranslateZ, thetafromY, alphafromX, startB, finB, numptsB, delayB, numptsN,delayN, ramprateB,nosave, fast string y_label, comments @@ -1834,9 +1963,9 @@ function Scan_VECfield(magnetIDX,magnetIDY,magnetIDZ, BTranslateX, BTranslateY, setlS625field(magnetIDY, BTranslateY+startB*cos(thetafromY*pi/180)) setlS625field(magnetIDZ, BTranslateZ+startB*sin(thetafromY*pi/180)*sin(alphafromX*pi/180)) - setlS625fieldWait(magnetIDX, BTranslateX+startB*sin(thetafromY*pi/180)*cos(alphafromX*pi/180)) //BTranslateX/Y/Z are the results of calibrations. - setlS625fieldWait(magnetIDY, BTranslateY+startB*cos(thetafromY*pi/180)) - setlS625fieldWait(magnetIDZ, BTranslateZ+startB*sin(thetafromY*pi/180)*sin(alphafromX*pi/180)) + setlS625fieldWait(magnetIDX, BTranslateX+startB*sin(thetafromY*pi/180)*cos(alphafromX*pi/180), short_wait=1) //BTranslateX/Y/Z are the results of calibrations. + setlS625fieldWait(magnetIDY, BTranslateY+startB*cos(thetafromY*pi/180), short_wait=1) + setlS625fieldWait(magnetIDZ, BTranslateZ+startB*sin(thetafromY*pi/180)*sin(alphafromX*pi/180), short_wait=1) // Let gates settle sc_sleep(S.delayy*5) @@ -1852,9 +1981,9 @@ function Scan_VECfield(magnetIDX,magnetIDY,magnetIDZ, BTranslateX, BTranslateY, setlS625field(magnetIDY, BTranslateY+setpointB*cos(thetafromY*pi/180)) setlS625field(magnetIDZ, BTranslateZ+setpointB*sin(thetafromY*pi/180)*sin(alphafromX*pi/180)) - setlS625fieldWait(magnetIDX, BTranslateX+setpointB*sin(thetafromY*pi/180)*cos(alphafromX*pi/180)) - setlS625fieldWait(magnetIDY, BTranslateY+setpointB*cos(thetafromY*pi/180)) - setlS625fieldWait(magnetIDZ, BTranslateZ+setpointB*sin(thetafromY*pi/180)*sin(alphafromX*pi/180)) + setlS625fieldWait(magnetIDX, BTranslateX+setpointB*sin(thetafromY*pi/180)*cos(alphafromX*pi/180), short_wait=1) + setlS625fieldWait(magnetIDY, BTranslateY+setpointB*cos(thetafromY*pi/180), short_wait=1) + setlS625fieldWait(magnetIDZ, BTranslateZ+setpointB*sin(thetafromY*pi/180)*sin(alphafromX*pi/180), short_wait=1) sc_sleep(S.delayy) j=0 do @@ -1874,6 +2003,81 @@ function Scan_VECfield(magnetIDX,magnetIDY,magnetIDZ, BTranslateX, BTranslateY, end +function Scan_VECfield_1D(magnetIDX,magnetIDY,magnetIDZ, BTranslateX, BTranslateY, BTranslateZ, thetafromY, alphafromX, startB, finB, numptsB, delayB, [ramprateB, y_label, comments, nosave, fast]) //Units: mV + //‘thetafromY' is the polar angle deviated from y-direction. Perpendicular: thetafromY=0deg In-Plane: thetafromY=90deg + //'alphafromX' is the azimuth angle deviated from x-direction. When thetafromY=90deg, B_x: alphafromX=0 B_z:alphafromX=90deg + //The 'magnitude' of \vec(B) can be negative---(-B0,theta,alpha)<==>(B0,pi-theta,alpha+pi) in para space + variable magnetIDX,magnetIDY,magnetIDZ, BTranslateX, BTranslateY, BTranslateZ, thetafromY, alphafromX, startB, finB, numptsB, delayB, ramprateB,nosave, fast + string y_label, comments + variable rampratey, rampratez + + // Reconnect instruments + sc_openinstrconnections(0) + + // Set defaults + comments = selectstring(paramisdefault(comments), comments, "") + //y_label = selectstring(paramisdefault(y_label), y_label, "Field /mT") + + + // Initialize ScanVars + struct ScanVars S + initScanVars(S, instrIDy=magnetIDx, starty=startB, finy=finB, numptsy=numptsB, delayy=delayB, rampratey=ramprateB, \ + instrIDx=magnetIDx, startx=startB, finx=finB, numptsx=numptsB, delayx=delayB, \ + y_label=y_label, comments=comments) + + S.is2d=0 + + + if (!paramIsDefault(ramprateB)) //If inputting a non-default ramprateB, then set all magnets' rate to it. + setLS625rate(magnetIDX,ramprateB) + setLS625rate(magnetIDY,ramprateB) + setLS625rate(magnetIDZ,ramprateB) + endif + print(BTranslateX+startB*sin(thetafromY*pi/180)*cos(alphafromX*pi/180)) + print(BTranslateY+startB*cos(thetafromY*pi/180)) + print( BTranslateZ+startB*sin(thetafromY*pi/180)*sin(alphafromX*pi/180)) + + setlS625field(magnetIDX, BTranslateX+startB*sin(thetafromY*pi/180)*cos(alphafromX*pi/180)) //BTranslateX/Y/Z are the results of calibrations. + setlS625field(magnetIDY, BTranslateY+startB*cos(thetafromY*pi/180)) + setlS625field(magnetIDZ, BTranslateZ+startB*sin(thetafromY*pi/180)*sin(alphafromX*pi/180)) + + setlS625fieldWait(magnetIDX, BTranslateX+startB*sin(thetafromY*pi/180)*cos(alphafromX*pi/180), short_wait=1) //BTranslateX/Y/Z are the results of calibrations. + setlS625fieldWait(magnetIDY, BTranslateY+startB*cos(thetafromY*pi/180), short_wait=1) + setlS625fieldWait(magnetIDZ, BTranslateZ+startB*sin(thetafromY*pi/180)*sin(alphafromX*pi/180), short_wait=1) + + // Let gates settle + sc_sleep(S.delayy*5) + + // Make waves and graphs etc + initializeScan(S) + + rampratey = getLS625rate(magnetIDY) + rampratez = getLS625rate(magnetIDZ) + + // Main measurement loop + variable i=0, j=0, setpointB + do + setpointB = S.starty + (i*(S.finy-S.starty)/(S.numptsy-1)) + setlS625field(magnetIDX, BTranslateX+setpointB*sin(thetafromY*pi/180)*cos(alphafromX*pi/180)) + setlS625field(magnetIDY, BTranslateY+setpointB*cos(thetafromY*pi/180)) + setlS625field(magnetIDZ, BTranslateZ+setpointB*sin(thetafromY*pi/180)*sin(alphafromX*pi/180)) + + sc_sleep(max(S.delayx, (S.delayx+60*abs(S.finy-S.starty)/S.numptsy/rampratez), (S.delayx+60*abs(S.finy-S.starty)/S.numptsy/rampratey))) + + + RecordValues(S, i, j) + i+=1 + while (i Date: Thu, 21 Sep 2023 16:31:28 -0700 Subject: [PATCH 3/5] Smaller changes good --- Required/Scans.ipf | 2 +- Required/keithley2400.ipf | 13 +++++++------ Scan_n_D_Bxyz.ipf | 24 +++++++++++++++++------- ips120_single_supply.ipf | 7 ++++--- 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/Required/Scans.ipf b/Required/Scans.ipf index debb93d8..f977922c 100644 --- a/Required/Scans.ipf +++ b/Required/Scans.ipf @@ -739,7 +739,7 @@ function Scank24002D(instrIDx, startx, finx, numptsx, delayx, rampratex, instrID // Ramp to start without checks because checked above rampK2400Voltage(S.instrIDx, startx, ramprate = rampratex) - rampK2400Voltage(S.instrIDy, starty, ramprate = rampratex) + rampK2400Voltage(S.instrIDy, starty, ramprate = rampratey) // Let gates settle sc_sleep(2) diff --git a/Required/keithley2400.ipf b/Required/keithley2400.ipf index 9d084025..6ff57265 100644 --- a/Required/keithley2400.ipf +++ b/Required/keithley2400.ipf @@ -291,10 +291,11 @@ end function/s getK2400Status(instrID) variable instrID -// string buffer = "" -// -// string gpib = num2istr(getAddressGPIB(instrID)) -// buffer = addJSONkeyvalpair(buffer, "gpib_address", gpib) -// -// return addJSONkeyvalpair("", "K2400_"+gpib, buffer) + string buffer = "" + + string gpib = num2istr(getAddressGPIB(instrID)) + buffer = addJSONkeyval(buffer, "gpib_address", gpib) + buffer = addJSONkeyval(buffer, "amplitude V", num2numStr(getk2400voltage(instrID)/1000)) + + return addJSONkeyval("", "K2400_"+gpib, buffer) end diff --git a/Scan_n_D_Bxyz.ipf b/Scan_n_D_Bxyz.ipf index 0be4a25b..ad186956 100644 --- a/Scan_n_D_Bxyz.ipf +++ b/Scan_n_D_Bxyz.ipf @@ -415,7 +415,7 @@ function Scan_n(instrIDx,instrIDy,fixedD,startn,finn,numptsn,delayn,rampraten, [ rampK2400Voltage(S.instrIDy, S.starty) // Let gates settle - sc_sleep(2) + sc_sleep(4) // Make waves and graphs etc initializeScan(S) @@ -1515,10 +1515,14 @@ function Scan_field_n_2D(keithleyIDtop,keithleyIDbtm,fixedD,startn, finn, numpts endif end -function ScanIPSMagnet(instrID, startx, finx, numptsx, delayx, [y_label, comments, nosave]) - variable instrID, startx, finx, numptsx, delayx, nosave +function ScanIPSMagnet(instrID, startx, finx, numptsx, delayx, [y_label, comments, nosave, fast]) + variable instrID, startx, finx, numptsx, delayx, nosave, fast string y_label, comments - //abort "WARNING: This scan has not been tested with an instrument connected. Remove this abort and test the behavior of the scan before running on a device!" + variable ramprate + + if(paramisdefault(fast)) + fast=0 + endif // Reconnect instruments sc_openinstrconnections(0) @@ -1532,6 +1536,7 @@ function ScanIPSMagnet(instrID, startx, finx, numptsx, delayx, [y_label, comment initScanVars(S, instrIDx=instrID, startx=startx, finx=finx, numptsx=numptsx, delayx=delayx, \ y_label=y_label, x_label = "Field /mT", comments=comments) + ramprate = getips120rate(instrID) // Ramp to start without checks because checked above setIPS120fieldWait(instrID, S.startx ) @@ -1546,8 +1551,14 @@ function ScanIPSMagnet(instrID, startx, finx, numptsx, delayx, [y_label, comment variable i=0, setpointx do setpointx = S.startx + (i*(S.finx-S.startx)/(S.numptsx-1)) - setIPS120fieldWait(instrID, setpointx) // Mr Ray changed this on August 04 - sc_sleep(S.delayx) + + if (fast==1) + setIPS120field(instrID, setpointx) + sc_sleep(max(S.delayx, (S.delayx+60*abs(finx-startx)/numptsx/ramprate))) + else + setIPS120fieldWait(instrID, setpointx) // Mr Ray changed this on August 04 + sc_sleep(S.delayx) + endif RecordValues(S, i, i) i+=1 while (i Date: Sun, 4 Aug 2024 17:42:11 -0700 Subject: [PATCH 4/5] New updates to the scan_n_d codes incorporating a division ratio in the gate capacitance New updates to the scan_n_d codes incorporating a division ratio in the gate capacitance --- Required/ScanController.ipf | 2 +- Required/Scans.ipf | 10 +++-- Required/fastdac.ipf | 2 +- Required/keithley2400.ipf | 22 ++++++---- Required/srs830.ipf | 22 ++++++---- Scan_n_D_Bxyz.ipf | 49 ++++++++++------------ ips120_single_supply.ipf | 84 ++++++++++++++++++++----------------- 7 files changed, 101 insertions(+), 90 deletions(-) diff --git a/Required/ScanController.ipf b/Required/ScanController.ipf index 08411222..04de0f1d 100644 --- a/Required/ScanController.ipf +++ b/Required/ScanController.ipf @@ -1388,7 +1388,7 @@ function scg_open1Dgraph(wn, x_label, [y_label, append_wn]) if (cmpstr(append_wn, "")) appendtograph /r $append_wn - makecolorful() +// makecolorful() legend endif diff --git a/Required/Scans.ipf b/Required/Scans.ipf index aa7edfca..de47559d 100644 --- a/Required/Scans.ipf +++ b/Required/Scans.ipf @@ -471,7 +471,7 @@ function ScanFastDacSlow(instrID, start, fin, channels, numpts, delay, ramprate, RampStartFD(S, ignore_lims=1) // Let gates settle - sc_sleep(1) + sc_sleep(15) // Make Waves and Display etc InitializeScan(S) @@ -925,7 +925,7 @@ function Scank2400(instrID, startx, finx, channelsx, numptsx, delayx, rampratex, rampK2400Voltage(S.instrIDx, startx, ramprate = rampratex) // Let gates settle - sc_sleep(2) + sc_sleep(5) // Make waves and graphs etc initializeScan(S) @@ -936,10 +936,12 @@ function Scank2400(instrID, startx, finx, channelsx, numptsx, delayx, rampratex, setpointx = S.startx + (i*(S.finx-S.startx)/(S.numptsx-1)) if (ramp ==1) rampK2400Voltage(S.instrIDx, setpointx, ramprate=S.rampratex) + asleep(S.delayx) else setK2400Voltage(S.instrIDx, setpointx) + sc_sleep(S.delayx) endif - sc_sleep(S.delayx) + RecordValues(S, i, i) i+=1 while (i-1) - // found an instrument with that name - // replace the visaID value in the other list - ips120_visaIDs = RemoveListItem(idx, ips120_visaIDs) - ips120_visaIDs = AddListItem(num2istr(localID), ips120_visaIDs, ";", idx) + + string comm = "" + sprintf comm, "name=IPS120,instrID=%s,visa_address=%s" instrVarName, visa_address + // string options = "baudrate=9600,databits=8,stopbits=2" + openVISAinstr(comm, localRM=localRM, verbose=verbose) + nvar localID = $(instrVarName) + + svar/z ips120_names + if(!svar_exists(ips120_names)) + string /g ips120_names = AddListItem(instrVarName, "") + string /g ips120_visaIDs =AddListItem(num2istr(localID), "") else - // this is a new variable name - // add additional entries to both lists - ips120_names = AddListItem(instrVarName, ips120_names) - ips120_visaIDs = AddListItem(num2istr(localID), ips120_visaIDs) + svar ips120_visaIDs + variable idx = WhichListItem(instrVarName, ips120_names) // lookup name + if(idx>-1) + // found an instrument with that name + // replace the visaID value in the other list + ips120_visaIDs = RemoveListItem(idx, ips120_visaIDs) + ips120_visaIDs = AddListItem(num2istr(localID), ips120_visaIDs, ";", idx) + else + // this is a new variable name + // add additional entries to both lists + ips120_names = AddListItem(instrVarName, ips120_names) + ips120_visaIDs = AddListItem(num2istr(localID), ips120_visaIDs) + endif + endif + + variable /g $("amps_per_tesla_"+instrVarName) = amps_per_tesla + variable /g $("max_field_"+instrVarName) = max_field + variable /g $("max_ramprate_"+instrVarName) = max_ramprate + + // a few quick setup commands to make sure this is in the right mode(s) + writeIPScheck(localID, "C3\r") // Remote and unlocked + sc_sleep(0.02) + writeIPScheck(localID, "M9\r") // Set display to Tesla + writeInstr(localID, "Q4\r") // Use extented resolusion (0.0001 amp/0.01 mT), no response from magnet + + if(!paramisdefault(hold) && hold==1) + writeIPScheck(localID, "A0\r") // Set to Hold endif endif - - variable /g $("amps_per_tesla_"+instrVarName) = amps_per_tesla - variable /g $("max_field_"+instrVarName) = max_field - variable /g $("max_ramprate_"+instrVarName) = max_ramprate - - // a few quick setup commands to make sure this is in the right mode(s) - writeIPScheck(localID, "C3\r") // Remote and unlocked - sc_sleep(0.02) - writeIPScheck(localID, "M9\r") // Set display to Tesla - writeInstr(localID, "Q4\r") // Use extented resolusion (0.0001 amp/0.01 mT), no response from magnet - - if(!paramisdefault(hold) && hold==1) - writeIPScheck(localID, "A0\r") // Set to Hold - endif - end function /s ips120_lookupVarName(instrID) From 6395069670ecda5c555cbd18e75836bb365addb1 Mon Sep 17 00:00:00 2001 From: folklab Date: Mon, 21 Oct 2024 12:42:25 -0700 Subject: [PATCH 5/5] after last experiment --- Required/Scans.ipf | 70 ++- Required/fastdac.ipf | 24 +- Required/srs830.ipf | 16 +- Scan_Compressibility.ipf | 1196 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 1302 insertions(+), 4 deletions(-) create mode 100644 Scan_Compressibility.ipf diff --git a/Required/Scans.ipf b/Required/Scans.ipf index de47559d..818b50e8 100644 --- a/Required/Scans.ipf +++ b/Required/Scans.ipf @@ -508,7 +508,7 @@ function ScanFastDacSlow(instrID, start, fin, channels, numpts, delay, ramprate, endif endfor - + // Save by default if (nosave == 0) EndScan(S=S) @@ -1523,6 +1523,74 @@ function ScanFastDACLS625Magnet2D(fdID, startx, finx, channelsx, magnetID, start end +function ScanFastDACIPS120Magnet2D(fdID, startx, finx, channelsx, magnetID, starty, finy, numptsy, [numpts, sweeprate, rampratex, delayy, startxs, finxs, y_label, comments, nosave, use_AWG]) + // 2D Scan with Fastdac on x-axis and magnet on y-axis + // Note: Must provide numptsx OR sweeprate in optional parameters instead + // Note: channels should be a comma-separated string ex: "0,4,5" + variable fdID, startx, finx, starty, finy, numptsy, numpts, sweeprate, magnetID, rampratex, delayy, nosave, use_AWG + string channelsx, y_label, comments, startxs, finxs + //abort "WARNING: This scan has not been tested with an instrument connected. Remove this abort and test the behavior of the scan before running on a device!" + + // Set defaults + delayy = ParamIsDefault(delayy) ? 0.01 : delayy + comments = selectstring(paramisdefault(comments), comments, "") + startxs = selectstring(paramisdefault(startxs), startxs, "") + finxs = selectstring(paramisdefault(finxs), finxs, "") + + // Reconnect instruments + sc_openinstrconnections(0) + + // Put info into scanVars struct (to more easily pass around later) + struct ScanVars S + // Init FastDAC part like usual, then manually set the rest + initScanVarsFD(S, fdID, startx, finx, channelsx=channelsx, rampratex=rampratex, numptsx=numpts, sweeprate=sweeprate, numptsy=numptsy, delayy=delayy, \ + startxs=startxs, finxs=finxs, comments=comments) + S.instrIDy = magnetID + s.is2d = 1 + S.starty = starty + S.finy = finy + S.y_label = selectString(paramIsDefault(y_label), y_label, "Magnet /mT") + + // Check software limits and ramprate limits and that ADCs/DACs are on same FastDAC + PreScanChecksFD(S, x_only=1) + // PreScanChecksMagnet(S, y_only=1) + + // Ramp to start without checks + RampStartFD(S, x_only=1, ignore_lims=1) + setips120fieldWait(S.instrIDy, S.starty) // Ramprate should be set beforehand for magnets + + // Let gates settle + sc_sleep(S.delayy*3) + + // Initialize waves and graphs + initializeScan(S) + + // Main measurement loop + variable setpointy + variable i=0, j=0 + string chy + for(i=0; i theta_min) + do + di = delta_max/(5*2^k) + setpoint = i*di + RampMultipleFDAC(fdID, channel2D, setpoint) + sc_sleep(delay) + response = str2num(queryInstr(srsID, "OUTP? 4\n")) + i = i + 1 + while (abs(response - theta0) > 3 && i < 5*2^k) + endif + sc_sleep(1) + response = str2num(queryInstr(srsID, "OUTP? 4\n")) + return response +end + + +// readSRSt_ZERO_V2(srs4, fd2, "BBGx111", 0, 5, 500) Example function call +function readSRSt_ZERO_V2(srsID, fdID, channel2D, theta0, theta_min, cB_period) //Units: rad + variable srsID, fdID, theta0, theta_min, cB_period // cb period expected in mV + string channel2D // Fastdac channel for the BBG gate + variable response, delta_max + + variable cumulativeSum = 0 // To store the cumulative sum of responses + variable iterationCount = 0 // To count the number of iterations + variable runningAverage // To store the running average + + Make /N=3/O waveResponseHistory + + delta_max = 2*cb_period // maxmimum change is 2 times the cB period + + variable j = 0 + do + sc_sleep(0.1) + response = str2num(queryInstr(srsID, "OUTP? 4\n")) // Measure + waveResponseHistory[j] = response + j += 1 + while (j <= 2) + + variable i + variable k + variable di, setpoint + + setpoint = 0 + if (abs(mean(waveResponseHistory) - theta0) > theta_min) // if THETA IS not acceptable + do + if (abs(response) > 90) + k = 6 + di = delta_max/(5*2^k) + setpoint += di // Increase the set point + RampMultipleFDAC(fdID, channel2D, setpoint) // INCREASE V2D + sc_sleep(0.1) + else + k = 9 + di = delta_max/(5*2^k) + setpoint += di // Increase the set point + RampMultipleFDAC(fdID, channel2D, setpoint) // INCREASE V2D + sc_sleep(0.1) + endif + + response = str2num(queryInstr(srsID, "OUTP? 4\n")) // Measure + + i = 1 + do + waveResponseHistory[i-1] = waveResponseHistory[i] + i += 1 + while(i < 3) + i = 1 + // Store the new response in the last position + waveResponseHistory[4] = response + + while (abs(mean(waveResponseHistory) - theta0) > theta_min && abs(setpoint) < delta_max) + endif + + if (abs(setpoint) > delta_max && abs(mean(waveResponseHistory) - theta0) > theta_min) + response = readSRSt_ZERO_V2(srsID, fdID, channel2D, theta0, theta_min, cB_period) + return response + else + sc_sleep(1) + response = str2num(queryInstr(srsID, "OUTP? 4\n")) + return response + endif +end + +//readSRSt_ZERO_V3(srs4, fd2, "BBGx111", 10, 500, 11); + +function readSRSt_ZERO_V3(srsID, fdID, channel2D, dT_max, cB_period, npts, ) //Units: rad + variable srsID, fdID, dT_max, cB_period, npts + string channel2D // Fastdac channel for the BBG gate + + variable multipoint = 5 + Make /N=(multipoint)/O THETA_0 + + variable j = 0 + do + asleep(0.3) + THETA_0[j] = abs(str2num(queryInstr(srsID, "OUTP? 4\n"))) // get value for phase + j += 1 + while (j <= multipoint-1) + + variable THETA_AVG = mean(THETA_0) + + if (THETA_AVG < dT_max || abs(THETA_AVG - 180) < dT_max) + return mean(THETA_0) + else + print("Re-adjusting operating point") + + variable scale = 2 + variable i = 0 + + double V_0 = getFDACOutput(fdID, 8) + variable zero_crossing = 0 + double PEAK_X, PEAK_Y + PEAK_Y = 0 + do + Make /N=(npts)/O HIST_Y // recording of SET current + Make /N=(npts)/O HIST_X // recording of SET POINT + i = 0 + double dV_window = cB_period/(2^scale) + double dV = dV_window/(npts - 1) + double setpoint + do + setpoint = V_0 - dV_window/2 + i*dV + // print setpoint + RampMultipleFDAC(fdID, channel2D, setpoint) // INCREASE V2D + if (i == 0) + sc_sleep(2) + else + sc_sleep(1) + endif + HIST_Y[i] = str2num(queryInstr(srsID, "OUTP? 1\n")) + HIST_X[i] = setpoint + + if (i==0 && PEAK_Y == 0) + PEAK_Y = HIST_Y[0] + PEAK_X = HIST_X[0] + endif + + if (abs(HIST_Y[i]) > abs(PEAK_Y)) + PEAK_Y = HIST_Y[i] + PEAK_X = HIST_X[i] + endif + print HIST_X[i] + print HIST_Y[i] + i += 1 + while(i < npts) + + double minValue, maxValue + + [minValue, maxValue] = WaveMinAndMax(HIST_Y) + + if (minValue*maxValue < 0) + zero_crossing = 1 + endif + + scale = scale - 1 + npts = npts*2 + + while (zero_crossing == 0 && scale >= 0) + + RampMultipleFDAC(fdID, channel2D, PEAK_X) + sc_sleep(2) + + j = 0 + do + THETA_0[j] = abs(str2num(queryInstr(srsID, "OUTP? 4\n"))) // get current value for phase + asleep(0.3) + j += 1 + while (j <= multipoint-1) + return mean(THETA_0) + endif +end + +function readSRSt_ZERO_V3_GRAD(srsID, fdID, channel2D, dT_max, cB_period, npts, VMAX, delay) //Units: rad + variable srsID, fdID, dT_max, cB_period, npts, VMAX, delay + string channel2D // Fastdac channel for the BBG gate + variable direction = 1 // sets the direction of how channel2D of fdID will be adjusted + variable multipoint = 2 + Make /N=(multipoint)/O THETA_0 + + variable j = 0 + do + asleep(delay) + THETA_0[j] = abs(str2num(queryInstr(srsID, "OUTP? 4\n"))) // get value for phase + j += 1 + while (j <= multipoint-1) + + variable THETA_AVG = mean(THETA_0) + + if (THETA_AVG < dT_max || abs(THETA_AVG - 180) < dT_max) + return mean(THETA_0) + else + print("Adjusting operating point of SET") + + variable i = 0 + + // get starting value of the fastdac + double V0 = getFDACOutput(fdID, 8) + + if (abs(V0 + cB_period) > VMAX) // reset the 2D gate back to 0 + RampMultipleFDAC(fdID, channel2D, 0) + V0 = 0 + sc_sleep(delay*5) + endif + + // estimate the local derivative by doing a second order finite difference approximation + double h = cB_period/npts // step size in finite difference + + double PEAK_X, PEAK_Y, PEAK_idx + PEAK_Y = 0 + + + Make /N=(npts)/O HIST_Y // recording of SET current + Make /N=(npts)/O HIST_X // recording of SET POINT + double setpoint, grad, new_grad, R0, R1 + variable peaked = 0 + + setpoint = V0 + sc_sleep(delay) + HIST_Y[0] = str2num(queryInstr(srsID, "OUTP? 1\n")) + HIST_X[0] = setpoint + + print HIST_X[0] + print HIST_Y[0] + + PEAK_Y = HIST_Y[0] + PEAK_X = HIST_X[0] + PEAK_idx = 0 + + grad = 0 + + i = 1 + do + setpoint = V0 + i*h + RampMultipleFDAC(fdID, channel2D, setpoint) // INCREASE V2D + sc_sleep(delay) + + HIST_Y[i] = str2num(queryInstr(srsID, "OUTP? 1\n")) + HIST_X[i] = setpoint + + if (abs(HIST_Y[i]) > abs(PEAK_Y)) + PEAK_Y = HIST_Y[i] + PEAK_X = HIST_X[i] + PEAK_idx = i + endif + print HIST_X[i] + print HIST_Y[i] + + new_grad = (HIST_Y[i] - HIST_Y[i-1])/(HIST_X[i] - HIST_X[i-1]) + if (new_grad*grad < 0) + peaked = 1 + endif + grad = new_grad + i += 1 + while(i < npts && peaked == 0) + + + h = max(abs(HIST_X[PEAK_idx-1] - HIST_X[PEAK_idx+1]), 0.4)/ceil(npts/2) + peaked = 0 + Make /N=(ceil(npts/2))/O HIST_Y // recording of SET current + Make /N=(ceil(npts/2))/O HIST_X // recording of SET POINT + + V0 = HIST_X[PEAK_idx-1] + RampMultipleFDAC(fdID, channel2D, V0) + + sc_sleep(1) + HIST_Y[0] = str2num(queryInstr(srsID, "OUTP? 1\n")) + HIST_X[0] = V0 + + print HIST_X[0] + print HIST_Y[0] + + PEAK_Y = HIST_Y[0] + PEAK_X = HIST_X[0] + PEAK_idx = 0 + grad = 0 + + i = 1 + do + setpoint = V0 + i*h + RampMultipleFDAC(fdID, channel2D, setpoint) // INCREASE V2D + sc_sleep(delay) + + HIST_Y[i] = str2num(queryInstr(srsID, "OUTP? 1\n")) + HIST_X[i] = setpoint + + if (abs(HIST_Y[i]) > abs(PEAK_Y)) + PEAK_Y = HIST_Y[i] + PEAK_X = HIST_X[i] + PEAK_idx = i + endif + print HIST_X[i] + print HIST_Y[i] + + new_grad = (HIST_Y[i] - HIST_Y[i-1])/(HIST_X[i] - HIST_X[i-1]) + if (new_grad*grad < 0) + peaked = 1 + endif + grad = new_grad + i += 1 + while(i < ceil(npts/2) && peaked == 0) + + + sc_sleep(delay) + +// j = 0 +// do +// THETA_0[j] = abs(str2num(queryInstr(srsID, "OUTP? 4\n"))) // get current value for phase +// asleep(delay) +// j += 1 +// while (j <= multipoint-1) + return abs(str2num(queryInstr(srsID, "OUTP? 4\n"))) + endif +end + +function local_grad(srsID, fdID, channel2D, h, delay) + variable srsID, fdID, h, delay + string channel2D + + double V0 = getFDACOutput(fdID, 8) + double R0, R1 + + RampMultipleFDAC(fdID, channel2D, V0 - h) + sc_sleep(delay) + R0 = str2num(queryInstr(srsID, "OUTP? 1\n")) + RampMultipleFDAC(fdID, channel2D, V0 + h) + sc_sleep(delay) + R1 = str2num(queryInstr(srsID, "OUTP? 1\n")) + + return (R1 - R0)/(2*h) +end + +function readSRSt_ZERO_Gradient(srsID, fdID, channel2D, dT_max, cB_period, npts, VMAX, learning_rate, tol) //npts is max number of iterations + variable srsID, fdID, dT_max, cB_period, npts, VMAX, learning_rate, tol + string channel2D // Fastdac channel for the BBG gate + + variable multipoint = 5 + Make /N=(multipoint)/O THETA_0 + + // read a phase value by averaging over multiple measurements + variable j = 0 + do + asleep(0.3) + THETA_0[j] = abs(str2num(queryInstr(srsID, "OUTP? 4\n"))) // get value for phase + j += 1 + while (j <= multipoint-1) + + variable THETA_AVG = mean(THETA_0) + + if (THETA_AVG < dT_max || abs(THETA_AVG - 180) < dT_max) + return mean(THETA_0) + else + print("Adjusting operating point of SET") + + variable i = 0 + + // get starting value of the fastdac + double V0 = getFDACOutput(fdID, 8) + + if (abs(V0 + cB_period) > VMAX) // reset the 2D gate back to 0 + RampMultipleFDAC(fdID, channel2D, 0) + V0 = 0 + sc_sleep(1) + endif + + // estimate the local derivative by doing a second order finite difference approximation + double h = cB_period/npts // step size in finite difference + double new_setpoint, setpoint, grad, R0, R1 + + variable conv = 0 + + Make /N=(npts*2)/O HIST_Y // recording of SET current + Make /N=(npts*2)/O HIST_X // recording of SET POINT + + setpoint = V0 + do +// grad = local_grad(srsID, fdID, channel2D, h, 1) + + + RampMultipleFDAC(fdID, channel2D, setpoint - h) + sc_sleep(1) + R0 = str2num(queryInstr(srsID, "OUTP? 1\n")) + RampMultipleFDAC(fdID, channel2D, setpoint + h) + sc_sleep(1) + R1 = str2num(queryInstr(srsID, "OUTP? 1\n")) + grad = (R1 - R0)/(2*h) + + + new_setpoint = setpoint + learning_rate*grad + + if (abs(learning_rate*grad) > tol) + setpoint = new_setpoint + RampMultipleFDAC(fdID, channel2D, setpoint) + sc_sleep(1) + else + conv = 1 + endif + while(i < npts && conv == 0) // while less than maximum iteration and not converged + + + +// i = 0 +// double dV_window = cB_period/(2^scale) +// double dV = dV_window/(npts - 1) +// double setpoint +// do +// setpoint = V_0 - dV_window/2 + i*dV +// // print setpoint +// +// if (i == 0) +// sc_sleep(2) +// else +// sc_sleep(1) +// endif +// HIST_Y[i] = str2num(queryInstr(srsID, "OUTP? 1\n")) +// HIST_X[i] = setpoint +// +// if (i==0 && PEAK_Y == 0) +// PEAK_Y = HIST_Y[0] +// PEAK_X = HIST_X[0] +// endif +// +// if (abs(HIST_Y[i]) > abs(PEAK_Y)) +// PEAK_Y = HIST_Y[i] +// PEAK_X = HIST_X[i] +// endif +// print HIST_X[i] +// print HIST_Y[i] +// i += 1 +// while(i < npts) +// +// double minValue, maxValue +// +// [minValue, maxValue] = WaveMinAndMax(HIST_Y) +// +// if (minValue*maxValue < 0) +// zero_crossing = 1 +// endif +// +// scale = scale - 1 +// npts = npts*2 +// +// +// RampMultipleFDAC(fdID, channel2D, PEAK_X) +// sc_sleep(2) +// +// j = 0 +// do +// THETA_0[j] = abs(str2num(queryInstr(srsID, "OUTP? 4\n"))) // get current value for phase +// asleep(0.3) +// j += 1 +// while (j <= multipoint-1) +// return mean(THETA_0) + endif +end + +macro LOCK_in_params() +print("BBG") +print "VBBG", getsrsamplitude(srs4) +print "Freq", getsrsfrequency(srs4) +print "TC", getsrstimeConst(srs4) +print "Phase", getsrsphase(srs4) +print "Sensitivity", getsrsSensitivity(srs4)/1e3 + +print("Back gate") +print "VBG", getsrsamplitude(srs2) +print "Freq", getsrsfrequency(srs2) +print "TC", getsrstimeConst(srs2) +print "Phase", getsrsphase(srs2) +print "Sensitivity", getsrsSensitivity(srs2)/1e3 +// +//print("BBG two Omega") +//print "TC",getsrstimeConst(srs1) +//print "Phase", getsrsphase(srs1) +//print "Sensitivity", getsrsSensitivity(srs1)/1e3 +endmacro + +function initCompressibilityDirection(direction) + variable direction // +1 for increasing VBBG, -1 for decreasing VBBG + variable/G CompDir = direction +endmacro + + +function initPIDCompressibilityDirection(direction, fdid_PID) + variable direction, fdid_PID // 0 for increasing VBBG, 1 for decreasing VBBG + variable/G CompDirPID = direction + Make /N=2/O V2D_history + setPIDDir(fdid_PID, direction) +endmacro + + +function getFADCchannel_PID(fdid, fdid_PID, channel, delta_max, delay, [len_avg]) + // Instead of just grabbing one single datapoint which is susceptible to high f noise, this averages data over len_avg and returns a single value + variable fdid, fdid_PID, channel, delta_max, delay, len_avg + nvar CompDirPID // 0 or 1 + wave V2D_history + len_avg = paramisdefault(len_avg) ? 0.03 : len_avg + + variable numpts = ceil(getFADCspeed(fdid)*len_avg) + if(numpts <= 0) + numpts = 1 + endif + + fd_readChunk(fdid, num2str(channel), numpts) // Creates fd_readChunk_# wave + + wave w = $"fd_readChunk_"+num2str(channel) + wavestats/q w + wave/t fadcvalstr + fadcvalstr[channel][1] = num2str(v_avg) + + V2D_history[0] = V2D_history[1] + V2D_history[1] = V_avg + //print(V2D_history[1] - V2D_history[0]) + if (abs(V2D_history[1] - V2D_history[0]) > delta_max) + asleep(delay) + endif + return V_avg +end + +//function find_mid_point(fdid, numpts, delay) +//variable fdid, numpts, delay +// +//make /N=(numpts)/O ISETDC_HIST +// +//variable i=0 +// +// +//end + + + +function readSRSt_ZERO_V4_GRAD(srsID, fdID, channel2D, dT_max, cB_period, npts, VMAX, delay) //Units: rad + variable srsID, fdID, dT_max, cB_period, npts, VMAX, delay + string channel2D // Fastdac channel for the BBG gate + nvar CompDir + // sets the direction of how channel2D of fdID will be adjusted + variable multipoint = 2 + Make /N=(multipoint)/O THETA_0, THETA_0_ABS + variable j = 0 + do + asleep(delay) + THETA_0[j] = str2num(queryInstr(srsID, "OUTP? 4\n")) // get value for phase + THETA_0_ABS[j] = abs(THETA_0[j]) + j += 1 + while (j <= multipoint-1) + + variable THETA_AVG = mean(THETA_0) + variable THETA_ABS_AVG = mean(THETA_0_ABS) + + if (THETA_ABS_AVG < dT_max || abs(THETA_ABS_AVG - 180) < dT_max) + return THETA_AVG + else + print("Adjusting operating point of SET") + + variable i = 0 + + // get starting value of the fastdac + double V0 = getFDACOutput(fdID, 8) + double max_window = V0 + CompDir*cB_period + if (abs(max_window) > VMAX) + CompDir = CompDir*-1 + endif + + // estimate the local derivative by doing a second order finite difference approximation + double h = cB_period/npts // step size in finite difference + + double PEAK_X, PEAK_Y, PEAK_idx + PEAK_Y = 0 + + + Make /N=(npts)/O HIST_Y // recording of SET current + Make /N=(npts)/O HIST_X // recording of SET POINT + double setpoint, grad, new_grad, R0, R1 + variable peaked = 0 + + setpoint = V0 + sc_sleep(delay) + HIST_Y[0] = str2num(queryInstr(srsID, "OUTP? 1\n")) + HIST_X[0] = setpoint + + print HIST_X[0] + print HIST_Y[0] + + PEAK_Y = HIST_Y[0] + PEAK_X = HIST_X[0] + PEAK_idx = 0 + + grad = 0 + + i = 1 + do + setpoint = V0 + CompDir*i*h + RampMultipleFDAC(fdID, channel2D, setpoint) // INCREASE V2D + sc_sleep(delay) + + HIST_Y[i] = str2num(queryInstr(srsID, "OUTP? 1\n")) + HIST_X[i] = setpoint + + if (abs(HIST_Y[i]) > abs(PEAK_Y)) + PEAK_Y = HIST_Y[i] + PEAK_X = HIST_X[i] + PEAK_idx = i + endif + print HIST_X[i] + print HIST_Y[i] + + new_grad = (HIST_Y[i] - HIST_Y[i-1])/(HIST_X[i] - HIST_X[i-1]) + if (new_grad*grad < 0) + peaked = 1 + endif + grad = new_grad + i += 1 + while(i < npts && peaked == 0) + + + h = max(abs(HIST_X[PEAK_idx-1] - HIST_X[PEAK_idx+1]), 0.4)/ceil(npts/2) + peaked = 0 + Make /N=(ceil(npts/2))/O HIST_Y // recording of SET current + Make /N=(ceil(npts/2))/O HIST_X // recording of SET POINT + + V0 = HIST_X[PEAK_idx-1] + RampMultipleFDAC(fdID, channel2D, V0) + + sc_sleep(1) + HIST_Y[0] = str2num(queryInstr(srsID, "OUTP? 1\n")) + HIST_X[0] = V0 + + print HIST_X[0] + print HIST_Y[0] + + PEAK_Y = HIST_Y[0] + PEAK_X = HIST_X[0] + PEAK_idx = 0 + grad = 0 + + i = 1 + do + setpoint = V0 + CompDir*i*h + RampMultipleFDAC(fdID, channel2D, setpoint) // INCREASE V2D + sc_sleep(delay) + + HIST_Y[i] = str2num(queryInstr(srsID, "OUTP? 1\n")) + HIST_X[i] = setpoint + + if (abs(HIST_Y[i]) > abs(PEAK_Y)) + PEAK_Y = HIST_Y[i] + PEAK_X = HIST_X[i] + PEAK_idx = i + endif + print HIST_X[i] + print HIST_Y[i] + + new_grad = (HIST_Y[i] - HIST_Y[i-1])/(HIST_X[i] - HIST_X[i-1]) + if (new_grad*grad < 0) + peaked = 1 + endif + grad = new_grad + i += 1 + while(i < ceil(npts/2) && peaked == 0) + + V0 = HIST_X[PEAK_idx] + RampMultipleFDAC(fdID, channel2D, V0) + print "Ramp to", V0 + + sc_sleep(delay) + +// j = 0 +// do +// THETA_0[j] = abs(str2num(queryInstr(srsID, "OUTP? 4\n"))) // get current value for phase +// asleep(delay) +// j += 1 +// while (j <= multipoint-1) + return str2num(queryInstr(srsID, "OUTP? 4\n")) + endif +end + + + + +function readSRSx_ZERO(srsID, fdID, channel2D, delta_max, cB_period, npts, VMAX, delay) //Units: rad + variable srsID, fdID, delta_max, cB_period, npts, VMAX, delay + string channel2D // Fastdac channel for the BBG gate + variable rescale = 1e4/(getsrsSensitivity(srsID)/1e3) + + nvar CompDir + + // sets the direction of how channel2D of fdID will be adjusted + variable multipoint = 2 + Make /N=(multipoint)/O READING + + variable j = 0 + do + asleep(delay) + READING[j] = rescale*str2num(queryInstr(srsID, "OUTP? 1\n")) // get value for x + j += 1 + while (j <= multipoint-1) + + variable READING_AVG = mean(READING) + + if (abs(READING_AVG) < delta_max) + return READING_AVG/rescale + else + print("Adjusting operating point of SET") + + variable i = 0 + + // get starting value of the fastdac + double V0 = getFDACOutput(fdID, 8) + double max_window = V0 + CompDir*cB_period + if (abs(max_window) > VMAX) + CompDir = CompDir*-1 + endif + + double h = cB_period/npts + + double MIN_X, MIN_Y, MIN_idx + + Make /N=(npts)/O HIST_Y // recording of SET current + Make /N=(npts)/O HIST_X // recording of SET POINT + double setpoint, R0, R1 + variable peaked = 0 + + setpoint = V0 + sc_sleep(delay) + HIST_Y[0] = rescale*str2num(queryInstr(srsID, "OUTP? 1\n")) + HIST_X[0] = setpoint + + print HIST_X[0] + print HIST_Y[0] + + MIN_Y = HIST_Y[0] + MIN_X = HIST_X[0] + MIN_idx = 0 + + i = 1 + do + setpoint = V0 + CompDir*i*h + RampMultipleFDAC(fdID, channel2D, setpoint) // INCREASE V2D + sc_sleep(delay) + + HIST_Y[i] = rescale*str2num(queryInstr(srsID, "OUTP? 1\n")) + HIST_X[i] = setpoint + + if (abs(HIST_Y[i]) < abs(MIN_Y)) // if the new value is closer to zero than the previous value + MIN_Y = HIST_Y[i] + MIN_X = HIST_X[i] + MIN_idx = i + endif + print "Iteration", i + print "V2Dx111", HIST_X[i] + print HIST_Y[i] + + + if (HIST_Y[i]*HIST_Y[i-1] < 0) + peaked = 1 + endif + i += 1 + while(i < npts && peaked == 0) + + V0 = HIST_X[MIN_idx-1] + RampMultipleFDAC(fdID, channel2D, V0) + + h = max(abs(3*h), 0.4)/ceil(npts/2) + peaked = 0 + Make /N=(ceil(npts/2))/O HIST_Y // recording of SET current + Make /N=(ceil(npts/2))/O HIST_X // recording of SET POINT + + + + sc_sleep(delay) + HIST_Y[0] = rescale*str2num(queryInstr(srsID, "OUTP? 1\n")) + HIST_X[0] = V0 + + print HIST_X[0] + print HIST_Y[0] + + MIN_Y = HIST_Y[0] + MIN_X = HIST_X[0] + MIN_idx = 0 + + i = 1 + do + setpoint = V0 + CompDir*i*h + RampMultipleFDAC(fdID, channel2D, setpoint) // INCREASE V2D + sc_sleep(delay) + + HIST_Y[i] = rescale*str2num(queryInstr(srsID, "OUTP? 1\n")) + HIST_X[i] = setpoint + + if (abs(HIST_Y[i]) < abs(MIN_Y)) + MIN_Y = HIST_Y[i] + MIN_X = HIST_X[i] + MIN_idx = i + endif + print "Fine iteration", i + print "V2Dx111", HIST_X[i] + print HIST_Y[i] + + if (HIST_Y[i]*HIST_Y[i-1] < 0) + peaked = 1 + endif + i += 1 + while(i < ceil(npts/2) && peaked == 0) + + V0 = HIST_X[MIN_idx] + RampMultipleFDAC(fdID, channel2D, V0) + print "Ramp to", V0 + + sc_sleep(delay) + return str2num(queryInstr(srsID, "OUTP? 1\n")) + endif +end + + +function readSRSx_ZERO_two_omega(srsID, srsID_two_omega, fdID, channel2D, dT_max, cB_period, npts, VMAX, delay) //Units: rad + variable srsID, srsID_two_omega, fdID, dT_max, cB_period, npts, VMAX, delay + string channel2D // Fastdac channel for the BBG gate + + + variable rescale = 1e4/(getsrsSensitivity(srsID_two_omega)/1e3) + + nvar CompDir + + // sets the direction of how channel2D of fdID will be adjusted + variable multipoint = 2 + Make /N=(multipoint)/O READING + + variable j = 0 + do + asleep(delay) + READING[j] = rescale*str2num(queryInstr(srsID_two_omega, "OUTP? 1\n")) // get value for x + j += 1 + while (j <= multipoint-1) + + variable READING_AVG = mean(READING) + + if (abs(READING_AVG) < dT_max) + return READING_AVG/rescale + else + print("Adjusting operating point of SET") + + variable i = 0 + + // get starting value of the fastdac + double V0 = getFDACOutput(fdID, 8) + double max_window = V0 + CompDir*cB_period + if (abs(max_window) > VMAX) + CompDir = CompDir*-1 + endif + + // estimate the local derivative by doing a second order finite difference approximation + double h = cB_period/npts // step size in finite difference + + double PEAK_X, PEAK_Y, PEAK_idx + + Make /N=(npts)/O HIST_Y // recording of SET current + Make /N=(npts)/O HIST_X // recording of SET POINT + double setpoint, grad, new_grad, R0, R1 + variable peaked = 0 + + setpoint = V0 + sc_sleep(delay) + HIST_Y[0] = str2num(queryInstr(srsID, "OUTP? 1\n")) + HIST_X[0] = setpoint + + print "Coarse iteration", 0 + print "V2Dx111", HIST_X[0] + print HIST_Y[0] + + PEAK_Y = HIST_Y[0] + PEAK_X = HIST_X[0] + PEAK_idx = 0 + + grad = 0 + + i = 1 + do + setpoint = V0 + CompDir*i*h + RampMultipleFDAC(fdID, channel2D, setpoint) // INCREASE V2D + sc_sleep(delay) + + HIST_Y[i] = str2num(queryInstr(srsID, "OUTP? 1\n")) + HIST_X[i] = setpoint + + if (abs(HIST_Y[i]) > abs(PEAK_Y)) + PEAK_Y = HIST_Y[i] + PEAK_X = HIST_X[i] + PEAK_idx = i + endif + print "Coarse iteration", i + print "V2Dx111", HIST_X[i] + print HIST_Y[i] + + new_grad = (HIST_Y[i] - HIST_Y[i-1])/(HIST_X[i] - HIST_X[i-1]) + if (new_grad*grad < 0) + peaked = 1 + endif + grad = new_grad + i += 1 + while(i < npts && peaked == 0) + + + h = max(abs(HIST_X[PEAK_idx-1] - HIST_X[PEAK_idx+1]), 0.4)/ceil(npts/2) + peaked = 0 + Make /N=(ceil(npts/2))/O HIST_Y2 // recording of SET current + Make /N=(ceil(npts/2))/O HIST_X2 // recording of SET POINT + + V0 = HIST_X[PEAK_idx-1] + RampMultipleFDAC(fdID, channel2D, V0) + + sc_sleep(1) + HIST_Y2[0] = str2num(queryInstr(srsID, "OUTP? 1\n")) + HIST_X2[0] = V0 + + print "Fine iteration", 0 + print "V2Dx111", HIST_X2[0] + print HIST_Y2[0] + + double PEAK_X2, PEAK_Y2, PEAK_idx2 + + PEAK_Y2 = HIST_Y2[0] + PEAK_X2 = HIST_X2[0] + PEAK_idx2 = 0 + grad = 0 + + i = 1 + do + setpoint = V0 + CompDir*i*h + RampMultipleFDAC(fdID, channel2D, setpoint) // INCREASE V2D + sc_sleep(delay) + + HIST_Y2[i] = str2num(queryInstr(srsID, "OUTP? 1\n")) + HIST_X2[i] = setpoint + + if (abs(HIST_Y2[i]) > abs(PEAK_Y2)) + PEAK_Y2 = HIST_Y2[i] + PEAK_X2 = HIST_X2[i] + PEAK_idx2 = i + endif + print "Fine iteration", i + print "V2Dx111", HIST_X2[i] + print HIST_Y2[i] + + new_grad = (HIST_Y2[i] - HIST_Y2[i-1])/(HIST_X2[i] - HIST_X2[i-1]) + if (new_grad*grad < 0) + peaked = 1 + endif + grad = new_grad + i += 1 + while(i < ceil(npts/2) && peaked == 0) + + if (abs(HIST_Y[PEAK_idx]) > abs(HIST_Y2[PEAK_idx2])) + V0 = HIST_X[PEAK_idx] + RampMultipleFDAC(fdID, channel2D, V0) + print "Ramp to", V0 + else + V0 = HIST_X2[PEAK_idx2] + RampMultipleFDAC(fdID, channel2D, V0) + print "Ramp to", V0 + + endif + sc_sleep(delay*2) + + return str2num(queryInstr(srsID_two_omega, "OUTP? 1\n")) + endif +end + +function readSRSx_HIGHSENSE(srsID) //Units: rad + variable srsID + setsrssensitivity(srsID, 500) + return 0 +end + +function Cal_V2(V1, R1, R2, Delta) + variable V1, R1, R2, Delta + return R2*(V1/R1 - Delta) +end + +function Cal_Delta(V1, V2, R1, R2) + variable V1, V2, R1, R2 + return V1/R1 - V2/R2 +end + +function Cal_shift(iset_dc, A, freq, D0) + variable iset_dc, A, freq, D0 + variable diff = iset_dc-D0 + if (abs(diff) > A) + diff = A + endif + + double xi = asin((diff)/A)/freq + + double d1, d2, d3 + d1 = 0 - xi + d2 = pi/freq - xi + d3 = -1*pi/freq - xi + + print d1, d2, d3 + + return d1 +end + +function rampfastdacdelta(instrID, instrID2, R1, R2, Delta, channels, channels2, setpoint) +variable instrID, instrID2, Delta, R1, R2, setpoint +string channels, channels2 + +RampMultipleFDAC(instrID, channels, setpoint); +RampMultipleFDAC(instrID2, channels2, Cal_V2(setpoint, R1, R2, Delta)); +end + +function Scan2FastDacSlow(instrID, instrID2, start, fin, R1, R2, Delta, channels, channels2, numpts, delay, ramprate, iset_dc, A, freq, D0, [y_label, comments, nosave]) //Units: mV + // Scans two channels from two different fastdacs + // instrID is the main fast dac, which is swept from start to fin + // instrID2 is the secondary fastdac + // R1 and R2 are voltage divider ratios + // Delta is the voltage difference that is maintained between channels of instrID and instrID2 + // channels should be a comma-sepa, rated string ex: "0, 4, 5" + variable instrID, instrID2, start, fin, , R1, R2, Delta, numpts, delay, ramprate, nosave, iset_dc, A, freq, D0 + string y_label, channels, channels2, 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 // Note, more like a BD scan if going slow + initScanVars(S, \ + instrIDx=instrID, \ + startx=start, \ + finx=fin, \ + numptsx=numpts, \ + delayx=delay, \ + rampratex=ramprate,\ + instrIDy=instrID2, \ + starty= Cal_V2(start, R1, R2, Delta), \ + finy= Cal_V2(fin, R1, R2, Delta), \ + numptsy=numpts, \ + delayy=delay, \ + rampratey=ramprate,\ + y_label=y_label, \ + comments=comments) + + S.is2d=0 + + RampMultipleFDAC(instrID, channels, start); + RampMultipleFDAC(instrID2, channels2, Cal_V2(start, R1, R2, Delta)); + + + // Let gates settle + sc_sleep(10) + + // Make Waves and Display etc + InitializeScan(S) + + // Main measurement loop + variable i=0, j=0, setpoint, setpoint2, shift + do + setpoint = start + (i*(fin-start)/(S.numptsx-1)) //the 2nd Keithley, y corresponds to i + setpoint2 = Cal_V2(setpoint, R1, R2, Delta) //the 1st Keithley, x corresponds to j + + + RampMultipleFDAC(instrID, channels, setpoint); + RampMultipleFDAC(instrID2, channels2, setpoint2); + sc_sleep(S.delayx) + +// iset_dc = getFADCchannel(instrID, 0) +// shift = Cal_shift(iset_dc, A, freq, D0) +// start = start - shift +// fin = fin - shift +// setpoint = start + (i*(fin-start)/(S.numptsx-1)) //the 2nd Keithley, y corresponds to i +// setpoint2 = Cal_V2(setpoint, R1, R2, Delta) //the 1st Keithley, x corresponds to j + + RecordValues(S, i, j) + i+=1 + j+=1 + + while (i