# HG changeset patch # User Malte Bayer # Date 1322658878 -3600 # Node ID 9af54a45ae4226156aad43b04a34393fb0b810ae # Parent 8b7cdb655e7b4dfb11d904a3b369a963a01234ae track switch now only triggers when car speed >0 diff -r 8b7cdb655e7b -r 9af54a45ae42 trackswitch/main.c --- 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;