meeting2 stuff

Fri, 18 Nov 2011 08:42:24 +0100

author
Malte Bayer <mbayer@neo-soft.org>
date
Fri, 18 Nov 2011 08:42:24 +0100
changeset 10
6d6e982bbc41
parent 9
20dbe0546a36
child 11
69c2a1408619

meeting2 stuff

blackbox/lowlevel.c file | annotate | diff | comparison | revisions
blackbox/main.c file | annotate | diff | comparison | revisions
receiver/main.c file | annotate | diff | comparison | revisions
--- a/blackbox/lowlevel.c	Wed Nov 16 17:04:10 2011 +0100
+++ b/blackbox/lowlevel.c	Fri Nov 18 08:42:24 2011 +0100
@@ -116,8 +116,12 @@
 
 void check_rails_shortcut(void) {
     // check for short circuit on the rails
+    uint8_t i = 100;
     if ((PIN(RAIL_DETECT_PORT) & _BV(RAIL_DETECT)) == 0) {
-        _delay_ms(2);
+        while (i>0) {
+            if ((PIN(RAIL_DETECT_PORT) & _BV(RAIL_DETECT)) != 0) return 0;
+            _delay_us(20);
+        }
         if ((PIN(RAIL_DETECT_PORT) & _BV(RAIL_DETECT)) == 0) {
             cli(); // disable ALL Interrupts
             RAIL_POWER_PORT &= ~_BV(RAIL_POWER); // disable rails power
--- a/blackbox/main.c	Wed Nov 16 17:04:10 2011 +0100
+++ b/blackbox/main.c	Fri Nov 18 08:42:24 2011 +0100
@@ -54,7 +54,11 @@
                     if (program_count == 0) {
                         program_id = buffer[3]-'0';
                         program_command = buffer[1]-'0';
+                        if (program_command > 9)
+                            program_command = buffer[1]-'A'+10;
                         program_parameter = buffer[2]-'0';
+                        if (program_parameter > 9)
+                            program_parameter = buffer[2]-'A'+10;
                         if (program_command < 4)
                             program_count = 0x02; // send commands twice (fuel, speed, brake)
                             else
@@ -91,19 +95,31 @@
     switch (controller) {
         case 0:
             tmp = ((getADC(CONTROLLER1_SPEED) / CONTROLLER_DIVISOR) & 0x0F) << 1;
-            if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER1_SW)) != 0) tmp |= (1<<5);
+            if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER1_SW)) != 0) {
+                tmp |= (1<<5);
+                LED(1,0);
+            } else LED(1,1);
             break;
         case 1:
             tmp = ((getADC(CONTROLLER2_SPEED) / CONTROLLER_DIVISOR) & 0x0F) << 1;
-            if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER2_SW)) != 0) tmp |= (1<<5);
+            if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER2_SW)) != 0) {
+                tmp |= (1<<5);
+                LED(2,0);
+            } else LED(2,1);
             break;
         case 2:
             tmp = ((getADC(CONTROLLER3_SPEED) / CONTROLLER_DIVISOR) & 0x0F) << 1;
-            if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER3_SW)) != 0) tmp |= (1<<5);
+            if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER3_SW)) != 0) {
+                tmp |= (1<<5);
+                LED(3,0);
+            } else LED(3,1);
             break;
         case 3:
             tmp = ((getADC(CONTROLLER4_SPEED) / CONTROLLER_DIVISOR) & 0x0F) << 1;
-            if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER4_SW)) != 0) tmp |= (1<<5);
+            if ( (PIN(CONTROLLER_PORT) & _BV(CONTROLLER4_SW)) != 0) {
+                tmp |= (1<<5);
+                LED(4,0);
+            } else LED(4,1);
             break;
         case 4: tmp = (1<<5); break; // todo regler 5
         case 5: tmp = (1<<5); break; // todo regler 6
@@ -157,7 +173,7 @@
 ISR ( TIMER1_COMPA_vect ) {
     // trigger packet transfer:
     transmit_len = transmit_len_next;
-    LED(2,2);
+    //LED(2,2);
 
     // here is some more time to do something else...
 }
@@ -201,14 +217,14 @@
         }
     }
 
-    LED(3,2);
+    //LED(3,2);
 }
 
 
 ISR ( TIMER0_OVF_vect ) {
 // TODO: last bit should be set by the sender, not from us!
     TCNT0 = TIMER0_250US;
-    LED(1,2);
+    //LED(1,2);
     if (timer0_delay == 0) {
         RAIL_POWER_PORT &= ~_BV(RAIL_POWER); // pull rails low
         _delay_us(28); // wait some cycles
@@ -283,6 +299,7 @@
                     program_parameter = 9;
                     program_id = 0;
                     program_count = 1;
+                    LAP_COUNTER_PORT |= _BV(LAP_COUNTER);
                 } else {
                     // do a reset, switch back to free drive mode 0
                     mode = 0;
@@ -291,6 +308,7 @@
                     program_parameter = 0;
                     program_id = 7;
                     program_count = 1;
+                    LAP_COUNTER_PORT &= ~_BV(LAP_COUNTER);
                 }
             }
             //LAP_COUNTER_PORT |= _BV(LAP_COUNTER);
--- a/receiver/main.c	Wed Nov 16 17:04:10 2011 +0100
+++ b/receiver/main.c	Fri Nov 18 08:42:24 2011 +0100
@@ -129,11 +129,11 @@
     SREG = sr;
 }
 
-volatile uint8_t pulse_counter = 0;
+volatile uint16_t pulse_counter = 0;
 volatile uint8_t measure_progress = 0;
-volatile uint8_t car_id = 0;
+volatile uint16_t car_id = 0;
 ISR(TIMER2_OVF_vect) {
-    //TCNT2 = 0x90;
+    TCNT2 = 0xF5;
     pulse_counter++;
 }
 
@@ -142,6 +142,7 @@
     //RS232_putc('x');
     if (measure_progress == 0) {
         // start measuring
+        TCNT2 = 0xF5;
         pulse_counter = 0;
         measure_progress = 1;
         // set INT1 to rising edge (stops current measurement)
@@ -179,20 +180,18 @@
     TIMSK = 1<<TOIE2;
 
     // configure INT0+1 for falling edge
-    MCUCR = _BV(ISC00) | _BV(ISC11);
-//    GICR = _BV(INT0) | _BV(INT1) ; // Enable INT0/2
-    GICR = _BV(INT1) ; // Enable INT0/2
+    // INT2 on every edge
+    //MCUCR = _BV(ISC00)  | _BV(ISC11);
+    MCUCR = _BV(ISC11);
+//    GICR = _BV(INT0) | _BV(INT1) ; // Enable INT0/1
+    GICR = _BV(INT1) ; // Enable INT1
 
     writeBit(DDRD, 4, 1);
 
 
-    RS232_init(); // initialize RS485 interface
+    RS232_init(); // initialize RS232 interface
     RS232_puts_p(PSTR("INIT OK\n"));
 
-    itoa (TIMER_100US, s, 10);
-    RS232_puts(s);
-
-    RS232_puts_p(PSTR(" timer\n"));
     i = 0;
     
     sei();

mercurial