blackbox/interrupts.c

Wed, 19 Dec 2012 20:16:42 +0100

author
Malte Bayer <mbayer@neo-soft.org>
date
Wed, 19 Dec 2012 20:16:42 +0100
changeset 131
fb998693e82c
parent 89
4b5b4c7ba03d
child 141
467e6351986e
permissions
-rw-r--r--

release prepare

53
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
1 ISR ( TIMER1_COMPA_vect ) {
89
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 73
diff changeset
2 if (mode==0xff) return; // panic mode, drop rest of routine
53
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
3 // trigger packet transfer:
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
4 if (sysclk_packettimer == 14) { // 15*500 = 7500 NS
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
5 transmit_len = transmit_len_next;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
6 sysclk_packettimer = 0;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
7 } else sysclk_packettimer++;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
8 // here is some more time to do something else...
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
9
89
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 73
diff changeset
10
53
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
11 // reset both car counters to overflow
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
12 car0_old = TIMER1_500NS;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
13 car1_old = TIMER1_500NS;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
14
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
15 sysclk.value++; // increment 500ns timer
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
16 }
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
17
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
18 ISR ( TIMER2_COMP_vect ) {
89
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 73
diff changeset
19 if (mode==0xff) return; // panic mode, drop rest of routine
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 73
diff changeset
20
69
27c0c0095e26 implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents: 56
diff changeset
21 uint8_t i;
53
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
22 //OCR2 = TIMER2_50US; // make sure that timer2 is 50µs !!!
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
23 // data packet timer 100µs pro bit...
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
24 if (transmit_len >= 0xFE) {
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
25 if (transmit_len != 0xFF) {
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
26 RAIL_POWER_PORT |= _BV(RAIL_POWER); // end of transmission
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
27 transmit_len = 0xFF;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
28 transmit_buffer = transmit_buffer_queue;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
29 transmit_buffer_queue = 0;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
30 transmit_len_next = transmit_len_queue;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
31
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
32 // start the response receiver timer
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
33 // TODO: only on 8 timeslots, not on every transmission
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
34 // TODO: give slot number to timer - then store the transmission to 8 slots array
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
35 TCNT0 = TIMER0_250US;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
36 timer0_delay = TIMER0_2300NS;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
37 response = 0;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
38 response_len = 0;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
39 TIMSK |= _BV(TOIE0);
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
40
69
27c0c0095e26 implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents: 56
diff changeset
41 // Try to read the stuff on the response wire
27c0c0095e26 implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents: 56
diff changeset
42 TIMSK &= ~_BV(OCIE2); // temporarily disable timer2 interrupts
27c0c0095e26 implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents: 56
diff changeset
43 responsewire_data = 0;
27c0c0095e26 implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents: 56
diff changeset
44 // wait a little and look if wire goes low
27c0c0095e26 implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents: 56
diff changeset
45 i = 100;
27c0c0095e26 implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents: 56
diff changeset
46 while ( ((PIN(RESPONSEWIRE_PORT) & _BV(RESPONSEWIRE_PIN)) != 0) && (i>0) ) {
27c0c0095e26 implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents: 56
diff changeset
47 i--;
27c0c0095e26 implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents: 56
diff changeset
48 _delay_us(5);
27c0c0095e26 implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents: 56
diff changeset
49 }
27c0c0095e26 implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents: 56
diff changeset
50 if (i>0) {
27c0c0095e26 implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents: 56
diff changeset
51 // response incoming!
27c0c0095e26 implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents: 56
diff changeset
52 // start feew µs later
27c0c0095e26 implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents: 56
diff changeset
53 _delay_us(5);
73
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
54 for (i=16; i>0; i--) { // start receiving all 16 bits -> shift them in same direction as they're shifted out
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
55 responsewire_data = (responsewire_data >> 1); // shift bits right, first received = bit0
69
27c0c0095e26 implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents: 56
diff changeset
56 if ((PIN(RESPONSEWIRE_PORT) & _BV(RESPONSEWIRE_PIN)) == 0) // phsyical low == logic 1
73
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
57 responsewire_data |= 0b1000000000000000;
69
27c0c0095e26 implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents: 56
diff changeset
58 _delay_us(48); // get to next bit
27c0c0095e26 implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents: 56
diff changeset
59 }
73
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
60 // we have some little time here to decode the response and do some action for refueling state of cars
ec888cfa024e bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents: 69
diff changeset
61 decode_responsewire();
69
27c0c0095e26 implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents: 56
diff changeset
62 }
27c0c0095e26 implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents: 56
diff changeset
63 TIMSK |= _BV(OCIE2); //enable timer2 interrupt
27c0c0095e26 implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents: 56
diff changeset
64 // end reading response wire
27c0c0095e26 implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents: 56
diff changeset
65
27c0c0095e26 implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents: 56
diff changeset
66
53
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
67 }
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
68 } else {
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
69 uint16_t bit = (1<<(transmit_len & 0b01111111));
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
70 uint16_t clock;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
71 if ((transmit_len & 0b10000000) == 0) clock = 0; else clock = 0xffff;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
72 if ( ((transmit_buffer ^ clock) & bit) != 0 )
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
73 RAIL_POWER_PORT |= _BV(RAIL_POWER); else
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
74 RAIL_POWER_PORT &= ~_BV(RAIL_POWER);
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
75 if ( (transmit_len & 0b10000000) == 0 ) {
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
76 // block 0
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
77 //if (transmit_len == 0) transmit_len = 0xFF; else transmit_len |= 0b10000000; // set clock
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
78 transmit_len |= 0b10000000; // set clock
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
79 } else {
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
80 // block 1, output the current bit
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
81 transmit_len &= 0b01111111; // reset clock
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
82 //if (transmit_len != 0) transmit_len--; // next bit
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
83 if (transmit_len == 0) transmit_len = 0xFE; else transmit_len--; // next bit
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
84 }
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
85 }
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
86 }
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
87
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
88
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
89 ISR ( TIMER0_OVF_vect ) {
89
4b5b4c7ba03d added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents: 73
diff changeset
90 if (mode==0xff) return; // panic mode, drop rest of routine
53
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
91 // TODO: last bit should be set by the sender, not from us!
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
92 TCNT0 = TIMER0_250US;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
93 if (timer0_delay == 0) {
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
94 RAIL_POWER_PORT &= ~_BV(RAIL_POWER); // pull rails low
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
95 _delay_us(28); // wait some cycles
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
96 if ((PIN(RAIL_DETECT_PORT) & _BV(RAIL_DETECT)) != 0) { // check for logic zero
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
97 if (response == 0) {
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
98 // there is no start bit, so stop the timer and cancel response receiving
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
99 TIMSK &= ~_BV(TOIE0);
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
100 } else {
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
101 // we received a bit (logic low)
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
102 response = response << 1;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
103 response_len++;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
104 }
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
105 } else {
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
106 // okay, we have logic high
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
107 response = response << 1;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
108 response |= 1;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
109 response_len++;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
110 }
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
111 if (response_len == 15) { // maximum response length reached
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
112 RAIL_POWER_PORT |= _BV(RAIL_POWER); // restore rails power
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
113 TIMSK &= ~_BV(TOIE0);
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
114 } else {
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
115 _delay_us(20); // wait some cycles
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
116 RAIL_POWER_PORT |= _BV(RAIL_POWER); // restore rails power
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
117 }
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
118 } else timer0_delay--; // 2.3 ms delay not reached yet
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
119 }
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
120
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
121 ISR (INT0_vect) {
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
122 // car0 detector
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
123 uint16_t tmp = 0;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
124 car0_new = TCNT1; // get current counter
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
125 if (car0_old < car0_new) {
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
126 // calculate difference
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
127 if (car0 == 0) tmp = car0_new-car0_old;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
128 if ( (tmp > 54) && (tmp < 74) ) car0 = 1;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
129 if ( (tmp > 118) && (tmp < 138) ) car0 = 2;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
130 if ( (tmp > 186) && (tmp < 206) ) car0 = 3;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
131 if ( (tmp > 246) && (tmp < 266) ) car0 = 4;
56
a20f59a3016c ui fix, added car5+6 detector to blackbox
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
132 if ( (tmp > 310) && (tmp < 330) ) car0 = 5;
a20f59a3016c ui fix, added car5+6 detector to blackbox
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
133 if ( (tmp > 374) && (tmp < 394) ) car0 = 6;
53
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
134 }
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
135 car0_old = car0_new;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
136 }
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
137
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
138 ISR (INT1_vect) {
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
139 // car1 detector
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
140 uint16_t tmp = 0;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
141 car1_new = TCNT1; // get current counter
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
142 if (car1_old < car1_new) {
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
143 // calculate difference
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
144 if (car1 == 0) tmp = car1_new-car1_old;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
145 if ( (tmp > 54) && (tmp < 74) ) car1 = 1;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
146 if ( (tmp > 118) && (tmp < 138) ) car1 = 2;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
147 if ( (tmp > 186) && (tmp < 206) ) car1 = 3;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
148 if ( (tmp > 246) && (tmp < 266) ) car1 = 4;
56
a20f59a3016c ui fix, added car5+6 detector to blackbox
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
149 if ( (tmp > 310) && (tmp < 330) ) car1 = 5;
a20f59a3016c ui fix, added car5+6 detector to blackbox
Malte Bayer <mbayer@neo-soft.org>
parents: 53
diff changeset
150 if ( (tmp > 374) && (tmp < 394) ) car1 = 6;
53
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
151 }
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
152 car1_old = car1_new;
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
153 }
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
154
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
155
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
156 ISR (INT2_vect) {
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
157 // Lap counter Interrupt
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
158 // do not know if this ever occurs ?! this is normally an output pin to trigger the counter start
f659e6faf18f moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff changeset
159 }

mercurial