From 35c123e5676bc0763d6becc5df4e804288b37a99 Mon Sep 17 00:00:00 2001 From: Ole Artz Date: Mon, 24 Aug 2020 10:10:23 +0200 Subject: [PATCH] DCDC MDC Single Dummy: correction of bit postion in shift_register for the resistors of voltage divider --- atmega32u4/dcdc_mdc_single_dummy/main.c | 68 ++++++++----------------- 1 file changed, 20 insertions(+), 48 deletions(-) diff --git a/atmega32u4/dcdc_mdc_single_dummy/main.c b/atmega32u4/dcdc_mdc_single_dummy/main.c index 3776d63..642791c 100644 --- a/atmega32u4/dcdc_mdc_single_dummy/main.c +++ b/atmega32u4/dcdc_mdc_single_dummy/main.c @@ -46,8 +46,8 @@ // |-----------|--------------------------------------------------------------| // | 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 | @@ -187,53 +187,25 @@ void switchLDO(uint8_t chan, uint8_t val) { 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(); } @@ -270,7 +242,7 @@ void setInfo(uint8_t chan, uint8_t val){ // |-----------|--------------------------------------------------------------| // | 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) | @@ -371,16 +343,16 @@ void getdata(uint8_t buf) { 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); } -- 2.43.0