Welcome | spec | C-PLOT | Support | Users | Contact
 
Contents -> STANDARD MACRO GUIDE -> Temperature Control Macros
spec Manual


3.10. - Temperature Control Macros

    te                              # Read or set the temperature
    settemp                         # Set the temperature
    measuretemp                     # Measure the temperature
    showtemp                        # Show temperature parameters
    teramp                          # Ramp the temperature
    


Methods for handling temperature control and other experimental parameters are likely to vary greatly from lab to lab and experiment to experiment. You may be able to modify these standard macros to suit your specific needs.

The temperature control model assumed by these macros uses two independent instruments: one instrument to control the temperature and one instrument to measure the temperature. The following global variables are used by the macros:
 TEMP_SP   The set point of the controller in ohms, volts, etc. 
 T_LO_SP   The lower limit for the controller set point. 
 T_HI_SP   The upper limit for the controller set point. 
 DEGC_SP   The temperature from which the set point is derived. 
  
 TEMP_CS   The value of the temperature sensor in ohms, volts, etc. 
 DEGC   The measured temperature. 



The macro below displays the current set point and measured temperature.
    # Display temperature parameters
    def showtemp '
          measuretemp
          printf("Temperature Setpoint = %g (%gC)\n",TEMP_SP,DEGC_SP)
          printf("            Measured = %g (%gC)\n",TEMP_CS,DEGC)
    '
    
You must supply the macro measuretemp. It should read TEMP_CS from the temperature sensor and convert it to DEGC. Sample measuretemp macros are given below.

The te macro is the one you would use most often to display or set the temperature set point.
    # Simple read or set temperature
    def te '
          if ($# == 1) {
                  settemp $1
                  qcomment "Temperature Setpoint at %g" "TEMP_SP"
          }
          onp; showtemp; offp
    '
    
If invoked without arguments, it simply displays the current temperature parameters. Otherwise it invokes the settemp macro. The settemp macro checks its argument against the set point limits and then calls the _settemp macro, which you must supply.
    # Assign the temperature setpoint
    def settemp '
          if ($# != 1) {
                  print "Usage:  settemp set_point"
                  exit
          } else {
                  local _1
                  _1 = $1
                  if (_1 < T_LO_SP || _1 > T_HI_SP) {
                          printf("Temp limits are %g to %g.\n",T_LO_SP,T_HI_SP)
                          exit
                  }
                  TEMP_SP = _1
                  _settemp
          }
    '
    

Here are examples of _settemp macros from several installations (the symbol _1 is defined in settemp):
    # Write setpoint to a Lakeshore 82C Controller on GPIB bus
    def _settemp '
          gpib_put(12, sprintf("S%6.4f", _1))
    '
    # Write setpoint to home-made GPIB device used at MIT
    def _settemp '{
          local _s
          _s = int(32767*_1/10)
          gpib_put(4, sprintf("%c%c%c%c\160\200",\
                  0x80|( _s     &0xF), 0x90|((_s>>4 )&0xF),\
                  0xA0|((_s>>8 )&0xF), 0xB0|((_s>>12)&0xF)))
    }'
    # Write setpoint to a home-made device used with CAMAC at Harvard
    def _settemp '
          ca_put(bcd(10000*_1), 0, 0)
    '
    
Here are examples of different measuretemp macros:
    # Read parameters from a Lakeshore 82C Controller on GPIB bus
    def measuretemp '{
          local _s
          gpib_put(12,"W0")
          _s=gpib_get(12)
          TEMP_SS=substr(_s,1,6)
          TEMP_CS=substr(_s,9,6)*100
          RtoT_0 DEGC TEMP_CS
          TEMP_SP=substr(_s,17,6)
          RtoT_0 DEGC_SP TEMP_SP
    }'
    # Read setpoint from CAMAC and temperature from GPIB device
    def measuretemp '
          TEMP_CS = gpib_get(1)/1000
          RtoT_0 DEGC TEMP_CS
          TEMP_SP = dcb(ca_get(0, 0))/10000
          RtoT_0 DEGC_SP TEMP_SP
    }'
    
Keep in mind that measuretemp is also called at each iteration of the standard scan macros.


The macro RtoT_0, used above, is one of several in the standard package that convert between degrees C and kilohms for common thermistors:
    #  Temperature to kohms
    def TtoR_0 '
          local _k        # YSI 44011 (100kohm @ 25C)  20 to 120 C
          $1 = exp(-11.2942              +5.3483e3   /(_k = ($2) + 273.15)\
                    -1.42016e5  /(_k*_k) -1.172e7    /(_k*_k*_k))
    '
    #  Kohms to temperature
    def RtoT_0 '
          local _l        # YSI 44011 (100kohm @ 25C)  20 to 120 C
          $1 = (1/(+2.2764e-3            +2.20116e-4 *(_l = log($2))\
                   +2.61027e-6 *_l*_l    +9.02451e-8 *_l*_l*_l) - 273.15)
    '
    
(The four parameters in each equation were obtained by fitting a table of values supplied by the manufacturer of the thermistors. No guarantees are made about the accuracy of the fitted parameters.)

The following macro will gradually change (or ramp) a temperature controller to a new set point. If the ramp time is greater than 500 seconds, the temperature is changed every 10 seconds, otherwise the temperature is changed every 2 seconds.
    # Read or set or ramp the temperature
    def teramp '{
          if ($# == 1) {
                  te $1
          } else if ($# == 2) {
                  local _i _s1 _f1 _d1 _rtime _stime
                  _f1 = $1
                  _rtime = $2
                  _stime = _rtime < 500? 2:10
                  _s1 = TEMP_SP
                  _d1 = (_f1 - _s1) / _rtime * _stime
                  qcomment "Ramp Temp Setpoint from %g to %g" "_s1,_f1"
                  for (_i=0; _i<=_rtime; _i+=_stime, _s1 += _d1) {
                          settemp _s1
                          measuretemp
                          printf("Set=%7.4f  Meas=%7.4fC\r",TEMP_SP,DEGC)
                          sleep(_stime)
                  }
                  showtemp
          } else {
                  print "Usage:  teramp set_point  or  teramp set_point time"
                  exit
          }
    }'
    



  Top
  Prev | Next