esrf

Beamline Instrument Software Support
SPEC Macro documentation: [ Macro Index | BCU Home ]

#%TITLE% k6514.mac
#%NAME% Extra functionalities for keithley 6514 on top of multim.mac
#
#%CATEGORY% Detection, Multimeter
#
#%DESCRIPTION% This macro set adds specific functionnalities to the general 
#   %B%multim%B% macro set to operate the electrometer k6514. The k6514 in an 
#   electrometer that can measure %B%current%B%, %B%voltage%B%, 
#   %B%resistance%B% or %B%charge%B%.  
#%BR% %BR%
#   It is particulary useful in case of %B%GPIB timeout%B% according to his 
#   auto delay settings which can be greater than the spec timeout.
#   For avoiding %B%GPIB timeout%B%, a current measurement used with a 
#   normalizing photodiode with a keithley 6514 in autorange must have a 
#   minimum autorange lower limit set to 2nA.   
#
#%EXAMPLE%
# %DL%
# %DT%#k6514_init counter=c6514 function=amps range=auto llim=2e-9
# %DD%This maco configure the counter c6514 in current, enables autorange and selects autorange lower limit to 2nA.
#
#%OVERVIEW% 
#%DEPENDENCIES% 
#%SETUP% This macro is an add-on to multim. %B%multimsetup%B% must be used before any k6514 functions.
#
#%END%


#%IU%(arg) Select a measurement function.
#%MDESC% arg must be "amps" or "volts" or "ohms" or "coulombs".
def _k6514_setfunction(function)  '{
     if(function=="amps") {
      if(K6514_DBG) {printf ("%s in _k6514_setfunction set function: CURR\.\n",counter)}
      function=sprintf("FUNC \'CURR\'")
    }
    if(function=="volts") {
      if(K6514_DBG) {printf("%s in _k6514_setfunction set function: VOLT\.\n",counter)}
      function_mode=sprintf("FUNC \'VOLT\'")
    }
    if(function=="ohms") {
      if(K6514_DBG) {printf("%s in _k6514_setfunction set function: RES\.\n",counter)}
      function=sprintf("FUNC \'RES\'")
    }
    if(function=="coulombs") {
      if(K6514_DBG) {printf("%s in _k6514_setfunction set function= CHAR\.\n",counter)}
      function=sprintf("FUNC \'CHAR\'")
    }
    return(function)
    
}'

#%IU%(arg1,arg2,arg3,arg4,arg5) Check the setings arguments.
#%MDESC% " counter" must not be empty.
# "function" must be "amps" or "volts" or "ohms" or "coulombs".
# "range" must be auto or not empty.
# If llim and hlim are defined, hlim must be greater than llim.
def _check_argument(counter,function,range,llim,hlim) '{

  if(cnt_num(counter) <= 0 || counter == 0) {
            printf ("%s counter must be a valid counter defined in the config file.\n",counter)
            return(-1)
   }
      
   if(function != "amps" && function != "volts" && function != "ohms" && function != "coulombs"){
            print "Syntax error in the function parameter.\n"   
            print "You did not enter amps or volts or ohms or coulombs.\n"
            return(-1)
   } 
  
   
   if (range == "auto") {
   
            if(llim !=-1 && hlim !=-1 && llim >= hlim){
                          printf("Error for %s: the higher limit (%1.0e) of autorange should be bigger than lower limit (%1.0e).\n",counter,hlim,llim)
                          return(-1)
            }
            
   } 
   else if(range == "" ){
            printf("Error for %s: the range is missing.\n",counter)
            return(-1)
   
   }    
}'

#%UU% initialisation parameters
# k6514_init counter=<counter_name> function=<function_name> range=<value> [llim=<value>] [hlim=<value>]
#%MDESC% Depending on the mode you can issue the following commands:
#%UL%
#%LI%k6514_init counter=counter_name function=amps range=200e-6
#%LI%k6514_init counter=counter_name function=amps range=auto 
#%LI%k6514_init counter=counter_name function=amps range=auto llim=2e-9 
#%LI%k6514_init counter=counter_name function=amps range=auto hlim=2e-3
#%LI%k6514_init counter=counter_name function=amps range=auto llim=2e-9 hlim=2e-3

#%XUL%
def k6514_init '{
  global MULTIM K6514_DBG
  K6514_DBG = 0
 
  if ($# < 3) {
   printf("Usage k6514_init counter=counter_name function=function_name  range=range_mode  [llim=llim_autorange_value] [hlim=hlim_autorange_value]\n")
   exit
  } else {
    if(_k6514_init("$*")== -1) {
      exit
    }
  }
}'

def _k6514_init(args) '{
  global MULTIM
  local nargs,larg1,larg2,larr, cntr

  list_init larg1
  list_init larg2
   nargs=list_splitadd(larg1, args)
  if(K6514_DBG) {p "larg1 " ; list_list(larg1)}
  
  for (i=1; i<=list_n(larg1); i++) {
      if (split(larg1[i], larr, "=") > 1){
         list_remove(larg1, larg1[i--])
         list_add(larg2, larr[0])
         list_setpar(larg2, larr[0], "value", larr[1])
      }
   }
    
 if(K6514_DBG) {p "larg2 " ; list_list(larg2)} 
 
 counter=list_getpar(larg2,"counter","value")
 cntr = cnt_num(counter)
 function=list_getpar(larg2,"function","value")
 range=list_getpar(larg2,"range","value")
 llim =list_getpar (larg2,"llim","value")
 hlim =list_getpar (larg2,"hlim","value")
  
 if(K6514_DBG){     
   p "====="
   p list_getpar(larg2,"counter","value")
   p cntr
   printf ("function = %s \n",function)
   p list_getpar(larg2,"range","value")
   p list_getpar(larg2,"llim","value")
   p list_getpar(larg2,"hlim","value")
  }
 
 if(_check_argument(counter,function,range,llim,hlim) == -1){exit}

     
 gpib_put(MULTIM[cntr]["address"], "*RST")
 MULTIM[cntr]["sample"]=1 # switch averaging off
 gpib_put(MULTIM[cntr]["address"], "SYST:ZCH ON")# enable zero check
 
 
 function=_k6514_setfunction(function) # set the string to be send by gpib
 printf ("%s select: %s \n",counter,function)
 gpib_put(MULTIM[cntr]["address"],function)
 
 gpib_put(MULTIM[cntr]["address"], "SYST:ZCOR ON") # perform zero correction
 gpib_put(MULTIM[cntr]["address"], "SYST:ZCOR OFF") # stop zero correction
    
if (range=="auto") {
   printf("%s select autorange.\n",counter)
   gpib_put(MULTIM[cntr]["address"], "CURR:RANG:AUTO ON") # enable auto range
    
   if(llim != -1){         
                printf("%s select autorange lower limit : %1.0e\n",counter,llim)
                gpib_put(MULTIM[cntr]["address"],sprintf("CURR:RANG:AUTO:LLIM %g\n",llim)) # lower limit for autorange
    }
    
   if(hlim != -1){
              printf ("%s select autorange upper limit : %1.0e\n",counter,hlim)
              gpib_put(MULTIM[cntr]["address"],sprintf("CURR:RANG:AUTO:ULIM %g\n",hlim)) # higher limit for autorange
    }
    
}
else{
     printf("%s select a fixed range : %g\n",counter,range)
     gpib_put(MULTIM[cntr]["address"],sprintf("CURR:RANG %g\n",range)) 
} 
 gpib_put(MULTIM[cntr]["address"], "SYST:ZCH OFF") # disable zero check
 gpib_put(MULTIM[cntr]["address"], "SYST:AZER OFF") # disable automatic autozeroing
 gpib_put(MULTIM[cntr]["address"], "READ?") # read one value to enable display
 gpib_get(MULTIM[cntr]["address"]) # empty the buffer 
}'
 
#%MACROS% 
#%IMACROS% 
#%AUTHOR% A. Mauro - G. Pepellin 
#%TOC%