Browse Source

add dac test code

git-svn-id: https://bucket.mit.edu/svn/nilm/zoom@8675 ddd99763-3ecb-0310-9145-efcb8ce7c51f
tags/zoom-1.0
jim 14 years ago
parent
commit
65bb278628
6 changed files with 171 additions and 1 deletions
  1. +4
    -1
      pc/Makefile
  2. +134
    -0
      pc/dactest.c
  3. +18
    -0
      pc/gpib.c
  4. +1
    -0
      pc/gpib.h
  5. +13
    -0
      pc/zoom.c
  6. +1
    -0
      pc/zoom.h

+ 4
- 1
pc/Makefile View File

@@ -1,6 +1,6 @@
CFLAGS=-Wall

all: read calibrate dctest
all: read calibrate dctest dactest

serial-util.o: serial-util.h

@@ -16,6 +16,8 @@ calibrate.o: serial-util.h gpib.h zoom.h

dctest.o: serial-util.h gpib.h zoom.h mt19937ar.h

dactest.o: serial-util.h gpib.h zoom.h mt19937ar.h

read: read.o serial-util.o

calibrate: calibrate.o serial-util.o gpib.o zoom.o
@@ -23,5 +25,6 @@ calibrate: calibrate.o serial-util.o gpib.o zoom.o
dctest: LDFLAGS=-lpthread
dctest: dctest.o serial-util.o gpib.o zoom.o mt19937ar.o

dactest: dactest.o serial-util.o gpib.o zoom.o mt19937ar.o
clean:
rm -f *.o read calibrate dctest

+ 134
- 0
pc/dactest.c View File

@@ -0,0 +1,134 @@
/* Test DAC for stability etc */

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <errno.h>
#include <unistd.h>
#include <getopt.h>
#include <stdint.h>
#include <string.h>
#include <syslog.h>
#include <err.h>
#include <linux/serial.h>
#include <sys/signal.h>
#include "serial-util.h"
#include "gpib.h"
#include "zoom.h"
#include <math.h>
#include "mt19937ar.h"

void write_random(int zoom, int gpib);

#define info(x...) fprintf(stderr,x)

int g_quit = 0;
void handle_sig(int sig) { g_quit = 1; }

int main(int argc, char *argv[])
{
char *zoomdev=strdup("/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A6007wc5-if00-port0");
char *gpibdev=strdup("/dev/serial/by-id/usb-Prologix_Prologix_GPIB-USB_Controller_PXQQY20G-if00-port0");
int getopt_index;
int zoom, gpib;
unsigned long seed = 1337;

static struct option long_opts[] = {
{ "zoom-device", required_argument, NULL, 'Z' },
{ "gpib-device", required_argument, NULL, 'G' },
{ "seed", required_argument, NULL, 's' },
{ "help", no_argument, NULL, 'h' },
{ 0, 0, 0, 0}
};
int help=0;
char c;

while ((c = getopt_long(argc, argv, "Z:G:s:h?",
long_opts, &getopt_index)) != -1) {
switch(c)
{
case 'Z':
free(zoomdev);
zoomdev = strdup(optarg);
break;
case 'G':
free(gpibdev);
gpibdev = strdup(optarg);
break;
case 's':
seed = atol(optarg);
if(seed == 0)
errx(1, "invalid seed: %s", optarg);
break;
case 'h':
case '?':
default:
help = 1;
break;
}
}
if (help) {
fprintf(stderr, "Zoom Nilm DC Test\n");
fprintf(stderr, "usage: %s [options]\n\n", *argv);
fprintf(stderr, " -Z, --zoom-device %-14s zoom NILM serial port\n", "/dev/xxx" /*zoomdev*/);
fprintf(stderr, " -G, --gpib-device %-14s GPIB serial port\n", "/dev/xxx" /*gpibdev*/);
fprintf(stderr, " -s, --seed %-16ld random seed\n", seed);
fprintf(stderr, " -h, --help this help\n");
return 1;
}

signal(SIGINT, handle_sig);

info("Initializing twister with seed %ld\n", seed);
init_genrand(seed);

info("Opening Zoom NILM device %s\n", zoomdev);
if ((zoom = serial_open(zoomdev, 115200)) == -1)
err(1, "failed to open zoom device %s", zoomdev);

info("Opening GPIB device %s\n", gpibdev);
if ((gpib = serial_open(gpibdev, 9600)) == -1)
err(1, "failed to open gpib device %s", gpibdev);

/* do it */
write_random(zoom, gpib);

close(zoom);
close(gpib);
return 0;
}

void write_random(int zoom, int gpib)
{
int dac;
double meas;

info("Initializing Zoom NILM\n");
if (zoom_init_nozero(zoom) < 0) goto fail;

info("Initializing GPIB\n");
if (gpib_init(gpib) < 0) goto fail;

info("Initializing Keithley\n");
if (gpib_addr(gpib, 23) < 0) goto fail;
if (keithley2002_init_volts(gpib) < 0) goto fail;
if (isnan(keithley2002_read(gpib))) goto fail;

info("Running\n");
while (!g_quit) {
dac = genrand_int32() & 0x3ff;
meas = keithley2002_read(gpib);
if (isnan(meas))
goto fail;
printf("%d %.12f\n", dac, meas);
}

safecleanup:
return;

fail:
info("Failed\n");
goto safecleanup;
}

+ 18
- 0
pc/gpib.c View File

@@ -1,6 +1,8 @@
#include <stdio.h>
#include <string.h>
#ifndef __USE_ISOC99
#define __USE_ISOC99
#endif
#include <math.h>
#include "gpib.h"
#include "serial-util.h"
@@ -108,6 +110,22 @@ int keithley2002_init2(int fd)
return 0;
}

int keithley2002_init_volts(int fd)
{
double i;
gput(":trac:cle");
gput(":sens:func 'volt:dc'");
gput(":sens:volt:dc:rang 5");
gput(":sens:volt:dc:dig 8");
gput(":form:elem read");
gput(":init:cont off");
drain(fd);
i = keithley2002_read(fd);
if (isnan(i))
return -1;
return 0;
}

double keithley2002_read(int fd)
{
char s[128];


+ 1
- 0
pc/gpib.h View File

@@ -11,6 +11,7 @@ int keithley_off(int fd);

int keithley2002_init(int fd);
int keithley2002_init2(int fd);
int keithley2002_init_volts(int fd);
double keithley2002_read(int fd);
double keithley2002_read2(int fd, double* tx);
#endif


+ 13
- 0
pc/zoom.c View File

@@ -1,6 +1,8 @@
#include <stdio.h>
#include <string.h>
#ifndef __USE_ISOC99
#define __USE_ISOC99
#endif
#include <math.h>
#include "zoom.h"
#include "serial-util.h"
@@ -78,6 +80,17 @@ int zoom_sweep(int fd, int dac[ZOOM_SWEEP_COUNT], int adc[ZOOM_SWEEP_COUNT])
return 0;
}

int zoom_write_dac(int fd, int dac)
{
char s[128];
sprintf(s, "v%04x", dac);
zputs(s);
if (verify_prompt(fd) < 0)
return -1;
return last_dac;
}

/* Run mode: */

void zoomrun_trigger_calibrate(int fd)


+ 1
- 0
pc/zoom.h View File

@@ -10,6 +10,7 @@ int zoom_init_real(int fd, int dozero);
int zoom_zero_start(int fd);
int zoom_zero_stop(int fd);
int zoom_sweep(int fd, int dac[ZOOM_SWEEP_COUNT], int adc[ZOOM_SWEEP_COUNT]);
int zoom_write_dac(int fd, int dac);

/* run mode */
void zoomrun_trigger_calibrate(int fd);


Loading…
Cancel
Save