// |-----------|--------------------------------------------------------------|
// | 0 | LDO ON/OFF |
// | 1 | DCDC set voltage adjustment resistors |
-// | 2 | Voltage V_in (RO) |
-// | 3 | Current C_in (RO) |
+// | 2 | Voltage V_in (NA) |
+// | 3 | Current C_in (NA) |
// | 4 | Temperature (RO) |
// | 5 | [15:4] Firmware; [3:2] reserved; [1] Switch ; [0] LED (RO) |
// | 6 | Current Offset |
void setDCDC(uint8_t chan, uint8_t val) {
//DCDC CH0
- if (chan == 3) {
+ if (chan == 3 & val<=7) {
shift_register &= ~((1<<15)|(1<<14)|(1<<13)); //clear decbitpos15-13
- if (val == 0) {}
- if (val == 1) {shift_register |= (1<<15);}
- if (val == 2) {shift_register |= (1<<14);}
- if (val == 3) {shift_register |= (1<<15)|(1<<14);}
- if (val == 4) {shift_register |= (1<<13);}
- if (val == 5) {shift_register |= (1<<15)|(1<<13);}
- if (val == 6) {shift_register |= (1<<14)|(1<<13);}
- if (val == 7) {shift_register |= (1<<15)|(1<<14)|(1<<13);}
- }
+ shift_register |= val<<13;
+ }
//DCDC CH1
- if (chan == 4) {
+ if (chan == 4 & val<=7) {
shift_register &= ~((1<<11)|(1<<10)|(1<<9));
- if (val == 0) {}
- if (val == 1) {shift_register |= (1<<11);}
- if (val == 2) {shift_register |= (1<<10);}
- if (val == 3) {shift_register |= (1<<11)|(1<<10);}
- if (val == 4) {shift_register |= (1<<19);}
- if (val == 5) {shift_register |= (1<<11)|(1<<9);}
- if (val == 6) {shift_register |= (1<<10)|(1<<9);}
- if (val == 7) {shift_register |= (1<<11)|(1<<10)|(1<<9);}
- }
+ shift_register |= val<<9;
+ }
//LDO CH1
- if (chan == 2) {
+ if (chan == 2 & val<=7) {
shift_register &= ~((1<<7)|(1<<6)|(1<<5));
- if (val == 0) {}
- if (val == 1) {shift_register |= (1<<7);}
- if (val == 2) {shift_register |= (1<<6);}
- if (val == 3) {shift_register |= (1<<7)|(1<<6);}
- if (val == 4) {shift_register |= (1<<5);}
- if (val == 5) {shift_register |= (1<<7)|(1<<5);}
- if (val == 6) {shift_register |= (1<<6)|(1<<5);}
- if (val == 7) {shift_register |= (1<<7)|(1<<6)|(1<<5);}
- }
+ shift_register |= val<<5;
+ }
//LDO CH0
- if (chan == 1) {
- shift_register &= ~((1<<2)|(1<<1)|(1<<0));
- if (val == 0) {}
- if (val == 1) {shift_register |= (1<<2);}
- if (val == 2) {shift_register |= (1<<1);}
- if (val == 3) {shift_register |= (1<<2)|(1<<1);}
- if (val == 4) {shift_register |= (1<<0);}
- if (val == 5) {shift_register |= (1<<2)|(1<<1);}
- if (val == 6) {shift_register |= (1<<1)|(1<<0);}
- if (val == 7) {shift_register |= (1<<2)|(1<<1)|(1<<0);}
- }
+ if (chan == 1 & val<=7) {
+ shift_register &= ~((1<<2)|(1<<1)|(1<<0));Sense5 Vmon1 LDO
+ shift_register |= val<<0;
+ }
setVoltages();
}
// |-----------|--------------------------------------------------------------|
// | 0 | LDO ON/OFF |
// | 1 | DCDC set voltage adjustment resistors |
-// | 2 | Voltage V_in (RO) |
+// | 2 | Voltage V_in Sense5 Vmon1 LDO (RO) |
// | 3 | Current C_in (RO) |
// | 4 | Temperature (RO) |
// | 5 | [15:4] Firmware; [3:2] reserved; [1] Switch ; [0] LED (RO) |
if (hex_to_int(rxbuf[5]) == 1) {
uint16_t read_setting = 0xFFFF;
//DCDC CH0
- if (hex_to_int(rxbuf[4]) == 3) {read_setting = ((shift_register >> 15) & 1) | ((shift_register >> 13) & 2) | ((shift_register >> 11) & 4);
+ if (hex_to_int(rxbuf[4]) == 3) {read_setting = (shift_register >> 13) & 7;
}
//DCDC CH1
- if (hex_to_int(rxbuf[4]) == 4) {read_setting = ((shift_register >> 11) & 1) | ((shift_register >> 9) & 2) | ((shift_register >> 7) & 4);
+ if (hex_to_int(rxbuf[4]) == 4) {read_setting = (shift_register >> 9) & 7;
}
//LDO CH1
- if (hex_to_int(rxbuf[4]) == 2) {read_setting = ((shift_register >> 7) & 1) | ((shift_register >> 5) & 2) | ((shift_register >> 3) & 4);
+ if (hex_to_int(rxbuf[4]) == 2) {read_setting = (shift_register >> 5) & 7;
}
//LDO CH0
- if (hex_to_int(rxbuf[4]) == 1) {read_setting = ((shift_register >> 2) & 1) | (shift_register & 2) | ((shift_register << 2) & 4);
+ if (hex_to_int(rxbuf[4]) == 1) {read_setting = shift_register & 7;
}
send_answer_hex(&rxbuf[0],read_setting);
}