/* ************************************************************** */ /* * Module VSCAN * This module contains functions to make voltage measurements from * one or more moving probes. The probes are moved continuously and the * measurements are triggered by an encoder. * * Zachary Wolf * 10/18/02 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include #include #include "hp3458.h" #include "movez.h" #include "vscan.h" #include "vscanui.h" /* ************************************************************** */ /* PRIVATE PARAMETERS */ static char log_file[100]; static struct vscan_param_struct vscan_param; /* ************************************************************** */ /* PRIVATE GLOBAL VARIABLES */ static int hp3458_ID[VSCAN_MAX_NUM_DVM]; static char msg[80]; /* ************************************************************** */ /* PRIVATE FUNCTIONS */ int vscan_check_param(void); void vscan_error(char* message); void vscan_message(char* message); void vscan_log_get_v(double start_pos, double dist_move, int num_dvm, struct vscan_dvm_info_struct dvm_info[], int num_samp); /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * vscan_init * This function is used to initialize the voltage scan * measurement system. * * Zachary Wolf * 10/18/02 */ void vscan_init(char log_file_in[], struct vscan_param_struct vscan_par) { /* Declare variables */ int err; int i; /* Save parameters for future use */ strcpy(log_file, log_file_in); vscan_param = vscan_par; /* Check all parameter values to find any problems */ err = vscan_check_param(); if (err != 0) { vscan_error("Problem with parameter values"); return; } /* Initialize the required hardware */ if (vscan_param.config == VSCAN_MOVEZ_HP3458) { for (i = 0; i < vscan_param.num_dvm; i++) hp3458_init(vscan_param.board_addr, vscan_param.dvm_info[i].addr, &hp3458_ID[i]); } else if (vscan_param.config == VSCAN_NONE_NONE) { } else { vscan_error("Unknown integrated voltage system configuration"); return; } /* Done */ return; } /* ************************************************************** */ /* * vscan_get_v * This function measures the voltages from the probes as they are moved. * * Input: * start_pos, start position of the probes (m) * dist_move, distance the probes move, sign gives the direction (m) * * Output: * num_dvm, the number of DVMs taking samples * dvm_info[0 to num_dvm - 1], information about each DVM * num_samp, the number of voltage samples taken by each DVM * pos_samp[0 to num_samp - 1], positions of the samples (m) * v_samp[0 to num_dvm - 1][0 to num_samp - 1], measured voltage samples from each DVM (V), (note dimensions on 2-D array) * * Zachary Wolf * 10/18/02 */ void vscan_get_v(double start_pos, double dist_move, int* num_dvm, struct vscan_dvm_info_struct dvm_info[], int* num_samp, double pos_samp[], double v_samp[VSCAN_MAX_NUM_DVM][VSCAN_MAX_NUM_SAMP]) { /* Declare variables */ int err; int i, j; /* Check input parameters */ if (fabs(start_pos) > 1.) { vscan_error("vscan_get_v: start_pos has improper value"); return; } if (fabs(dist_move) < 1.e-6 || fabs(dist_move) > 10.) { vscan_error("vscan_get_v: dist_move has improper value"); return; } /* Check all module level parameter values */ err = vscan_check_param(); if (err != 0) { vscan_error("Problem with parameter values"); return; } /* Get the number of DVMs */ *num_dvm = vscan_param.num_dvm; /* Get the information about each DVM */ for (i = 0; i < *num_dvm; i++) dvm_info[i] = vscan_param.dvm_info[i]; /* Calculate the number of voltage samples to take */ *num_samp = fabs(dist_move) / vscan_param.dist_btwn_trig_pulse; if (*num_samp < 1 || *num_samp > VSCAN_MAX_NUM_SAMP) { vscan_error("vscan_get_v: num_samp has improper value"); return; } /* Calculate the positions of the samples */ for (j = 0; j <= *num_samp; j++) pos_samp[j] = start_pos + (dist_move / fabs(dist_move)) * j * vscan_param.dist_btwn_trig_pulse; /* Perform the measurement with the appropriate hardware */ if (vscan_param.config == VSCAN_MOVEZ_HP3458) { /* Move to the starting point */ movez_abs_move(start_pos); /* Begin sampling */ for (i = 0; i < *num_dvm; i++) hp3458_setup_triggered_voltage_samples(hp3458_ID[i], vscan_param.dvm_info[i].range, 1, *num_samp); for (i = 0; i < *num_dvm; i++) hp3458_start_triggered_voltage_samples(hp3458_ID[i]); /* Move the probe */ movez_abs_move(start_pos + dist_move); /* Get the samples */ for (i = 0; i < *num_dvm; i++) hp3458_collect_triggered_voltage_samples(hp3458_ID[i], *num_samp, v_samp[i]); } else if (vscan_param.config == VSCAN_NONE_NONE) { for (i = 0; i < *num_dvm; i++) {for (j = 0; j < *num_samp; j++) v_samp[i][j] = 0.;} } else { vscan_error("Unknown system configuration"); return; } /* Log the measurement */ vscan_log_get_v(start_pos, dist_move, *num_dvm, dvm_info, *num_samp); /* Done */ return; } /* ************************************************************** */ /* * vscan_move_probe_abs * This function is used by higher level functions to move the * probe to a desired position. * * Input: * pos, nominal position to move the probe to (m) * * Zachary Wolf * 10/23/02 */ void vscan_move_probe_abs(double pos) { /* Declare variables */ int err; /* Check all parameter values */ err = vscan_check_param(); if (err != 0) { vscan_error("Problem with parameter values"); return; } /* Move to the desired position */ if (vscan_param.config == VSCAN_MOVEZ_HP3458) { movez_abs_move(pos); } else if (vscan_param.config == VSCAN_NONE_NONE) { } else { vscan_error("Unknown system configuration"); return; } /* Done */ return; } /* ************************************************************** */ /* * vscan_set_zero_pos * This function has the user move the probe to the zero position * and then it zeros the stages. * * Zachary Wolf * 10/23/02 */ void vscan_set_zero_pos(void) { /* Declare variables */ int err; /* Check all parameter values */ err = vscan_check_param(); if (err != 0) { vscan_error("Problem with parameter values"); return; } /* Zero the stages */ if (vscan_param.config == VSCAN_MOVEZ_HP3458) { movez_zero(); } else if (vscan_param.config == VSCAN_NONE_NONE) { } else { vscan_error("Unknown system configuration"); return; } /* Done */ return; } /* ************************************************************** */ /* * vscan_exit * This function is used to exit the integrated voltage * measurement system. * * Zachary Wolf * 10/23/02 */ void vscan_exit(void) { /* Declare variables */ int i; /* Exit the hardware */ if (vscan_param.config == VSCAN_MOVEZ_HP3458) { for (i = 0; i < vscan_param.num_dvm; i++) hp3458_exit(hp3458_ID[i]); } else if (vscan_param.config == VSCAN_NONE_NONE) { } else { vscan_error("Unknown system configuration"); return; } /* Done */ return; } /* ************************************************************** */ /* INTERNAL FUNCTIONS */ /* ************************************************************** */ /* * vscan_error * This function handles errors for the VSCAN module. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 10/11/98 */ void vscan_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nVSCAN ERROR: %s\n", message); Beep(); Delay(.5); Beep(); /* Terminate the program if the operator desires */ printf("Press ENTER to continue.\nPress any key then ENTER to terminate program.\n"); fgets(buf, 80, stdin); if (buf[0] == '\n') return; else exit(0); } /* ************************************************************** */ /* * vscan_message * This function handles messages for the IMAG module. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 10/12/98 */ void vscan_message(char* message) { /* Print the message */ printf("%s\n", message); /* Done */ return; } /* ************************************************************** */ /* * vscan_check_param * This function checks that all required parameters have been assigned * appropriate values. * * Output: * err, 0 = no error, non-zero = error * * Zachary Wolf * 10/23/02 */ int vscan_check_param() { /* Declare variables */ int i; /* log_file */ if (CompareStrings(log_file, 0, "", 0, 0) == 0) { vscan_error("Log file not defined."); return -1; } /* vscan_param.board_addr */ if (vscan_param.board_addr < 0 || vscan_param.board_addr > 10) { Fmt(msg, "%s VSCAN_MAX_NUM_DVM) { Fmt(msg, "%s 30) { Fmt(msg, "%s 100.) { Fmt(msg, "%s .01) { Fmt(msg, "%s