DECLARE SUB coilfindpeak (n%, v!(), npeak%, nzero1%, nzero2%) DECLARE SUB coilintpeak (n%, t!, v!(), vt!) DECLARE SUB coillogplotv (logfile$, n%, t!, v!()) DECLARE SUB coillogvt (logfile$, nave%, vtp!(), vtn!(), vt!, sigvt!) DECLARE SUB hp3457cntv (c%, n%, t!, v!()) DECLARE SUB IntegrateVector (y!(), samper!, xl%, xh%, ans!) '**************************************************************************** 'Module COIL 'This module contains drivers to measure the coil voltages and return 'quantities of interest such as the integrated voltage over a half 'cycle. ' 'The following parameters must be in param.inc. 'coilnptsP%, the number of voltage samples the DVM takes 'coildeltatP!, the time interval between samples 'coilnaveP%, the number of ivdt measurements for average ' 'Zachary Wolf '6/1/94 '**************************************************************************** 'Get the required parameters REM $INCLUDE: 'param.inc' SUB coilfindpeak (n%, v!(), npeak%, nzero1%, nzero2%) '**************************************************************************** 'This subroutine finds the positive peak in a set of voltage samples. 'A -1 returned indicates a problem. ' 'Input: ' n%, number of voltage samples ' v!(0 to n%-1), voltage samples ' 'Output: ' npeak%, the sample number of the maximum voltage ' nzero1%, the sample number of the first point in the peak ' nzero2%, the sample number of the last point in the peak ' 'Zachary Wolf '4/10/94, 12/29/94, 3/18/95 '**************************************************************************** 'Initialize npeak% = -1 nzero1% = -1 nzero2% = -1 'Find the peak npeak% = 0 FOR i% = 1 TO n% - 1 IF v!(i%) > v!(npeak%) THEN npeak% = i% NEXT i% IF v!(npeak%) < 0 OR npeak% = 0 THEN npeak% = -1 GOTO nopeak END IF 'Find the zero crossing before the peak FOR i% = npeak% TO 0 STEP -1 IF v!(i%) < 0 THEN nzero1% = i% + 1 EXIT FOR END IF NEXT i% 'Find the zero crossing after the peak FOR i% = npeak% TO n% - 1 STEP 1 IF v!(i%) < 0 THEN nzero2% = i% - 1 EXIT FOR END IF NEXT i% 'Problem exit nopeak: END SUB SUB coilintpeak (n%, t!, v!(), vt!) '**************************************************************************** 'This subroutine integrates the voltage from a rotating coil as it is flipped. 'It finds the maximum voltage and integrates to the zeros on either side. ' 'Input: ' n%, number of voltage samples ' t!, time between each voltage sample ' v!(0 to n%-1), voltage samples ' 'Output: ' vt!, integral of the voltage ' 'Zachary Wolf '4/10/94, 12/29/94, 3/18/95 '**************************************************************************** 'Initialize vt! = 0! 'Find the positive peak in the coil voltage CALL coilfindpeak(n%, v!(), npeak%, nzero1%, nzero2%) 'Check IF npeak% < 0 OR nzero1% < 1 OR nzero2% < 0 OR nzero2% > n% - 2 THEN PRINT PRINT "Problem integrating the voltage samples!!!" PRINT "This needs to be looked into!" GOTO pbm END IF 'Find the voltage integral contributions near the first zero crossing 'using linear interpolation y0! = v!(nzero1% - 1) y1! = v!(nzero1%) 'i0! = .5 * y0! * (-y0! * t!) / (y1! - y0!) i1! = .5 * y1! * (t! - (-y0! * t!) / (y1! - y0!)) 'Find the voltage integral contributions near the second zero crossing 'using linear interpolation y0! = v!(nzero2%) y1! = v!(nzero2% + 1) i3! = .5 * y0! * (-y0! * t!) / (y1! - y0!) 'i4! = .5 * y1! * (t! - (-y0! * t!) / (y1! - y0!)) 'Integrate from the first zero crossing to the second using Simpson's rule CALL IntegrateVector(v!(), t!, nzero1%, nzero2%, i2!) 'Sum to get the total integral vt! = i1! + i2! + i3! 'For debug PRINT PRINT "I1 = "; i1!; ", I2 = "; i2!; ", I3 = "; i3!; " VS" 'Problem exit pbm: END SUB SUB coillogplotv (logfile$, n%, t!, v!()) '**************************************************************************** 'This subroutine writes voltage samples to the log file. ' 'Inputs: ' logfile$, the name of the log file ' n%, the number of voltage samples ' t!, the time between samples ' v!(0 to n%-1), the voltage samples ' 'Zachary Wolf '3/16/95 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Write the samples to the log file FOR k% = 0 TO n% - 1 PRINT #filenum%, USING "###"; k%; PRINT #filenum%, USING " ###.###"; k% * t!; PRINT #filenum%, USING " ###.#####"; v!(k%) NEXT k% 'Close the log file CLOSE filenum% END SUB SUB coillogvt (logfile$, nave%, vtp!(), vtn!(), vt!, sigvt!) '**************************************************************************** 'This subroutine records the integrated voltage from the rotating coil 'to the log file. ' 'Input: ' logfile$, the name of the log file ' nave%, the number of measurements used in the average ' vtp!(1 to nave%), the positive voltage integrals ' vtn!(1 to nave%), the negative voltage integrals ' vt!, the average voltage integral ' sigvt!, the standard deviation of the voltage integrals ' 'Zachary Wolf '11/25/94 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Write the integrated voltages PRINT #filenum%, PRINT #filenum%, TIME$; " Integrated Voltage Measurements:" FOR i% = 1 TO nave% STEP 3 PRINT #filenum%, "VT+- = "; FOR j% = 0 TO 2 IF i% + j% > nave% THEN EXIT FOR PRINT #filenum%, USING " ##.#####"; vtp!(i% + j%); PRINT #filenum%, USING " ##.#####"; vtn!(i% + j%); NEXT j% PRINT #filenum%, NEXT i% 'Write the average and standard deviation PRINT #filenum%, "Average: VT = "; vt!; " +- "; sigvt! 'Close the log file CLOSE filenum% END SUB SUB coilmeasvt (vt!, sigvt!) '**************************************************************************** 'This subroutine finds the average integrated voltage and standard 'deviation as a coil is rotated through 180 degrees. ' 'Output: ' vt!, the average integrated voltage ' sigvt!, the error estimate on vt! ' 'Zachary Wolf '5/14/94, 12/28/94, 3/18/95 '**************************************************************************** 'Simplify the notation c% = coilhpchanP% nave% = coilnaveP% n% = coilnptsP% t! = coildeltatP! 'Declare arrays DIM vtp!(1 TO nave%) 'holds +vt values during averaging DIM vtn!(1 TO nave%) 'holds -vt values during averaging DIM v!(0 TO n% - 1) 'voltage samples from the coil DIM negv!(0 TO n% - 1) 'negative of voltage samples from the coil 'Find the integrated voltage from the coil nave times FOR j% = 1 TO nave% 'Sample the voltage from the coil over a forward and reverse half cycle CALL hp3457cntv(c%, n%, t!, v!()) 'Compute the time integral of the positive peak of the coil voltage CALL coilintpeak(n%, t!, v!(), vt1!) 'Change the sign of the voltage to get the negative peak FOR i% = 0 TO n% - 1 negv!(i%) = -v!(i%) NEXT i% 'Compute the time integral of the negative peak of the coil voltage CALL coilintpeak(n%, t!, negv!(), vt2!) vt2! = -vt2! 'Check for a forward and reverse half cycle IF vt1! * vt2! >= 0 THEN PRINT PRINT "Problem!!!! Did not get + and - coil voltages!" PRINT "Bad data! Please look into the problem and re-run the program." END IF 'Store the result IF vt1! > 0 THEN vtp!(j%) = vt1! vtn!(j%) = vt2! ELSE vtn!(j%) = vt1! vtp!(j%) = vt2! END IF 'End averaging loop NEXT j% 'Find the mean of the integrated voltage values sum! = 0 FOR j% = 1 TO nave% sum! = sum! + vtp!(j%) sum! = sum! - vtn!(j%) NEXT j% vt! = sum! / (2 * nave%) 'Find the standard deviation of the integrated voltage values sum! = 0 FOR j% = 1 TO nave% sum! = sum! + (vtp!(j%) - vt!) ^ 2 sum! = sum! + (-vtn!(j%) - vt!) ^ 2 NEXT j% sigvt! = sum! / (2 * nave%) sigvt! = SQR(sigvt!) 'Write the voltage integrals to the log file CALL coillogvt(logfileP$, nave%, vtp!(), vtn!(), vt!, svt!) END SUB SUB coilntvsim (n%, t!, v!()) '**************************************************************************** 'This subroutine generates n% samples of a sine wave at intervals t!. 'The sine wave has amplitude A and a period of L seconds. 'The + and - voltage integrals are AL/pi. A and L are parameters internal 'to this routine. ' 'Input: ' n%, the number of samples desired ' t!, the time between samples ' 'Output: ' v!(0 to n%-1), generated samples ' 'Zachary Wolf '4/11/94 '**************************************************************************** 'Define the parameters CONST pi! = 3.141593 CONST a! = 1! CONST phi! = 2! * pi! / 10! 'Generate the samples FOR i% = 0 TO n% - 1 v!(i%) = a! * SIN((1.2 * 2! * pi! * i% / n%) - phi!) ' v!(i%) = v!(i%) + .05 * (RND - .5) NEXT i% 'Message 'VT = 2 * A / omega PRINT "COILNTVSIM test data, VT = "; 2! * a! / (1.2 * 2! * pi! / (n% * t!)) END SUB SUB coilplotv 'Simplify the notation c% = coilhpchanP% n% = coilnptsP% t! = coildeltatP! 'Initialize DIM v!(0 TO n% - 1) 'Sample the voltage from the coil over the forward and reverse half cycles CALL hp3457cntv(c%, n%, t!, v!()) 'Initialize a plot file pltfilecoilP$ = "vcoilplt.dat" filenum% = FREEFILE OPEN pltfilecoilP$ FOR OUTPUT AS filenum% CLOSE filenum% 'Plot the results CALL coillogplotv(pltfilecoilP$, n%, t!, v!()) END SUB