my $help;
my $ser_dev;
my $isTrbNet = 0;
-Getopt::Long::Configure(qw(gnu_getopt));
+Getopt::Long::Configure(qw(gnu_getopt pass_through));
GetOptions(
'help|h' => \$help,
'device|d=s' => \$ser_dev,
my $ch = hex(substr($s,4,1));
my $uC = hex(substr($s,1,2));
my $answ = hex(substr($s,6));
-
+ print $s."\n";
print "-----------------------------------------------\n";
print "Board: ".$uC."\t";
print "Channel: ".$ch."\n";
print "SEL status : ".(($answ>>1) & 0x1)."\n";
print "LED status : ".($answ & 0x1)."\n";
}
+ if ($command == 6) { #Current Offset
+ $answ = $answ >> 4;
+ my $calc = (($answ&0x7F)-(($answ>>7)&0x1)*128)*$FSR*2; # 500mV/A -> Thats why multiplied by 2
+ printf "set Current offset : %.3f Ampere (RAW: 0x%x)\n", ($calc) , ($answ);
+ }
+
+
print "\n";
}
}
my $rw = "R";
my $val = 0x0000;
- my $cmd = sprintf("%s%02x0%01x%01x%04x",$rw,$uC,$ch,$reg,$val);
+ my $cmd = sprintf("%s%02x0%01x%01x%04x",$rw,$uC,$ch,$reg,$val&0xFFFF);
#print $cmd."\n";
PrintAnswerNice(Cmd($cmd)) #Answer without \n
} else {
# Register
$reg = $ARGV[4];
if (substr($reg,0,2) eq "0x") {$reg= hex(substr($reg,2));}
- if ($reg >= 6) {
+ if ($reg >= 7) {
die "This register does not exist\n";
}
if ($val > 0xFFFF) {
die "The value is greater than 16 bit! Only 16 bit are allowed\n";
}
- my $cmd = sprintf("%s%02x0%01x%01x%04x",$rw,$uC,$ch,$reg,$val);
+ if($reg == 6) {$val *= 16;}
+
+ my $cmd = sprintf("%s%02x0%01x%01x%04x",$rw,$uC,$ch,$reg,$val&0xffff);
print $cmd."\n";
PrintAnswerNice(Cmd($cmd)) #Answer without \n
} else {
uint16_t adc_temp = 0;
uint16_t information = 1;
uint8_t isMaster = 0;
+int8_t curr_offset = 0;
uint8_t nib_to_hex(uint16_t in, uint8_t nib) {
uint8_t t = (in >> (nib*4)) & 0xF;
* 3 | Current C_in
* 4 | Temperature
* 5 | [15:4] Firmware; [3:2] reserved; [1] Switch ; [0] LED
+ * 6 | Current Offset
***/
void getdata(uint8_t buf) {
send_answer_hex(&rxbuf[0],hex_to_int(rxbuf[9]));
break;
+ // set current offset
+ case 6: curr_offset = (hex_to_int(rxbuf[7])*16+hex_to_int(rxbuf[8]))&0xFF;
+ eeprom_update_byte((uint8_t*)(0x20+hex_to_int(rxbuf[4])),curr_offset);
+ send_answer_hex(&rxbuf[0],curr_offset*16);
+
+ break;
+
// set Infos register
case 5: setInfo(hex_to_int(rxbuf[4]),/* hex_to_int(rxbuf[6])*4096
+hex_to_int(rxbuf[7])*256
if (hex_to_int(rxbuf[5]) == 2) {
send_answer_hex(&rxbuf[0],adc_volt);
}
-
// get current C_in
if (hex_to_int(rxbuf[5]) == 3) {
send_answer_hex(&rxbuf[0],adc_curr);
information |= (FIRMWARE_VERSION<<4);
send_answer_hex(&rxbuf[0],information);
}
+
+ // get current offset
+ if (hex_to_int(rxbuf[5]) == 6) {
+ send_answer_hex(&rxbuf[0],curr_offset*16);
+ }
}
}
}
dcdc_settings[3][2] = (eeprom_value >> 2)& 0x1;
dcdc_settings[3][3] = (eeprom_value >> 3)& 0x1;
+ curr_offset = eeprom_read_byte((uint8_t*)0x26);
+
setVoltages();
SHIFT_EN_OUTPUT(); // Enable output of shift register to mosfet
sei();
//~330us for each conversion
if (ADC_State == 3) {adc_temp = read_ADC(); ADC_State = 0;}
if (ADC_State == 2) {adc_volt = read_ADC(); ADC_State = 3;}
- if (ADC_State == 1) {adc_curr = read_ADC(); ADC_State = 2;}
+ if (ADC_State == 1) {adc_curr = read_ADC() + curr_offset*16; ADC_State = 2;}
if (ADC_State == 0) ADC_State = 1;
conversion_ADC(ADC_State - 1);