track switch now only triggers when car speed >0

Wed, 30 Nov 2011 14:14:38 +0100

author
Malte Bayer <mbayer@neo-soft.org>
date
Wed, 30 Nov 2011 14:14:38 +0100
changeset 22
9af54a45ae42
parent 21
8b7cdb655e7b
child 23
6edcf4666e3b
child 28
d4235895fdbc

track switch now only triggers when car speed >0

trackswitch/main.c file | annotate | diff | comparison | revisions
--- a/trackswitch/main.c	Wed Nov 30 14:07:57 2011 +0100
+++ b/trackswitch/main.c	Wed Nov 30 14:14:38 2011 +0100
@@ -25,6 +25,8 @@
 #define SOLENOID_A_PIN  PB1
 #define SOLENOID_B_PIN  PB2
 
+// internal analog comparator doesnt work well
+//#define ANALOG_COMPARATOR       1
 
 volatile uint16_t data = 0;
 volatile uint8_t data_len = 0;
@@ -112,6 +114,7 @@
 }
 
 // ISR (TIMER1_CAPT_vect) {
+#ifdef ANALOG_COMPARATOR
 ISR (ANA_COMP_vect) {
     // car1 detector
     uint16_t tmp = 0;
@@ -126,7 +129,7 @@
     }
     car1_old = car1_new;
 }
-
+#else
 // ALTERNATIV:
 ISR (TIMER1_CAPT_vect) {
     // car1 detector
@@ -142,14 +145,13 @@
     }
     car1_old = car1_new;
 }
-
+#endif
 
 void solenoid_delay(void) {
     _delay_ms(10);
 }
 
 
-//#define ANALOG_COMPARATOR       1
 
 int main(void)
 {
@@ -198,9 +200,10 @@
 
         if (car0 != car0_state) {
             car0_state = car0;
-            if ( (car0_state != 0) && (car_switch[car0_state-1] == 0) ) {
+            if ( (car0_state != 0) && (car_switch[car0_state-1] == 0) && (car_speed[car0_state-1]>0) ) {
                 // trigger solenoid A
                 RS232_putc('A');
+                RS232_putc('B');
                 RS232_putc('0'+car0_state);
                 RS232_putc('\n');
 
@@ -209,14 +212,21 @@
                 SOLENOID_A_PORT &= ~_BV(SOLENOID_A_PIN);
                 solenoid_delay();
             }
+            if (car0_state != 0) {
+                RS232_putc('A');
+                RS232_putc('A');
+                RS232_putc('0'+car0_state);
+                RS232_putc('\n');
+            }
         } car0 = 0;
 
 
         if (car1 != car1_state) {
             car1_state = car1;
-            if ( (car1_state != 0) && (car_switch[car1_state-1] == 0) ) {
+            if ( (car1_state != 0) && (car_switch[car1_state-1] == 0) && (car_speed[car1_state-1]>0) ) {
                 // trigger solenoid A
                 RS232_putc('B');
+                RS232_putc('A');
                 RS232_putc('0'+car1_state);
                 RS232_putc('\n');
 
@@ -225,6 +235,12 @@
                 SOLENOID_B_PORT &= ~_BV(SOLENOID_B_PIN);
                 solenoid_delay();
             }
+            if (car1_state != 0) {
+                RS232_putc('B');
+                RS232_putc('B');
+                RS232_putc('0'+car1_state);
+                RS232_putc('\n');
+            }
         } car1 = 0;
 
 

mercurial