From 2cc08730e3fd7a89b5888e117ef188eff7925a96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Tue, 3 Jun 2014 16:47:18 +0200 Subject: [PATCH] there is still a nasty fucking bug with OCR1A --- .../displayboard_servo/software/src/main.c | 28 +++++++++++-------- schaltungen/displayboard_servo/tester.py | 11 ++++---- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/schaltungen/displayboard_servo/software/src/main.c b/schaltungen/displayboard_servo/software/src/main.c index 82cdea9..653005c 100644 --- a/schaltungen/displayboard_servo/software/src/main.c +++ b/schaltungen/displayboard_servo/software/src/main.c @@ -58,7 +58,7 @@ static void work_uart() { reset_input_buffer(); } -#ifdef DEBUG +#ifdef DEBUG1 for(uint8_t i=0;i 1) { // \n + if (cur == 13) { // \n power = atol(data_in); if(power > POWER_MAX) power = POWER_MAX; @@ -76,10 +76,10 @@ static void work_uart() { uart_puts_P("power = "); uart_print_uint16(power); uart_puts_P("\r\n"); - #endif - - set_servo(power); + if(power > 0) { + set_servo(power); + } reset_input_buffer(); } @@ -113,13 +113,17 @@ void set_servo(uint16_t display) { // check if timer is currently in the small pulse, then sleep here 2ms // and do again - if(OCR1A < 2250) { - _delay_ms(2); + + + if(OCR1A <= 2250) { + _delay_ms(10); } - cli(); // read and write atomic - OCR1A = 2500-display; - sei(); + //cli(); // read and write atomic + TIMSK &= ~(_BV(OCIE1A)); + OCR1A = 2500-display; + //sei(); + TIMSK |= _BV(OCIE1A); } @@ -143,13 +147,13 @@ int main(void) { timer_init(); uart_init(UART_BAUD_SELECT(38400,F_CPU)); reset_input_buffer(); - demo_display(); + //demo_display(); while(1) { work_uart(); - if(syscounter >= 100) { + if(syscounter >= 10) { reset_input_buffer(); uart_putc('a'); // send a to receive values from master box syscounter = 0; diff --git a/schaltungen/displayboard_servo/tester.py b/schaltungen/displayboard_servo/tester.py index e877887..0a3420f 100755 --- a/schaltungen/displayboard_servo/tester.py +++ b/schaltungen/displayboard_servo/tester.py @@ -11,11 +11,10 @@ incdec = 0 while 1: tdata = ser.read() - time.sleep(1) if tdata == 'a': print power - ser.write(str(power) + '\n') + ser.write(str(power) + '\x0d') #ser.write('100\n') ser.flush() @@ -31,7 +30,7 @@ while 1: if power < 0: power = 0 incdec = 0 - else: - data_left = ser.inWaiting() - tdata += ser.read(data_left) - print tdata + #else: + #data_left = ser.inWaiting() + #tdata += ser.read(data_left) + #print tdata