esrf

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

#%TITLE% ASL.MAC
#%NAME% 
#   Temperature scans with the Alpha Sigma Lambda temperature controller
#%CATEGORY% temperature
#%DESCRIPTION%
#This scan measures photon-counts rate as a function of the difference in 
#temperature between two crystals. One thing is to perform a linear 
#temperature ramp as a function of time, while continuously counting, between 
#start and end temperature values. Counts and temperature are continuously 
#read. The temperature difference between the two crystals is directly read 
#from the ASL bridge. The photon count per second rate is calculated all along
#the scan as delta-counts/delta-time between each calculation points. To 
#obtain maximal linearity, the setpoint is set to a new value some time before
#we actually reach the setpoint. The calculated photon per second rate as a 
#function of temperature difference between both crystals is plotted, as well 
#as the temperature difference between crystals as a function of time allowing
#user to check the ramp linearity. 
#%EXAMPLE%
#%DL%
#%DT%aslscan 2 10 8 
#%DD%
#We will do a scan starting at a difference in temperature of 2, ending at 10,
#in 8 steps, i.e. defining temperature increments of 1 degree. Assuming that 
#setpoint reset ratio is 50% (according to 3rd aslsetup request), the first 
#setpoint is set to 2-1*50/100=1.5 (start-increment*ratio). The software waits
#until this is reached before starting the scan itself. Then the counter is 
#started. The first setpoint in the scan is 2.5 (setpoint+increment). When
#temperature go through the value 2 (setpoint-increment*ratio), the setpoint 
#is changed to be 3 (setpoint=setpoint+increment*ratio). %BR%
#The photon per second rate is calculated at this point. Then, when 
#temperature go through the value 2.5 (setpoint-increment*ratio), the setpoint
#becomes 3.5 and so on ... 
#%XDL%
#%END%

#%UI%
#%MDESC%
def asl_calc_ph_sec '
#---------------------------------------------------------------------------

global ASL_PH_SEC ASL_OLDTIME ASL_OLDCOUNTS 

if (ASL_OLDTIME=0) {
	ASL_PH_SEC=0
  	}
else {
  	ASL_PH_SEC = (S[det]-ASL_OLDCOUNTS) / (S[sec]-ASL_OLDTIME)
  	}

ASL_OLDCOUNTS = S[det]
ASL_OLDTIME = S[sec]
'

#%UI%
#%MDESC%
def asl_gpibputc '
#---------------------------------------------------------------------------

if (set_sim(-1)) {
  	printf ("Simulate a put to device %d : %s\n",$1,"$2")
  	}
else {
  	gpib_put($1,"$2")
  	sleep(.3)
  	}
'

#%UI%
#%MDESC%
def asl_gpibputv '
#---------------------------------------------------------------------------

if (set_sim(-1)) {
  	printf ("Simulate a put to device %d : %s\n",$1,$2)
  	}
else {
  	gpib_put($1,$2)
  	sleep(.3)
  	}
'

#%UI%
#%MDESC%
def asl_gpibget '
#---------------------------------------------------------------------------

global ASLSIM ASLSIMC
if (set_sim(-1)) {
  	printf ("Simulate a get from device %d : %s\n",$2,ASLSIM[ASLSIMC++])
  	}
else {
  	sleep(.3) 
  	$1 = gpib_get($2)
  	}
'

#%UI%
#%MDESC%
def asl_end_scan '
#---------------------------------------------------------------------------


#### stop asl controller
asl_gpibputc ASL_GPIB "m0\r"

#### final plot
asl_splot
'

#%UI%
#%MDESC%
def asl_splot '
#---------------------------------------------------------------------------

plot_cntl("filter1")
plot_cntl("-ylog,dots,lines,-ebars")
asl_splot1 1 0 2
plot_move(0,0)
plot_cntl("filter2")
plot_cntl("-ylog,dots,lines,-ebars")
asl_splot1 1 2 3
plot_move(0,3)
'

#%UI%
#%MDESC%
def asl_read_temp '
#---------------------------------------------------------------------------
{
local tr tra

asl_gpibputc ASL_GPIB "d\r"
asl_gpibget tr ASL_GPIB

split(tr,tra)

ASL_TEMP=ASL_SETPOINT+tra[0]

#print "DEBUG: Read temperature " ASL_TEMP
}
'

#%UI%
#%MDESC%
def asl_rplot '
#---------------------------------------------------------------------------

if (PLOT_MODE&128) {
	plot_cntl(sprintf("colors=%s",rplot_col))
	plot_cntl("open")
	}

if ((_stype&8? _g1:NPTS) == 0) {
	plot_cntl("erase")
	plot_range("auto","auto",YMIN,"auto")
	plot_move(0,1,sprintf("Scan %d",SCAN_N))
	plot_move(0,2,ASL_LABEL[$3])
	plot_move(0,-1,ASL_LABEL[$2])
	}

plot_cntl("addpoint")
data_plot($1,0,0,$2,$3)

'

#%UI%
#%MDESC%
def asl_setpoint '
#---------------------------------------------------------------------------

global ASL_SETPOINT ASL_INCR

#### compute SETPOINT

if ("$1"=="prep") {
	ASL_INCR = (ASL_END_TEMP - ASL_START_TEMP) / ASL_NPTS
	ASL_SETPOINT = (ASL_START_TEMP - (ASL_INCR * ASL_INCR_RATIO / 100))
	
	#### debug
	if (set_sim(-1)) {
	  	printf ("Prepare Setpoint : \
			ASL_INCR %f \nASL_START_TEMP %f\n ASL_END_TEMP %f\n\ 
			ASL_NPTS %f\nASL_SETPOINT %f \n ASL_INCR_RATIO %f \n"\
			,ASL_INCR,ASL_START_TEMP,ASL_END_TEMP,ASL_NPTS,\
			ASL_SETPOINT,ASL_INCR_RATIO)
	  	}
	}        

if ("$1"=="loop") {
	ASL_SETPOINT+=ASL_INCR*$2
	
	#### debug
	if (set_sim(-1)) {
	  	printf ("Loop Setpoint : \
		ASL_INCR %f \nASL_SETPOINT %f \n",\
		ASL_INCR,ASL_SETPOINT)
	  	}
	}        

#### send SETPOINT to device 

print "DEBUG: Setting the setpoint to " ASL_SETPOINT 
asl_gpibputv ASL_GPIB sprintf("p%f\r",ASL_SETPOINT)

#### This stupid controller sends us the old temp value if we do not wait
#### for at least 2 seconds. !!!!!!!! So take a nap

sleep(2)
'

#%UI%
#%MDESC%
def asl_splot1 '
#---------------------------------------------------------------------------

if (PLOT_MODE&128) 
{
	plot_cntl(sprintf("colors=%s",splot_col))
	plot_cntl("open")
}
plot_cntl("erase")
plot_range("auto","auto",YMIN,"auto")
plot_move(0,1,sprintf("Scan %d",SCAN_N))

_pl_arg $*

plot_move(0,2,ASL_LABEL[pl_y])
plot_move(0,-1,ASL_LABEL[pl_x])

data_plot(pl_g,0,0,pl_x,pl_y) 

#plot_move(-50,0,splot_res1)
#plot_move(-50,1,splot_res2)

plot_move(0,3)
'

#%UI%
#%MDESC%
def asl_wait '
#---------------------------------------------------------------------------

{
local band_high band_low t oldt teinband waitnotfinished

band_high = ASL_SETPOINT + ASL_STAB_BAND / 2
band_low = ASL_SETPOINT - ASL_STAB_BAND / 2

for (waitnotfinished = 1;waitnotfinished;) {
  	asl_read_temp
 	asl_tell_temp
  	if ((ASL_TEMP >= band_low) && (ASL_TEMP <= band_high)) {
    		teinband = 1
    		oldt = time()

    		for(t=0 ; (t<ASL_STAB_T) && teinband ; t=time()-oldt) {
      			asl_read_temp
      			asl_tell_temp			
      			if ((ASL_TEMP<=band_low) || (ASL_TEMP>=band_high)) {
				teinband=0
				}
      			}
    		if (teinband) {
      			waitnotfinished=0
      			print "\nWait finished"	
      			}
    		} 
  	}
}
'

#%UI%
#%MDESC%
def asl_tell_temp '
#---------------------------------------------------------------------------
printf ("\r Actual Temp: %10.5f",ASL_TEMP)
'

#%UU% <start_temp> <final_temp> <steps_number>
#%MDESC%
#This is the macro that manages the temperature scan . The arguments give the 
#increment value %B%(final_temp> - <start_temp>) / <steps_number> %B%
def aslscan '
#---------------------------------------------------------------------------

#### variables

global ASL_START_TEMP ASL_END_TEMP ASL_NPTS
global ASL_TEMP 

#### check usage aslscan start end npts
aslscan_usage $*

#### initialisations

ASL_START_TEMP = $1
ASL_END_TEMP = $2
ASL_NPTS = $3
ASL_OLDTIME=0
ASL_OLDCOUNTS=0

#### check limits 
aslscan_check_lm

#### definition of emergency stop  cleanup1 

rdef cleanup1 \'
	undef cleanup1
	asl_end_scan
	\'

#### prepare scan

gpib_put(10,"m2\r")
asl_setpoint "prep"
#### todo:Check here if scan possible READ temp and tell user that we will wait
asl_wait
count_em 900000

#### LOOP ######## 

asl_rplot0
asl_setpoint "loop" 1

{
local ii 

for(ii=0 ; ASL_TEMP<=ASL_END_TEMP ; ii++) {
	asl_read_temp
	getcounts
	if (fabs(ASL_TEMP-ASL_SETPOINT) < fabs(ASL_INCR*ASL_INCR_RATIO/100)) {
  	  	print "DEBUG DeltaT = " ASL_TEMP-ASL_SETPOINT " < " ASL_INCR*ASL_INCR_RATIO/100
          	asl_setpoint "loop" (ASL_INCR_RATIO/100)
	  	}
	asl_calc_ph_sec
	data_nput(1,ii,S[sec],S[det],ASL_TEMP,ASL_PH_SEC)
	asl_rplot1
	}
}

undef cleanup1
 
#### stop counter
count_em 0.1

#### final plot
asl_end_scan

'

#%UI%
#%MDESC%
def asl_rplot0 '
#---------------------------------------------------------------------------
plot_cntl("filter1")
plot_cntl("-ylog,dots,lines,-ebars")
plot_cntl("filter2")
plot_cntl("-ylog,dots,lines,-ebars")
'

#%UI%
#%MDESC%
def asl_rplot1 '
#---------------------------------------------------------------------------
plot_cntl("filter1")
asl_rplot 1 0 2
plot_move(0,0)
plot_cntl("filter2")
asl_rplot 1 2 3
plot_move(0,3) 
'

#%UU%
#%MDESC%
#Has to be called first to prepare the scan . It will ask a few questions :
#%UL%
#%LI%1 - Setpoint stabilisation band in degree,
#%LI%2 - Setpoint stabilisation time in sec, %BR%
#both to determine if the setpoint
# is reached or not,
#%LI%3 - Setpoint ratio to reset in %,
#%LI%4 - Lower limit for temperature,    	
#%LI%5 - Upper limit for temperature,    	
#%LI%6 - Temp. controller GPIB address, 	
#%LI%7 - Initial Bridge Current 0..3 (0=0.1, 1=0.3, 2=1.0 3=3.0),
#%LI%8 - Initial Sensitivity 0..2 (0=LOW, 1=MED, 2=HIGH).
#%XUL%
def aslsetup '
#---------------------------------------------------------------------------

global ASL_GPIB 
global ASL_LM_INF ASL_LM_SUP
global ASL_INCR_RATIO ASL_STAB_BAND ASL_STAB_T
global ASL_LABEL ASL_CURRENT ASL_SEN

#### software settings

print "** I will ask you some questions, which will help me to determine"
print "   if we reached the temperature you asked for"

getvar "Setpoint stabilisation band in degree	" ASL_STAB_BAND
getvar "Setpoint stabilisation time in sec	" ASL_STAB_T

print 
print "** To obtain maximal linearity, we will set the setpoint to a new"
print "   value some time before we actually reach the setpoint"

getvar "setpoint ratio to reset it in %	" ASL_INCR_RATIO

####### limits			

print
print "** The following questions will help me to protect your sample"

getvar "Lower limit for temperature    		" ASL_LM_INF
getvar "Upper limit for temperature    		" ASL_LM_SUP

print
print "** Some hardware related questions" 

getvar "Temp. controller GPIB address 		" ASL_GPIB
getvar "Initial Bridge Current 0..3 (0=0.1, 1=0.3, 2=1.0 3=3.0)" ASL_CURRENT 
getvar "Initial Sensitivity 0..2 (0=LOW, 1=MED, 2=HIGH)" ASL_SEN

#### data new group 

data_grp(1,8000,4)

#### plot labeling 

split("Sec. Detector ASL/Temp Ph./sec.",ASL_LABEL)

#### hardware setting 

asl_gpibputv ASL_GPIB sprintf("s%d\r",ASL_SEN) # set sensitivity  
asl_gpibputv ASL_GPIB sprintf("i%d\r",ASL_CURRENT) # set current 
asl_gpibputc ASL_GPIB "u2\r" # set degrees celcius units
asl_gpibputc ASL_GPIB "m2\r" # set deviation mode 

'

#%UI% 
#%MDESC%
def aslscan_usage '
#---------------------------------------------------------------------
if ($#!=3) {
	print "usage : aslscan start end npts"
	exit
	}

if ($3<=0) {
	print " npts should be > 0"
	exit
	}

'

#%UI%
#%MDESC%
def aslscan_check_lm '
#----------------------------------------------------------------------
if ((ASL_START_TEMP < ASL_LM_INF)||(ASL_END_TEMP < ASL_LM_INF)||(ASL_START_TEMP > ASL_LM_SUP)||(ASL_END_TEMP > ASL_LM_SUP)) {
	print "low limit is " ASL_LM_INF
	print "high limit is " ASL_LM_SUP
	exit
	}
'

#%UU% 
#%MDESC%Simply read and print the temperature.
def aslreadte '
#----------------------------------------------------------
asl_read_temp
asl_tell_temp
'

#%UI%
#%MDESC%
def asl_end_pid '
#--------------------------------------------------------------

#### stop asl controller
asl_gpibputc ASL_GPIB "m0\r"

#### final plot
asl_pidsplot 1 0 2
'

#%UI%
#%MDESC%
def asl_pidrplot '
#-----------------------------------------------------------------

if (PLOT_MODE&128) {
        plot_cntl(sprintf("colors=%s",rplot_col))
        plot_cntl("open")
        }

if ((_stype&8? _g1:NPTS) == 0) {
        plot_cntl("erase")
        plot_range("auto","auto",YMIN,"auto")
        plot_move(0,1,sprintf("Scan %d",SCAN_N))
        plot_move(0,2,ASL_LABEL[$3])
        plot_move(0,-1,ASL_LABEL[$2])
        }

plot_cntl("addpoint")
if (PLOT_MODE&2048) {
        data_plot($1,0,0,"all")
        }
else {
        data_plot($1,0,0,$2,$3)
        }
#{
#local c; c = PLOT_MODE&128? 80:COLS
#local pl_g pl_x pl_y; pl_g = $1; pl_x = $2; pl_y = $3
#plot_move(9,2,sprintf("%*.*s",c-9,c-9,rplot_res))
#}
plot_move(0,0)
'

#%UI%
#%MDESC%
def asl_pidsplot '
#-------------------------------------------------------------

if (PLOT_MODE&128) 
{
        plot_cntl(sprintf("colors=%s",splot_col))
        plot_cntl("open")
}
plot_cntl("erase")
plot_range("auto","auto",YMIN,"auto")
plot_move(0,1,sprintf("Scan %d",SCAN_N))

_pl_arg $*

plot_move(0,2,ASL_LABEL[pl_y])
plot_move(0,-1,ASL_LABEL[pl_x])

if (PLOT_MODE&2048) { 
  data_plot(pl_g,0,0,"all")  
  }
else { 
  data_plot(pl_g,0,0,pl_x,pl_y) 
  }

#plot_move(-50,0,splot_res1)
#plot_move(-50,1,splot_res2)

plot_move(0,3)
'

#%UI%
#%MDESC%
def asl_wait_pid '
#--------------------------------------------------------------

{
local  ii simte jj

for (ii=0,jj=0;;ii++) {
  	asl_read_temp
  	getcounts
	if (set_sim(-1)) {
		simte=(1-exp(-ii*0.2))+25
		ASL_TEMP=simte
		S[sec]=ii
  		printf ("Simul a read temp of : %f\n",ASL_TEMP)
  		printf ("Simul a timer val of : %d\n",S[sec])
  		}
	sleep(0.5)
	data_nput(1,ii,S[sec],0,ASL_TEMP,0)
	asl_pidrplot 1 0 2
#  	if (((ii/5)-int(ii/5))==0) {
#		data_nput(1,jj,S[sec],0,ASL_TEMP,0)
#		asl_pidrplot 1 0 2
#		jj++
#		}
	}	

}
'

#%UU% <setpoint>
#%MDESC%
#This macro is there to help users in tuning the P I D terms of the controller.
#%BR%
#The setpoint is send to the controller, the timer is started and then the 
#temperature as a function of time is plotted, showing the system response to 
#a setpoint increment.

def aslpid '
#-------------------------------------------------------------------------

#### variables

#### check usage aslpid setpoint

if ($#!=1) 
{
        print "usage : aslpid setpoint"
        exit
}

#### initialisations

ASL_SETPOINT=$1

#### check limits 

if ((ASL_SETPOINT < ASL_LM_INF)||(ASL_SETPOINT > ASL_LM_SUP)) {
        print "low limit is " ASL_LM_INF
        print "high limit is " ASL_LM_SUP
        exit
	}

#### definition of emergency stop  cleanup1 

rdef cleanup1 \'
        undef cleanup1
        asl_end_pid
        \'

#### prepare scan

gpib_put(10,"m2\r")

asl_setpoint 
#### check if setpoint is higher than temperature READ temp and tell user 
#### that we will wait
if (set_sim(-1)) {
	simte=25
	}

count_em 900000

#### LOOP ######## 

plot_cntl("-ylog,dots,lines,-ebars")
asl_wait_pid

undef cleanup1 

#### stop counters
count_em 0.1

#### final plot

asl_end_pid


'

#%MACROS%
#%IMACROS%
#%ATTENTION%
#The controller is in deviation mode during the scan to allow setpoint control.#Ending the scan means that you turn it back to direct mode. No more feedback 
#control is done and the direct temperature of one of the two crystals is read.
#%DEPENDENCIES%
The file asl.mac has to b read in
#%AUTHOR% Jorg KLORA, Marie-Claire LAGIER - 01.12.93
#%TOC%