changed currents to unsigned int and checked while getting these values.

This commit is contained in:
Lucas Pleß 2013-06-14 22:46:01 +02:00
parent 1a7c59bed8
commit cc96b5baf3
3 changed files with 17 additions and 23 deletions

View File

@ -8,8 +8,8 @@
volatile uint16_t syscounter = 0; volatile uint16_t syscounter = 0;
uint16_t voltage = 0; uint16_t voltage = 0;
int16_t current_in = 0; uint16_t current_in = 0;
int16_t current_out = 0; uint16_t current_out = 0;
uint8_t overvoltage_counter1 = 0; uint8_t overvoltage_counter1 = 0;
uint8_t overvoltage_off_counter1 = 0; uint8_t overvoltage_off_counter1 = 0;
@ -33,16 +33,20 @@ static void ports_init(void) {
} }
void measure(void) { void measure(void) {
static int16_t temp;
voltage = adc_read_avg(AD_V, 4); voltage = adc_read_avg(AD_V, 4);
voltage *= VOLTAGE_PER_TICK; voltage *= VOLTAGE_PER_TICK;
current_in = adc_read_avg(AD_I_GEN, 4); temp = adc_read_avg(AD_I_GEN, 4);
current_in -= CURRENT_OFFSET; temp -= CURRENT_OFFSET;
current_in *= CURRENT_PER_TICK; if(temp < 0) temp = 0;
current_in = temp * CURRENT_PER_TICK;
current_out = adc_read_avg(AD_I_LOAD, 4); temp = adc_read_avg(AD_I_LOAD, 4);
current_out -= CURRENT_OFFSET; temp -= CURRENT_OFFSET;
current_out *= CURRENT_PER_TICK; if(temp < 0) temp = 0;
current_out = temp * CURRENT_PER_TICK;
} }
uint16_t get_power(uint16_t voltage, int16_t currents) { 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("mV\r\n");
uart_puts_P("Load: "); uart_puts_P("Load: ");
uart_print_int16(current_out); uart_print_uint16(current_out);
uart_puts_P("mA "); uart_puts_P("mA ");
uart_print_uint16( get_power(voltage, current_out)); uart_print_uint16( get_power(voltage, current_out));
uart_puts_P("W\r\n"); uart_puts_P("W\r\n");
uart_puts_P("Generator: "); uart_puts_P("Generator: ");
uart_print_int16(current_in); uart_print_uint16(current_in);
uart_puts_P("mA "); uart_puts_P("mA ");
uart_print_uint16(get_power(voltage, current_in)); uart_print_uint16(get_power(voltage, current_in));
uart_puts_P("W\r\n"); uart_puts_P("W\r\n");
@ -165,7 +169,7 @@ static void work_uart(void) {
break; break;
case 'a': case 'a':
uart_putc('A'); uart_putc('A');
uart_print_voltage(voltage); uart_print_uint16(voltage);
uart_putc(','); uart_putc(',');
uart_print_uint16(current_in); uart_print_uint16(current_in);
uart_putc(','); uart_putc(',');
@ -180,9 +184,10 @@ static void work_uart(void) {
uart_putc(48 + (IS_DUMP_ON >> DUMPSW)); uart_putc(48 + (IS_DUMP_ON >> DUMPSW));
uart_putc(','); uart_putc(',');
uart_putc(48 + (IS_GEN_ON >> GENSW)); uart_putc(48 + (IS_GEN_ON >> GENSW));
uart_putc('B');
break; break;
} }
uart_putc('\n');
} }
} }

View File

@ -25,16 +25,6 @@ void uart_print_uint8(uint8_t x) {
uart_putc(48 + (x % 10)); 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) { void uart_print_uint16(uint16_t x) {
uart_putc(48 + (x / 10000)); uart_putc(48 + (x / 10000));
uart_putc(48 + (x % 10000 /1000)); uart_putc(48 + (x % 10000 /1000));

View File

@ -4,7 +4,6 @@
extern void wait(uint8_t count); extern void wait(uint8_t count);
extern void uart_print_voltage(uint16_t); extern void uart_print_voltage(uint16_t);
extern void uart_print_uint8_t(uint8_t); extern void uart_print_uint8_t(uint8_t);
extern void uart_print_int16(int16_t);
extern void uart_print_uint16(uint16_t); extern void uart_print_uint16(uint16_t);
#endif #endif