calibration routine.. maybe
git-svn-id: https://bucket.mit.edu/svn/nilm/zoom@7610 ddd99763-3ecb-0310-9145-efcb8ce7c51f
This commit is contained in:
parent
c8c5a7a846
commit
624b6e42b9
|
@ -13,15 +13,13 @@
|
|||
#include "serial-util.h"
|
||||
#include "gpib.h"
|
||||
#include "zoom.h"
|
||||
#include "math.h"
|
||||
|
||||
void calibrate(int zoom, int gpib);
|
||||
#define info(x...) fprintf(stderr,x)
|
||||
|
||||
int quit = 0;
|
||||
void handle_sig(int sig)
|
||||
{
|
||||
quit = 1;
|
||||
}
|
||||
int g_quit = 0;
|
||||
void handle_sig(int sig) { g_quit = 1; }
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -83,32 +81,60 @@ int main(int argc, char *argv[])
|
|||
|
||||
void calibrate(int zoom, int gpib)
|
||||
{
|
||||
float i;
|
||||
float idesired, iactual;
|
||||
int i;
|
||||
int zero;
|
||||
int dac[ZOOM_SWEEP_COUNT];
|
||||
int adc[ZOOM_SWEEP_COUNT];
|
||||
|
||||
info("Initializing Zoom NILM\n");
|
||||
if (zoom_init(zoom) < 0) {
|
||||
info("Not responding\n");
|
||||
return;
|
||||
}
|
||||
if (zoom_init(zoom) < 0) goto fail;
|
||||
|
||||
info("Zeroing\n");
|
||||
if (zoom_zero_start(zoom) < 0) goto fail;
|
||||
|
||||
info("Initializing GPIB\n");
|
||||
gpib_init(gpib);
|
||||
if (gpib_init(gpib) < 0) goto fail;
|
||||
|
||||
info("Initializing Keithley\n");
|
||||
gpib_addr(gpib, 24);
|
||||
if (keithley_init(gpib) < 0) {
|
||||
info("Not responding\n");
|
||||
return;
|
||||
}
|
||||
|
||||
info("Sweep\n");
|
||||
for (i = -1.0; i <= 1.0; i += 0.01) {
|
||||
keithley_current(gpib, i);
|
||||
printf("requested %f, actual %f\n", i, keithley_read(gpib));
|
||||
if (quit) break;
|
||||
usleep(10000);
|
||||
if (quit) break;
|
||||
if (gpib_addr(gpib, 24) < 0) goto fail;
|
||||
if (keithley_init(gpib) < 0) goto fail;
|
||||
if (keithley_current(gpib, 0) < 0) goto fail;
|
||||
if (isnan(keithley_read(gpib))) goto fail;
|
||||
|
||||
info("Stop zeroing\n");
|
||||
if (zoom_zero_stop(zoom) < 0) goto fail;
|
||||
|
||||
info("Sweeping\n");
|
||||
for (idesired = -1.0; idesired <= 1.0 && !g_quit; idesired += 0.01) {
|
||||
info("Zeroing\n");
|
||||
if (zoom_zero_start(zoom) < 0) goto fail;
|
||||
|
||||
info("Setting current: %f\n", idesired);
|
||||
keithley_current(gpib, idesired);
|
||||
iactual = keithley_read(gpib);
|
||||
info("Actual current: %f\n", iactual);
|
||||
|
||||
info("Stop zeroing\n");
|
||||
if ((zero = zoom_zero_stop(zoom)) < 0) goto fail;
|
||||
info("DAC zero point = %d\n", zero);
|
||||
|
||||
info("Sweeping\n");
|
||||
if (zoom_sweep(zoom, dac, adc) < 0) goto fail;
|
||||
|
||||
info("Results:\n");
|
||||
for (i = 0; i < ZOOM_SWEEP_COUNT; i++) {
|
||||
printf("%8f %d %d\n", iactual, dac[i], adc[i]);
|
||||
}
|
||||
}
|
||||
|
||||
zoom_zero_start(zoom);
|
||||
keithley_off(gpib);
|
||||
usleep(100000);
|
||||
zoom_zero_stop(zoom);
|
||||
return;
|
||||
|
||||
fail:
|
||||
info("Failed\n");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#define zputs(s) do { if (safewrite(fd, s, strlen(s)) != strlen(s)) return -1; } while(0)
|
||||
#define zputc(ch) do { const char ____c = ch; if (safewrite(fd, &____c, 1) != 1) return -1; } while(0)
|
||||
|
||||
static int last_dac, last_adc;
|
||||
|
||||
static int verify_prompt(int fd)
|
||||
{
|
||||
char s[128];
|
||||
|
@ -19,6 +21,8 @@ static int verify_prompt(int fd)
|
|||
return -1;
|
||||
if (dac1 != dac2 || adc1 != adc2)
|
||||
return -1;
|
||||
last_dac = dac1;
|
||||
last_adc = adc1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -49,7 +53,7 @@ int zoom_zero_stop(int fd)
|
|||
zputc(' ');
|
||||
if (verify_prompt(fd) < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
return last_dac;
|
||||
}
|
||||
|
||||
int zoom_sweep(int fd, int dac[ZOOM_SWEEP_COUNT], int adc[ZOOM_SWEEP_COUNT])
|
||||
|
|
Loading…
Reference in New Issue
Block a user