feeling a little better from the flu so i thought I give processing raw dump. it mostly works wellish. some benefits so far. is I can get sample from all analog port (8) every ~1/2 second . where as doing it the normal way the more ports you have the longer the wait time would become …
but the strange behaviour, and I can not figure out why it does it… when I run the program…for some reason when usage is at zero it sits at 2.6 amps… and it seams maintain this until I pass the 2.6 amps threshold for usage. then once it passes that for usage - it works fine .
I wrote a small program that look at the raw data and extract only the peek and valley. it sits at almost a constant when at zero usage and and as you increase usage the variation increases as expected
here my code for just one analog pin
#!/usr/bin/perl -w -s
system("stty -F /dev/ttyS18 115200 cs8 raw");
open INFILE, "/dev/ttyS18"
or die "\nCannot open the device!\n";
@data = ();
$buf = "";
$cnt = 0;
$started = 0;
$st= 0;
$ICAL=60.606;
$offsetI = (1023>>1);
# looks at udp stream thats linked to a virtual port to find the start bit of 0xaa and extracts the whole key
sub processPacket($);
while (read(INFILE, $buf, 1)) {
$d = ord($buf) ;
if ($d == 0xaa && $started == 0) {
$started = 1;
$a = 0;
}
if ($started == 1) {
$data[$a] = $d;
$sum += $data[$a];
# printf("0x%02X ", $data[$a]);
$a++;
if ($a >= 17) {
# $sum -= $data[16];
# $sum &= 0xff;
$sum = 0;
if ($sum == 0) { processPacket($data); }
$started=1;
$a = 0;
# print "\n";
}
}
}
# Working sub process packet converts the bits back to usable info
sub processPacket($) {
local($data) = @_;
$A0 = ($data[1]<<8) + $data[2];
$A1 = ($data[3]<<8) + $data[4];
$A2 = ($data[5]<<8) + $data[6];
$A3 = ($data[7]<<8) + $data[8];
$A4 = ($data[9]<<8) + $data[10];
$A5 = ($data[11]<<8) + $data[12];
$A6 = ($data[13]<<8) + $data[14];
$A7 = ($data[15]<<8) + $data[16];
# print "$A0,$A1,$A2,$A3,$A4.$A5,$A6,$A7\n";
{
$sampleI = ($A0);
$offsetI = ($offsetI + ($sampleI-$offsetI)/1024);
$filteredI = $sampleI - $offsetI;
$sqI = $filteredI * $filteredI;
$sumI += $sqI;
}
$cnt1++;
if ($cnt1==2000){
$I_RATIO = $ICAL *((5000/1000.0) / (1024));
$Irms = $I_RATIO * sqrt($sumI / 2000);
$sumI = 0;
$cnt1=0;
print " amps $Irms\n";
}
}
close INFILE;
so curiously would anyone have explanation for the strange behaviour and perhaps a suggestion on how to correct it … my brain just not working yet