#include "inst.h" #include #include #include #include #include #define NSAMP 10 #define NSTEP 10 #define STRLEN 100 static void usage () { fprintf(stderr, "cadc: usage: cadc -c chn -b board\n"); exit(1); } int main (int argc, char **argv) { #ifdef BUILD_LOAD int i; int chn = -1; char c; long id = 0; long ov; char bname[STRLEN] = { 0 }; float v; load_init(); while ((c = getopt(argc, argv, "c:b:")) != -1) { switch (c) { case 'c': chn = atoi(optarg); break; case 'b': strncpy(bname, optarg, STRLEN - 1); bname[STRLEN - 1] = 0; break; default: strncpy(bname, optarg, STRLEN - 1); bname[STRLEN - 1] = 0; break; case '?': usage(); } } if (strlen(bname) == 0 || chn < 0) usage(); fprintf(stderr, "Calibrating board %s, chn %d\n", bname, chn); if (surf_brd_ena(bname, chn, 1) < 0) return 2; if (surf_brd_end(bname, chn, 1) < 0) return 2; for (i = 0; i < NSTEP; ++i) { int j; int adc; float sum_a = 0, sum_d = 0; float adc_a = 0, adc_d = 0; /* set currents */ load_set_current(1, 1.3 * i / (double)(NSTEP - 1)); load_set_current(2, 1.6 * i / (double)(NSTEP - 1)); for (j = 0; j < NSAMP; ++j) { usleep(5e5); sum_d += 1.3 * i / (double)(NSTEP - 1); /* load_get_current is a scam anyways */ sum_a += 1.6 * i / (double)(NSTEP - 1); if ((adc = surf_brd_get_dig_i_adc(bname, chn)) < 0) return 2; adc_d += adc; if ((adc = surf_brd_get_anl_i_adc(bname, chn)) < 0) return 2; adc_a += adc; /* printf(" %3x", adc); */ /* fflush(stdout); */ } printf("%.3f / %4d (digital)\t%.3f / %4d (analog)\n", sum_d / (double)NSAMP, (int)rint(adc_d / (double)NSAMP), sum_a / (double)NSAMP, (int)rint(adc_a / (double)NSAMP)); fflush(stdout); } if (surf_brd_ena(bname, chn, 0) < 0) return 2; if (surf_brd_end(bname, chn, 0) < 0) return 2; #endif return 0; }