--- a/blackbox/main.c Wed Dec 07 15:56:05 2011 +0100 +++ b/blackbox/main.c Wed Dec 07 16:50:51 2011 +0100 @@ -30,6 +30,10 @@ #define MAX_SLOTS 6 +volatile uint16_t sysclk_ms_low = 0; +volatile uint16_t sysclk_ms_high = 0; +volatile uint8_t sysclk_packettimer = 0; + volatile uint8_t speedlimit[MAX_SLOTS]; volatile uint8_t fuel[MAX_SLOTS]; volatile uint8_t jumpstart_time[MAX_SLOTS]; @@ -134,8 +138,7 @@ void jumpstart(uint8_t controller) { if (jumpstart_time[controller] == 0) { - jumpstart_time[controller] = 1; - // todo: later the timestamp should written instead of just "1" + jumpstart_time[controller] = sysclk_ms_low; RS232_putc('~'); RS232_putc('0'-controller); RS232_putc('\n'); @@ -238,14 +241,21 @@ } ISR ( TIMER1_COMPA_vect ) { + //PORTC ^= _BV(PC0); // DEBUG OUTPUT SYSTEM CLOCK + // trigger packet transfer: - transmit_len = transmit_len_next; + if (sysclk_packettimer == 14) { // 15*500 = 7500 NS + transmit_len = transmit_len_next; + sysclk_packettimer = 0; + } else sysclk_packettimer++; // here is some more time to do something else... // reset both car counters to overflow - car0_old = TIMER1_7500NS; - car1_old = TIMER1_7500NS; + car0_old = TIMER1_500NS; + car1_old = TIMER1_500NS; + sysclk_ms_low++; // increment 500ns timer + if (sysclk_ms_low == 0) sysclk_ms_high++; // increment upper 16bits } ISR ( TIMER2_COMP_vect ) { @@ -360,7 +370,7 @@ void reset_vars(void) { uint8_t i; for (i=0; i<MAX_SLOTS; i++) { - speedlimit[i] = 15; + if (i<4) speedlimit[i] = 15; else speedlimit[i] = 0; fuel[i] = 100; jumpstart_time[i] = 0; } @@ -381,6 +391,8 @@ case 2: LED(4, 1); break; case 1: LED(5, 1); break; case 0: { // RACE START! + sysclk_ms_low = 1; + sysclk_ms_high = 0; LEDS_OFF(); LED(3, 1); mode = 3; @@ -459,6 +471,8 @@ RS232_puts_p(prepare); } else if (mode == 1) { // Initiate race countdown + sysclk_ms_low = 1; + sysclk_ms_high = 0; countdown = 5; countdown_loops = COUNTDOWN_DELAY; mode = 2;