diff --git a/display/software/powerboard/src/main.c b/display/software/powerboard/src/main.c index baf5298..59daa8f 100644 --- a/display/software/powerboard/src/main.c +++ b/display/software/powerboard/src/main.c @@ -8,8 +8,8 @@ volatile uint16_t syscounter = 0; uint16_t voltage = 0; -int16_t current_in = 0; -int16_t current_out = 0; +uint16_t current_in = 0; +uint16_t current_out = 0; uint8_t overvoltage_counter1 = 0; uint8_t overvoltage_off_counter1 = 0; @@ -33,16 +33,20 @@ static void ports_init(void) { } void measure(void) { + static int16_t temp; + voltage = adc_read_avg(AD_V, 4); voltage *= VOLTAGE_PER_TICK; - current_in = adc_read_avg(AD_I_GEN, 4); - current_in -= CURRENT_OFFSET; - current_in *= CURRENT_PER_TICK; + temp = adc_read_avg(AD_I_GEN, 4); + temp -= CURRENT_OFFSET; + if(temp < 0) temp = 0; + current_in = temp * CURRENT_PER_TICK; - current_out = adc_read_avg(AD_I_LOAD, 4); - current_out -= CURRENT_OFFSET; - current_out *= CURRENT_PER_TICK; + temp = adc_read_avg(AD_I_LOAD, 4); + temp -= CURRENT_OFFSET; + if(temp < 0) temp = 0; + current_out = temp * CURRENT_PER_TICK; } uint16_t get_power(uint16_t voltage, int16_t currents) { @@ -56,13 +60,13 @@ void pretty_print_all_values(void) { uart_puts_P("mV\r\n"); uart_puts_P("Load: "); - uart_print_int16(current_out); + uart_print_uint16(current_out); uart_puts_P("mA "); uart_print_uint16( get_power(voltage, current_out)); uart_puts_P("W\r\n"); uart_puts_P("Generator: "); - uart_print_int16(current_in); + uart_print_uint16(current_in); uart_puts_P("mA "); uart_print_uint16(get_power(voltage, current_in)); uart_puts_P("W\r\n"); @@ -165,7 +169,7 @@ static void work_uart(void) { break; case 'a': uart_putc('A'); - uart_print_voltage(voltage); + uart_print_uint16(voltage); uart_putc(','); uart_print_uint16(current_in); uart_putc(','); @@ -180,9 +184,10 @@ static void work_uart(void) { uart_putc(48 + (IS_DUMP_ON >> DUMPSW)); uart_putc(','); uart_putc(48 + (IS_GEN_ON >> GENSW)); + uart_putc('B'); break; } - uart_putc('\n'); + } } diff --git a/display/software/powerboard/src/utils.c b/display/software/powerboard/src/utils.c index 4551a32..466bfec 100644 --- a/display/software/powerboard/src/utils.c +++ b/display/software/powerboard/src/utils.c @@ -25,16 +25,6 @@ void uart_print_uint8(uint8_t x) { uart_putc(48 + (x % 10)); } - -void uart_print_int16(int16_t x) { - if(x <0) uart_putc('-'); - uart_putc(48 + (x / 10000)); - uart_putc(48 + (x % 10000 /1000)); - uart_putc(48 + (x % 1000 / 100 )); - uart_putc(48 + (x % 100 / 10 )); - uart_putc(48 + (x % 10)); -} - void uart_print_uint16(uint16_t x) { uart_putc(48 + (x / 10000)); uart_putc(48 + (x % 10000 /1000)); diff --git a/display/software/powerboard/src/utils.h b/display/software/powerboard/src/utils.h index d348e09..2573b6a 100644 --- a/display/software/powerboard/src/utils.h +++ b/display/software/powerboard/src/utils.h @@ -4,7 +4,6 @@ extern void wait(uint8_t count); extern void uart_print_voltage(uint16_t); extern void uart_print_uint8_t(uint8_t); - extern void uart_print_int16(int16_t); extern void uart_print_uint16(uint16_t); #endif