DECLARE SUB coilgetf (f!) DECLARE SUB coilgetvn (nh%, vm!(), vp!()) DECLARE SUB blncalcbln (rcoil!, nturns%, fcoil!, nh%, vm!(), vp!(), bln!(), thn!()) DECLARE SUB blngetbln (nh%, bln!(), thn!()) DECLARE SUB blnlogbln (logfile$, rcoil!, nturns%, fcoil!, nh%, vm!(), vp!(), bln!(), thn!()) DECLARE SUB blnlogblnav (logfile$, nh%, bln!(), sbln!(), thn!(), sthn!()) '**************************************************************************** 'Module BLN.BAS ' 'These subroutines find the strengths of the multipole components of 'the magnet. ' 'Zachary Wolf '5/3/95 '**************************************************************************** 'Open the parameter file REM $INCLUDE: 'param.inc' 'The required parameters are in 'BLN 'COIL 'FILE ' 'The required parameters are 'logfileP$ 'coilradiusmP! 'coilnturnsP% 'coilnrotaveP% 'blnnmeasaveP% ' 'Sample BLN parameters 'BLN 'CONST blnnmeasaveP% = 4 'the number of measurements for B average SUB blncalcbln (rcoil!, nturns%, fcoil!, nh%, vm!(), vp!(), bln!(), thn!()) '**************************************************************************** 'This subroutine calculates the integrated field strength of each field 'harmonic at the coil radius. 'It also calculates the angle of the first south pole of each harmonic field. ' 'Input: ' rcoil!, the coil radius ' nturns%, the number of turns on the coil ' fcoil!, the coil rotation frequency (1/s) ' nh%, the number of voltage harmonics recorded ' vm!(1 to nh%), the voltage magnitudes (V) ' vp!(1 to nh%), the voltage phases (deg) ' 'Output: ' bln!(1 to nh%), the integrated strength of each harmonic at the coil radius (T) ' thn!(1 to nh%), the angle of the first south pole of each harmonic wrt horizontal (deg) ' 'Zachary Wolf '1/2/94, 5/3/95 '**************************************************************************** 'Some Math 'BL 'Vn = Nturns * velocity * Bn * L ' = Nturns * Rcoil * ang_freq * (BLn) 'BLn = Vn / (Nturns * Rcoil * ang_freq) 'TH 'Field expansion of intz(Br): BLr(r,th) = Sum BLrn(r,th) ' BLrn(r,th) = bln * r^(n-1) * cos(n*(th - THspole)) 'At the coil radius, BLrn(th) = BLn * cos(n*(th - THspole)) 'The coil voltage Vn(th) = Nturns * velocity * BLrn(th) ' = Nturns * Rcoil * 2pi * Freq * BLn * cos(n*(th - THspole)) 'The FFT gives Vn and PhiVn in the formula 'Vn(i) = Vn * cos(n*2pi*i/N + PhiVn), V(i) = Sum(Vn(i)) 'So, Nturns * Rcoil * 2pi * Freq * BLn = Vn ' -n * THspole = PhiVn 'Then, BLn = Vn / (Nturns * Rcoil * 2pi * Freq) ' THspole = -PhiVn / n 'Simplify the notation pi! = 3.1415926# 'Compute the strength of each field harmonic at the coil radius FOR i% = 1 TO nh% bln!(i%) = vm!(i%) / (nturns% * rcoil! * 2! * pi! * fcoil!) NEXT i% 'Compute the angle of the first south pole wrt horizontal for each harmonic FOR i% = 1 TO nh% thn!(i%) = -vp!(i%) / i% NEXT i% END SUB SUB blngetbln (nh%, bln!(), thn!()) '**************************************************************************** 'This subroutine performs a measurement of the field harmonics in a magnet. ' 'Input: ' nh%, the number of harmonics to record ' 'Output: ' bln!(1 to nh%), the integrated strength of each harmonic at the coil radius (T) ' thn!(1 to nh%), the angle of the first south pole of each harmonic wrt horizontal (deg) ' 'Zachary Wolf '1/4/95, 5/3/95 '**************************************************************************** 'Initialize data arrays DIM vm!(1 TO nh%) DIM vp!(1 TO nh%) 'Measure the coil rotation frequency CALL coilgetf(f1!) SLEEP 1 CALL coilgetf(f2!) 'Measure the coil voltage CALL coilgetvn(nh%, vm!(), vp!()) 'Measure the coil rotation frequency again after the coil voltage CALL coilgetf(f3!) 'Compute the average of the coil rotation frequency measurements fcoil! = (f1! + f2! + f3!) / 3! 'Compute the harmonics CALL blncalcbln(coilradiusmP!, coilnturnsP%, fcoil!, nh%, vm!(), vp!(), bln!(), thn!()) 'Log the results CALL blnlogbln(logfileP$, coilradiusmP!, coilnturnsP%, fcoil!, nh%, vm!(), vp!(), bln!(), thn!()) END SUB SUB blngetblnav (nh%, bln!(), sbln!(), thn!(), sthn!()) '**************************************************************************** 'This subroutine measures BLn several times and returns the average 'and rms variation. ' 'Input: ' nh%, the number of harmonics to record ' 'Output: ' bln!(1 to nh%), the integrated strength of each harmonic at the coil radius (T) ' sbln!(1 to nh%), rms variation of bl ' thn!(1 to nh%), the angle of the first south pole of each harmonic wrt horizontal (deg) ' sthn!(1 to nh%), rms variation of th ' 'Zachary Wolf '1/4/95, 5/5/95 '**************************************************************************** 'Simplify the notation nm% = blnnmeasaveP% 'Initialize data arrays DIM bln1!(1 TO nh%) DIM thn1!(1 TO nh%) DIM bln2!(1 TO nh%, 1 TO nm%) DIM thn2!(1 TO nh%, 1 TO nm%) 'Loop over the measurements FOR i% = 1 TO nm% 'Measure BLn CALL blngetbln(nh%, bln1!(), thn1!()) 'Store the results FOR j% = 1 TO nh% bln2!(j%, i%) = bln1!(j%) thn2!(j%, i%) = thn1!(j%) NEXT j% 'End the loop over the measurements NEXT i% 'Compute averages FOR j% = 1 TO nh% bln!(j%) = 0! thn!(j%) = 0! FOR i% = 1 TO nm% bln!(j%) = bln!(j%) + bln2!(j%, i%) thn!(j%) = thn!(j%) + thn2!(j%, i%) NEXT i% bln!(j%) = bln!(j%) / nm% thn!(j%) = thn!(j%) / nm% NEXT j% 'Compute rms deviations FOR j% = 1 TO nh% sbln!(j%) = 0! sthn!(j%) = 0! FOR i% = 1 TO nm% sbln!(j%) = sbln!(j%) + (bln2!(j%, i%) - bln!(j%)) ^ 2 sthn!(j%) = sthn!(j%) + (thn2!(j%, i%) - thn!(j%)) ^ 2 NEXT i% sbln!(j%) = SQR(sbln!(j%) / nm%) sthn!(j%) = SQR(sthn!(j%) / nm%) NEXT j% 'Write the results to the log file CALL blnlogblnav(logfileP$, nh%, bln!(), sbln!(), thn!(), sthn!()) END SUB SUB blnlogbln (logfile$, rcoil!, nturns%, fcoil!, nh%, vm!(), vp!(), bln!(), thn!()) '**************************************************************************** 'This subroutine writes the harmonics measurements to the log file. ' 'Inputs: ' logfile$, the name of the log file ' rcoil!, the coil radius ' nturns%, the number of coil turns ' fcoil!, the coil rotation frequency ' nh%, the number of harmonics to print out ' vm!(1 to nh%), voltage magnitudes ' vp!(1 to nh%), voltage phases ' bln!(1 TO nh%), field strength at Rcoil of the n'th harmonic ' thn!(1 TO nh%), field angle in degrees ' 'Zachary Wolf '1/5/95, 5/3/95 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Print the results to the log file PRINT #filenum%, PRINT #filenum%, " FIELD HARMONICS CALCULATION" PRINT #filenum%, PRINT #filenum%, "Coil Radius, Rcoil = "; rcoil!; " m, # Turns, Nturns = "; nturns% PRINT #filenum%, "Coil Rotation Frequency, Fcoil = "; fcoil! PRINT #filenum%, PRINT #filenum%, " N Vm Vp BLn THspole" PRINT #filenum%, " (V) (deg) (Tm) (deg) " PRINT #filenum%, "--- ----------- ------- ----------- -------" FOR j% = 1 TO nh% PRINT #filenum%, USING "###"; j%; PRINT #filenum%, USING " ##.########"; vm!(j%); PRINT #filenum%, USING " ####.##"; vp!(j%); PRINT #filenum%, USING " ##.########"; bln!(j%); PRINT #filenum%, USING " ####.##"; thn!(j%) NEXT j% 'Close the log file CLOSE filenum% END SUB SUB blnlogblnav (logfile$, nh%, bln!(), sbln!(), thn!(), sthn!()) '**************************************************************************** 'This subroutine writes the average and rms BLn measurements to the log file. ' 'Inputs: ' logfile$, the name of the log file ' nh%, the number of harmonics to print out ' bln!(1 TO nh%), field strength at Rcoil of the n'th harmonic ' sbln!(1 TO nh%), standard deviation of Bn ' thn!(1 TO nh%), field angle in degrees ' sthn!(1 TO nh%), standard deviation of THn ' 'Zachary Wolf '7/9/94, 8/14/94, 1/4/95 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Print the results to the log file PRINT #filenum%, PRINT #filenum%, " FIELD HARMONICS" PRINT #filenum%, PRINT #filenum%, "Coil Radius, Rcoil = "; coilradiusmP!; " m" PRINT #filenum%, "Coil # Turns, Nturns = "; coilnturnsP% PRINT #filenum%, "Average, # Rotations/Measurement = "; coilnrotaveP%; ", # Measurements = "; blnnmeasaveP% PRINT #filenum%, PRINT #filenum%, " N BLn sigBLn THspole sigTH " PRINT #filenum%, " (Tm) (Tm) (deg) (deg) " PRINT #filenum%, "--- --------+-------- --------+--------" FOR j% = 1 TO nh% PRINT #filenum%, USING "###"; j%; PRINT #filenum%, USING " ##.#####"; bln!(j%); PRINT #filenum%, USING " ##.#####"; sbln!(j%); PRINT #filenum%, USING " ####.##"; thn!(j%); PRINT #filenum%, USING " ####.##"; sthn!(j%) NEXT j% 'Close the log file CLOSE filenum% END SUB SUB blnlogcalc (logfile$) '**************************************************************************** 'This subroutine summarizes the calculations used in the program. ' 'Inputs: ' logfile$, the name of the log file ' 'Zachary Wolf '9/22/94, 12/3/94, 5/4/95 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Header PRINT #filenum%, PRINT #filenum%, " SUMMARY OF THE CALCULATIONS AND CONVENTIONS USED" 'Field expansion PRINT #filenum%, PRINT #filenum%, PRINT #filenum%, "Field Expansion:" PRINT #filenum%, "The expansion of the radial and azimuthal field in polar" PRINT #filenum%, "coordinates is" PRINT #filenum%, " Br(r,th) = Sum Bn (r/rref)^(n-1) cos(n(th-thspole))" PRINT #filenum%, " Bth(r,th) = -Sum Bn (r/rref)^(n-1) sin(n(th-thspole))" PRINT #filenum%, "Our convention is to set rref = Rcoil." PRINT #filenum%, "Thspole is the angle of the first magnetic south pole" PRINT #filenum%, "with respect to the horizontal, measured ccw by a shaft" PRINT #filenum%, "encoder in the system." PRINT #filenum%, PRINT #filenum%, "Coil Voltage:" PRINT #filenum%, "The coil voltage from each field harmonic is" PRINT #filenum%, " Vn(th) = Nturns * velocity * Brn(Rcoil,th) * L" PRINT #filenum%, "L is the magnet effective length, or BLn is the integrated" PRINT #filenum%, "field strength of the n'th harmonic." PRINT #filenum%, "At the coil radius, the radial field as a function of angle is," PRINT #filenum%, " Brn(Rcoil,th) * L = BLn * cos(n*(th - thspole))" PRINT #filenum%, "The coil voltage is" PRINT #filenum%, " Vn(th) = Nturns * velocity * BLn * cos(n*(th - thspole))" PRINT #filenum%, " = Nturns * Rcoil * ang_freq * BLn * cos(n*(th - THspole))" PRINT #filenum%, "An FFT of the coil voltage gives Vn and PhiVn according to the formula" PRINT #filenum%, " Vn(i) = Vn * cos(n*2pi*i/N + PhiVn)" PRINT #filenum%, PRINT #filenum%, "Multipole Field Calculations:" PRINT #filenum%, "To find the multipole field magnitudes and phases," PRINT #filenum%, "the measured voltage harmonics are related to their values" PRINT #filenum%, "calculated from the field harmonics:" PRINT #filenum%, " Nturns * Rcoil * ang_freq * BLn = Vn" PRINT #filenum%, " -n * thspole = PhiVn" PRINT #filenum%, "Or," PRINT #filenum%, " BLn = Vn / (Nturns * Rcoil * ang_freq)" PRINT #filenum%, " thspole = -PhiVn / n" 'Close the log file CLOSE filenum% END SUB