Browse Source

Update scaling with new values, and fix bug in combination

git-svn-id: https://bucket.mit.edu/svn/nilm/zoom@7590 ddd99763-3ecb-0310-9145-efcb8ce7c51f
tags/zoom-1.0
jim 15 years ago
parent
commit
c3bd4a62d7
1 changed files with 30 additions and 6 deletions
  1. +30
    -6
      pc/read.c

+ 30
- 6
pc/read.c View File

@@ -14,6 +14,7 @@
#include <linux/serial.h>

int hex = 0;
int dec = 0;
int screen = 0;
int unprocessed = 0;
int total = 0;
@@ -75,7 +76,9 @@ int main(int argc, char *argv[])
{ "device", required_argument, NULL, 'd' },
{ "rate", required_argument, NULL, 'r' },
{ "hex", no_argument, NULL, 'x' },
{ "dec", no_argument, NULL, 'D' },
{ "total", no_argument, NULL, 't' },
{ "raw", no_argument, NULL, 'R' },
{ "unprocessed", no_argument, NULL, 'u' },
{ "screen", no_argument, NULL, 's' },
{ "help", no_argument, NULL, 'h' },
@@ -84,7 +87,7 @@ int main(int argc, char *argv[])
int help=0;
char c;

while ((c = getopt_long(argc, argv, "d:r:xutsh?",
while ((c = getopt_long(argc, argv, "d:r:xDutsh?",
long_opts, &getopt_index)) != -1) {
switch(c)
{
@@ -100,6 +103,9 @@ int main(int argc, char *argv[])
case 'x':
hex = 1;
break;
case 'D':
dec = 1;
break;
case 't':
total = 1;
break;
@@ -148,11 +154,27 @@ int main(int argc, char *argv[])
return 1;
}

uint16_t current_to_dac(float amps)
{
float tmp;
uint16_t dacc;

tmp = 536.0 / 1.0 * amps + 32524;
if (tmp < 0)
tmp = 0;
if (tmp > 65535)
tmp = 65535;
dacc = (uint16_t)(tmp + 0.5);

return dacc;
}

/* Convert the DAC output value to an effective current in the measuring loop */
float dac_to_current(uint16_t dacv)
{
float amps;
amps = dacv * (20.0 / 32768.0) - 20.0;
return amps;
amps = ((float)dacv - 32524.0) * 1.0 / 536.0;
return amps;
}

float adc12_to_current(int16_t picv)
@@ -164,7 +186,7 @@ float adc12_to_current(int16_t picv)
if (picv > 2047)
picv = 2047;
amps = (1024.0 - picv) / 3522.6;
amps = (picv - 1024.0) / 404.0;
return amps;
}

@@ -215,11 +237,13 @@ int process(const uint8_t *buf, int len)
/* send it out */
if (hex) {
printf("%04x %03x", dac, adc & 0x0FFF);
} else if (dec) {
printf("%d %d", dac, adc & 0x0FFF);
} else if (total) {
printf("%.6f", idac + iadc);
printf("%.6f", idac - iadc);
} else {
printf("DAC: %5d (% f) ADC: % 5d (% f) Total: % 10.6f amps",
dac, idac, (int16_t)adc, iadc, idac + iadc);
dac, idac, (int16_t)adc, iadc, idac - iadc);

if (adc < 0 || adc >= 2047)
printf(" **** adc limit");


Loading…
Cancel
Save