DECLARE SUB psdac488getcv (c%, v!) DECLARE SUB psdac488setcv (c%, v!) DECLARE SUB pshp3457cmon (c%) DECLARE SUB pshp3457cv (c%, v!) DECLARE SUB ips123checkpar (ok$) DECLARE SUB ips123getdac (imag!) DECLARE SUB ips123getpsni (nps%, ips!) DECLARE SUB ips123logpsni (logfile$, nps%, ips!) DECLARE SUB ips123ramp (rr!, inom!) DECLARE SUB ips123rampfr (rr!, fr!, ifin!) DECLARE SUB ips123seti (imag!) DECLARE SUB ips123setpsni (nps%, ips!) '**************************************************************************** 'Module IPS123 'This module contains drivers to set and measure the magnet current. 'It is to be used with the three 1200 A, 120 V power supplies in bldg 26. ' 'Zachary Wolf '7/21/95 '**************************************************************************** 'Common area for shared parameters COMMON SHARED /ips123/ logfileP$, imagconfigP$, imagtstableP% 'Semi-permanent parameters CONST vtransperimagP! = .005 'transductor voltage per magnet amp CONST imagpervdacP! = 120 'power supply amps per DAC volts CONST ips1hpchanP% = 1 'PS1 read channel CONST ips2hpchanP% = 2 'PS2 read channel CONST ips3hpchanP% = 3 'PS3 read channel CONST ips1dacchanP% = 1 'PS1 DAC channel CONST ips2dacchanP% = 2 'PS2 DAC channel CONST ips3dacchanP% = 3 'PS3 DAC channel SUB ips123checkpar (ok$) '**************************************************************************** 'This subroutine checks that all required parameters have been assigned 'values. ' 'Output: ' ok$, "y" if parameter assignments are ok, "n" otherwise ' 'Zachary Wolf '9/18/95 '**************************************************************************** 'Default value ok$ = "n" 'logfileP$ IF logfileP$ = "" THEN PRINT "IPS123: Log file not defined" EXIT SUB END IF 'imagconfigP$ IF imagconfigP$ <> "1" AND imagconfigP$ <> "2" AND imagconfigP$ <> "3" AND imagconfigP$ <> "12S" AND imagconfigP$ <> "12P" AND imagconfigP$ <> "123P" THEN PRINT "IPS123: Unknown power system configuration" EXIT SUB END IF 'ips1hpchanP% IF ips1hpchanP% < 0 OR ips1hpchanP% > 9 THEN PRINT "IPS123: ipshpchan has improper value" EXIT SUB END IF 'ips2hpchanP% IF ips2hpchanP% < 0 OR ips2hpchanP% > 9 THEN PRINT "IPS123: ipshpchan has improper value" EXIT SUB END IF 'ips3hpchanP% IF ips3hpchanP% < 0 OR ips3hpchanP% > 9 THEN PRINT "IPS123: ipshpchan has improper value" EXIT SUB END IF 'ips1dacchanP% IF ips1dacchanP% <= 0 OR ips1dacchanP% > 4 THEN PRINT "IPS123: ipsdacchan has improper value" EXIT SUB END IF 'ips2dacchanP% IF ips2dacchanP% <= 0 OR ips2dacchanP% > 4 THEN PRINT "IPS123: ipsdacchan has improper value" EXIT SUB END IF 'ips3dacchanP% IF ips3dacchanP% <= 0 OR ips3dacchanP% > 4 THEN PRINT "IPS123: ipsdacchan has improper value" EXIT SUB END IF 'vtransperimagP! IF vtransperimagP! <= 0! OR vtransperimagP! > 2! THEN PRINT "IPS123: vtransperimag has improper value" EXIT SUB END IF 'imagpervdacP! IF imagpervdacP! <= 0 OR imagpervdacP! > 1000! THEN PRINT "IPS123: imagpervdac has improper value" EXIT SUB END IF 'imagtstableP% IF imagtstableP% < 0 OR imagtstableP% > 120 THEN PRINT "IPS123: imagtstable has improper value" EXIT SUB END IF 'If we made it this far, all parameters have values ok$ = "y" END SUB SUB ips123getdac (imag!) '**************************************************************************** 'This subroutine gets the DAC output and converts it to a current. ' 'Output: ' imag!, the magnet current calculated from the DAC output ' 'Zachary Wolf '7/23/95 '**************************************************************************** 'Make sure all parameters have been defined CALL ips123checkpar(ok$) IF ok$ <> "y" THEN imag! = 0! EXIT SUB END IF 'Power supply 1 IF imagconfigP$ = "1" THEN CALL psdac488getcv(1, vdac!) 'Power supply 2 ELSEIF imagconfigP$ = "2" THEN CALL psdac488getcv(2, vdac!) 'Power supply 3 ELSEIF imagconfigP$ = "3" THEN CALL psdac488getcv(3, vdac!) 'Power supplies 1 and 2 in parallel ELSEIF imagconfigP$ = "12P" THEN CALL psdac488getcv(1, vdac1!) CALL psdac488getcv(2, vdac2!) vdac! = vdac1! + vdac2! 'Power supplies 1, 2, and 3 in parallel ELSEIF imagconfigP$ = "123P" THEN CALL psdac488getcv(1, vdac1!) CALL psdac488getcv(2, vdac2!) CALL psdac488getcv(3, vdac3!) vdac! = vdac1! + vdac2! + vdac3! 'Power supplies 1 and 2 in series ELSEIF imagconfigP$ = "12S" THEN CALL psdac488getcv(1, vdac!) 'Unknown power supply configuration ELSE PRINT "IPS123GETDAC: unknown power supply configuration." imag! = 0! EXIT SUB END IF 'Convert the DAC voltage to a current imag! = vdac! * imagpervdacP! END SUB SUB ips123geti (imag!) '**************************************************************************** 'This subroutine gets the magnet current. ' 'Output: ' imag!, the measured magnet current ' 'Zachary Wolf '7/21/95 '**************************************************************************** 'Make sure all parameters have been defined CALL ips123checkpar(ok$) IF ok$ <> "y" THEN imag! = 0! EXIT SUB END IF 'Power supply 1 IF imagconfigP$ = "1" THEN CALL ips123getpsni(1, imag!) 'Power supply 2 ELSEIF imagconfigP$ = "2" THEN CALL ips123getpsni(2, imag!) 'Power supply 3 ELSEIF imagconfigP$ = "3" THEN CALL ips123getpsni(3, imag!) 'Power supplies 1 and 2 in parallel ELSEIF imagconfigP$ = "12P" THEN CALL ips123getpsni(1, ips1!) CALL ips123getpsni(2, ips2!) imag! = ips1! + ips2! 'Power supplies 1, 2, and 3 in parallel ELSEIF imagconfigP$ = "123P" THEN CALL ips123getpsni(1, ips1!) CALL ips123getpsni(2, ips2!) CALL ips123getpsni(3, ips3!) imag! = ips1! + ips2! + ips3! 'Power supplies 1 and 2 in series ELSEIF imagconfigP$ = "12S" THEN CALL ips123getpsni(1, imag!) 'Unknown power supply configuration ELSE PRINT "IPS123GETI: unknown power supply configuration." imag! = 0! EXIT SUB END IF END SUB SUB ips123getpsni (nps%, ips!) '**************************************************************************** 'This subroutine gets the transductor output voltage from a given power 'supply. It then applies the calibration constant to get the power 'supply current. ' 'Input: ' nps%, the number of the power supply to get the current from ' 'Output: ' ips!, the measured power supply current ' 'Zachary Wolf '7/23/95 '**************************************************************************** 'Make sure all parameters have been defined CALL ips123checkpar(ok$) IF ok$ <> "y" THEN ips! = 0! EXIT SUB END IF 'Determine which transductor to read IF nps% = 1 THEN hpchan% = ips1hpchanP% ELSEIF nps% = 2 THEN hpchan% = ips2hpchanP% ELSEIF nps% = 3 THEN hpchan% = ips3hpchanP% ELSE PRINT "IPS123GETPSNI: Unknown power supply number." ips! = 0! EXIT SUB END IF 'Measure the voltage from the transductor CALL pshp3457cv(hpchan%, vtrans!) 'Apply the conversion factor ips! = vtrans! / vtransperimagP! 'Log the value CALL ips123logpsni(logfileP$, nps%, ips!) END SUB SUB ips123init '**************************************************************************** 'This subroutine does the initial turn on of the power supplies to a small 'current. ' 'Zachary Wolf '10/1/95 '**************************************************************************** 'Make sure all parameters have been defined CALL ips123checkpar(ok$) IF ok$ <> "y" THEN EXIT SUB 'Message PRINT PRINT "Initial power supply turn on." PRINT "Ramp each supply to 20 A, stabilize, ramp to 0..." 'Ramp each supply to 20 A IF imagconfigP$ = "1" OR imagconfigP$ = "2" OR imagconfigP$ = "3" OR imagconfigP$ = "12S" THEN CALL ips123ramp(10!, 20!) ELSEIF imagconfigP$ = "12P" THEN CALL ips123ramp(10!, 40!) ELSEIF imagconfigP$ = "123P" THEN CALL ips123ramp(10!, 60!) END IF 'Stabilize SLEEP 30 'not imagtstable, initial turn on time is different 'Ramp to 0 CALL ips123ramp(10!, 0!) END SUB SUB ips123logpsni (logfile$, nps%, ips!) '**************************************************************************** 'This subroutine writes the power supply current to the log file. ' 'Input: ' logfile$, the name of the log file ' nps%, the power supply number ' ips!, the measured power supply current ' 'Zachary Wolf '7/23/95 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Print the results PRINT #filenum%, TIME$; " Power Supply "; nps%; " Current, Ips = "; ips!; " A" 'Close the log file CLOSE filenum% END SUB SUB ips123monitor '**************************************************************************** 'This subroutine sets up the HP3457 to monitor the transductor. ' 'Zachary Wolf '7/27/95 '**************************************************************************** 'Make sure all parameters have been defined CALL ips123checkpar(ok$) IF ok$ <> "y" THEN EXIT SUB 'Set the DVM so the current can be monitored IF imagconfigP$ = "2" THEN hpchan% = ips2hpchanP% ELSEIF imagconfigP$ = "3" THEN hpchan% = ips3hpchanP% ELSE hpchan% = ips1hpchanP% END IF CALL pshp3457cmon(hpchan%) END SUB SUB ips123ramp (rr!, inom!) '**************************************************************************** 'This subroutine supervises the ramp of the magnet current. ' 'Input: ' rr!, the ramp rate ' inom!, the desired magnet current ' 'Zachary Wolf '7/23/95 '**************************************************************************** 'Make sure all parameters have been defined CALL ips123checkpar(ok$) IF ok$ <> "y" THEN EXIT SUB 'First ramp to 90% of the desired current CALL ips123rampfr(rr!, .9, inom!) 'Next ramp to 99% of the desired current at 10% of the ramp rate CALL ips123rampfr(.1 * rr!, .9, inom!) 'Now finish the the remaining 1% of the ramp at 1% of the initial ramp rate CALL ips123rampfr(.01 * rr!, 1!, inom!) 'Let the power supply and magnet stabilize at the final current SLEEP imagtstableP% END SUB SUB ips123rampfr (rr!, fr!, ifin!) '**************************************************************************** 'This subroutine generates a fraction of the magnet current ramp. 'The complete ramp (fr!=1) would be from the present current to ifin!. 'This routine generates a fraction fr! of this ramp. 'The points making up the ramp are updated every 0.1 second. 'This routine can be called several times to approach the final magnet 'current at a low ramp rate. ' 'Input: ' rr!, the magnet current ramp rate ' fr!, the fraction of the ramp to be done from the present current to ifin! ' ifin!, the desired final magnet current ' 'Zachary Wolf '7/23/95 '**************************************************************************** 'Define a local parameter, the time between ramp steps dt! = .1 'Get the initial current from the DAC output 'This is to avoid current jumps at the beginning of the ramp CALL ips123getdac(iini!) 'Find the required current change deltai! = ABS(ifin! - iini!) 'Find the time required to ramp deltat! = deltai! / rr! 'Find the number of ramp steps required at dt! per step nr% = deltat! / dt! 'Make sure we take at least one step so we are sure to end at ifin! IF nr% = 0 THEN nr% = 1 'Find the size of each current step istep! = (ifin! - iini!) / nr% 'Compute the current at each step DIM imag!(0 TO nr%) FOR i% = 0 TO nr% imag!(i%) = iini! + istep! * i% NEXT i% imag!(nr%) = ifin! 'eliminate rounding errors 'Output fraction fr! of the calculated ramp 'Only fr! = 1 guarantees a ramp to the final value for small nr% FOR i% = 0 TO nr% * fr! tstep! = TIMER CALL ips123seti(imag!(i%)) WHILE TIMER - tstep! < dt! WEND NEXT i% END SUB SUB ips123seti (imag!) '**************************************************************************** 'This subroutine sets the magnet current. ' 'Input: ' imag!, the desired magnet current ' 'Zachary Wolf '7/23/95 '**************************************************************************** 'Make sure all parameters have been defined CALL ips123checkpar(ok$) IF ok$ <> "y" THEN EXIT SUB 'Power supply 1 IF imagconfigP$ = "1" THEN CALL ips123setpsni(1, imag!) 'Power supply 2 ELSEIF imagconfigP$ = "2" THEN CALL ips123setpsni(2, imag!) 'Power supply 3 ELSEIF imagconfigP$ = "3" THEN CALL ips123setpsni(3, imag!) 'Power supplies 1 and 2 in parallel ELSEIF imagconfigP$ = "12P" THEN CALL ips123setpsni(1, imag! / 2) CALL ips123setpsni(2, imag! / 2) 'Power supplies 1, 2, and 3 in parallel ELSEIF imagconfigP$ = "123P" THEN CALL ips123setpsni(1, imag! / 3) CALL ips123setpsni(2, imag! / 3) CALL ips123setpsni(3, imag! / 3) 'Power supplies 1 and 2 in series ELSEIF imagconfigP$ = "12S" THEN CALL ips123setpsni(1, imag!) 'Unknown power supply configuration ELSE PRINT "IMAGSETI: unknown power supply configuration." EXIT SUB END IF END SUB SUB ips123setpar (logfile$, imagconfig$, imagtstable%) '**************************************************************************** 'This subroutine sets parameter values for the Kepco power supply. ' 'Input: ' logfile$, log file ' imagconfig$, power system configuration ' imagtstable%, settling time to wait after a ramp ' 'Zachary Wolf '9/21/95 '**************************************************************************** 'Place the parameters in the local common block for future use logfileP$ = logfile$ imagconfigP$ = imagconfig$ imagtstableP% = imagtstable% END SUB SUB ips123setpsni (nps%, ips!) '**************************************************************************** 'This subroutine sets the current in a given power supply. ' 'Input: ' nps%, the number of the power supply ' ips!, the desired power supply current ' 'Zachary Wolf '7/23/95 '**************************************************************************** 'Make sure all parameters have been defined CALL ips123checkpar(ok$) IF ok$ <> "y" THEN EXIT SUB 'Determine which DAC channel to set IF nps% = 1 THEN dacchan% = ips1dacchanP% ELSEIF nps% = 2 THEN dacchan% = ips2dacchanP% ELSEIF nps% = 3 THEN dacchan% = ips3dacchanP% ELSE PRINT "IPS123SETPSNI: Unknown power supply number." EXIT SUB END IF 'Find the required DAC output vdac! = ips! / imagpervdacP! 'Output the DAC voltage CALL psdac488setcv(dacchan%, vdac!) END SUB