Temperature Control

by Peter Duesing, 1997
This should be read ON A COMPUTER, so you can jump past all the tedious bits RIGHT TO WHERE YOU WANT. Start up netscape, open up tc1.html in the TCONTROL folder on our server with the ever-changing name...Have a nice day!

Basic concept:

TV6 or the user selects a set temperature value.
This value is transmitted to the Octagon
The Octagon receives temperature reading from the temperature sensor electronics in the TC-box, which in turn read the RTD on the sample stage.
Based on the above the Octagon computes a sensible heating/cooling current value and transmits a corresponding analogue signal to the current control electronics in the TC-box.
The current control electronics control the current provided by a big external power supply flowing through the peltier heating elements according to the signal received from the Octagon.

 Come again graphically? A Schematic!

The active components

  1. Octagon
  2. Using smartlink on the PC
  3. NIM-BIN
  4.  TC-Box
  5. Bits in the sample cell
  6. Temperature control program
  7. Performance
  8. Safety features

1. The Octagon

The Octagon is a - not very powerful - computer with a variety of easy to use connections to the outside world. Boiled down to essentials, it receives a temperature reading (in the form of an input voltage) from the TC-box, runs a BASIC program to compute a suitable output current, given a set-voltage (provided either from the computer running TV6 via an RS232 lead labeled "J1" or by toggling switches on the TC box, which corresponds to sending signals on various lines of the Octagon J3 port) and sets the computed current in the form of an output voltage (0-5V), which is transmitted to the TC box.

TV6 can generally interface with the Octagon and alter the values for the set temperature (S% in the temperature control program) or receive the measured temperature (T%). It does this through a program called smartlink, which is also used for downloading the initial BASIC program to the Octagon and communicating to the Octagon in real-time. While the temperature control program is running, the Octagon logs back the critical parameters of the temperature control program to the main computer, which can be observed (and presumably recorded) in smartlink.

 On the PM beam-line the Octagon is also responsible for controlling the shutters. Again simply by sending out a signal on one of its output ports, which is converted into the sudden current release from some large capacitors to a solenoid powering the shutters.

 The Octagons are placed into individual boxes, which include a power-supply and a little LCD screen used mostly for displaying the current temperature or, while manually setting, the set temperature.

Octagon connections to the outside world are:

Connections inside the Octagon box

Octagon board slides into power supply socket.
Power supply mains cable is connected to pins on NIM.
LCD screen plugs into J6 and the 5V port on the power supply board.
Two (optional) digital analogue converter chips sit in slots U11 and U12. Jumper points W2 and W3 are set to give appropriate voltage range. These are responsible for DA0 and DA1.
EPROM (optional non-volatile memory) sits in slot U3. W1 jumper selects appropriate type.

 Octagon manuals are located both in the computer room and in the equipment filing cabinets under "O".

2. Using Smartlink

Smartlink is the terminla emulation software, that allows a PC to talk to the Octagon. Start by typing "sl" while in the "smartlk" directory.
Allows terminal emulation access to the Octagon and thus facilities such as editing programs line by line using the Octagons primitive in-built editing facilities (See Octagon manual).
Hitting "escape" interrupts programs running on the Octagon.

 Can also down-load:
Control+"D" gets you into down-loading mode. Type in name of file to download... watch it get there...

3. The NIM-BIN

We use the NIM-BIN largely to provide housing and mains. On PM it also provides 24 V in lieu of an internal power supply in the TC-Box. Check appropriate pin numbers for the socket on the back of NIM boxes in the NIM manuals in the equipment filing cabinets under "P" (for Phillips) or in the NIM-BIN section of the temperature control ring binder.

 Commonly used pins are:
28: +24V
29: -24V
33: 117V AC (H)
34: Power Return Ground
41: 117 V AC (N)
42: High Quality Ground

4. The TC Box

The TC box houses both the temperature reading electronics and the current control electronics.

Temperature reading electronics

Temperature is read using an Analog Devices AC1211/AC1213 Board. Documentation is found in the Analog Devices Databook under 2B30/2B31J or in the T-sensor board section of the temperature control ring binder. The board slots into an edge connector. The following pins are connected:
B: - sense
K: -Vs
L: +Vs
N: Ground
V: Output
W: - Input
Z: + Input
4: Iexc out
 It sends out a sensing current to the RTDs in four-wire mode from Pins B and 4. The small return signal coming in from the other two wires on pins W and Z is amplified to give an output voltage on pin V, relative to Ground on pin N. This output signal is then transmitted to the Octagon's analogue input channel AD0, as well as the current control electronics for hardware overheat protection. The board is powered on pins K and L from a small internal power supply, to avoid long term drift.

Current control electronics

The current control electronics (see schematics) regulate the heating/cooling current going through the Peltiers, in proportion to a 0-5V output provided by the Octagon's DA0 channel. The direction is switched according to a digital signal on pin 10 of the Octagon J3. Power is provided by an external power supply with a large current rating (~6 A). Further features of the current control electronics include hardware overheat protection, which shuts down the current when the temperature reading exceeds a reference value as determined by the overheat trimpot setting on the TC-box front panel. A yellow LED is lit in this case. While the current is going through the Peltiers in the heating direction, a red LED is lit, when a cooling current is sent out, a green LED is lit.

Manual Tset switches

The final component of the TC-box are the manual Tset switches (see schematics), which are directly connected to the Octagon J3 lines. The Octagon is programmed such that if the T-set switch is toggled to manual, the two buttons can be used to move the set temperature up or down, as indicated by the readings on the Octagon display.

 See "Designing the temperature control electronics" for more details of the TC-Box interior.

5. Bits in the Sample cell

Changing the Peltiers:

Each sample stage is heated or cooled by two peltiers which are sandwiched between a backplate held at constant temperature using a water bath and the sample stage itself. Replacing the Peltiers, it is important to conserve polarity (unlike resistive heating, the direction of current matters). Also Peltiers vary in thickness, so care should be taken to match two of very much the same thickness. Thermal contact between the Peltiers and both backplate and sample stage is improved with that horrible white gooey paste, that gets everywhere but can be washed off...

 Peltier life ends when the connections corrode, which is largely a function of operating hours not under vacuum. Catch the drift?

 When maintenance is being done on the beam-line and the sample-cell is thus not under vacuum for prolonged periods, it is probably a good idea to shut off any heating or cooling current (switch of the appropriate power supply), and to avoid water bath temperatures running through the Peltier backplates that cause condensation.

Changing the RTDs:

The RTDs have fragile connections. To avoid those constantly being broken, they are glued to the sample stage, from where flexible wires carry the signals to the next connector. This arrangement is very worthwhile and avoids not only the constant hunt for the soldering iron, but also decreases the likelihood of molten sample cells brought about by temperature readings un-coupled from the location of heating. Further information about RTDs can be found in the OMEGA catalogue or in the RTD section of the temperature control ring binder.

Calibrating the RTDs:

The Octagon's temperature control program includes a clever little routine which takes most of the pain out of calibrating the RTDs, by going through a series of reference measurements with high accuracy resistors and then computing the constants the program requires to work out the right temperature automatically. The user then still has to physically change these constants in the program, which are the DATA elements in line 10100, using some suitable editor. Hint: If the new constants are a long way off the old ones, something is WRONG.

 Start the program by escaping the control program and typing (in smartlink) " GOSUB 4000" or "GOSUB .. calibrate temperature conversions". Can also push the two set-buttons on the TC-box simultaneously, or something like that. Have the three resistors (133.00 Ohms, 114.69 Ohms, 93. Ohms) ready. They come mounted in one box with a convenient connector to plug in at the sample chamber and are located in the " T-calibration" box in the " X-ray 1" metal cabinet in the old Rigaku room. Further information about high precision resistors can be found in the Vishay catalogue or in the Precision Resistors section of the temperature control ring binder.

Follow instructions, i.e. connect a new resistor every time the display tells you to and then press and hold the Tset up switch. The required constants finally appear on the PC screen in smartlink. Edit them in the file in the smartlk directory and download the corrected program. Save the program into non-volatile memory.

6. T-control Program


Let's have a look at the routine actually used to compute the output current and thereby regulate the temperature. Should realize that in most applications the actual ramping time from one set temperature to another is not critical. Instead overshoot should be avoided, so as not to mess with the inherent hystereses of biological systems. A long-term control stability of 0.1 K would also be nice. The existing programs use a very robust little routine to do that (basically proportional/integral/derivative (PID) control) that cycles every 0.3 seconds or so and each time adjusts the current according to:

 In+1 = I n + c1 (Tr-Ts) + c2 dT/dt

 where Tr is the temperature reading and Ts is the set temperature.

 By choosing the constants conservatively enough, this works fine throughout the temperature range (even when dT/dI is not perfectly constant), can deal with changes in the reference temperature quite readily (i.e. changing the temperature of the Peltier water bath does not affect things) and is not even particularly sensitive to sample stage geometry (within reason), so that the same values for c1 and c2 can in fact be used on all beam-lines.

 Fine-tuning c1 and c2 to get fastest ramping (making them too large induces oscillations) is adventurous, not only because of current/temperature non-linearity, but also because the T-reading and particularly the routine computing dT/dt have a lot of noise on it (quite comparable to our long-term precision goal), that can throw off long-term stability.

 Effectively, we have ramp-times not much worse than 5 minutes for any T-distance now, and I guess we can live with that. If a better performance is required , let me humbly suggest a paper by Duesing et al. (Rev. Sci. Inst. due out 12.96) which talks about a nifty routine which however requires tedious T-I calibrations and generally a lot more thinking.

Commented listing

Anyway, here is the current T-control program, with my added comments in bold. The language is the Octagon's own breed of BASIC. Details can be found in the Octagon manual. In normal operation it will control the temperature and log the relevant parameters (temperature reading, set temperature, rate of change of temperature and output current) on the monitor.

 Only flaw I could find is that upon turning on it might overshoot on the first T-setting, as it will remember the last current value put out - which might be very large - and take it from there. As it doesn't only accelerate very slowly, but also brakes very slowly, this might send it too far by a full 5 K. Can remedy this real easy by adding a line C% = 0 somewhere for start-up, but that would then imply a big temperature deviation if the power only goes out momentarily. Personally, I think that would be worse.

10 CONFIG COM$ 0,0,1,0,0,0
20 CONFIG AIN 0,0,1 That's the T-reading channel
30 CONFIG 4,64:CONFIG 5,0,1,0,1,1: ..Sets up A&C as input, B as output
40 ON BIT 0,66,0 GOSUB 3500:.. manual set If the Manual-set switch is toggled-
45 ON BIT 1,66,2 GOSUB 3700:..RESET CURRENT If both buttons are pressed-
60 DIM T(8):DIM LU(14): FOR I=1 TO 8:T(I)=0:NEXT I
70 C3=100:CZ=C%:C2=1.2:C1=C2/100:C7=1000:C8=-5000:C9=25000
Set a few constants. C1 and C2 are identical to above text. C8 is minimum T. C7 is (disabled) distance between read and desired temperature which instantaneously induces max. heating or cooling. C9 is maximum allowed temperature.
90 B=-1
100 ON COM$ 0 GOSUB 3000
140 IF ABS(S%)> 11000 THEN S%=2000 Make sure T-set is not above 110 C
150 IF ABS(C%)>4095 THEN C%=0 Make sure output current is not above max.
1000 .. Main Temperature control loop
1010 GOSUB ..RTD:.. get current temperature
1020 CZ = C%
1030 IF T% < C8 THEN PRINT#2:PRINT#2,"RTD Disconnected";:AOT 0,0:GOTO
If the T-reading is lower then the minimum expected Temperature, then that would indicate that the measurement is flawed, thus give a warning and set out zero current (AOT 0,0)
1040 C5=C2
1045 IF S%<0 THEN C5=C2*2
Different C% (C2 in text) settings for positive and negative currents. Not sure if that's good.
1050 .. IF (S% - T%) > C7 THEN GOSUB 1400: .. heat at max
Disabled attempt to give instantaneous max. current output for T-ramps. Not a good idea for this set-up, as braking is VERY slow (i.e. would require very large C7)
1051 .. IF (T% - S%) > C7 THEN GOSUB 1500: .. cool at max
1060 C% = CZ+ C1*(S%-T%)- C5 * V% : .. set current
Actual kernel of the entire routine
1070 IF C% < 0 THEN OUT 65,0 ELSE OUT 65,1
Set direction
1080 IF C% > 4095 THEN C%=4095
1090 IF C% < -4095 THEN C%=-4095
Make sure maxima aren't exceeded
1095 IF T% > C9 THEN AOT 0,0:GOTO 1120
Make sure Temperature is not above maximum defined as C9
1100 AOT 0,ABS(C%)
Send out the current
1110 PRINT TICK(0);T%;S%;V%;C%
Log Temperature, set temperature, dT/dt and current on monitor
1115 IF C%*CZ<0 THEN FOR I=0 TO 1000:NEXT I
Avoid rapid toggling of current direction relay
1120 GOTO 1000

 1300 .. get steady current from lut
1310 I1 = INT((S%+4000)/1000)
1320 T1 = (I1-4)*1000: M= (LU(I1+1)-LU(I1))/1000:B=LU(I1)-M*T1
1330 CS = M*S% + B

 Disabled max. heating routine
1400 .. heat at max until within c7 of setpoint
1410 GOSUB ..RTD
1420 IF T% < C8 THEN GOTO 1000
1422 IF T% > C9 THEN AOT 0,0:GOTO 1430
1425 OUT 65,1:AOT 0,4095
1430 PRINT TICK(0)/100;T%/100;S%;V%,4095
1440 IF S% - T% < C7 THEN CZ = CS:V%=0: RETURN
1450 GOTO 1400
1500 REM
1510 GOSUB ..RTD
1520 IF T% < C8 GOTO 1000
1522 IF T% > C9 THEN AOT 0,0:GOTO 1530
1525 OUT 65,0:AOT 0,4095
1530 PRINT TICK(0)/100;T%/100;S%;V%;-4095
1540 IF T% - S% < C7 THEN CZ = CS: RETURN
1550 GOTO 1500

 This part actually reads the temperature and computes dT/dt (V%)
2000 ..RTD
2001 .. read RTD, convert to Temp.
2010 TS = 0:VS = 0
2040 S = 0
2050 FOR K=1 TO C3
2060 S = S + AIN(0)
2070 NEXT K: S = S/C3
2080 T% = X% + Y%*S + Z%*S*S
2100 FOR K=7 TO 1 STEP -1
2105 T(K+1)=T(K)
2110 NEXT K
2120 T(1) = T%
2130 V% = T(1)+T(2)+T(3)+T(4)-T(5)-T(6)-T(7)-T(8):V%=V%/8
2140 IF (B<0) THENPRINT#2:PRINT#2,"Temp ";:PRINT#2,!"###.##";INT(T%)/100;
2145 IF B>=0 THEN PRINT#2:PRINT#2,"Temp ";:PRINT#2,!"###.##";INT(T%)/100;:PRINT#2," C";

 2500 ..CALCHECK
2520 READ X,Y,Z
2530 IF ABS(X%-X) > 5000 THEN X%=X
2540 IF ABS(Y%-Y) > 10 THEN Y%=Y
2550 IF ABS(Z%-Z) > 1 THEN Z%=Z
2555 X%=X: Y%=Y: Z%=Z

2600 ..SETV
2610 FOR I=1 TO 9
2620 GOSUB ..RTD
2630 NEXT I

 3000 .. serial communications
3005 X$=COM$(0)
3010 ON COM$ 0 GOSUB
3011 CLEAR COM$ 0
3012 CONFIG COM$ 0,0,1,0,0,0
3015 PRINT X$
3020 IF X$="G" THEN PRINT!"g #####";T%:GOTO 3090
3030 IF X$="S" THEN 3040
3031 IF X$="C" THEN 5000
3032 IF X$="X" THEN 5400
3035 GOTO 3090
3040 INPUT S%
3045 PRINT#2:PRINT#2,"Set:";S%/100;
3050 IF S% < C8 THEN S%=C8
3060 IF S% > C9 THEN S%=C9
3070 ON TICK 100 GOSUB:B=-1
3090 ON COM$ 0 GOSUB 3000

 3500 .. manual_set
3505 Q=0:QQ=2
3510 PRINT #2
3515 STOP BIT 1
3520 PRINT #2,"Set:";
3530 PRINT #2,!"###.##";INT(S%)/100;
3540 OUT &E8,0
3545 IF Q > 50 THEN QQ = 100
3550 IF S%>C9 THEN S%=C9
3560 IF S%<C8 THEN S%=C8
3570 IF BIT(66,0) = 1 THEN RETURN
3575 IF BIT(66,1) = 1 AND BIT(66,2)=1 THEN QQ = 2:Q=0
3580 IF BIT(66,1) = 0 AND BIT(66,2) =0 THEN GOSUB 4000
3590 IF BIT(66,1) = 0 THEN S%=S%-QQ: Q=Q+1:GOTO 3510
3600 IF BIT(66,2) = 0 THEN S%=S%+QQ: Q=Q+1:GOTO 3510
3610 GOTO 3540
3620 ON BIT 1,66,2 GOSUB 3700:START BIT 1
3700 CZ=0:C%=0: RETURN

 This is the routine that works out the constants to convert an imput voltage into a T-reading, asking you to put in calibration resistors.
4000 .. calibrate temperature conversions
4010 WA=0:WB=0:WC=0:C6=500
4020 PRINT#2:PRINT#2,"calibration";:FOR I=1 TO 5000:NEXT I
4030 PRINT#2:PRINT#2,"contr. cancel";:FOR I=1 TO 5000:NEXT I
4040 .. IF INP(66) AND 1 THEN RETURN
4050 PRINT#2:PRINT#2,"#1 133.00 Ohms";:TA=8730
4060 IF INP(66) AND 4 THEN 4060
4070 FOR I=1 TO 25000:NEXT
4080 FOR I = 1 TO C6: WA = WA + AIN(0): NEXT I : WA = WA/C6
4090 PRINT#2:PRINT#2,"#2: 114.68 Ohms";:TB = 3777
4100 IF INP(66) AND 4 THEN 4100
4110 FOR I=1 TO 25000:NEXT
4120 FOR I = 1 TO C6: WB = WB + AIN(0): NEXT I : WB = WB/C6
4130 PRINT#2:PRINT#2,"#3: 93.01 Ohms";:TC = -1785
4140 IF INP(66) AND 4 THEN 4140
4150 FOR I=1 TO 25000:NEXT
4160 FOR I = 1 TO C6: WC = WC + AIN(0): NEXT I : WC = WC/C6
4170 Z% = (TC-TB)/(WC-WB) - (TA-TB)/(WA-WB):Z% = Z%/(WC-WA)
4180 Y% = (TA-TB)/(WA-WB) - Z%*(WA+WB)
4190 X% = TA - Y%*WA - Z%*WA*WA
4200 PRINT "x% = ";X%
4210 PRINT "y% = ";Y%
4220 PRINT "z% = ";Z%

 5000 ..CYCLE : rem cycle temperature between two setpoints
5010 INPUT "Enter T1,T2,Interval";S1,S2,WT:WT=WT/100
5011 IF WT=0 THEN WT=1
5015 S%=S1
5020 B = 0
5030 ON TICK 100 GOSUB 5300
5035 ON COM$ 0 GOSUB 3000
5300 B=B+1
5310 IF (B MOD WT) = 0 THEN S%=S2
5320 IF (B MOD (2 *WT)) = 0 THEN S%=S1

 5400 ON TICK 100 GOSUB
5410 ON COM$ 0 GOSUB 3000
5420 B=-1

 The last of these contains the T-conversion constants currently in use
10000 DATA -2038,-1112,-532,-113,87,330,571
10010 DATA 789,981,1157,1319,1456,1583,1718
10100 DATA -7455.9,6.06511,9.8959e-5

Saving the Program in non-volatile memory

The Octagons come with optional EPROM or EEPROM attached. When for instance the RTD calibration is changed, the new program wants to be stored in non-volatile memory, to make it come up automatically when the Octagon is switched on (or comes up again after a power-blitch). This is done by down-loading the version of the program wanted (Start Smartlink ("sl" in Smartlk" directory), "Escape" any program that's running, Alt +"D" gives download (type in appropriate file name), wait) typing "Save 0", turning on the "Program" switch on the Octagon, pressing "enter", waiting a few minutes and upon prompt switching off the "Program" switch and again typing "enter". See appropriate page in Octagon User Manual (not programming manual) for more on that.

Location of current temperature control programs

The temperature control programs are stored in the " smartlk" directories on the C-drives of the appropriate PC for every beam-line. Another copy of each is kept on the O-drive, in the " T-Control" (that's " T-Contro" if you happen to be in a DOS environment) folder. Use the following files:

7. Performance

Temperature measurement:

RTDs have:

Temperature control

Given the inaccuracy of the temperature readings, the current set-up will control to within 0.1 K.

 While theoretical maximum heating/cooling rates are large (>1K/s), current software requires up to five minutes between two set temperatures (only slightly dependent on the difference between them).

8. Safety features

We have the already described Vprog pull-down mechanism when T-readings get too high. In addition, whenever the Octagon gets unconvincing (too low) readings it will say "RTD disconnected" and send out zero current. Also at least on SIT there is a thermostat for the back-wall of the Peltiers, which closes down the heating-current when the waterbath is not functioning and heating or cooling sends the back wall temperature off in some direction. (Note that I'm not sure if that works in both directions). What isn't there (and is difficult to achieve) is a current shut-off when the T-reading seems reliable but is in fact disconnected from heating (e.g. because a reference resistor is plugged in). Could include a software routine that throws up question marks if the output current is very large but the slope remains at zero. Have to be clever to avoid triggering when controlling at - 50 °C, say, which will require a large current at equilibrium.