fixed shortcut detection

Sat, 03 Dec 2011 11:55:01 +0100

author
Malte Bayer <mbayer@neo-soft.org>
date
Sat, 03 Dec 2011 11:55:01 +0100
changeset 33
c261350bb394
parent 32
b83d239fe719
child 34
d12d095e3282

fixed shortcut detection

blackbox/Makefile file | annotate | diff | comparison | revisions
blackbox/lowlevel.c file | annotate | diff | comparison | revisions
blackbox/main.c file | annotate | diff | comparison | revisions
--- a/blackbox/Makefile	Sat Dec 03 11:11:06 2011 +0100
+++ b/blackbox/Makefile	Sat Dec 03 11:55:01 2011 +0100
@@ -1,6 +1,7 @@
 PRG=main
 
 MCU=atmega16
+#FUSES=-U lfuse:w:0x3f:m -U hfuse:w:0xd8:m
 FUSES=-U lfuse:w:0x2f:m -U hfuse:w:0xc8:m
 BOOTFUSES=-U lfuse:w:0xff:m -U hfuse:w:0xce:m
 
@@ -9,7 +10,7 @@
 
 F_CPU = 8000000
 
-BAUD=38400
+BAUD=57600
 ISP_BAUD = 115200
 
 #SRC = main.c seriald.c driver/ADC.c driver/clock.c driver/timer.c
--- a/blackbox/lowlevel.c	Sat Dec 03 11:11:06 2011 +0100
+++ b/blackbox/lowlevel.c	Sat Dec 03 11:55:01 2011 +0100
@@ -50,8 +50,6 @@
 
 
     RS232_init(); // initialize RS485 interface
-    RS232_puts_p(PSTR("CARRERA beta loading\n"));
-
     initADC();
     SFIOR = 0;
 
@@ -108,11 +106,14 @@
     OCR1A = TIMER1_7500NS;
     TIMSK |= 1<<OCIE1A; //enable timer1 interrupt
 
-    RS232_puts_p(PSTR("INIT OK\n"));
+    RS232_puts_p(PSTR("FreeSlot Blackbox v1.0\n"));
 
 }
 
 
+void blinkdelay(void) {
+   _delay_ms(100);
+}
 
 void check_rails_shortcut(void) {
     // check for short circuit on the rails
@@ -121,6 +122,7 @@
         while (i>0) {
             if ((PIN(RAIL_DETECT_PORT) & _BV(RAIL_DETECT)) != 0) return 0;
             _delay_us(20);
+            i--;
         }
         if ((PIN(RAIL_DETECT_PORT) & _BV(RAIL_DETECT)) == 0) {
             cli(); // disable ALL Interrupts
@@ -136,13 +138,13 @@
                 LED(2, 2);
                 LED(4, 2);
                 LED(5, 2);
-                _delay_ms(100);
+                blinkdelay();
                 LED(3, 2);
-                _delay_ms(100);
+                blinkdelay();
                 LED(3, 2);
-                _delay_ms(100);
+                blinkdelay();
                 LED(3, 2);
-                _delay_ms(100);
+                blinkdelay();
                 LED(3, 2);
             }
         }
--- a/blackbox/main.c	Sat Dec 03 11:11:06 2011 +0100
+++ b/blackbox/main.c	Sat Dec 03 11:55:01 2011 +0100
@@ -32,6 +32,7 @@
 volatile uint8_t  transmit_len_queue;
 
 volatile uint16_t response;
+volatile uint8_t response_len;
 volatile uint8_t timer0_delay;
 
 
@@ -195,6 +196,7 @@
             TCNT0 = TIMER0_250US;
             timer0_delay = TIMER0_2300NS;
             response = 0;
+            response_len = 0;
             TIMSK |= _BV(TOIE0);
 
         }
@@ -235,16 +237,21 @@
             } else {
                 // we received a bit (logic low)
                 response = response << 1;
+                response_len++;
             }
         } else {
             // okay, we have logic high
             response = response << 1;
             response |= 1;
-            //debug:
-            RS232_puts("ANSWER RX\n");
+            response_len++;
         }
-        _delay_us(20); // wait some cycles
-        RAIL_POWER_PORT |= _BV(RAIL_POWER); // restore rails power
+        if (response_len == 15) { // maximum response length reached
+            RAIL_POWER_PORT |= _BV(RAIL_POWER); // restore rails power
+            TIMSK &= ~_BV(TOIE0);
+        } else {
+            _delay_us(20); // wait some cycles
+            RAIL_POWER_PORT |= _BV(RAIL_POWER); // restore rails power
+        }
     } else timer0_delay--; // 2.3 ms delay not reached yet
 }
 
@@ -285,6 +292,15 @@
         // check for short circuit on the rails
         check_rails_shortcut();
 
+        if (response_len > 0) {
+            itoa(response, s, 2);
+            response_len = 0;
+            RS232_puts("ANSWER RX: ");
+            RS232_puts(s);
+            RS232_putc('\n');
+        }
+
+
         // read in button presses
         btn_start = (PIN(SW_START_PORT) & _BV(SW_START));
         if (old_start != btn_start) {

mercurial