Sat, 10 Dec 2011 14:47:34 +0100
tuning: decreased solenoid switch time
53
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
1 | ISR ( TIMER1_COMPA_vect ) { |
69
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
2 | PORTC ^= _BV(PC0); // DEBUG OUTPUT SYSTEM CLOCK |
53
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
3 | |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
4 | // trigger packet transfer: |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
5 | 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
|
6 | transmit_len = transmit_len_next; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
7 | sysclk_packettimer = 0; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
8 | } else sysclk_packettimer++; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
9 | // 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
|
10 | |
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 ) { |
69
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
19 | uint8_t i; |
53
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
20 | //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
|
21 | // 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
|
22 | if (transmit_len >= 0xFE) { |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
23 | if (transmit_len != 0xFF) { |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
24 | 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
|
25 | transmit_len = 0xFF; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
26 | transmit_buffer = transmit_buffer_queue; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
27 | transmit_buffer_queue = 0; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
28 | transmit_len_next = transmit_len_queue; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
29 | |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
30 | // start the response receiver timer |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
31 | // 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
|
32 | // 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
|
33 | TCNT0 = TIMER0_250US; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
34 | timer0_delay = TIMER0_2300NS; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
35 | response = 0; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
36 | response_len = 0; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
37 | TIMSK |= _BV(TOIE0); |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
38 | |
69
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
39 | // 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
|
40 | TIMSK &= ~_BV(OCIE2); // temporarily disable timer2 interrupts |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
41 | responsewire_data = 0; |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
42 | // 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
|
43 | i = 100; |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
44 | 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
|
45 | i--; |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
46 | _delay_us(5); |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
47 | } |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
48 | if (i>0) { |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
49 | // response incoming! |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
50 | // start feew µs later |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
51 | _delay_us(5); |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
52 | for (i=16; i>0; i--) { // start receiving all 16 bits |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
53 | PORTC ^= _BV(PC1); // DEBUG |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
54 | responsewire_data = (responsewire_data << 1); // shift bits |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
55 | if ((PIN(RESPONSEWIRE_PORT) & _BV(RESPONSEWIRE_PIN)) == 0) // phsyical low == logic 1 |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
56 | responsewire_data |= 1; |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
57 | _delay_us(48); // get to next bit |
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 | itoa(responsewire_data, s, 16); |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
60 | RS232_puts("RW:"); |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
61 | RS232_puts(s); |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
62 | RS232_putc('\n'); |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
63 | } |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
64 | TIMSK |= _BV(OCIE2); //enable timer2 interrupt |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
65 | // end reading response wire |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
66 | |
27c0c0095e26
implemented responsewire in CU firmware
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
67 | |
53
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
68 | } |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
69 | } else { |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
70 | 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
|
71 | uint16_t clock; |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
72 | 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
|
73 | if ( ((transmit_buffer ^ clock) & bit) != 0 ) |
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); else |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
75 | RAIL_POWER_PORT &= ~_BV(RAIL_POWER); |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
76 | if ( (transmit_len & 0b10000000) == 0 ) { |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
77 | // block 0 |
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 = 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
|
79 | transmit_len |= 0b10000000; // set clock |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
80 | } else { |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
81 | // block 1, output the current bit |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
82 | transmit_len &= 0b01111111; // reset clock |
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--; // next bit |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
84 | 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
|
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 | |
f659e6faf18f
moved ISRs from main.c to interrupts.c
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
90 | ISR ( TIMER0_OVF_vect ) { |
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 | } |