DECLARE SUB tachgetv (ns%, v!(), sv!()) DECLARE SUB tachlogplotv (logfile$, ns%, v!(), dv!(), corr!()) DECLARE SUB tachlogv (logfile$) DECLARE SUB hp3457cnvtrig (c%, n%, v!()) DECLARE FUNCTION FFTMagnitude! (xr(), yi(), n%, i%) DECLARE FUNCTION FFTPhase! (xr(), yi(), n%, i%) '**************************************************************************** 'Module TACH.BAS ' 'Zachary Wolf '1/7/95 '**************************************************************************** 'Open the parameter file REM $INCLUDE: 'param.inc' SUB tachcorrspeed (ns%, v!(), vt!(), vc!()) '**************************************************************************** 'This subroutine corrects the coil voltage samples to the values if the 'speed were constant at the average value. ' 'Input: ' ns%, the number of samples per revolution ' v!(0 to ns%-1), voltage samples from the coil ' vt!(0 to ns%-1), voltage samples from the tachometer ' 'Output: ' vc!(0 to ns%-1), the corrected coil voltage samples ' 'Zachary Wolf '9/7/94, 11/15/94 '**************************************************************************** 'Initialize data arrays DIM corr!(0 TO ns% - 1) 'correction factor 'Find the average tachometer voltage avevt! = 0! FOR i% = 0 TO ns% - 1 avevt! = avevt! + vt!(i%) NEXT i% avevt! = avevt! / ns% 'Find the correction factor to take out speed variations FOR i% = 0 TO ns% - 1 corr!(i%) = avevt! / vt!(i%) NEXT i% 'Apply the correction FOR i% = 0 TO ns% - 1 vc!(i%) = v!(i%) * corr!(i%) NEXT i% END SUB SUB tachgetv (ns%, v!(), sv!()) '**************************************************************************** 'This subroutine gets the triggered voltages from the tachometer. ' 'Input: ' ns%, the number of voltage samples per revolution ' 'Output: ' v!(0 to ns%-1), the average voltage at each sample point ' sv!(0 to ns%-1), the standard deviation of v at each sample point ' 'Zachary Wolf '1/7/95 '**************************************************************************** 'Simplify the notation c% = tachhpchanP% nr% = nrotaveP% 'Initialize data arrays DIM vnr!(0 TO nr% * ns% - 1) 'voltage samples DIM v2d!(0 TO ns% - 1, 1 TO nr%) 'put samples in 2d array 'Make the measurement over nr% rotations CALL hp3457cnvtrig(c%, nr% * ns%, vnr!()) 'Put the samples in a 2d array for ease of handling FOR i% = 0 TO ns% - 1 FOR j% = 1 TO nr% v2d!(i%, j%) = vnr!(i% + (j% - 1) * ns%) NEXT j% NEXT i% 'Compute the average at each sample point FOR i% = 0 TO ns% - 1 v!(i%) = 0! FOR j% = 1 TO nr% v!(i%) = v!(i%) + v2d!(i%, j%) NEXT j% v!(i%) = v!(i%) / nr% NEXT i% 'Compute the standard deviation of the voltage at each sample point FOR i% = 0 TO ns% - 1 sv!(i%) = 0! FOR j% = 1 TO nr% sv!(i%) = sv!(i%) + (v2d!(i%, j%) - v!(i%)) ^ 2 NEXT j% sv!(i%) = SQR(sv!(i%) / nr%) NEXT i% 'Log that a measurement was made CALL tachlogv(logfileP$) END SUB SUB tachlogplotv (logfile$, ns%, v!(), dv!(), corr!()) '**************************************************************************** 'This subroutine writes voltage samples to the log file. ' 'Inputs: ' logfile$, the name of the log file ' ns%, the number of voltage samples ' v!(0 to ns%-1), the voltage samples ' dv!(0 to ns%-1), voltage deviations ' corr!(0 to ns%-1), correction factors for speed variations ' 'Zachary Wolf '11/11/94 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Write the samples to the log file FOR k% = 0 TO ns% - 1 PRINT #filenum%, USING "###"; k%; PRINT #filenum%, USING " ###.####"; v!(k%); PRINT #filenum%, USING " ##.#####"; dv!(k%); PRINT #filenum%, USING " ##.#####"; corr!(k%) NEXT k% 'Close the log file CLOSE filenum% END SUB SUB tachlogv (logfile$) '**************************************************************************** 'This subroutine writes to the log file that a tachometer voltage measurement 'was made. ' 'Input: ' logfile$, the name of the log file ' 'Zachary Wolf '1/7/95 '**************************************************************************** 'Open the log file filenum% = FREEFILE OPEN logfile$ FOR APPEND AS filenum% 'Print the results PRINT #filenum%, PRINT #filenum%, TIME$; " Tachometer Voltage Measurement Made" 'Close the log file CLOSE filenum% END SUB SUB tachplotv 'Set the parameters for the tach measurement c% = tachhpchanP% ns% = nsampleP% 'Initialize data arrays DIM v!(0 TO ns% - 1) 'voltage samples DIM sv!(0 TO ns% - 1) 'voltage samples DIM dv!(0 TO ns% - 1) 'voltage deviations DIM corr!(0 TO ns% - 1) 'factor to correct for speed variations 'Sample the tach voltage CALL tachgetv(ns%, v!(), sv!()) 'Find the average tachometer voltage avev! = 0! FOR i% = 0 TO ns% - 1 avev! = avev! + v!(i%) NEXT i% avev! = avev! / ns% 'Find the deviations from the average FOR i% = 0 TO ns% - 1 dv!(i%) = v!(i%) - avev! NEXT i% 'Find the correction factor to take out speed variations FOR i% = 0 TO ns% - 1 corr!(i%) = avev! / v!(i%) NEXT i% 'Initialize a plot file pltfiletachP$ = "tachpltv.dat" filenum% = FREEFILE OPEN pltfiletachP$ FOR OUTPUT AS filenum% CLOSE filenum% 'Plot the results CALL tachlogplotv(pltfiletachP$, ns%, v!(), dv!(), corr!()) END SUB