# HG changeset patch # User Malte Bayer # Date 1321602144 -3600 # Node ID 6d6e982bbc416ede9d7f58248725a7084fa70ccf # Parent 20dbe0546a36156b4a89222fba18eb32eb33929a meeting2 stuff diff -r 20dbe0546a36 -r 6d6e982bbc41 blackbox/lowlevel.c --- 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 diff -r 20dbe0546a36 -r 6d6e982bbc41 blackbox/main.c --- 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); diff -r 20dbe0546a36 -r 6d6e982bbc41 receiver/main.c --- 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<