Thu, 15 Dec 2011 17:58:22 +0100
betatest corrections
53
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
1 | ISR ( TIMER1_COMPA_vect ) { |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
2 | // trigger packet transfer: |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
3 | 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
|
4 | transmit_len = transmit_len_next; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
5 | sysclk_packettimer = 0; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
6 | } else sysclk_packettimer++; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
7 | // 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
|
8 | |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
9 | // reset both car counters to overflow |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
10 | car0_old = TIMER1_500NS; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
11 | car1_old = TIMER1_500NS; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
12 | |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
13 | sysclk.value++; // increment 500ns timer |
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 | |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
16 | ISR ( TIMER2_COMP_vect ) { |
69
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
17 | uint8_t i; |
53
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
18 | //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
|
19 | // 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
|
20 | if (transmit_len >= 0xFE) { |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
21 | if (transmit_len != 0xFF) { |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
22 | 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
|
23 | transmit_len = 0xFF; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
24 | transmit_buffer = transmit_buffer_queue; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
25 | transmit_buffer_queue = 0; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
26 | transmit_len_next = transmit_len_queue; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
27 | |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
28 | // start the response receiver timer |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
29 | // 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
|
30 | // 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
|
31 | TCNT0 = TIMER0_250US; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
32 | timer0_delay = TIMER0_2300NS; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
33 | response = 0; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
34 | response_len = 0; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
35 | TIMSK |= _BV(TOIE0); |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
36 | |
69
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
37 | // 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
|
38 | TIMSK &= ~_BV(OCIE2); // temporarily disable timer2 interrupts |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
39 | responsewire_data = 0; |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
40 | // 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
|
41 | i = 100; |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
42 | 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
|
43 | i--; |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
44 | _delay_us(5); |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
45 | } |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
46 | if (i>0) { |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
47 | // response incoming! |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
48 | // start feew µs later |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
49 | _delay_us(5); |
73
ec888cfa024e
bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents:
69
diff
changeset
|
50 | 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
|
51 | 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
|
52 | 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
|
53 | responsewire_data |= 0b1000000000000000; |
69
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
54 | _delay_us(48); // get to next bit |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
55 | } |
73
ec888cfa024e
bugfix: responsewire bitmap, todo: trackswitch response
Malte Bayer <mbayer@neo-soft.org>
parents:
69
diff
changeset
|
56 | // 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
|
57 | decode_responsewire(); |
69
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
58 | } |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
59 | TIMSK |= _BV(OCIE2); //enable timer2 interrupt |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
60 | // end reading response wire |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
61 | |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
62 | |
53
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
63 | } |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
64 | } else { |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
65 | 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
|
66 | uint16_t clock; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
67 | 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
|
68 | if ( ((transmit_buffer ^ clock) & bit) != 0 ) |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
69 | 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
|
70 | RAIL_POWER_PORT &= ~_BV(RAIL_POWER); |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
71 | if ( (transmit_len & 0b10000000) == 0 ) { |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
72 | // block 0 |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
73 | //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
|
74 | transmit_len |= 0b10000000; // set clock |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
75 | } else { |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
76 | // block 1, output the current bit |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
77 | transmit_len &= 0b01111111; // reset clock |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
78 | //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
|
79 | 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
|
80 | } |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
81 | } |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
82 | } |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
83 | |
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 | ISR ( TIMER0_OVF_vect ) { |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
86 | // 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
|
87 | TCNT0 = TIMER0_250US; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
88 | if (timer0_delay == 0) { |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
89 | 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
|
90 | _delay_us(28); // wait some cycles |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
91 | 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
|
92 | if (response == 0) { |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
93 | // 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
|
94 | TIMSK &= ~_BV(TOIE0); |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
95 | } else { |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
96 | // we received a bit (logic low) |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
97 | response = response << 1; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
98 | response_len++; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
99 | } |
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 | // okay, we have logic high |
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 |= 1; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
104 | response_len++; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
105 | } |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
106 | 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
|
107 | 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
|
108 | TIMSK &= ~_BV(TOIE0); |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
109 | } else { |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
110 | _delay_us(20); // wait some cycles |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
111 | 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
|
112 | } |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
113 | } 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
|
114 | } |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
115 | |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
116 | ISR (INT0_vect) { |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
117 | // car0 detector |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
118 | uint16_t tmp = 0; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
119 | car0_new = TCNT1; // get current counter |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
120 | if (car0_old < car0_new) { |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
121 | // calculate difference |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
122 | 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
|
123 | 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
|
124 | 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
|
125 | 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
|
126 | 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
|
127 | 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
|
128 | 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
|
129 | } |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
130 | car0_old = car0_new; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
131 | } |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
132 | |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
133 | ISR (INT1_vect) { |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
134 | // car1 detector |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
135 | uint16_t tmp = 0; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
136 | car1_new = TCNT1; // get current counter |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
137 | if (car1_old < car1_new) { |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
138 | // calculate difference |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
139 | 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
|
140 | 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
|
141 | 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
|
142 | 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
|
143 | 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
|
144 | 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
|
145 | 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
|
146 | } |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
147 | car1_old = car1_new; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
148 | } |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
149 | |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
150 | |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
151 | ISR (INT2_vect) { |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
152 | // Lap counter Interrupt |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
153 | // 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
|
154 | } |