main.c: disabled workaround; replaced MAX232 and capacitors => UART works fine

This commit is contained in:
Christian Kroll 2014-06-17 02:05:02 +02:00
parent 39796a93be
commit f1dca77db9
1 changed files with 11 additions and 25 deletions

View File

@ -14,12 +14,8 @@
#define BUFSIZE 10
/* ugly workaround for massive out of sequence power values,
* USART code seems to forget characters from time to time */
#define MAX_ALLOWED_DEVIATION 50
#define MAX_FAILS 3
#define DEBUG2
// #define DEBUG_UART
volatile uint16_t syscounter = 0;
uint8_t data_count = 0;
@ -55,8 +51,6 @@ static void ports_init(void) {
static void work_uart() {
static uint16_t power;
static uint8_t fail_counter = 0;
uint16_t new_power = 0, diff = 0;
uint16_t c = uart_getc();
if ( !(c & UART_NO_DATA) ) {
@ -80,28 +74,20 @@ static void work_uart() {
#endif
if (cur == 13 || cur == '\n') {
new_power = atoi(data_in);
uint16_t new_power = atoi(data_in);
new_power = new_power <= POWER_MAX ? new_power : POWER_MAX;
diff = new_power > power ? new_power - power : power - new_power;
if(diff < MAX_ALLOWED_DEVIATION || fail_counter > MAX_FAILS) {
#ifdef UART_DEBUG
uart_puts_P("Transmitted power = ");
uart_print_uint16(power);
uart_puts_P("\r\n");
#endif
power = new_power;
fail_counter = 0;
set_servo(power);
#ifdef DEBUG_UART
uint16_t diff = new_power > power ? new_power - power : power - new_power;
if(diff > 50) {
uart_puts_P("WARNING! Deviation greater than 50! ");
}
else {
#ifdef UART_DEBUG
uart_puts_P("Oooooooops!!! Transmitted power = ");
uart_print_uint16(new_power);
uart_puts_P("\r\n");
uart_puts_P("Transmitted power = ");
uart_print_uint16(new_power);
uart_puts_P("\r\n");
#endif
fail_counter++;
}
power = new_power;
set_servo(power);
reset_input_buffer();
}
}